The TUI and UI integration tests moved under tests/all; comments and step docs name the new paths, and docs/H.2.md and AGENTS.md give the --test all commands.
11 KiB
H.2: P-APP, whole-app parity
P-APP runs one scenario through the whole TypeScript TUI and the whole Rust TUI. Both get the same server responses, events, and keys. P-APP then compares the screens cell by cell at each checkpoint, and compares the requests each side sent (P-REQ). It needs no server process and no drive endpoint (plan 7.2).
parity/scenarios/<step>/<name>.app.ts one scenario, written by hand
│ bun test ./app/scenarios.test.tsx (TS runner, createAppFixture)
▼
parity/fixtures/<step>/<name>.app.json the recording: scenario, requests and responses
parity/fixtures/<step>/<name>/<checkpoint>.json cells, in H.1's fixture format
│ cargo test -p opencode-tui --test all app:: (Rust runner, TestApp over opencode_api::memory)
▼
pass, or a report of the differing cells and requests
TS is the source of truth. Fixtures are committed and regenerated with bun run --cwd packages/cli-rs fixtures. Rust never writes them.
A scenario
A scenario is one small file. E.2, E.6a, E.9a, E.11a, and later steps each add their own files under
parity/scenarios/<step>/. They never edit a shared list: both runners find scenarios by glob.
// parity/scenarios/H.2/session-open.app.ts
import { defineApp, session, user, assistant } from "../../lib/app"
export default defineApp({
width: 100, // default 100
height: 30, // default 30
config: {}, // cli.json `Info`; both sides add `animations: false`
args: { sessionID: "ses_b" }, // or { continue: true }; default: home
routes: [
{ path: "/api/session/ses_b", json: { data: session("ses_b", "Fix the parser") } },
{ path: "/api/session/ses_b/message", json: { data: [assistant("msg_2", "Done."), user("msg_1", "Why?")], cursor: {} } },
],
steps: [
{ checkpoint: "open", until: "Why?", deviation: ["V01-plain-transcript"] },
{ keys: ["ctrl+x", "n"] },
{ event: { type: "session.text.delta", data: { /* … */ } } },
{ type: "hello" },
{ checkpoint: "home", until: "Ask anything", masks: [{ line: "Ask anything….*", reason: "random placeholder" }] },
],
})
routesuse H.3's route shape (parity/lib/fake-server.ts):method(defaultGET),pathwith:namesegments,status, andjson,body, or neither (204). They are matched before the TUI test defaults ofpackages/tui/test/fixture/tui-client.ts, which answer everything else the TS TUI reads at startup. The defaults answer/api/sessionwith an empty list, so a scenario with sessions routes it.args:sessionIDopens a session (TSargs.sessionID, RustRoute::Session);continueis-c.- Steps run in order:
keys: shortcuts in opentui-rust's syntax (KeyEvent::from_shortcut):enter,escape,tab,backspace,space,up,down,left,right,pageup,pagedown, a character, withctrl+,shift+,alt+. TS sends them withmockInputin kitty mode.type: text, one key press per character.click:[x, y], a left press and release at a cell. TS sends it withmockMouse.click, Rust withTestApp::click.event: one/api/eventevent. TS emits it oncreateEventStream; Rust sends it on the in-memory event stream. The stream starts withserver.connectedon both sides, as the TS fixture does.checkpoint: a named screen, compared cell by cell.
- Checkpoint fields:
until: text the TS frame must contain before the capture. Rust waits for it too, but at most 2 s, so a screen Rust does not draw yet still gets compared and reported.masks: cells blanked on both sides before the comparison, each with areason. A mask is a rectangle{ x, y, width, height }or alineregex, which blanks every match on every row. Masks are for nondeterministic text (the random prompt placeholder, durations, relative times). Plan 7.5: a mask over a whole widget needs a deviation file.deviation: a list of names ofparity/deviations/<name>.md, one per row that differs. The checkpoint may then differ: the Rust runner prints a one-line summary and passes (PARITY_VERBOSE=1prints the full report). A difference without a deviation fails, and so does a missing file. A checkpoint that now matches prints a note to remove its deviations.
requests: { deviation }at the top level does the same for P-REQ, with one name.
Scenario data uses fixed IDs and times, so no ID or time normalizer is needed in cells. Helpers in
parity/lib/app.ts (session, user, assistant) build valid wire objects with fixed times.
The recording
parity/fixtures/<step>/<name>.app.json, pretty JSON:
{
"scenario": "H.2/session-open",
"width": 100, "height": 30,
"directory": "/tmp/opencode/packages/tui",
"config": { "animations": false },
"args": { "sessionID": "ses_b" },
"routes": [ … as in the scenario … ],
"steps": [ … as in the scenario; each checkpoint gains "fixture": "H.2/session-open/open" … ],
"requests": {
"writes": [ { "method": "POST", "path": "…", "query": {…}, "body": …, "status": 204 } ],
"reads": [ { "method": "GET", "path": "/api/vcs", "query": {…}, "status": 200, "json": … } ]
}
}
- Each entry holds the request and the response it got (
status, thenjson, ortextandcontentType). - A read is a GET or a plugin RPC named
get(POST /api/rpc/<plugin>/get; the goal footer posts one). Everything else is a write.isReadin the TS runner andis_readinopencode_parity::apphold the rule. readsare sorted by method, path, and query, with duplicates removed. The TS TUI starts many reads at once, so their order is not stable; sorting keeps two replays byte-identical.writeskeep the order in which they were sent.- The event stream is not logged.
directoryis the location the TS fixture serves (tui-client.ts,directory). Rust gets it asDeps.directory.- The one query value that depends on the machine, the
fs/liststartup probe ofprocess.cwd(), is normalized to<cwd>. - Each checkpoint's cells are written to
parity/fixtures/<step>/<name>/<checkpoint>.json, H.1's format, with masked cells blanked as" "in style#00000000 #00000000 0.
The TS runner
parity/app/scenarios.test.tsx makes one bun test case per scenario file. PARITY_SCENARIO=<step>/<name>
selects one. Each case:
- starts
createAppFixture(packages/tui/test/fixture/app.ts) at the scenario size, with the config and args. Its fetch override serves the routes, then a privatecreateFetchfor the defaults, and records each exchange./api/eventis left to the fixture's stream; - awaits
ready, then runs the steps; - at a checkpoint, polls every 30 ms with a 5 s wall-clock deadline, until the frame contains
untiland three polls in a row read the same cells, not only the same characters. Highlighting changes colors after the text shows. A poll that meets a frame in progress (OutputBusy) is skipped. The process runs withTZ=UTC, so dates in the cells are the same on every machine; - stays open until 1.5 s after
ready, so the migration status poll, which starts 1 s after mount (packages/tui/src/component/migration-overlay.tsx:19), is recorded in every scenario; - writes the cell files and the recording.
Replaying a scenario twice must give byte-identical files. That is the step's TS-against-TS proof.
The in-memory transport
opencode_api::memory::Memory implements Transport:
- it serves a list of routes, each with a method, a path pattern, a query, a status, and a body. Routes are tried in order, so the scenario routes come before the recorded reads. A route without a query matches any query. A recorded read matches its exact query first, then by path alone;
/api/eventreturns atext/event-streambody fed by an unbounded channel. Events are scenario data and few, so the channel cannot grow without limit.Memory::emit(json)sends one event. The stream starts withserver.connected;- it logs every request (method, path, decoded query, JSON body). A request no route answers gets a 404,
and the log marks it
unmatched; - it counts requests in flight, so a test can wait until the client is idle.
It knows nothing of scenarios, so other tests can use it as a small fixture server.
The Rust runner
crates/tui/tests/all/app.rs, one test, scenarios, which runs every recording under parity/fixtures/*/
(PARITY_SCENARIO selects one) and fails at the end with every failing scenario's report:
- builds
Memoryfrom the recording's routes, then its reads and writes by exact query, then by path; - mounts the TUI on
TestApp::new(width, height)withopencode_tui::mount(app, Deps { events: true, directory, config, route, continue_ }), the T.1 hook; - runs the steps:
keyswithTestApp::press,typewithTestApp::type_text,clickwithTestApp::click, andeventwithMemory::emit; - at a checkpoint, waits until no request is in flight and two renders 25 ms apart are equal (and
untilshows, for up to 2 s), then compares withopencode_parity::app::compare_checkpoint; - compares P-REQ (
opencode_parity::app::compare_requests):- writes: method, path, and JSON body, in order;
- reads: every Rust read must be answered (
unmatchedfails with the request's name). TS reads that Rust does not send are listed, not failed: the Rust TUI is missing most features in MS1, and each feature step proves its own reads.
opencode_parity::app (in crates/parity/src/app.rs) holds the recording types, masks, and both
comparisons. It does not depend on the TUI, so the parity crate stays a leaf.
Adding a scenario (E.2, E.6a, E.9a, E.11a, …)
- Write
parity/scenarios/<step>/<name>.app.ts. - Record it:
PARITY_SCENARIO=<step>/<name> bun test --cwd packages/cli-rs/parity ./app/scenarios.test.tsx. Run it twice;git statusmust show no change after the second run. - Replay it:
PARITY_SCENARIO=<step>/<name> bun run --cwd packages/cli-rs cargo test -p opencode-tui --test all app::scenarios -- --nocapture. On a difference, the runner writes the Rust cells to$TMPDIR/opencode-parity/<step>/<name>/<checkpoint>.jsonfor a diff against the recorded file. - When a step makes a checkpoint match, remove the deviation names from the scenario. When no scenario names a deviation file any more, delete the file.
Out of scope
- Mouse steps, resize steps, and time steps. A later step adds
mouseandresizewhen it needs them. There is no time step: TS runs withanimations: false, and Rust's clock is manual. - File state (P-FILE). A scenario runs with no config or state roots on the Rust side (
roots: None). The TS fixture uses a fresh temporary state directory.