Repository navigation
test: automated two-subject test for VM demo B (#367 item 3) - #371
Conversation
The automated, GitHub-free rehearsal of the demo's two-user acceptance run, as called for by rossoctl#367 scope item 3. The existing cross-tenant suites prove ownership at handler level with hand-built principals; these files drive the same story end to end over real HTTP with the smoke.sh stand-in (api tokens minted by the control plane's own signing key), which is the shape that catches wiring regressions the handler tests cannot see. packages/control-plane/test/two-subject.test.ts: two minted subjects, disjoint session lists over the wire, cross-owner 404s on GET/DELETE/ token re-mint (indistinguishable from an unknown id), scope enforcement against real signed tokens, and the exchange refusing a session token whose subject is not the record's owner. packages/knative-server/test/two-subject-turn.test.ts: the demo's negative verbatim — user 1's valid session token posted to user 2's session id is 400 session_mismatch, on the JSON and SSE branches both, with no turn executed and the credential exchange never consulted; each subject driving their own session is the sanity around it. No production code changed. Existing suites already cover the handler-level cases (route-authz-enumeration, handlers-sessions, exchange); the audit that preceded this found no ownership bug. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
mrsabath
left a comment
There was a problem hiding this comment.
Test-only PR, no production code touched. I verified the two load-bearing claims against source rather than taking the description's word:
- "the refusal happens before the exchange is consulted" holds:
turn-auth.ts:220throwssession_mismatch, andexchange(presented, deps)is not reached until line 229. SincecpCallsis counted by the scripted control plane itself,expect(cpCalls).toHaveLength(0)cannot pass vacuously — the test proves what it claims. - "cross-owner 404 is indistinguishable from unknown-id" matches
assertOwner(handlers.ts:89-92), which collapses not-found and not-owned into onesession_not_found.
The suites are well-built: fixtures assert their own preconditions before testing the negative (two-subject.test.ts:185,187), each negative is bracketed by a sanity test so a blanket-rejection regression cannot pass unnoticed, and notsecret markers are on every literal that needs one. Two non-blocking test-hygiene notes inline.
On the failing proto check
Pre-existing on main, not caused by this PR. The same job fails at the same step 10 ("Build and test remote-worker") on this PR's own base commit 73f1bf41 — run 36659151151, a push to main, before this branch existed. proto is Go/protobuf work; this PR adds two .ts files and zero Go/proto files.
It should not block on the merits, but mergeable_state is blocked, so main's proto job needs fixing (or the gate overriding) before this can land.
Areas reviewed: TypeScript/tests, CI
Commits: 1, signed off, DCO passing
CI status: 12 pass, 1 fail (inherited from main)
| const created = await createSession(ALICE, 'a-1'); | ||
| const rec = await d.index.get('a-1'); | ||
| expect(rec?.owner).toBe(ALICE); // the fixture is what we think it is before we break it | ||
| await d.index.create({ ...rec!, owner: BOB }); |
There was a problem hiding this comment.
d.index.create({ ...rec!, owner: BOB }) re-points the hash's owner, which is what assertOwner reads via index.get() — so the refusal asserted below is sound and tests the right thing.
But create() also zAdds to the new owner's index (ownership.ts:117-119) without zRem-ing the old one, so after this line a-1 sits in both owner:github:1234 and owner:github:9999 sorted sets. Production never reaches that state: a session is created once, under one owner.
This does not invalidate the test — assertOwner goes through the hash, not the zset. It is a hazard for the next reader, who might add a listByOwner assertion after the re-point and get a puzzling result. Worth either a one-line note that the zset is deliberately left stale, or fixing both sides in the fake.
Suggestion, not blocking.
There was a problem hiding this comment.
Done in cb60620: added the note at the re-point, including the pointer not to add a listByOwner assertion below it without fixing the fake's zset bookkeeping first. Left the fake untouched — the comment is the contract here, and touching fake-redis.ts would bleed into the five suites that share it.
| // proves the refusal happens BEFORE the credential exchange is consulted. | ||
|
|
||
| vi.mock('@moca/harness/run-turn', () => ({ | ||
| runTurn: vi.fn(async () => ({ sessionId: 'sid-1', response: 'ok', stopReason: 'end_turn' })), |
There was a problem hiding this comment.
Both mocks (this line and executeTurn on the next) return a hardcoded sessionId: 'sid-1', but every test in the file drives a-1 or b-1.
Harmless today, since no assertion reads the returned sessionId — the 200-path tests check upstreamCredential and the call counts instead. Returning the driven sid (or expect.anything()) would stop a future assertion on the response body from being quietly wrong against a value no test actually uses.
Nit.
There was a problem hiding this comment.
Done in cb60620: both mocks now echo the sid the caller drove (runTurn takes (prompt, sessionId?, config?), executeTurn the input object), with a 'unset' fallback rather than a wrong value.
There was a problem hiding this comment.
Done in cb60620: both mocks now echo the sid the caller drove (runTurn takes (prompt, sessionId?, config?), executeTurn the input object), with an 'unset' fallback rather than a wrong value.
…em 3) Two non-blocking hygiene notes from PR rossoctl#371 review: - two-subject.test.ts: document why the owner re-point deliberately leaves the zset stale (create zAdds without zRem-ing; the exchange reads the hash, not listByOwner) so the next reader does not add a listByOwner assertion below the re-point and get a puzzling result. - two-subject-turn.test.ts: the runTurn/executeTurn mocks echo the sid the caller drove instead of a hardcoded 'sid-1' no test uses, so a future assertion on a response body cannot be quietly wrong. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Part of #367 (VM demo B, epic #370). This PR covers scope item 3 only: the automated two-subject test that runs without GitHub.
What
An audit of the existing suites found every handler-level ownership property already covered (disjoint lists, cross-owner 404s, the exchange's owner check,
session_mismatch), but nothing drove the two-subject story end to end over HTTP the waydeploy/compose/smoke.shdoes for one subject. These two files add exactly that integration shape — api tokens minted by the control plane's own signing key, per the smoke.sh stand-in named in the issue:packages/control-plane/test/two-subject.test.ts(7 tests, real HTTP againststartControlPlane): two minted subjects; disjoint session lists over the wire; cross-owner 404 on GET/DELETE/token re-mint, indistinguishable from an unknown id; scope enforcement against real signed tokens; the exchange refusing a session token whose subject is not the record's owner.packages/knative-server/test/two-subject-turn.test.ts(4 tests, real HTTP againststartServer): the demo's negative verbatim — user 1's valid session token posted to user 2's session id is 400session_mismatchon both the JSON and SSE branches, with no turn executed and the credential exchange never consulted; sanity tests prove each subject drives their own session fine.No production code changed; no existing suites restructured (the #368 session may be editing neighbors).
Audit result
No ownership bug found.
assertOwner(handlers.ts:72-90),listByOwnerscoping, the exchange's owner re-check, andresolveTurnAuth's sid binding are all sound; the gap was purely integration coverage.Test results
control-plane: 385 passed, 3 skippedknative-server: 412 passedmake typecheckandmake lintclean🤖 Generated with Claude Code