the provider round and the provider-flow round, plus the template and box packages

the provider round (2026-11-18, batteries-included): providers are first-class entities, the config is server-written state (state/config.json), and a fresh clone boots playable -- the opencode/free singleton auto-added and discovered on the empty list, playable with zero secrets. Every request resolves a full spec {provider, model, effort}: no unset effort, the per-run params layer retired, the mind verb the only sampling source. The registry is per-provider sections (state/models.json), refine caches adjudications under the double spec tuple (state/refine-cache.json), run picks are invalidatable (a removed provider or drifted model blocks the run with the note naming what died), and the housekeeper inherits the player spec's provider default (#16 closed). The no-legacy pass died the same day it shipped: bootImport deleted (server.json is bind + contwin), the registry's v1/v2 in-memory migrations deleted (models.json rewritten on disk into the per-provider shape), bare-string model picks deleted (Chloe's run.json migrated to spec objects, shape-preserving), the clerk's create model arg deleted, apiKeyEnv and the contextWindow alias gone. The live arc proven from a bare boot: invite minted, o/f auto-added, a custom provider with a bogus key (the recognizable 401), the auth fixed (13 models), the default pair selected, and a real glm-5.3 turn through the full path. Two live findings: opencode.ai serves 89 models keyless but 401s an empty Bearer header (the auth header rides only when a key exists), and the failure log line rides stderr.

the provider-flow round (2026-11-19, GM-designed): discovery IS the probe. The add takes only the endpoint -- {slug, baseUrl} or {builtin: true}, an apiKey in the body 400s (the auth route is the only key path) -- and a working keyless listing never sees a key field. A 401/403 stands the provider broken: the entity carries a probe record (outcome ok/auth/error, detail, at), the card opens the ask, and only the explicit acts move the record -- add, key, remove-key, discover; usage errors are transient and the op's to fix, nothing in the runtime flips provider state. The auth route is probe-then-save: the candidate key checks on reception, saves only on success -- a still-refused key never reaches the config, the previous state returns, the ask repeats. Every other discovery failure refuses the add outright with rollback: an endpoint that cannot answer is not a provider, nothing stands (the old code let it stand on any failure). The remove-key control (custom providers, armed) clears and re-probes: a provider gone public lands working keyless, a locked one re-opens the ask -- which is the key-replacement path. o/f never asks in any state: its auth failures are upstream breakage to show, not a prompt. The universal retry rule: NO automatic retries anywhere -- every inference call is user-initiated (the send, the housekeeping run, the refine) and every act has its manual retry; the curator's one auto-retry (the 2026-11-17 hiccup lesson) is deleted, the machine-label fallback the designed outcome. And failures never cache (GM: a failure is the absence of a measurement, not a measurement) -- the adjudication cache skips inference:false entries, the receipt line says "never cached, retried at every refine", and a transient battery error can never pin a false verdict; gev's 400s cost one cheap probe per refine and self-heal the day the backend learns tools. En-route fix the smoke earned: the create route validated body.spec AFTER the clerk built the run dir -- a refused spec left an orphan run (restart-check's exact count caught the sixth run); the spec validates first now, nothing lands on refusal.

the sheet's transport at the lint: the record is the only channel, the tag is view machinery composed by renderView, never authored by anyone -- the authored gate names the tag in any content (hers would never apply and primes the guarded emission; GM prose rides the view and story raw, the GM-side strips do not know it), names a sheet record on her turn, and checks object-ness on GM-turn records and boundary state notes both kinds; her emitted sheet in a carried tail stays legitimate history (the log keeps guard-conflicted emissions verbatim, and a stop can move one into the slidwin). The carryover editor teaches its own format now: a per-file hint between the editor and the save bar (one JSON object per line; status and agenda ride her turns; the sheet rides yours as the "sheet" field, never as a tag; the sigils and $VARS expand at start on the authored opening only).

the packages: template (the base for new packages -- the mood-indexed voice examples, the settings comment convention, non-playable as-is) and box (the sheet's first consumer: an incremental-game economy as ERP, GP and BP as two currencies with the room pushing her to fund her own punishments; the opening turn third-person per the typography ruling, ending on the display that needs a second read; the amnesiac rings empty by design; the erased name reading "(redacted)" after sigil expansion). The review found and fixed: both carryovers were pretty-printed JSON with duplicate keys -- unstartable under every per-line reader, flattened to true JSONL; the box's opening sheet rode her authored prose -- dead on every surface (the scan reads GM-turn records only, the strips eat it) and priming the exact emission the guard conflicts -- moved to the GM turn's sheet record, the override's shape; the gm.md "take of leave" typo fixed in all three packages.

the lint's rule 4 scoped to the substrate (GM, 2026-11-19): a banned word in a package's prose is fine -- the packages are the fiction and their words are the story's; README and the root prompts stay patrolled, and the box's "Or windows" is an architectural plural in a padded cell.

verified: typecheck green both programs; smoke ALL PASS (+27 the provider-flow battery: apiKey-on-add 400, the dead-endpoint refusal with config rollback, the auth-standing card with its probe record, probe-then-save both ways, the remove-key round trip, the o/f guards, the failures-never-cache proof over mock-fail -- verdict with the marker, absent from the cache file, re-probed fresh while the passing three serve from cache, not selectable, no orphan run; +8 the sheet-transport lint battery); restart + reminder checks green; a browser pass driving the whole add-flow machine on a mock+debug server (the hidden key field opening on the 401, the key landing through the auth route, the remove-key round trip re-opening the ask, the dead add refusing with the banner and no card, zero console errors beyond the expected 401/500 resource lines); check-repo clean with the box's windows. detention stays untracked WIP, untouched.
This commit is contained in:
2026-11-19 08:35:23 +00:00
parent 14b9b01d86
commit e60fd63d2b
42 changed files with 3071 additions and 1086 deletions
+381 -87
View File
@@ -1,12 +1,15 @@
// test/smoke.mjs -- end-to-end multiuser pass against the --mock
// server. Covers: bootstrap, claim, spent-invite rejection, second
// 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 reasoning-effort knob (the battery's effort probe, the
// max-mean default that sends, the override that rides the turn,
// hidden from the model), the request record -- resolved model +
// effective params on
// user, the provider round (GM, 2026-11-18: the self-heal boot --
// the empty provider list auto-added and discovered; the op acts
// ride the per-provider surface -- the binary add choice, the o/f
// singleton's authless guard, the selection {model, effort} that
// names the refine curator, per-provider refine with the meter and
// the receipt, the spec-keyed adjudication cache, the run spec
// picks {provider, model, effort} with no unset effort, the
// invalidation surface -- a removed provider blocks its runs until
// the GM re-picks, the removal guard on the singleton, the request
// record -- resolved spec + 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,
@@ -46,7 +49,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';
import { renderView, lintCarryover } from '../server/session.mjs';
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
const BASE = process.env.RP_BASE ?? 'http://127.0.0.1:7350';
@@ -108,55 +111,199 @@ const ashId = r.data.user.id;
r = await call('/invites', { method: 'POST', token: ash, body: {} });
ok('invite mint is op-only', r.status === 403);
// 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));
// 7b. providers and the registry: the fresh deployment self-heals
// (the empty provider list is auto-added and discovered at boot),
// the op's acts ride the per-provider surface (selection, discover,
// refine), the adjudication cache survives churn, and model use
// stays registry-gated
{
r = await call('/models', { token: op });
let boot = r.data.providers ?? [];
for (let i = 0; i < 50 && boot.filter((p) => p.models.length > 0).length < 2; i++) {
await new Promise((res) => setTimeout(res, 100));
r = await call('/models', { token: op });
boot = r.data.providers ?? [];
}
ok('the self-heal boot: the empty provider list is auto-added and discovered',
boot.length === 2 && boot.every((p) => ['mock-a', 'mock-b'].includes(p.slug) && p.phase === 'preliminary' && p.models.length > 0),
JSON.stringify(boot.map((p) => [p.slug, p.phase, p.models.length])));
const cfgFile = JSON.parse(readFileSync(`${ROOT}/state/config.json`, 'utf8'));
ok('the config file holds the provider entities (server-written state)',
cfgFile.providers.length === 2 && cfgFile.providers.every((p) => typeof p.slug === 'string' && typeof p.baseUrl === 'string'),
JSON.stringify(cfgFile.providers?.map((p) => p.slug)));
// the op's acts are op-only
r = await call('/providers', { method: 'POST', token: ash, body: { slug: 'nope', baseUrl: 'https://x.example/v1' } });
ok('provider add is op-only', r.status === 403);
// the add flow: bad inputs refuse
r = await call('/providers', { method: 'POST', token: op, body: { slug: 'Bad Slug', baseUrl: 'https://x.example/v1' } });
ok('a bad slug refuses', r.status === 400 && /slug/.test(r.data.error), r.data.error ?? '');
r = await call('/providers', { method: 'POST', token: op, body: { slug: 'mock-a', baseUrl: 'https://x.example/v1' } });
ok('a duplicate slug refuses', r.status === 409, r.data.error ?? '');
r = await call('/providers', { method: 'POST', token: op, body: { slug: 'nope', baseUrl: 'not a url' } });
ok('a bad baseUrl refuses', r.status === 400 && /baseUrl/.test(r.data.error), r.data.error ?? '');
// the binary choice: the o/f singleton adds and discovers (the
// mock surface serves any slug), and never takes a key
r = await call('/providers', { method: 'POST', token: op, body: { builtin: true } });
ok('the o/f singleton adds and discovers', r.status === 200 && r.data.provider === 'opencode/free' && r.data.models > 0, JSON.stringify(r.data));
r = await call('/providers', { method: 'POST', token: op, body: { builtin: true } });
ok('the singleton is single', r.status === 409 && /already/.test(r.data.error), r.data.error ?? '');
r = await call(`/providers/${encodeURIComponent('opencode/free')}/auth`, { method: 'POST', token: op, body: { apiKey: 'sk-x' } });
ok('the o/f singleton never takes a key', r.status === 403 && /anonymous/.test(r.data.error), r.data.error ?? '');
// the selection: the provider's default {model, effort} -- also
// the refine curator
r = await call('/providers/mock-a/refine', { method: 'POST', token: op, body: {} });
ok('refine requires the selection (the default is the curator)', r.status === 409 && /select/.test(r.data.error), r.data.error ?? '');
r = await call('/providers/mock-a/default', { method: 'POST', token: op, body: { model: 'nope', effort: 'max' } });
ok('a selection outside the registry refuses', r.status === 400 && /registry/.test(r.data.error), r.data.error ?? '');
r = await call('/providers/mock-a/default', { method: 'POST', token: op, body: { model: 'mock', effort: 'turbo' } });
ok('a bogus effort level refuses', r.status === 400 && /must be one of/.test(r.data.error), r.data.error ?? '');
r = await call('/providers/mock-a/default', { method: 'POST', token: op, body: { model: 'mock', effort: 'max' } });
ok('the selection lands (the provider default)', r.status === 200 && JSON.stringify(r.data.default) === '{"model":"mock","effort":"max"}', JSON.stringify(r.data));
r = await call('/providers/mock-b/default', { method: 'POST', token: op, body: { model: 'mock-cheap', effort: 'high' } });
ok('the second provider selects too', r.status === 200, r.data.error ?? '');
// refine: per provider, the meter, the receipt, the verdicts
r = await call('/providers/mock-a/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 jobA = null;
for (let i = 0; i < 40; i++) {
r = await call('/models', { token: op });
jobA = (r.data.providers ?? []).find((p) => p.slug === 'mock-a')?.job ?? null;
if (jobA?.state !== 'running') break;
await new Promise((res) => setTimeout(res, 100));
}
ok('refine applied', jobA?.state === 'applied', JSON.stringify(jobA ?? null));
ok('the refine meter closed its steps (one per model + the curator\'s two)', jobA?.steps?.total === 4 && jobA?.steps?.done === 4,
JSON.stringify(jobA?.steps ?? null));
ok('the refine receipt logged every battery and the curator',
(jobA?.lines ?? []).length === 3
&& jobA.lines.some((l) => l.includes('mock: reasoning deep'))
&& jobA.lines.some((l) => l.includes('mock-tie: reasoning deep'))
&& jobA.lines.some((l) => l.includes('curator (mock): curated')),
JSON.stringify(jobA?.lines ?? null));
r = await call('/providers/mock-b/refine', { method: 'POST', token: op, body: {} });
ok('the second provider refines', r.status === 200, r.data.error ?? '');
for (let i = 0; i < 40; i++) {
r = await call('/models', { token: op });
if ((r.data.providers ?? []).find((p) => p.slug === 'mock-b')?.job?.state !== 'running') break;
await new Promise((res) => setTimeout(res, 100));
}
const refined = (r.data.providers ?? []);
const secA = refined.find((p) => p.slug === 'mock-a');
const secB = refined.find((p) => p.slug === 'mock-b');
ok('the refined sections carry verdicts and curation',
secA?.phase === 'refined' && secA.models.some((m) => m.id === 'mock' && m.inference === true && m.reasoning === 'deep' && m.label === 'Mock' && m.family === 'mock')
&& secA.models.some((m) => m.id === 'mock-tie' && m.reasoning === 'deep' && m.label === 'Mock (tie)')
&& secB?.phase === 'refined' && secB.models.some((m) => m.id === 'mock-cheap' && m.reasoning === 'standard'),
JSON.stringify({ a: secA?.models.map((m) => [m.id, m.label]), b: secB?.models.map((m) => [m.id, m.label]) }));
ok('the curator\'s recommendation is intel on the section (never auto-applied)',
JSON.stringify(secA?.recommendation ?? null) === '{"model":"mock","effort":"max"}' && JSON.stringify(secA.default) === '{"model":"mock","effort":"max"}',
JSON.stringify({ recommendation: secA?.recommendation, default: secA.default }));
ok('the effort probe: measured ladders and the max-mean defaults',
secA?.models.some((m) => m.id === 'mock' && m.effortDefault === 'max' && m.efforts?.max === 500 && m.efforts?.none === 0)
&& secB?.models.some((m) => m.id === 'mock-cheap' && m.effortDefault === 'high' && m.efforts?.max === undefined),
JSON.stringify([...(secA?.models ?? []), ...(secB?.models ?? [])].filter((m) => m.efforts).map((m) => ({ id: m.id, effortDefault: m.effortDefault }))));
const regFile = JSON.parse(readFileSync(`${ROOT}/state/models.json`, 'utf8'));
ok('the registry file is per-provider sections (the section names the route)',
regFile.providers?.['mock-a']?.models?.length === 2 && regFile.providers?.['mock-b']?.models?.length === 1
&& regFile.providers['mock-b'].models[0].id === 'mock-cheap'
&& regFile.providers['mock-a'].models.every((m) => m.endpoint === undefined),
JSON.stringify(Object.entries(regFile.providers ?? {}).map(([s, x]) => [s, x.models.length])));
// the adjudication cache: a re-refine over the same tuple reuses
// every entry -- churn is the point (o/f rotates models; the
// survivors keep their measured selves between refines)
r = await call('/providers/mock-a/refine', { method: 'POST', token: op, body: {} });
ok('a re-refine starts', r.status === 200, r.data.error ?? '');
let jobC = null;
for (let i = 0; i < 40; i++) {
r = await call('/models', { token: op });
jobC = (r.data.providers ?? []).find((p) => p.slug === 'mock-a')?.job ?? null;
if (jobC?.state !== 'running') break;
await new Promise((res) => setTimeout(res, 100));
}
ok('the cached re-refine applied', jobC?.state === 'applied', JSON.stringify(jobC ?? null));
ok('the cache served both models',
(jobC?.lines ?? []).filter((l) => l.includes('from cache')).length === 2
&& jobC.lines.some((l) => l.includes('curator')),
JSON.stringify(jobC?.lines ?? null));
const cacheFile = JSON.parse(readFileSync(`${ROOT}/state/refine-cache.json`, 'utf8'));
const cacheKeys = Object.keys(cacheFile.entries ?? {}).filter((k) => k.startsWith('mock-a::'));
ok('the cache file holds the adjudications under their spec tuples',
cacheKeys.length === 2 && cacheKeys.every((k) => k.startsWith('mock-a::') && k.includes('::max::mock::max')),
JSON.stringify(Object.keys(cacheFile.entries ?? {})));
}
// 7c. the add-flow machine (GM, 2026-11-19): discovery is the probe.
// A keyless working endpoint never sees a key field; a 401/403 stands
// the provider broken and opens the key path (checked on reception,
// saved on success, asked again on refusal -- a failed candidate
// never saves); every other failure refuses the add outright,
// nothing stands. The key removal probes again, and o/f never asks.
{
// the add takes no key -- the auth route is the only key path
r = await call('/providers', { method: 'POST', token: op, body: { slug: 'mock-keyed', baseUrl: 'https://k.example/v1', apiKey: 'sk-x' } });
ok('apiKey on the add refuses', r.status === 400 && /apiKey/.test(r.data.error), r.data.error ?? '');
// a dead endpoint: the add is refused outright, nothing stands
r = await call('/providers', { method: 'POST', token: op, body: { slug: 'mock-dead', baseUrl: 'https://dead.example/v1' } });
ok('a non-auth discovery failure refuses the add', r.status === 500 && /did not answer/.test(r.data.error), `${r.status} ${r.data.error ?? ''}`);
r = await call('/models', { token: op });
ok('the refused add left no card behind', !(r.data.providers ?? []).some((p) => p.slug === 'mock-dead'), JSON.stringify((r.data.providers ?? []).map((p) => p.slug)));
const cfgNoDead = JSON.parse(readFileSync(`${ROOT}/state/config.json`, 'utf8'));
ok('the refused add never reached the config', !cfgNoDead.providers.some((p) => p.slug === 'mock-dead'), '');
// an auth-shaped refusal: the provider stands broken, the ask opens
r = await call('/providers', { method: 'POST', token: op, body: { slug: 'mock-auth', baseUrl: 'https://auth.example/v1' } });
ok('a 401 listing stands the provider broken', r.status === 401 && /refused/.test(r.data.error), `${r.status} ${r.data.error ?? ''}`);
r = await call('/models', { token: op });
const authCard = (r.data.providers ?? []).find((p) => p.slug === 'mock-auth');
ok('the broken card carries the probe record (the ask)', authCard?.phase === 'none' && authCard?.probe?.outcome === 'auth' && authCard?.hasKey === false, JSON.stringify(authCard?.probe ?? null));
// the key path: checked on reception, saved on success
r = await call('/providers/mock-auth/auth', { method: 'POST', token: op, body: { apiKey: 'sk-mock' } });
ok('a working key lands (probe-then-save)', r.status === 200 && r.data.models > 0, JSON.stringify(r.data));
const cfgKeyed = JSON.parse(readFileSync(`${ROOT}/state/config.json`, 'utf8'));
ok('the successful key saved', cfgKeyed.providers.find((p) => p.slug === 'mock-auth')?.apiKey === 'sk-mock', '');
r = await call('/models', { token: op });
ok('the keyed card reads working', (r.data.providers ?? []).find((p) => p.slug === 'mock-auth')?.probe?.outcome === 'ok', '');
// a key that still meets the refusal is never saved
r = await call('/providers', { method: 'POST', token: op, body: { slug: 'mock-lock', baseUrl: 'https://lock.example/v1' } });
ok('the locked provider stands broken too', r.status === 401 && /refused/.test(r.data.error), `${r.status} ${r.data.error ?? ''}`);
r = await call('/providers/mock-lock/auth', { method: 'POST', token: op, body: { apiKey: 'sk-nope' } });
ok('a refused key is not saved (the ask repeats)', r.status === 401 && /refuses every listing/.test(r.data.error), `${r.status} ${r.data.error ?? ''}`);
const cfgLock = JSON.parse(readFileSync(`${ROOT}/state/config.json`, 'utf8'));
ok('the failed key never reached the config', cfgLock.providers.find((p) => p.slug === 'mock-lock')?.apiKey === undefined, '');
// the key removal: the control for a provider gone public (or the
// first half of a replacement -- the ask re-opens on the 401)
r = await call('/providers/mock-auth/auth', { method: 'DELETE', token: op, body: {} });
ok('the key removes', r.status === 200, JSON.stringify(r.data));
const cfgUnkeyed = JSON.parse(readFileSync(`${ROOT}/state/config.json`, 'utf8'));
ok('the key left the config', cfgUnkeyed.providers.find((p) => p.slug === 'mock-auth')?.apiKey === undefined, '');
r = await call('/models', { token: op });
ok('the keyless probe re-met the 401 (the ask re-opened)', (r.data.providers ?? []).find((p) => p.slug === 'mock-auth')?.probe?.outcome === 'auth', '');
r = await call('/providers/mock-lock/auth', { method: 'DELETE', token: op, body: {} });
ok('removing a missing key refuses', r.status === 404, `${r.status}`);
r = await call(`/providers/${encodeURIComponent('opencode/free')}/auth`, { method: 'DELETE', token: op, body: {} });
ok('the o/f singleton never loses a key it never had', r.status === 403 && /anonymous/.test(r.data.error), r.data.error ?? '');
// the machine's fixtures leave before the later counts
for (const slug of ['mock-auth', 'mock-lock']) {
await call(`/providers/${slug}`, { method: 'DELETE', token: op, body: {} });
}
r = await call('/models', { token: op });
ok('the fixtures cleaned up', !(r.data.providers ?? []).some((p) => p.slug === 'mock-auth' || p.slug === 'mock-lock'), '');
}
ok('refine applied', reg.data.job?.state === 'applied', JSON.stringify(reg.data.job ?? null));
ok('the refine meter closed its steps', reg.data.job?.steps?.total === 5 && reg.data.job?.steps?.done === 5,
JSON.stringify(reg.data.job?.steps ?? null));
ok('the refine receipt logged every battery and the curator',
(reg.data.job?.lines ?? []).length === 4
&& reg.data.job.lines.some((l) => l.includes('mock: reasoning deep'))
&& reg.data.job.lines.some((l) => l.includes('mock-cheap: reasoning standard'))
&& reg.data.job.lines.some((l) => l.includes('curator (mock-tie): curated')),
JSON.stringify(reg.data.job?.lines ?? 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));
ok('the effort probe: measured ladders and the max-mean defaults',
reg.data.models.some((m) => m.id === 'mock' && m.effortDefault === 'max' && m.efforts?.max === 500 && m.efforts?.none === 0)
&& reg.data.models.some((m) => m.id === 'mock-cheap' && m.effortDefault === 'high' && m.efforts?.max === undefined),
JSON.stringify(reg.data.models.filter((m) => m.efforts).map((m) => ({ id: m.id, effortDefault: m.effortDefault }))));
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' } });
r = await call('/runs', { method: 'POST', token: op, body: { package: 'la-caramba', pc: 'Smokina', name: 'Smoke Story', spec: { provider: 'mock-a', model: 'mock', effort: 'max' } } });
ok('create run', r.status === 200 && !!r.data.run?.id, r.data.error ?? r.data.run?.id);
const runId = r.data.run?.id;
ok('owner stamped', meta(runId).owner === opId);
@@ -222,7 +369,7 @@ 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, the measured effort default included)',
!!viaMsg && viaMsg.via.model === 'mock' && JSON.stringify(viaMsg.via.params) === '{"reasoning_effort":"max"}', JSON.stringify(viaMsg?.via ?? null));
!!viaMsg && viaMsg.via.model === 'mock' && viaMsg.via.provider === 'mock-a' && JSON.stringify(viaMsg.via.params) === '{"reasoning_effort":"max"}', 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(`<status>cuffed, belted, naked, barefoot, ${pickedStatus}</status>`)), pickedStatus);
@@ -424,49 +571,50 @@ ok('the log keeps her words verbatim (the over-cap emission is intact)',
r = await call(`/runs/${runId}/turn`, { method: 'POST', token: op, body: { line: '( ooc with an edit )', status: ['x'] } });
ok('an override cannot ride an OOC turn', r.status === 400 && /OOC/.test(r.data.error), r.data.error ?? '');
// 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: { reasoning_effort: 'low' } } } });
ok('the effort knob sets', r.status === 200 && r.data.params.player?.reasoning_effort === 'low', JSON.stringify(r.data.params));
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: ash, body: { params: { player: { reasoning_effort: 'turbo' } } } });
// 12b. models: the run's spec picks {provider, model, effort},
// registry-gated, owner-only. The per-run params layer is gone (GM,
// 2026-11-18): the <mind> verb is the only sampling source, per-turn
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: ash, body: { player: { provider: 'mock-b', model: 'mock-cheap', effort: 'low' }, housekeeper: { provider: 'mock-a', model: 'mock-tie', effort: 'max' } } });
ok('set spec picks',
r.status === 200 && JSON.stringify(r.data.models.player) === '{"provider":"mock-b","model":"mock-cheap","effort":"low"}'
&& JSON.stringify(r.data.models.housekeeper) === '{"provider":"mock-a","model":"mock-tie","effort":"max"}',
JSON.stringify(r.data));
ok('the specs are stamped in run.json', JSON.stringify(meta(forkId).models?.player) === '{"provider":"mock-b","model":"mock-cheap","effort":"low"}');
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: ash, body: { player: { provider: 'mock-b', model: 'mock-cheap', effort: 'turbo' } } });
ok('a bogus effort level refuses', r.status === 400 && /must be one of/.test(r.data.error), r.data.error ?? '');
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: ash, body: { params: { player: { reasoning_effort: null } } } });
ok('a null effort clears back to the measured default', r.status === 200 && r.data.params.player?.reasoning_effort === undefined, JSON.stringify(r.data.params));
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: ash, body: { params: { player: { reasoning_effort: 'low' } } } });
ok('the effort override stays for the turn', r.status === 200 && r.data.params.player?.reasoning_effort === 'low', 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: { player: { provider: 'nope', model: 'x', effort: 'low' } } });
ok('an unconfigured provider refuses', r.status === 400 && /no provider named/.test(r.data.error), r.data.error ?? '');
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: ash, body: { player: { provider: 'mock-b', model: 'not-a-model', effort: 'low' } } });
ok('a model outside the registry refuses', r.status === 400 && /not usable/.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' } });
ok('clear a role (the housekeeper inherits the player provider\'s default)',
r.status === 200 && r.data.models.housekeeper === undefined && r.data.modelState?.housekeeper?.ok === true && r.data.modelState.housekeeper.inherited === true,
JSON.stringify(r.data.modelState ?? null));
r = await call(`/runs/${forkId}/model`, { method: 'POST', token: op, body: { player: { provider: 'mock-a', model: 'mock', effort: 'max' } } });
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 && 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 -- the run's knob under the mind layer (her restated mind
// rides over the run layer, the layering the tunables round built)
ok('detail exposes the picks, their health, and the provider defaults',
JSON.stringify(r.data.run.models?.player) === '{"provider":"mock-b","model":"mock-cheap","effort":"low"}'
&& r.data.run.modelState?.player?.ok === true
&& Array.isArray(r.data.run.providerDefaults) && r.data.run.providerDefaults.length >= 2,
JSON.stringify({ models: r.data.run.models, modelState: r.data.run.modelState }));
// a turn on the re-picked run: the recording proves what was sent --
// the spec's effort riding under the mind layer (her restated mind is
// the only params source, layered over nothing)
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 ?? '');
ok('gm turn on the fork (post-picks)', 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 under the mind layer',
!!viaTurn?.via && viaTurn.via.model === 'mock' && viaTurn.via.params.max_tokens === 4096 && viaTurn.via.params.temperature === 1.2
&& viaTurn.via.params.reasoning_effort === 'low',
ok('the recorded request carries the spec under the mind layer',
!!viaTurn?.via && viaTurn.via.model === 'mock-cheap' && viaTurn.via.provider === 'mock-b'
&& viaTurn.via.params.temperature === 1.2 && viaTurn.via.params.reasoning_effort === 'low',
JSON.stringify(viaTurn?.via ?? null));
r = await call('/models', { token: ash });
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));
ok('model listing (the per-provider registry)',
r.status === 200 && (r.data.providers ?? []).some((p) => p.slug === 'mock-a' && p.phase === 'refined' && p.models.some((m) => m.id === 'mock' && m.label === 'Mock')),
JSON.stringify((r.data.providers ?? []).map((p) => [p.slug, p.phase])));
// 13. ash saves a draft as a package (save-package is a draft act --
// the played-run refusal is checked at the end)
@@ -504,7 +652,7 @@ ok('user package survives, ownerless', !!saved2 && saved2.owner === null && save
r = await call(`/runs/${forkId}/fork`, { method: 'POST', token: op, body: {} });
ok('op forks the ownerless run', r.status === 200 && !!r.data.run, r.data.error ?? r.data.run);
const reforkId = r.data.run;
ok('fork carries the models', meta(reforkId).models?.player === 'mock');
ok('fork carries the model specs', JSON.stringify(meta(reforkId).models?.player) === '{"provider":"mock-b","model":"mock-cheap","effort":"low"}');
// 16. users list, self-revoke refused
r = await call('/users', { token: op });
@@ -733,6 +881,43 @@ ok('the sheet crossed the boundary (the note feeds the new session\'s scan)', JS
ok('session 5 renders the sheet chunk from the carried note', chunk?.content === '<sheet>{}</sheet>', chunk?.content ?? 'no chunk');
}
// 23b. the sheet's transport at the lint (the box round, GM, 2026-11-19):
// the record is the only channel, the tag is view machinery -- the
// authored gate names every wrong shape, the boundary note is checked
// on both kinds, and her carried emission stays legitimate history
{
const la = (a) => lintCarryover(a, { authored: true });
ok('lint: a scalar sheet record is named', la([
{ t: 'msg', m: { role: 'assistant', content: 'x' } },
{ t: 'msg', m: { role: 'user', content: 'y' }, sheet: 'nope' },
]).some((e) => e.includes('sheet record must be a JSON object')), '');
ok('lint: an array sheet record is named', la([
{ t: 'msg', m: { role: 'assistant', content: 'x' } },
{ t: 'msg', m: { role: 'user', content: 'y' }, sheet: ['nope'] },
]).some((e) => e.includes('sheet record must be a JSON object')), '');
ok('lint: a sheet record on her turn is named', la([
{ t: 'msg', m: { role: 'assistant', content: 'x' }, sheet: {} },
]).some((e) => e.includes('rides GM turns only')), '');
ok('lint: the tag in her authored turn is named', la([
{ t: 'msg', m: { role: 'assistant', content: 'x <sheet>{}</sheet>' } },
]).some((e) => e.includes('never authored')), '');
ok('lint: the tag in GM prose is named', la([
{ t: 'msg', m: { role: 'assistant', content: 'x' } },
{ t: 'msg', m: { role: 'user', content: 'y <sheet>{}</sheet>' } },
]).some((e) => e.includes('never authored')), '');
ok('lint: a good sheet record passes clean', la([
{ t: 'msg', m: { role: 'assistant', content: 'x' } },
{ t: 'msg', m: { role: 'user', content: 'y' }, sheet: { GP: 0 } },
]).length === 0, '');
ok('lint: a scalar sheet on a boundary note is named (both kinds)', lintCarryover([
{ t: 'note', kind: 'state', status: [], sheet: 7 },
], { authored: false }).some((e) => e.includes('state.sheet must be a JSON object')), '');
ok('lint: her emitted sheet in a carried tail is legitimate history', lintCarryover([
{ t: 'msg', m: { role: 'user', content: 'y' } },
{ t: 'msg', m: { role: 'assistant', content: 'x <sheet>{"gp": 99}</sheet>' } },
], { authored: false }).length === 0, '');
}
// 24. the rewind (GM, 2026-11-17): the GM's take-back. The send that
// carries rewind replaces the target GM turn -- the target and
// everything after it leave the log (physical truncation; fork is the
@@ -790,6 +975,115 @@ ok('the sheet crossed the boundary (the note feeds the new session\'s scan)', JS
ok('the story drops the cut range', r.data.sessions.every((s) => s.turns.every((t) => !/Rewind battery two/.test(t.text))), 'the dropped prose survived in the story');
}
// 24b. invalidation and the removal guard (GM, 2026-11-18): a run's
// picks are settings the run came with -- when the server stops
// carrying them (the provider removed), the run blocks until the GM
// sets them up again; and the o/f singleton is removable only while
// another provider stands in its place (the empty list is an error
// state; the fallback is what keeps it unreachable)
{
// a custom provider, a run riding it
r = await call('/providers', { method: 'POST', token: op, body: { slug: 'mock-c', baseUrl: 'https://mock.c.example/v1' } });
ok('a custom provider adds and discovers', r.status === 200 && r.data.models > 0, JSON.stringify(r.data));
// the failures-never-cache rule (GM, 2026-11-19): a failure is the
// absence of a measurement, not a measurement -- mock-fail lands
// its verdict fresh at every refine, while the passing models
// persist from the cache
r = await call('/providers/mock-c/default', { method: 'POST', token: op, body: { model: 'mock', effort: 'max' } });
ok('the custom provider selects its curator', r.status === 200, r.data.error ?? '');
r = await call('/providers/mock-c/refine', { method: 'POST', token: op, body: {} });
ok('the custom provider refines', r.status === 200, r.data.error ?? '');
let jobCC = null;
for (let i = 0; i < 40; i++) {
r = await call('/models', { token: op });
jobCC = (r.data.providers ?? []).find((p) => p.slug === 'mock-c')?.job ?? null;
if (jobCC?.state !== 'running') break;
await new Promise((res) => setTimeout(res, 100));
}
ok('the mock-c refine applied', jobCC?.state === 'applied', JSON.stringify(jobCC?.reason ?? null));
ok('the failing model landed its verdict with the no-cache marker',
(jobCC?.lines ?? []).some((l) => l.includes('mock-fail: failed the tool probe') && l.includes('never cached')),
JSON.stringify(jobCC?.lines ?? null));
const cacheFail = JSON.parse(readFileSync(`${ROOT}/state/refine-cache.json`, 'utf8'));
ok('the failure is absent from the cache',
!Object.keys(cacheFail.entries ?? {}).some((k) => k.startsWith('mock-c::mock-fail::')),
JSON.stringify(Object.keys(cacheFail.entries ?? {}).filter((k) => k.startsWith('mock-c::'))));
r = await call('/providers/mock-c/refine', { method: 'POST', token: op, body: {} });
ok('the re-refine starts', r.status === 200, r.data.error ?? '');
for (let i = 0; i < 40; i++) {
r = await call('/models', { token: op });
jobCC = (r.data.providers ?? []).find((p) => p.slug === 'mock-c')?.job ?? null;
if (jobCC?.state !== 'running') break;
await new Promise((res) => setTimeout(res, 100));
}
ok('the re-refine re-probed the failure (never from cache)',
(jobCC?.lines ?? []).some((l) => l.includes('mock-fail: failed the tool probe'))
&& !(jobCC?.lines ?? []).some((l) => l.includes('mock-fail: from cache')),
JSON.stringify(jobCC?.lines ?? null));
ok('the passing models served from cache on the re-refine',
(jobCC?.lines ?? []).filter((l) => l.includes('from cache')).length === 3,
JSON.stringify(jobCC?.lines ?? null));
const failRun = await call('/runs', { method: 'POST', token: op, body: { package: 'la-caramba', pc: 'Failcheck', name: 'Fail Check', spec: { provider: 'mock-c', model: 'mock-fail', effort: 'max' } } });
ok('the failing model is not selectable (the registry gates it)', failRun.status === 400, 'a failed model was selectable');
if (failRun.status === 200) await call(`/runs/${failRun.data.run.id}`, { method: 'DELETE', token: op, body: {} }); // never expected -- the backstop
r = await call('/runs', { token: op });
ok('the refused create left no orphan run (validate before anything lands)', !(r.data ?? []).some((x) => x.pc === 'Failcheck'), 'an orphan dir survived the refusal');
r = await call(`/runs/${reforkId}/model`, { method: 'POST', token: op, body: { player: { provider: 'mock-c', model: 'mock', effort: 'high' } } });
ok('the refork re-picks onto the custom provider', r.status === 200, r.data.error ?? '');
r = await call(`/runs/${reforkId}/turn`, { method: 'POST', token: op, body: { line: '*Riding the custom provider.*' } });
ok('the turn rides the custom provider', r.status === 200, r.data.error ?? '');
// the removal: the run invalidates, loudly, on every surface
r = await call('/providers/mock-c', { method: 'DELETE', token: op, body: {} });
ok('the custom provider removes', r.status === 200, r.data.error ?? '');
r = await call(`/runs/${reforkId}`, { token: op });
ok('the run\'s health carries the note (the invalidation surface)',
r.data.run.modelState?.player?.ok === false && /no longer configured/.test(r.data.run.modelState.player.note ?? ''),
JSON.stringify(r.data.run.modelState ?? null));
r = await call(`/runs/${reforkId}/turn`, { method: 'POST', token: op, body: { line: '*No.*' } });
ok('the send refuses with the same note', r.status === 409 && /no longer configured/.test(r.data.error), r.data.error ?? '');
const goneFile = JSON.parse(readFileSync(`${ROOT}/state/models.json`, 'utf8'));
ok('the provider\'s registry section went with it', goneFile.providers?.['mock-c'] === undefined, JSON.stringify(Object.keys(goneFile.providers ?? {})));
const goneCache = JSON.parse(readFileSync(`${ROOT}/state/refine-cache.json`, 'utf8'));
ok('the provider\'s cache entries went with it', !Object.keys(goneCache.entries ?? {}).some((k) => k.startsWith('mock-c::')), JSON.stringify(Object.keys(goneCache.entries ?? {})));
// the GM sets it up again: the run unblocks
r = await call(`/runs/${reforkId}/model`, { method: 'POST', token: op, body: { player: { provider: 'mock-a', model: 'mock', effort: 'max' } } });
ok('the re-pick lands', r.status === 200, r.data.error ?? '');
r = await call(`/runs/${reforkId}/turn`, { method: 'POST', token: op, body: { line: '*Back on the stand-ins.*' } });
ok('the run plays again after the re-pick', r.status === 200, r.data.error ?? '');
// the removal guard: pare down to the singleton, then it holds
r = await call('/providers/mock-b', { method: 'DELETE', token: op, body: {} });
ok('mock-b removes (a stand-in, not the fallback)', r.status === 200, r.data.error ?? '');
r = await call('/providers/mock-a', { method: 'DELETE', token: op, body: {} });
ok('mock-a removes', r.status === 200, r.data.error ?? '');
r = await call(`/providers/${encodeURIComponent('opencode/free')}`, { method: 'DELETE', token: op, body: {} });
ok('the singleton holds while it is all that stands', r.status === 409 && /fallback/.test(r.data.error), r.data.error ?? '');
// restore the mock world for the restart checks: re-add, rediscover,
// re-select, re-refine (fresh -- the cache purged with the provider)
r = await call('/providers', { method: 'POST', token: op, body: { slug: 'mock-a', baseUrl: 'https://mock.a.example/v1' } });
ok('mock-a re-adds', r.status === 200, r.data.error ?? '');
r = await call('/providers', { method: 'POST', token: op, body: { slug: 'mock-b', baseUrl: 'https://mock.b.example/v1' } });
ok('mock-b re-adds', r.status === 200, r.data.error ?? '');
r = await call('/providers/mock-a/default', { method: 'POST', token: op, body: { model: 'mock', effort: 'max' } });
ok('mock-a re-selects', r.status === 200, r.data.error ?? '');
r = await call('/providers/mock-b/default', { method: 'POST', token: op, body: { model: 'mock-cheap', effort: 'high' } });
ok('mock-b re-selects', r.status === 200, r.data.error ?? '');
r = await call('/providers/mock-a/refine', { method: 'POST', token: op, body: {} });
ok('mock-a re-refines (fresh probes -- the cache purged)', r.status === 200, r.data.error ?? '');
let jobR = null;
for (let i = 0; i < 40; i++) {
r = await call('/models', { token: op });
jobR = (r.data.providers ?? []).find((p) => p.slug === 'mock-a')?.job ?? null;
if (jobR?.state !== 'running') break;
await new Promise((res) => setTimeout(res, 100));
}
ok('the restored world refined', jobR?.state === 'applied', JSON.stringify(jobR ?? null));
}
console.log(`\nrun ids: source=${runId} draft=${draftId} fork=${forkId} second=${secondId} refork=${reforkId}`);
writeFileSync(TOKEN_FILE, `${op} ${reforkId} ${secondId}`);
console.log(failures ? `\n${failures} FAILURES` : '\nALL PASS');