Files
interactive-story/frontend/src/test/helpers.jsx
T
JesseMarkowitzandClaude Opus 5 ef25b0a876 Stop re-reading the whole prompt every turn, and let a lost run carry on
M01, the hundred-turn campaign, is the one REQUIRED test still
outstanding. Everything here is about it finishing, and being worth
believing when it does. No requirement changed, no acceptance test was
retired or relaxed, and M11 §P.1's "no performance requirement" still
stands: what changed is the cost of a turn, not what a turn contains.

An inference server caches a prompt by its prefix. The history window
gave up its oldest action every turn, which changed the prompt near the
front and threw that cache away, so nearly the whole prompt was
reprocessed every turn however little had actually changed. The window
now snaps the oldest depth to a block and holds it, stepping every few
turns. Measured on real builder output at an 8,192-token budget: 124.0s
per turn against 362.4s. The cost is history depth, bounded by
TRIM_FRACTION at a quarter of the window, which is the dial between
recent history and speed.

A run that dies no longer starts again from turn one. m11_long_run
checkpoints resume.json after the prologue, after every scheduled step
and after every turn, and --resume reattaches to the same campaign. A
finished run deletes it, so the file's presence means an unfinished run
and starting fresh over one is refused. The model timeout is an option
rather than a hard-coded 600s, a turn that overruns is a failed turn
instead of an unhandled exception that ends the run with no summary,
and a run that has stopped producing turns writes its evidence and
stops.

Two checks could not fail. M04's planted clue went into an add_fact
"detail" key that the event does not define, so it was dropped and
fact_still_in_state could never be true; it is now in "value" and
proved at turn one, which stops a run measuring nothing for hours.
m11_browser degraded silently without a narrator into two failures that
read exactly like a product regression, and now requires one, with
--no-narrator as an explicit opt-out that marks the run partial.

Window discovery speaks Ollama's native API, so against vLLM or
llama.cpp's own server the window goes unverified and the budget
uncapped -- M11's own failure mode reached by another route.
context_window_override lets the operator state what they launched the
server with, and is used only where discovery left a hole: a verified
window always wins, so a declaration can lower an unknown ceiling into
existence and never raise a known one. "verified" still means the
server answered, so window_verified in a turn's provenance keeps the
meaning M11's report counts on.

planning/README.md said the M11 tree was staged rather than committed,
in two places; it was committed and signed. Planning package v3.8.

Backend 1,376 passed, 17 skipped, 0 failed; frontend 161; lint and
build clean. Every M11 harness re-run on this tree: browser 38/0/0,
offline 23/0, identity clean, contrast unchanged, recovery 14/0 on a
small bundle. M01 itself has not been run.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E9LiyxBxnMTXV2wRjdyDGB
2026-09-10 06:13:55 -04:00

112 lines
3.4 KiB
React

/* Shared fixtures for the component tests.
*
* `renderWith` supplies the two contexts every screen needs — a router and the
* model status — so a test can render one component rather than the whole app.
* The model status is faked at the `api` boundary rather than by mocking the
* hook, so the provider's own logic (which of the five states a given settings
* row and connection result produce) is exercised by the tests that depend on
* it instead of being assumed.
*/
import { act, render } from '@testing-library/react'
import { MemoryRouter } from 'react-router-dom'
import { vi } from 'vitest'
import { ModelStatusProvider } from '../modelStatus'
import { ToastHost } from '../components'
/** A settings row with the shape the real API returns. */
export const SETTINGS = {
endpoint_url: 'http://127.0.0.1:11434/v1',
model: 'qwen2.5:3b-instruct',
api_mode: 'chat',
temperature: 0.2,
max_output_tokens: 400,
context_token_budget: 8000,
model_timeout_seconds: 600,
// Null is the shipped default: nobody has declared a window, so the server is
// asked for one. See `contextwindow.py`.
context_window_override: null,
summary_model: '',
embedding_model: 'nomic-embed-text',
memory_bank_capacity: 200,
memory_top_k: 5,
narrator_prompt: 'You are the narrator.',
}
/**
* Points `api.getSettings` and `api.testConnection` at a given world.
*
* `models` defaults to a listing containing the configured model, which is the
* ordinary "everything works" case.
*/
export function mockModelStatus(api, {
settings = SETTINGS,
ok = true,
models = ['qwen2.5:3b-instruct', 'nomic-embed-text'],
detail = '',
warning = '',
} = {}) {
vi.spyOn(api, 'getSettings').mockResolvedValue(settings)
vi.spyOn(api, 'testConnection').mockResolvedValue(
ok ? { ok: true, models, ...(warning ? { warning } : {}) } : { ok: false, detail },
)
}
/**
* Renders inside the router and the model-status provider.
*
* Async because the provider fetches settings and runs a connection test on
* mount; awaiting here lets those promises settle inside `act`, so a test sees
* the resolved status rather than "checking" and React emits no warning about
* an unwrapped update.
*/
export async function renderWith(ui, { route = '/' } = {}) {
let view
await act(async () => {
view = render(
<MemoryRouter initialEntries={[route]}>
<ModelStatusProvider>
<ToastHost>{ui}</ToastHost>
</ModelStatusProvider>
</MemoryRouter>,
)
})
return view
}
/**
* An accepted narrator turn, in the shape the actions API returns.
*
* **`ActionOut` carries no `branch_id`, and this must not either.** A fixture
* that supplies one models a payload the server never sends, and it hid a real
* defect: the take pager compared `target.branch_id !== action.branch_id`,
* which against the real payload is always `number !== undefined` and therefore
* always true. With a `branch_id` in the fixture the comparison looked correct
* and the tests passed against broken code.
*/
export function narratorAction(overrides = {}) {
return {
id: 2,
type: 'ai',
text: 'The tavern is warm and loud.',
reasoning: '',
world_changes: null,
take_count: 1,
take_index: 0,
...overrides,
}
}
/** An accepted player turn. */
export function playerAction(overrides = {}) {
return {
id: 1,
type: 'do',
text: 'I walk into the tavern.',
reasoning: '',
take_count: 1,
take_index: 0,
...overrides,
}
}