the 2026-11-16 rounds, the whole day in one commit: model discovery (the two-step op act -- discover scrapes the provider metadata, refine runs the deterministic battery over every id and hands the adjudicated results to the best passing model for the curated registry; state/models.json is the truth of selectable models and gates all model use, a fresh deployment has none; the five named sampling knobs ride run.json params over server.json params, sent only when set; the curator call retries once on the host's network hiccups, its output strictly validated with the machine-list fallback, and the do-not-deliberate line keeps its thinking tokens down); the pick rule reworked on the GM's rulings -- the dv endpoint's 5.2/5.3-max flip was an alias (one model behind both ids), the rank keys on the reasoning bucket not the raw token count (within-bucket differences are sampling noise, the thresholds sit in the endpoint's observed gaps) and full ties settle sort-lex-pick-bottom, with the mock registry carrying a canned tie pair (mock/mock-tie) and the smoke asserting the lex-bottom pick; the play-protocol batch (OOC GM turns carry no cache blocks, memory.json is authored draft applied by the start gate's reapply over a fresh db, /story filters OOC whole, the per-turn raw control on the table); the tunables UX round (web/knobs.mjs: the definitions table with the GM's hint texts and the probed this-endpoint bounds, the per-knob explicit override toggle replacing implicit empty-means-unset diffing, the shared focus-driven hint bar; the run detail and /model responses carry paramDefaults, the deployment layer -- the only default anyone can honestly name); request recording (every provider call lands its resolved model + effective params on the msg event as via, a failed call lands a req event with the failure, both surface on the raw tab and the per-turn raw control on no model-facing surface, a req riding the slidwin tail passes the start lint as conversation machinery; the housekeeping pass log names its model via the clerk's --model flag); the mind verb (<mind> JSON in a player turn sets its sampling for its next turn -- one-shot, max_tokens excluded, a budget not a mind; bounds enforced in KNOB_BOUNDS with the range named in the conflict and the heal restatement the statement that counts; derive() makes a statement live until a player reply consumes it, honest across restarts, session boundaries and forks -- an unconsumed mind rides on); the full-block protocol (the GM rewrote system/invariants/reminder to eliminate the diff verbs: she emits whole <status>/<agenda> at her turn tail, a present block is a whole-list set, absent means unchanged never blank, over-cap agendas evict from the bottom silently -- ruled a feature, silent to her, the note shows the GM; renderView strips every copy and stamps the newest of each kind at the tail of her most recent prose turn, her own emission, so the context reads as the same sequence of events the game had; GM prose goes pure, old logs' composited rides strip, they were never GM words; <mind> is write-only, its tags strip from the view; every turn of hers carries its <model> block -- the params it rode, bare JSON from the via record, the current call included, suppressed when nothing is set, emitting one refused with a pointer at <mind>; the clerk's status-apply/agenda-apply delta verbs RETIRED with their dispatch and collectors, status-set/agenda-set are the player path now; the story strips her blocks, the table chips them; the smoke imports renderView and asserts the view policy directly -- the pattern for testing view-only policy no API exposes); and the opening event RETIRED (the start gate seeds the clerk from her last authored turn's blocks -- the GM moved la-caramba's initial status into her opening turn; old carryovers keep their events as inert history; the event's pre-existing double-landing in every started log, pre-bundle and in-carry, died with the branch); smoke ALL PASS + restart + reminder + repo checks green, browser passes over the knob UX and the new chips and notes with zero console errors, typecheck green on both programs; README and DICTIONARY carry the durable design, HANDOFF trimmed to the map

This commit is contained in:
2026-11-16 21:32:02 +00:00
parent 193dc336be
commit 894737fcf3
30 changed files with 2193 additions and 518 deletions
+216 -38
View File
@@ -1,13 +1,26 @@
// test/smoke.mjs -- end-to-end multiuser pass against the --mock
// server. Covers: bootstrap, claim, spent-invite rejection, second
// user, the session lifecycle (create dormant -> start -> live ->
// user, the model registry (a fresh deployment has no models,
// discover scrapes, refine runs the battery + the curator, registry-
// gated picks, the pick rule's lex tie-break, the named sampling
// knobs, the request record -- resolved model + effective params on
// every turn, the pass log's model), the mind verb (the player sets
// its sampling for its next turn: one-shot, JSON, bounds enforced,
// conflict-healed, carried unconsumed across a session boundary,
// inherited by a fork), the full-block protocol (whole-list status
// and agenda sets, absent = unchanged, the silent over-cap eviction,
// the view stamping at the canon point, the <model> display blocks,
// the emitted-<model> guard, GM prose pure), the session lifecycle
// (create dormant -> start -> live ->
// stop -> dormant -> re-run -> start -> the auto-send rule -> the
// start lint), non-owner 403s, fork, save-package, create-from-user-
// package, revocation, ownerless state, the agenda deltas + self-
// heal, the reminder ride, per-run models, variant literature (the
// random pick, the /table projection, the variance metric), the
// slidwin (move-at-stop, exactly-one-jsonl), and the whole-story
// /story render with no doubles.
// start lint), the draft's memory.json (authored while draft, the
// start gate applies it, provenance once live), the OOC GM turn,
// non-owner 403s, fork, save-package,
// create-from-user-package, revocation, ownerless state, the
// reminder ride, variant
// literature (the random pick, the /table projection, the variance
// metric), the slidwin (move-at-stop, exactly-one-jsonl), and the
// whole-story /story render with no doubles.
// Prints PASS/FAIL per step; exit code carries the verdict.
//
// Expects a CLEAN state/ (no users) and a running --mock server:
@@ -20,6 +33,7 @@ import { readFileSync, writeFileSync, appendFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { join, dirname } from 'node:path';
import { tmpdir } from 'node:os';
import { renderView } from '../server/session.mjs';
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
const BASE = process.env.RP_BASE ?? 'http://127.0.0.1:7350';
@@ -81,7 +95,42 @@ const ashId = r.data.user.id;
r = await call('/invites', { method: 'POST', token: ash, body: {} });
ok('invite mint is op-only', r.status === 403);
// 8. op creates a run -- dormant session one, memory applied at creation
// 7b. the model registry: a fresh deployment has no models, discovery
// is the op's two-step act, and model use is registry-gated
r = await call('/models', { token: op });
ok('fresh deployment: no registry', r.status === 200 && r.data.phase === 'none' && r.data.models.length === 0, JSON.stringify({ phase: r.data.phase }));
r = await call('/models/discover', { method: 'POST', token: ash, body: {} });
ok('discover is op-only', r.status === 403);
r = await call('/models/refine', { method: 'POST', token: op, body: {} });
ok('refine refuses before discovery', r.status === 409, r.data.error ?? '');
r = await call('/models/discover', { method: 'POST', token: op, body: {} });
ok('discover scrapes (no inference)', r.status === 200 && r.data.phase === 'preliminary', r.data.error ?? JSON.stringify(r.data));
r = await call('/models', { token: op });
ok('the preliminary list carries the scrape', r.data.phase === 'preliminary'
&& r.data.models.some((m) => m.id === 'mock' && m.status === 'unrefined')
&& r.data.models.every((m) => m.inference === undefined && m.label === undefined), JSON.stringify(r.data.models));
r = await call('/models/refine', { method: 'POST', token: op, body: {} });
ok('refine starts the job', r.status === 200 && r.data.state === 'running', r.data.error ?? JSON.stringify(r.data));
let reg = null;
for (let i = 0; i < 40; i++) {
reg = await call('/models', { token: op });
if (reg.data.job?.state !== 'running') break;
await new Promise((res) => setTimeout(res, 100));
}
ok('refine applied', reg.data.job?.state === 'applied', JSON.stringify(reg.data.job ?? null));
ok('the refined registry carries verdicts and curation', reg.data.phase === 'refined'
&& reg.data.models.some((m) => m.id === 'mock' && m.inference === true && m.reasoning === 'deep' && m.label === 'Mock' && m.family === 'mock')
&& reg.data.models.some((m) => m.id === 'mock-tie' && m.reasoning === 'deep' && m.label === 'Mock (tie)')
&& reg.data.models.some((m) => m.id === 'mock-cheap' && m.reasoning === 'standard'), JSON.stringify(reg.data.models));
const regFile = JSON.parse(readFileSync(`${ROOT}/state/models.json`, 'utf8'));
ok('the pick rule: deepest reasoning wins, full ties settle sort-lex-pick-bottom',
regFile.defaults.player === 'mock-tie' && regFile.defaults.housekeeper === 'mock-tie', JSON.stringify(regFile.defaults));
const cfgModels = JSON.parse(readFileSync(`${ROOT}/server.json`, 'utf8')).models ?? {};
ok('the op\'s explicit config beats the registry default', reg.data.defaults.player === (cfgModels.player ?? regFile.defaults.player),
JSON.stringify({ api: reg.data.defaults.player, cfg: cfgModels.player ?? null }));
// 8. op creates a run -- dormant session one, memory.json waits for
// the start gate
r = await call('/runs', { method: 'POST', token: op, body: { package: 'la-caramba', pc: 'Smokina', name: 'Smoke Story' } });
ok('create run', r.status === 200 && !!r.data.run?.id, r.data.error ?? r.data.run?.id);
const runId = r.data.run?.id;
@@ -89,36 +138,66 @@ ok('owner stamped', meta(runId).owner === opId);
r = await call(`/runs/${runId}`, { token: op });
ok('born dormant', r.data.phase === 'dormant' && r.data.sessions === 1 && r.data.draft === true,
JSON.stringify({ phase: r.data.phase, sessions: r.data.sessions }));
ok('memory applied at creation', r.data.fill.a === 4 && r.data.fill.b === 1, JSON.stringify(r.data.fill));
ok('the draft holds no rings yet (memory.json waits for the start gate)', r.data.fill.a === 0 && r.data.fill.b === 0, JSON.stringify(r.data.fill));
r = await call(`/runs/${runId}/files`, { token: op });
ok('the draft editor surface', r.data.files['carryover.jsonl']?.mode === 'rw' && r.data.files['memory.json']?.mode === 'ro'
ok('the draft editor surface', r.data.files['carryover.jsonl']?.mode === 'rw' && r.data.files['memory.json']?.mode === 'rw'
&& r.data.files['handbook.md']?.mode === 'rw', JSON.stringify(Object.fromEntries(Object.entries(r.data.files).map(([k, v]) => [k, v.mode]))));
// 8b. the draft's starting memories: memory.json is authored material
// -- a save is a plain file write, and the start gate applies it
const memBefore = r.data.files['memory.json'].content;
const memParsed = JSON.parse(memBefore);
const memEdited = JSON.stringify({
...memParsed,
insert: [...memParsed.insert, { ring: 'a', type: 'fact', label: 'The smoke fact', detail: 'the draft edit landed', reason: 'the draft edit test' }],
}, null, 2) + '\n';
r = await call(`/runs/${runId}/files/memory.json`, { method: 'PUT', token: op, body: { content: memEdited } });
ok('memory.json saves while draft', r.status === 200, r.data.error ?? '');
r = await call(`/runs/${runId}/files/memory.json`, { method: 'PUT', token: op, body: { content: '{ not json' } });
ok('a broken memory.json refuses at save', r.status === 400 && /JSON object/.test(r.data.error), r.data.error ?? '');
r = await call(`/runs/${runId}/files/memory.json`, { method: 'PUT', token: op, body: { content: JSON.stringify({ session: '0', summary: 'bad on purpose', insert: [{ ring: 'x', type: 'fact', label: 'L', reason: 'r' }] }) } });
ok('a bad manifest still saves (the start gate judges it)', r.status === 200, r.data.error ?? '');
r = await call(`/runs/${runId}/sessions`, { method: 'POST', token: op, body: {} });
ok('the start gate refuses the bad manifest', r.status === 422 && /insert\[0\]\.ring must be a\|b/.test(JSON.stringify(r.data.detail ?? {})),
JSON.stringify(r.data).slice(0, 160));
r = await call(`/runs/${runId}`, { token: op });
ok('the refused start landed nothing', r.data.phase === 'dormant' && r.data.draft === true, JSON.stringify({ phase: r.data.phase }));
r = await call(`/runs/${runId}/files/memory.json`, { method: 'PUT', token: op, body: { content: memEdited } });
ok('the good edit goes back in', r.status === 200, r.data.error ?? '');
// 9. start: lint, freeze, consume -- the carryover lands behind the
// bundle. It ends on her turn, so no auto-send: the table waits.
r = await call(`/runs/${runId}/sessions`, { method: 'POST', token: op, body: {} });
ok('start', r.status === 200 && r.data.session === 1 && r.data.autoSend === false, r.data.error ?? JSON.stringify(r.data));
r = await call(`/runs/${runId}`, { token: op });
ok('live', r.data.phase === 'live' && r.data.open === true);
ok('the opening status applied', JSON.stringify(r.data.status) === '["cuffed","belted","naked","barefoot","worried"]', JSON.stringify(r.data.status));
ok('the draft edit is what she starts with', r.data.fill.a === 5 && r.data.fill.b === 1, JSON.stringify(r.data.fill));
const filesLive = await call(`/runs/${runId}/files`, { token: op });
ok('memory.json is provenance once live', filesLive.data.files['memory.json']?.mode === 'ro', filesLive.data.files['memory.json']?.mode ?? 'missing');
ok('her authored blocks seed the clerk', JSON.stringify(r.data.status) === '["cuffed","belted","naked","barefoot","worried"]', JSON.stringify(r.data.status));
r = await call(`/runs/${runId}/table`, { token: op });
ok('the opening renders on the table', r.data.entries.some((e) => e.t === 'msg' && e.m.role === 'assistant' && /Modesty, decency or respect/.test(e.m.content ?? '')));
ok('the opening event rides the log', r.data.entries.some((e) => e.t === 'opening'));
ok('the opening event is retired (her authored blocks are the seed)', r.data.entries.every((e) => e.t !== 'opening'), 'an opening event rode the log');
ok('the sigil expanded at start', r.data.entries.some((e) => e.t === 'msg' && e.m.role === 'assistant' && /Smokina was staring/.test(e.m.content ?? '')), 'a raw @PC reached the table');
// 10. the exchanges (mock: variant literature, the ask, the deltas, the self-heal)
// 10. the exchanges (mock: variant literature with per-variant status
// blocks, the ask, the whole-list sets, the silent eviction, the
// model guard, the mind)
r = await call(`/runs/${runId}/turn`, { method: 'POST', token: op, body: { line: '*The tide comes in.*' } });
ok('gm turn -> variant literature', r.status === 200 && r.data.variants?.count === 2 && [0, 1].includes(r.data.variants.chosen), r.data.error ?? JSON.stringify(r.data.variants ?? null));
const pickedDelta = r.data.variants.chosen === 0 ? 'determined' : 'cautious';
const pickedStatus = r.data.variants.chosen === 0 ? 'determined' : 'cautious';
r = await call(`/runs/${runId}`, { token: op });
ok("the picked variant's delta applied", r.data.status.includes(pickedDelta), JSON.stringify(r.data.status));
ok("the picked variant's status applied", r.data.status.includes(pickedStatus), JSON.stringify(r.data.status));
r = await call(`/runs/${runId}/session`, { token: op });
ok('raw session keeps the whole block', r.data.entries.some((e) => e.t === 'msg' && e.m.role === 'assistant' && /<variants>/.test(e.m.content ?? '')), 'no <variants> in the raw log');
const pickNote = r.data.entries.find((e) => e.t === 'note' && e.kind === 'pick');
ok('pick note logged (the metric)', !!pickNote && pickNote.count === 2 && [0, 1].includes(pickNote.chosen), JSON.stringify(pickNote ?? null));
const viaMsg = r.data.entries.find((e) => e.t === 'msg' && e.m.role === 'assistant' && e.via);
ok('the request record rides the turn (resolved model + effective params)',
!!viaMsg && viaMsg.via.model === 'mock' && JSON.stringify(viaMsg.via.params) === '{}', JSON.stringify(viaMsg?.via ?? null));
r = await call(`/runs/${runId}/table`, { token: op });
ok('the table carries only the picked variant', r.data.entries.every((e) => e.t !== 'msg' || e.m.role !== 'assistant' || !/<\/?variants?>/.test(e.m.content ?? '')), 'variant syntax leaked into the table');
ok('the picked turn is her turn on the table', r.data.entries.some((e) => e.t === 'msg' && e.m.role === 'assistant' && e.m.content.includes(`<gained>${pickedDelta}`)), pickedDelta);
ok('the picked turn is her turn on the table', r.data.entries.some((e) => e.t === 'msg' && e.m.role === 'assistant' && e.m.content.includes(`<status>cuffed, belted, naked, barefoot, ${pickedStatus}</status>`)), pickedStatus);
ok('the table drops thinking', r.data.entries.every((e) => e.m?.reasoning_content === undefined));
ok('the variance metric', r.data.variance.picks === 1 && r.data.variance.offered === 2 && r.data.variance.maxVariants === 2, JSON.stringify(r.data.variance));
@@ -127,38 +206,104 @@ ok('gm turn -> pending ask', r.status === 200 && !!r.data.pendingAsk, r.data.err
r = await call(`/runs/${runId}/ask`, { method: 'POST', token: op, body: { answer: 'yes, clear toward the bow' } });
ok('ask answered', r.status === 200, r.data.error ?? '');
// 10b. the agenda: same-verb blocks combine (two <add> and two <gained>
// blocks in one turn); a bad drop conflicts, and the conflict goes back
// as its own message -- the model heals inside the same turn
// 10b. the full-block protocol: a present block is a whole-list SET
// (absent = unchanged, never blank); an over-cap agenda evicts from
// the bottom silently -- to her; the note shows the GM
r = await call(`/runs/${runId}`, { token: op });
ok('two add blocks combined, order kept', JSON.stringify(r.data.agenda) === '["find fresh water","signal any passing ship","build a shelter"]', JSON.stringify(r.data.agenda));
ok('two gained blocks combined', JSON.stringify(r.data.status.slice(-2)) === '["settled","curious about the clicking"]', JSON.stringify(r.data.status));
ok('the agenda block sets the whole list', JSON.stringify(r.data.agenda) === '["find fresh water","signal any passing ship","build a shelter"]', JSON.stringify(r.data.agenda));
ok('the status block sets the whole list', JSON.stringify(r.data.status.slice(-2)) === '["settled","curious about the clicking"]', JSON.stringify(r.data.status));
r = await call(`/runs/${runId}/turn`, { method: 'POST', token: op, body: { line: '*Evening comes.*' } });
ok('gm turn (drop)', r.status === 200, r.data.error ?? '');
ok('a restated agenda replaces the list', r.status === 200, r.data.error ?? '');
r = await call(`/runs/${runId}`, { token: op });
ok('agenda after drop', JSON.stringify(r.data.agenda) === '["signal any passing ship","build a shelter"]', JSON.stringify(r.data.agenda));
ok('agenda after restatement', JSON.stringify(r.data.agenda) === '["signal any passing ship","build a shelter"]', JSON.stringify(r.data.agenda));
r = await call(`/runs/${runId}/turn`, { method: 'POST', token: op, body: { line: '*Night falls.*' } });
ok('bad drop self-heals in the same turn', r.status === 200 && !r.data.conflicts, r.data.error ?? JSON.stringify(r.data.conflicts ?? null));
ok('the over-cap turn is clean (eviction is silent)', r.status === 200 && !r.data.conflicts, r.data.error ?? JSON.stringify(r.data.conflicts ?? null));
r = await call(`/runs/${runId}`, { token: op });
ok('heal applied (multi-index drop)', JSON.stringify(r.data.agenda) === '[]', JSON.stringify(r.data.agenda));
ok('an over-cap agenda keeps the top five', JSON.stringify(r.data.agenda) === '["item one","item two","item three","item four","item five"]', JSON.stringify(r.data.agenda));
ok('the omitted status means unchanged',
JSON.stringify(r.data.status) === '["cuffed","belted","naked","barefoot","settled","curious about the clicking"]', JSON.stringify(r.data.status));
r = await call(`/runs/${runId}/session`, { token: op });
const conflictMsg = r.data.entries.find((e) => e.conflictOnly);
ok('conflict went as its own message', !!conflictMsg && /<conflict>agenda has no item at index 9<\/conflict>/.test(conflictMsg.m.content), conflictMsg?.m.content ?? 'none');
const cIdx = r.data.entries.indexOf(conflictMsg);
ok('the model answered the conflict', r.data.entries.slice(cIdx + 1).some((e) => e.t === 'msg' && e.m.role === 'assistant'), '');
const evictNote = r.data.entries.find((e) => e.t === 'note' && e.kind === 'agenda' && e.evicted?.length);
ok('the eviction is visible to the GM (the note)',
!!evictNote && JSON.stringify(evictNote.evicted) === '["item six","item seven"]', JSON.stringify(evictNote ?? null));
r = await call(`/runs/${runId}/turn`, { method: 'POST', token: op, body: { line: '*Dawn breaks.*' } });
ok('next gm turn is clean', r.status === 200, r.data.error ?? '');
ok('next gm turn is clean', r.status === 200 && !r.data.conflicts, r.data.error ?? JSON.stringify(r.data.conflicts ?? null));
// 10c. the <model> guard: display-only -- the conflict points at
// <mind>, the heal restates plain, and the turn heals in the same turn
r = await call(`/runs/${runId}/session`, { token: op });
const guardConflict = r.data.entries.find((e) => e.conflictOnly && /read-only display/.test(e.m.content));
ok('an emitted <model> block conflicts', !!guardConflict, guardConflict?.m.content ?? 'no conflict');
ok('the guard conflict healed in the same turn',
!!guardConflict && r.data.entries.slice(r.data.entries.indexOf(guardConflict)).some((e) => e.t === 'msg' && e.m.role === 'assistant' && /watching the water/.test(e.m.content ?? '')),
'no heal');
// 10d. the mind verb: <mind>{"temperature": 1.2}</mind> sets her
// sampling for her NEXT turn (one-shot, JSON, max_tokens excluded)
r = await call(`/runs/${runId}/session`, { token: op });
const mindSetter = r.data.entries.filter((e) => e.t === 'msg' && e.m.role === 'assistant').find((e) => /race ahead of her feet/.test(e.m.content ?? ''));
ok('the mind verb: the setting turn does not ride at it (next turn only)',
mindSetter?.via?.params?.temperature === undefined, JSON.stringify(mindSetter?.via ?? null));
ok('the mind verb: the note records the statement',
r.data.entries.some((e) => e.t === 'note' && e.kind === 'mind' && e.params?.temperature === 1.2), 'no mind note');
const guardTurn = r.data.entries.find((e) => e.t === 'msg' && e.m.role === 'assistant' && /squints at the horizon/.test(e.m.content ?? ''));
ok('the mind verb: her next turn rides at the stated mind',
guardTurn?.via?.params?.temperature === 1.2, JSON.stringify(guardTurn?.via ?? null));
const lastGm = [...r.data.entries].reverse().find((e) => e.t === 'msg' && e.m.role === 'user' && !e.conflictOnly);
ok('no conflict attached to the GM turn', !/<conflict>/.test(lastGm.m.content), lastGm.m.content.slice(-100));
ok('the empty agenda rides honestly', /<agenda><\/agenda>/.test(lastGm.m.content), lastGm.m.content.slice(-120));
ok('GM prose goes pure', !/<\/?(status|agenda)>/.test(lastGm.m.content), lastGm.m.content.slice(-120));
r = await call(`/runs/${runId}/agenda`, { method: 'POST', token: op, body: { items: ['climb the ridge', 'rest'] } });
ok('agenda-set (GM override)', r.status === 200 && JSON.stringify(r.data.agenda) === '["climb the ridge","rest"]', JSON.stringify(r.data.agenda));
// 10d. an OOC GM turn: the paren channel carries no cache blocks -- an
// OOC exchange does not move her state, the next IC turn re-carries them
r = await call(`/runs/${runId}/turn`, { method: 'POST', token: op, body: { line: '( mock GM checking in )' } });
ok('ooc gm turn sends', r.status === 200, r.data.error ?? '');
r = await call(`/runs/${runId}/session`, { token: op });
const oocGm = [...r.data.entries].reverse().find((e) => e.t === 'msg' && e.m.role === 'user' && !e.conflictOnly);
ok('the ooc turn carries no cache blocks', /\( mock GM checking in \)/.test(oocGm.m.content) && !/<\/?(status|agenda)>/.test(oocGm.m.content), oocGm.m.content.slice(-90));
// the OOC reply states an out-of-bounds mind: the conflict names the
// range, the heal restates -- and the turn after the riding turn is
// back at defaults (one-shot)
const scatterTurn = r.data.entries.find((e) => e.t === 'msg' && e.m.role === 'assistant' && /thoughts scatter/.test(e.m.content ?? ''));
ok('the mind is one-shot (the turn after the riding turn is at defaults)',
scatterTurn?.via?.params?.temperature === undefined, JSON.stringify(scatterTurn?.via ?? null));
const mindConflict = r.data.entries.find((e) => e.conflictOnly && /must be at least 0 and up to 2/.test(e.m.content));
ok('an out-of-bounds mind conflicts with the range named', !!mindConflict, mindConflict?.m.content ?? 'no conflict');
ok('the mind conflict healed in-turn',
!!mindConflict && r.data.entries.slice(r.data.entries.indexOf(mindConflict)).some((e) => e.t === 'note' && e.kind === 'mind' && e.params?.temperature === 1.2),
'no healed restatement');
ok('the mind statements number two (the refused one never stashed)',
r.data.entries.filter((e) => e.t === 'note' && e.kind === 'mind').length === 2, 'wrong count');
// 10e. the view policy (the full-block protocol): render the session
// log through the same renderer the loop uses and assert the stamping
const view1 = renderView({ lines: jsonl(runId, 1, 'log.jsonl'), pendingAsk: null });
const her1 = view1.filter((m) => m.role === 'assistant');
const lastHer = [...her1].reverse().find((m) => typeof m.content === 'string' && /breathes until the numbers behave/.test(m.content));
ok('the view stamps the newest status and agenda at her latest turn',
!!lastHer && /<status>cuffed, belted, naked, barefoot, settled, curious about the clicking<\/status>/.test(lastHer.content)
&& /<agenda>item one\nitem two\nitem three\nitem four\nitem five\nitem six\nitem seven<\/agenda>/.test(lastHer.content),
(lastHer?.content ?? 'none').slice(-220));
ok('the stamped agenda is her own emission (the eviction stays silent to her)',
!!lastHer && (lastHer.content.match(/<agenda>/g) ?? []).length === 1 && /item seven<\/agenda>/.test(lastHer.content),
'the stamp leaked the clerk truth');
ok('superseded copies strip from the view',
her1.filter((m) => m !== lastHer).every((m) => !/<\/?(status|agenda)>/.test(String(m.content ?? ''))), '');
ok('her mind tags are write-only (stripped from the view)',
her1.every((m) => !/<mind>/.test(String(m.content ?? ''))), '');
ok('an emitted <model> block strips from the view',
her1.every((m) => !/\n<model>/.test(String(m.content ?? ''))), '');
ok('each past turn carries its <model> block when params rode',
her1.some((m) => String(m.content ?? '').startsWith('<model>{"temperature":1.2}</model>')), '');
ok('GM prose goes pure in the view',
view1.filter((m) => m.role === 'user').every((m) => !/<\/?(status|agenda)>/.test(String(m.content ?? ''))), '');
// 10c. the reminder: a system chunk after every GM turn, one live copy
r = await call(`/runs/${runId}/session`, { token: op });
const reminders = r.data.entries.filter((e) => e.reminder);
ok('reminder rode every GM turn', reminders.length === 5 && reminders.every((x) => x.m.role === 'system'), `${reminders.length} in the log`);
ok('reminder rode every GM turn', reminders.length === 6 && reminders.every((x) => x.m.role === 'system'), `${reminders.length} in the log`);
ok('reminder carries the turn protocol', /How to compose your turn/i.test(reminders[0]?.m.content ?? ''), (reminders[0]?.m.content ?? '').slice(0, 60));
r = await call(`/runs/${runId}/agenda`, { method: 'POST', token: ash, body: { items: [] } });
ok('agenda override owner-only', r.status === 403);
@@ -206,11 +351,24 @@ r = await call(`/runs/${forkId}`, { token: ash });
ok('fork live session carried over', r.status === 200 && r.data.open === true, r.data.error ?? '');
r = await call(`/runs/${forkId}/turn`, { method: 'POST', token: ash, body: { line: '*She looks around.*' } });
ok('ash turns on the fork', r.status === 200, r.data.error ?? '');
r = await call(`/runs/${forkId}/session`, { token: ash });
const forkReply = [...r.data.entries].reverse().find((e) => e.t === 'msg' && e.m.role === 'assistant');
ok('the fork inherits her unconsumed mind', forkReply?.via?.params?.temperature === 1.2, JSON.stringify(forkReply?.via ?? null));
// 12b. models: per-run overrides of the deployment defaults
// 12b. models: per-run overrides of the deployment defaults, the
// registry-gated picks, and the named sampling knobs
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: ash, body: { player: 'mock', housekeeper: 'mock-cheap' } });
ok('set models', r.status === 200 && r.data.models.player === 'mock' && r.data.models.housekeeper === 'mock-cheap', JSON.stringify(r.data));
ok('models stamped in run.json', meta(forkId).models?.player === 'mock' && meta(forkId).models?.housekeeper === 'mock-cheap');
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: ash, body: { params: { player: { temperature: 0.7, max_tokens: 4096 } } } });
ok('set knobs', r.status === 200 && r.data.params.player?.temperature === 0.7 && r.data.params.player?.max_tokens === 4096, JSON.stringify(r.data));
ok('knobs stamped in run.json', meta(forkId).params?.player?.temperature === 0.7);
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: ash, body: { params: { player: { temperature: null } } } });
ok('a null knob clears', r.status === 200 && r.data.params.player?.temperature === undefined && r.data.params.player?.max_tokens === 4096, JSON.stringify(r.data.params));
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: ash, body: { params: { player: { vibes: 1 } } } });
ok('an unknown knob refuses', r.status === 400 && /unknown knob/.test(r.data.error), r.data.error ?? '');
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: ash, body: { player: 'not-a-model' } });
ok('a model outside the registry refuses', r.status === 400 && /registry/.test(r.data.error), r.data.error ?? '');
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: ash, body: { housekeeper: null } });
ok('clear a role back to default', r.status === 200 && r.data.models.housekeeper === undefined && r.data.models.player === 'mock', JSON.stringify(r.data));
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: op, body: { player: 'x' } });
@@ -218,9 +376,17 @@ ok('model set is owner-only', r.status === 403);
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: ash, body: { bard: 'x' } });
ok('unknown role rejected', r.status === 400);
r = await call(`/runs/${forkId}`, { token: ash });
ok('detail exposes models + defaults', r.data.run.models?.player === 'mock' && !!r.data.run.modelDefaults?.player, JSON.stringify(r.data.run.models));
ok('detail exposes models + defaults', r.data.run.models?.player === 'mock' && !!r.data.run.modelDefaults?.player && r.data.run.params?.player?.max_tokens === 4096 && !!r.data.run.paramDefaults, JSON.stringify(r.data.run.models));
// a turn on the knob-carrying run: the recording proves what was sent
r = await call(`/runs/${forkId}/turn`, { method: 'POST', token: ash, body: { line: '*She keeps watch.*' } });
ok('gm turn on the fork (post-knobs)', r.status === 200, r.data.error ?? '');
r = await call(`/runs/${forkId}/session`, { token: ash });
const viaTurn = [...r.data.entries].reverse().find((e) => e.t === 'msg' && e.m.role === 'assistant');
ok('the recorded request carries the run\'s knobs',
!!viaTurn?.via && viaTurn.via.model === 'mock' && viaTurn.via.params.max_tokens === 4096 && viaTurn.via.params.temperature === undefined,
JSON.stringify(viaTurn?.via ?? null));
r = await call('/models', { token: ash });
ok('model listing', r.status === 200 && Array.isArray(r.data) && r.data.includes('mock'));
ok('model listing (the registry)', r.status === 200 && r.data.phase === 'refined' && r.data.models.some((m) => m.id === 'mock' && m.label === 'Mock'), JSON.stringify(r.data.phase));
// 13. ash saves a draft as a package (save-package is a draft act --
// the played-run refusal is checked at the end)
@@ -288,6 +454,8 @@ ok('dormant after stop', r.data.phase === 'dormant' && r.data.sessions === 2 &&
JSON.stringify({ phase: r.data.phase, sessions: r.data.sessions, ready: r.data.ready }));
r = await call(`/runs/${runId}/housekeeping`, { token: op });
ok('the job names the pass and the target', r.data.state === 'applied' && r.data.session === 1 && r.data.target === 2, JSON.stringify(r.data));
r = await call(`/runs/${runId}/housekeeping/log`, { token: op });
ok('the pass log names its model', r.status === 200 && /housekeeper: mock/.test(r.data.content), r.status === 200 ? r.data.content.split('\n').slice(0, 3).join(' / ') : r.data.error);
// the move: each line exists in exactly one jsonl, ever
const log1 = jsonl(runId, 1, 'log.jsonl');
@@ -306,9 +474,10 @@ ok('the dormant preview renders the carry', r.status === 200 && r.data.session =
r = await call(`/runs/${runId}/story`, { token: op });
const gmTexts = r.data.sessions.flatMap((s) => s.turns.filter((t) => t.who === 'gm').map((t) => t.text));
ok('the story has every GM turn exactly once', gmTexts.length === 5 && new Set(gmTexts).size === 5, `${gmTexts.length} gm turns across ${r.data.sessions.length} sessions`);
ok('the story carries no OOC', r.data.sessions.every((s) => s.turns.every((t) => !/^\(/.test(t.text) && !/\( mock GM checking in \)/.test(t.text))), 'OOC leaked into the story');
ok('the story reads the dormant carryover at the live edge', r.data.sessions.some((s) => s.turns.length >= 10));
const storyPlayer = r.data.sessions.flatMap((s) => s.turns.filter((t) => t.who === 'player').map((t) => t.text));
ok('the story strips the verbs', storyPlayer.every((t) => !/<\/?(lost|gained|add|drop)>/.test(t)), '');
ok('the story strips the verbs', storyPlayer.every((t) => !/<\/?(lost|gained|add|drop|mind|status|agenda|model)>/.test(t)), '');
ok('the story carries no variant syntax', storyPlayer.every((t) => !/<\/?variants?>/.test(t)), '');
ok('the story strips the rides from GM prose', r.data.sessions.every((s) => s.turns.every((t) => t.who !== 'gm' || !/<\/?(status|agenda)>/.test(t.text))), '');
@@ -317,20 +486,26 @@ await stopAndSettle('re-run housekeeping (session 1)');
r = await call(`/runs/${runId}`, { token: op });
ok('still dormant, still ready', r.data.phase === 'dormant' && r.data.sessions === 2 && r.data.ready === true);
r = await call(`/runs/${runId}`, { token: op });
ok('the rebase kept the rings single-applied', r.data.fill.b === 2 && r.data.fill.a === 4, JSON.stringify(r.data.fill)); // 1 seeded + 1 inserted, once
ok('the rebase kept the rings single-applied', r.data.fill.b === 2 && r.data.fill.a === 5, JSON.stringify(r.data.fill)); // 4 packaged + 1 draft edit + 1 inserted, once
// start session 2: the carry lands behind the bundle
r = await call(`/runs/${runId}/sessions`, { method: 'POST', token: op, body: {} });
ok('start session 2', r.status === 200 && r.data.session === 2 && r.data.autoSend === false, r.data.error ?? JSON.stringify(r.data));
r = await call(`/runs/${runId}/table`, { token: op });
ok('the carry landed behind the bundle', r.data.entries.some((e) => e.t === 'bundle' && e.part === 'ring-a')
&& r.data.entries.some((e) => e.t === 'msg' && e.m.role === 'assistant' && /waits for the world to move/.test(e.m.content ?? '')));
&& r.data.entries.some((e) => e.t === 'msg' && e.m.role === 'assistant' && /breathes until the numbers behave/.test(e.m.content ?? '')));
ok('the frozen bundle is session 2\'s own', r.data.entries.some((e) => e.t === 'bundle') && r.data.session === 2);
r = await call(`/runs/${runId}`, { token: op });
ok('her agenda carried across the stop', r.data.agenda.includes('climb the ridge'), JSON.stringify(r.data.agenda));
r = await call(`/runs/${runId}/turn`, { method: 'POST', token: op, body: { line: '*She wakes on the sand.*' } });
ok('session 2 plays on', r.status === 200 && !!r.data.player, r.data.error ?? '');
// her last stated mind, unconsumed in the carried log, rode that turn
r = await call(`/runs/${runId}/session`, { token: op });
const s2Reply = [...r.data.entries].reverse().find((e) => e.t === 'msg' && e.m.role === 'assistant');
ok('an unconsumed mind carries across the session boundary',
s2Reply?.via?.params?.temperature === 1.2, JSON.stringify(s2Reply?.via ?? null));
// 18. the auto-send rule: stop again, hand-append a GM turn to the
// carryover (the future editor's one edit), start -- the turn fires
await stopAndSettle('stop (session 2)');
@@ -345,6 +520,9 @@ ok('start auto-sends the GM-ending carryover', r.status === 200 && r.data.autoSe
r.data.error ?? JSON.stringify({ autoSend: r.data.autoSend, player: r.data.player?.slice(0, 40) }));
r = await call(`/runs/${runId}/session`, { token: op });
ok('her reply answered the carried cue', [...r.data.entries].reverse().find((e) => e.t === 'msg' && !e.reminder)?.m?.role === 'assistant');
const s3Reply = [...r.data.entries].reverse().find((e) => e.t === 'msg' && e.m.role === 'assistant');
ok('the mind is one-shot (spent by the turn that rode it)',
s3Reply?.via?.params?.temperature === undefined, JSON.stringify(s3Reply?.via ?? null));
// 19. the start lint: a malformed carryover refuses, nothing starts
await stopAndSettle('stop (session 3)');