Skip to content

test: automated two-subject test for VM demo B (#367 item 3) - #371

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:feat/367-vm-demo-b-two-subject-test
Sep 30, 2026
Merged

pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:feat/367-vm-demo-b-two-subject-test

Conversation

@pdettori

Copy link
Copy Markdown
Member

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 way deploy/compose/smoke.sh does 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 against startControlPlane): 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 against startServer): the demo's negative verbatim — user 1's valid session token posted to user 2's session id is 400 session_mismatch on 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), listByOwner scoping, the exchange's owner re-check, and resolveTurnAuth's sid binding are all sound; the gap was purely integration coverage.

Test results

  • New suites: 7/7 and 4/4 green
  • Full control-plane: 385 passed, 3 skipped
  • Full knative-server: 412 passed
  • make typecheck and make lint clean

🤖 Generated with Claude Code

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]>
@pdettori

pdettori commented Sep 30, 2026 •

Copy link
Copy Markdown
Member Author

Implements scope item 3 of #367 (part of #370); items 1 and 2 remain, so the issue stays open until the two-user acceptance run.

@mrsabath mrsabath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:220 throws session_mismatch, and exchange(presented, deps) is not reached until line 229. Since cpCalls is 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 one session_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 });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' })),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants