test(interactive): a sealed session refuses input on the control endpoint (#6074)
Part of #6074. This PR carries the RED test only; the fix lands after the security design gate on #6074 is approved by a non-author reviewer.
What
prompt, steer and follow_up sent to a TUI session's control endpoint whose session file is sealed (moved away, or a copy revoked with move_session revoke, #4004) must answer the same typed refusal the RPC host sends since #5906, before any turn starts:
{"type":"response","command":"prompt","success":false,"error":"This session was moved to ...","errorCode":"session_moved_away","errorData":{"state":"moved"}}
The test pins both halves of that contract: the typed refusal, and that no turn starts (agent_start stays empty) while the session file stays byte-identical.
Why
packages/coding-agent/src/modes/interactive/session-control-rpc-commands.ts admits input through the session's external admission with no ownership check, so the endpoint answered started and the write guard refused the message only later, when the turn tried to persist it. Three consequences:
- A client branching on codes could not tell the session was read-only, so a desktop thread could offer an editor for input that is thrown away (desktop app item 4049, tracked internally).
- A turn started on a session that cannot be written, spending a provider call and surfacing a
transcript_write_failed. - The answer claimed the input had landed.
Tests
packages/coding-agent/test/suite/regressions/6074-interactive-sealed-session-refusal.test.ts
RED on main (9613617994^): 3 of 4 failed, each on the refusal assertion:
AssertionError: expected { id: 'sealed-prompt', …(4) } to match object { command: 'prompt', …(3) }
- "errorCode": "session_moved_away",
- "errorData": { "state": "moved" },
- "success": false,
+ "success": true,
The fourth case (a session this process still owns admits a prompt and starts its turn) passes, so the failure is the seal, not the fixture.
Summary by cubic
Adds a RED test proving the interactive control endpoint must refuse input into a sealed session before any turn starts.
A session whose file was moved away (or revoked via move_session revoke) is read-only, but the endpoint currently admits prompt, steer, and follow_up, answers started, and only the write guard refuses the message later when the turn tries to persist it. The test pins the typed session_moved_away refusal and that no agent_start event fires and the session file stays byte-identical.
- Runs RED on main: 3 of 4 cases fail on the refusal assertion (
successistrue,errorCodeabsent); the owned-session case passes, so the fixture is sound. - Test only; the fix lands after review per #6074.