Validation and Testing - ItsChrisOfficial/perchance-bot-workshop GitHub Wiki
This repository enforces import safety through automated validation. Every export must pass these checks before it is considered finished.
Validates a single Perchance export JSON against import-safety requirements:
node scripts/validate-perchance-export.js /absolute/path/to/export.json- Fails with actionable error messages describing what's wrong and how to fix it
- Returns non-zero exit code on failure
- Must be run with an absolute path to the export file
Runs the Python unittest suite that exercises the validator against known-good and known-bad fixtures:
python -m unittest tests/test-validate-perchance-export.pyNo bot can be promoted to completed unless both commands succeed.
The export validator (scripts/validate-perchance-export.js) performs these checks:
- File parses as valid JSON
- Root has
formatName,formatVersion, anddata formatName === "dexie"formatVersion === 1data.databaseName === "chatbot-ui-v1"data.databaseVersion === 90-
data.tablesis an array -
data.datais an array
- All 9 canonical tables are present
- Every table has a matching
data.dataentry - Every
rowsvalue is an array - Every
rowCountmatchesrows.length
-
characterstable contains the expected character rows -
nameexists and is a string -
roleInstructionexists and is a string -
customCodeexists and is a string -
initialMessagesis an array -
shortcutButtonsis an array
- Every seeded message has string
content - Every seeded message has valid
author("user","ai", or"system") - Every
hiddenFromis an array if present - Every
expectsReplyis boolean or omitted
- Every shortcut is an object
-
nameis a string -
messageis a string -
insertionTypeis"replace","prepend", or"append" -
autoSendandclearAfterSendare booleans
-
customCodeis a string type - Extracted
customCodepasses JavaScript syntax validation
The test suite uses fixtures in tests/fixtures/:
-
canonical-valid.json— a known-good minimal export
Each fixture is intentionally broken for one specific reason:
| Fixture file | What it tests |
|---|---|
broken-json.json |
JSON parse failure |
missing-table.json |
Incomplete canonical table set |
rowcount-mismatch.json |
rowCount / rows.length inconsistency |
invalid-message-author.json |
Invalid author enum value in seeded message |
invalid-shortcut-insertion-type.json |
Invalid insertionType enum value in shortcut button |
malformed-customcode.json |
JavaScript syntax failure in customCode
|
customcode-not-string.json |
customCode stored as non-string type |
The repository includes a CI workflow at .github/workflows/ci.yml that runs validation checks automatically on pushes and pull requests.
Run the validator frequently as you build your bot:
# Validate your export
node scripts/validate-perchance-export.js "$(pwd)/bots/in-progress/my-bot/my-bot-v0.1.0.json"Run the full validation suite:
# 1. Validate the specific export
node scripts/validate-perchance-export.js "$(pwd)/bots/in-progress/my-bot/my-bot-v1.0.0.json"
# 2. Run the test suite
python -m unittest tests/test-validate-perchance-export.py
# 3. Apply the PERCHANCE_IMPORT_VERIFICATION.md checklist manuallyDocument validation evidence in the bot's RELEASE.md:
## Verification evidence
- [x] `node scripts/validate-perchance-export.js <path>` passed
- [x] `python -m unittest tests/test-validate-perchance-export.py` passed
- [x] `docs/PERCHANCE_IMPORT_VERIFICATION.md` checklist applied| Error | Likely cause | Fix |
|---|---|---|
| JSON parse error | Malformed JSON (trailing commas, unescaped chars) | Use a JSON linter/formatter |
| Missing table | Not all 9 canonical tables included | Start from a template that includes all tables |
| rowCount mismatch | Added/removed rows without updating table metadata | Ensure rowCount matches rows.length
|
| Invalid author | Message uses author other than user/ai/system
|
Fix the author field |
| Invalid insertionType | Button uses type other than replace/prepend/append
|
Fix the insertionType field |
| customCode not a string |
customCode stored as object, number, or null |
Ensure it's a string value |
| JS syntax error |
customCode has unterminated string, missing bracket, etc. |
Syntax-check your JavaScript separately |