Testing and release
Run from the repository root:
pnpm install
pnpm run typecheck
pnpm run test
pnpm run build
pnpm --dir docs run build
Node.js 22 or later is required. Do not treat a successful build as sufficient for changes involving persistence, agent sequencing, or browser UI.
Test by risk
| Change | Minimum additional verification |
|---|---|
| Canonical model or world format | parser problems, round-trip fixtures, session population, authoring tools |
| SQLite schema | fresh database, migration from prior schema, snapshot/restore, branch |
| Record wire format | JSON Schema, parser, atomic application, read-back, keeper verification |
| Recall | character isolation, no-vector fallback, vector invalidation, story-time fading |
| Orchestration | protocol order, retries, cancellation, stable child prefix, background settling |
| DSH integration | contract test, hot reload, chat open/reopen, archive/delete |
| Browser UI | typecheck, production build, and live verification in a dedicated profile |
| Documentation | English and Chinese production builds with broken links treated as errors |
tests/support/architecture.spec.ts in the core package and tests/architecture.spec.ts in the state package read the source imports and fail on a broken layering: shared code imports only itself and the model; the browser half never imports host code, Node or the state package; the host never imports the browser half; packages are used only through their root exports; SQLite is reached through the driver alone; the tools, records and memory never see the driver; the model package imports nothing but itself. When a new rule is wanted, add it there rather than describing it.
Two cross-cutting tests guard what no single feature test would notice. tests/host/prompts/rules-coverage.spec.ts lists, for each rule that prompts of a kind must carry (work only from what is given; write in the language the chat's prompts name), the prompts that carry it and, with a reason, every one that need not, in each shipped language; a prompt added later is in neither list and fails until someone decides. A loop test reads every request a character was sent and fails on a key or on the number of a turn or round: the story has names and times, the numbers belong to the code.
Use deterministic fakes for agent-loop tests. Assert tool calls and state transitions, not model prose. Concurrency tests should force overlapping turns/jobs and verify serialization, cancellation, and cleanup. Failure tests must confirm that a partially completed operation either rolls back or remains explicitly resumable.
Quality gate
Pull requests and pushes to main run type-checking, the tests with coverage, the release build and the release check, then a SonarQube analysis whose quality gate must pass. Publishing waits for both. Run the same coverage locally:
pnpm test:coverage
Each package writes packages/<name>/coverage/lcov.info; scripts/merge-coverage.mjs joins them into coverage/lcov.info with paths relative to the repository root, which is what sonar-project.properties reads. Every source file of a package is listed, so a file no test loads counts as uncovered rather than missing. Tests, built output, starter worlds, shipped packs and configuration files are left out of the analysis or the coverage figures. The scan needs the SONAR_TOKEN repository secret and does not run for pull requests from forks. Fix what the gate reports instead of excluding the file; add an exclusion only for code that cannot be run by a test, and say why in the pull request.
Live evaluation
Scripted-model tests cannot show what a real model does with the prompts. eval/ plays scenarios (look around and talk, walk through an exit, try something the world's rules forbid, wait for hours, say something a character must remember) into a running dev DSH with the model you want to judge, then checks the story's database, the chat log and the helpers' record. Use a throwaway roleplay root, never your own:
node eval/run.mjs "<dsh url with token>" --label qwen-35b
node eval/run.mjs "<dsh url with token>" --label qwen-35b-2 --baseline eval/results/qwen-35b.json
Scenarios that a model plays (soak: it pursues a goal in its own words for a few turns, and the story must stay sound) need a model for the player, any OpenAI-compatible endpoint, and are skipped without one:
node eval/run.mjs "<dsh url with token>" --only soak --player-model <name> [--player-url http://localhost:8081/v1] [--player-key-env VAR] [--player-reasoning none|omit|low|high]
The player is bounded on every side: at most --player-turns turns (default 6, never above 30), --player-tokens tokens spent by the player's own model (default 30000), --player-minutes of wall time (default 40) and none that would pass it by the typical turn time; one reply is at most 160 tokens and an action 300 characters; it is sent only the latest narration and its last five actions, never the whole story. It stops when it says it is done, repeats itself, is given nothing to read twice, writes something that is not an action (a / command), or a turn fails or ends without delivering anything, and the report says which (stop: done, turns, tokens, time, stuck, invalid, failed). eval/player.test.mjs tests these limits against a stub (node --test eval/player.test.mjs).
A finished story can also be audited afterwards, read-only: node eval/audit.mjs <session folder> --url <openai base url> --model <name> [--scope story|character:<name>|turn:<n>] [--out report.json]. A judge model reads the story's records (for a character, only what it took part in or perceived) and names errors from eval/audit-criteria.json (contradiction, fabrication, timeline, knowledge leak, memory lapse, persona drift, speaking for the player, repetition), each with the record it rests on. Every dimension starts at 100 and the script, not the model, subtracts the penalty of each valid error; an error with no record number or not on the list is not counted, and when the records cannot show a dimension the judge abstains and the score is null. The criteria list errors only, never a model answer, and are an editable file; narrative quality is not scored. eval/audit.test.mjs tests the scoring and evidence against a stub.
A report is written to eval/results/<label>.json. With --baseline the run says which scenarios got more than twice as slow and which checks passed before and fail now, and exits non-zero. Scenarios are small files in eval/scenarios/; add one when a live session finds a bug.
The check benchmark
The world checks have a labelled benchmark in packages/dsh-agentic-roleplay-core/tests/benchmark/. Its base is Salt Harbor, an invented harbor town written in English and in Chinese with the same structure, that uses every part of the world format: a cast with sheets, voices, feelings, goals, relationships, knowledge and routines; places with features and ways of every state, and a lock; things of every kind, hidden, locked, worn and in containers; organisations with members and goals; background of both scopes with dates and links; tracked values of every kind and subject; triggers of the main condition and effect types; dice, a plot, a calendar, rules, prompts and openings. Each case is the base with one defect planted (or none, or an ambiguous pair that is not a defect) and names the findings the checks must make and nothing else.
- Always run (
pnpm test):coverage.spec.tsstarts a story from the base world in both languages and asserts that every part of it reached the story, by feature, so a part that stops arriving is named.cases.spec.tsruns the cases the program decides, the consistency, quality, first-scene and card-comparison checks, in both languages, with the exact findings expected. - Live, against the development machine's models, scored for precision, recall, false alarms, retries, fallbacks and time:
BENCH_LIVE=1 BENCH_LABEL=<name> BENCH_MODE=llm|decision|hybrid npx vitest run tests/benchmark/live.spec.tsruns the cases a model judges (meaning-level duplicates of values and names, contradictory background, thin sheets, flat openings, gaps, and the comparison with the card, including a paraphrase and a translation that must not be flagged). The result is written toeval/results/checks-<label>.json.BENCH_ONLY,BENCH_LANGSandBENCH_REPEATnarrow or repeat it; run a case several times before trusting a difference, because a model's answer is chance per call. - Tracked values:
tests/benchmark/variable-cases.tsholds 23 labelled turns of a small story in both languages (a number, a flag and a choice value; changes to several values and to several people at once; turns that only mention, remember, fear or do something to somebody else, which must change nothing), andvariables-harness.tsruns the product's tracker on each at planted starting values.variables-cases.spec.tsalways runs and checks the cases with a model that knows the answers. Live:BENCH_LIVE=1 BENCH_LABEL=<name> BENCH_MODE=llm|decision|hybrid npx vitest run tests/benchmark/variables.spec.tswriteseval/results/variables-<label>.jsonwith precision and recall of which values changed, the share of new values that are right, refused edits and a breakdown by kind of value. A change the case does not ask for but that can be argued is counted apart (tolerated).BENCH_TRACE=1keeps what each model was asked and answered, including the decision model's probabilities. - Picture reuse:
reuse-cases.tsholds 12 moments in both languages, each with two to four stored pictures that were close by words (the one that shows the moment, if any, and near misses: another hour, other people, a different state of the same place).BENCH_LIVE=1 BENCH_LABEL=<name> BENCH_THRESHOLD=<cut> npx vitest run tests/benchmark/reuse.spec.tsputs them to the decision model with the shipped question and counts picks, wrong first picks (the product shows the first accepted picture) and misses. - Status panels:
panel-cards.tsholds invented cards in both languages that carry their state the way community cards do: a bar in a fenced block, a block of markup, a layout of nested tags of the card's own invention (names in the card's language, fill-in placeholders, contact message blocks, options, scripts that draw it, a second entry about how its messages are written) and a state-tracking framework (starting values and an update block). Nothing in them is taken from a real card.panels-cases.spec.tsruns in the normal suite and scores the deterministic parts with an oracle of its own: no panel in the opening or the pieces the entities are made from, the panels handed to the variable job, the print-this entries cleaned, a game master that imitates the opening sent back and then cut, and its story and utterances kept.BENCH_LIVE=1 BENCH_LABEL=<name> npx vitest run tests/benchmark/panels.spec.tsimports each card with real models through survey, build and finish and fails on any bar, block of tags, placeholder, update call or print-this sentence in the world, on aquality-panelsfinding, or on no variable at all (the shortfall is in the summary); the result goes toeval/results/panels-<label>.json.cases.tshasquality-panelsdefects in both languages. - Framework (data-driven):
tests/benchmark/framework/reads everything it runs from files undertests/benchmark/data: base worlds (worlds/<id>/<language>/world, a world folder in the product's format, plusbench.jsonwith theme and languages), layers (layers/<id>.json:requires,conflicts,fits, andremove/add/patchoperations, the patch being an RFC 7386 merge patch), rows (rows/*.json: world, language, layers, cast, the features the composed world must have, why, optional script and probe) andexcluded.json(combinations left out on purpose, with the reason).data.spec.tsfails on an unknown layer, a missing requirement or conflict, a layer outside its theme that is not declared a probe, a claim about features or cast size that the composed world does not bear out, or a composed world that fails the program's own checks; its coverage report lists each feature seen in fewer than two themes or one language, and the cast tiers a theme lacks. Adding a world, layer or row needs no code change. Salt Harbor is the first base world: a full row, a solo row (one character the story can ask) and a small row (three) in each language, made with layers that remove characters and everything that referred to them.rows.spec.tsstarts each row as a real story and checks who plays, how many others the story can ask, and that each claimed feature reaches the story while no unclaimed one does. A row can name a script (data/scripts/<id>.json): the player's turns in the language the chat is played in, each with expectations from a closed list, and a step can also regenerate the last turn or take the story back to an earlier one (/ooc,/waitand/rollare written as the player would). On one turn's narration: no panel, the right language, holds or lacks a text, a character speaks, the player's character is given no words. On the whole story: how many turns, a character exists and is placed, a tracked value the player may read has changed or shows a text, a trigger has fired, a character stands in a place, a character holds a thing, the world author has made up new people, no sentence is delivered twice. An expectation the run could not observe is reported as not judged, never as held. A step can also wait for real minutes with nobody writing, for a story that goes on without its player. More expectations read a message a character left, the opening, a story setting, the interface pack in use and the files in a folder. A row can give the story folders for its file tools (a script names them by{workspace},{folder:<name>}and{outside}) and the start dialog's answers to the world's start questions. The results report each kind of expectation by language and theme, never averaged, and list expectations that held in some repeats and failed in others. A row can also carry chat settings (which tests, for example, a world told in the other language, the real clock, or the output gates) and a planted fault: a layer that adds a style prompt demanding a status bar, or the world's secret, with the program's own check expected to flag the world. Its result is reported apart as caught or defended and left out of the score. Worlds derived from scenarios exist too: an assistant that builds a web page with real file tools on scratch folders (scored by the files it leaves), companion stories about characters from public-domain works, written so that what the characters know comes from the world and not from the model's memory of the books, and a fair whose crowd the story has to make up. Five genre worlds exist: Salt Harbor (mystery, English and a Chinese translation), Noodle Street (daily life, written in Chinese), Ashen Road (fantasy, written in English), Qingshi Town (a wuxia fantasy, written in Chinese) and Pemberton's Bakery (daily life, written in English), so that each theme is seen in both languages except mystery.BENCH_LIVE=1 BENCH_URL=<DSH url with token> BENCH_ROOT=<the throwaway root> npx vitest run tests/benchmark/rows-live.spec.tsplays the scripted rows as real stories against a running DSH (BENCH_ROWSpicks rows,BENCH_REPEATrepeats), writes a trace per run with the game master's chat log beside it and onehelperevent for each helper the story started (characters, record keeper, authors, suggester: its instructions, brief, every step and call, how it ended, and a problem when it ended badly or never handed back a result; the raw logs are kept in a folder beside the trace), and puts the scores, by row and language, ineval/results/rows-<label>.json. - Traces: every live benchmark case writes a trace (
<out>/traces/<label>/<language>-<case>-<run>.jsonl, one JSON event a line) as it runs, so a failure that cannot be repeated is on disk the first time it appears. It holds the models and sampling used, every request sent whole (never keys), every raw answer with its time, each answer a job's own check refused with the reason, the answer it accepted, named snapshots of the state the scorer reads (the card, classification, extracted entities, the world's texts, a tracked-value case's setup and tracker report) and one entry per expectation with whether it held and what was found.BENCH_TRACE=0turns it off andBENCH_TRACE_DIRmoves it. A recorded run can be scored again without a model:BENCH_REPLAY_DIR=<folder> npx vitest run tests/benchmark/panels-replay.spec.tsruns each recorded panel import with the model answering from its recording and requires the verdicts to be those of the live run, which also shows that the oracle and the importer still catch what they caught.trace.spec.tschecks the writing, the secrecy of keys, the completeness check and the replay with a stub model. - Traces in Langfuse: with the AI providers plugin's observability on (settings, or
traceEnabled,traceSinkandlangfuseHostin its patch row), a live run's models, turns and helpers are also recorded as nested traces; setBENCH_LANGFUSE_HOST,BENCH_LANGFUSE_PUBLIC_KEYandBENCH_LANGFUSE_SECRET_KEYand each row's verdicts are written as scores (bench.row,bench.<kind>) on the story's session, so a failed expectation is found beside the requests that led to it. Keys go in the environment or the credential store, never in a file of the repository. - Voice judge:
BENCH_LIVE=1 npx vitest run tests/benchmark/voice.spec.tsputs 24 lines in each language (6 invented characters with a speech style, lines that fit and lines that break it in register, tone or manner) to the decision model, one yes-or-no each, and scores them against the labels (BENCH_DECISION_URL,BENCH_DECISION_MODEL,BENCH_THRESHOLD). Thespeaks-in-voiceexpectation of a script uses the same question for the lines a character spoke in a story: it needsBENCH_DECISION_URLin the live row run and is not judged without it. Kev-9B at the cut 0.5 separated all 96 lines (two runs); the misfits are blatant, so the result says the judge works, not that it sees small drifts. - Reranker trial:
BENCH_LIVE=1 npx vitest run tests/benchmark/rerank.spec.tsranks every pair of three labelled sets (values, things, background) by embedding closeness and by a reranker, and counts how many of the real pairs land among the twelve a check asks a model about.
Do not tune a threshold from an unlabelled collection of worlds: add a case here first.
Persisted compatibility
Never edit an existing migration after release. Add a new ordered migration and keep row mapping tolerant only where the schema explicitly permits it. Opening a session that is behind the latest schema first checks its integrity and keeps a copy of it as it was in migration-backups/schema-<version>.sqlite beside the database; a migration that damages data can be undone by putting that copy back as session.sqlite. Keep world files human-editable and report all validation problems in one pass. Stable ids and media paths must not be silently rewritten.
Release review
Before publishing:
- inspect generated JavaScript and declarations for private-package imports;
- confirm bundle dependencies and
cordis.patch.ymlinclude every required plugin once conceptually; - check package files include prompts, client output, and public entry points;
- verify English and Chinese prompt sets have identical names and variables;
- test without each optional AI capability;
- check configuration is represented by Schemastery and documented;
- update both documentation locales and user-visible release notes;
- review
git difffor generated caches, local profiles, test worlds, credentials, and other machine-specific files.
Use a dedicated development profile and disposable session/world fixtures. Never validate by modifying a user's normal DSH profile.