test(tool-bash): make the notice fake's agentId differ from its session token (Codex review)

Codex flagged (C) a test-sufficiency gap: the completion-notice fake had
`agent.id === session.header.id`, so the notice test could not distinguish the
code matching on the registry KEY (agentId) from matching on the session TOKEN
(session.header.id). The production code deliberately matches on
`session.header.id` because a config agent has `agentId !== sessionId` — but a
same-value fake passes either way (the "hits the line but not the scenario"
trap).

Give the registered fake a distinct agentId (`agent-<sessionId>`). Verified the
notice test now FAILS if the match is regressed to `a.id` and passes on
`a.session.header.id` — so it actually pins the discriminating behavior.
This commit is contained in:
Tianyi Cui
2026-06-20 09:57:05 +08:00
parent b58f1dd5c8
commit be6cf4510b

View File

@@ -37,7 +37,13 @@ async function setup() {
*/
const fakeAgentDisposers = new Map<Context, (() => void)[]>()
function registerFakeAgent(ctx: Context, sessionId: string, inject: (...args: unknown[]) => void): Agent {
const agent = { id: sessionId, inject, session: { header: { version: 1, id: sessionId, createdAt: 0 } } } as unknown as Agent
// The registry KEY (agent.id) is deliberately DIFFERENT from the session
// token (session.header.id) — a config agent has `agentId !== sessionId`. The
// owner token IS the session id, so the notice path must find the agent by
// `session.header.id`, NOT the registry key. Using distinct values here makes
// the test fail if a regression matched on the wrong field (a same-value fake
// would pass either way — the "hits the line but not the scenario" trap).
const agent = { id: `agent-${sessionId}`, inject, session: { header: { version: 1, id: sessionId, createdAt: 0 } } } as unknown as Agent
const dispose = ctx.agents.register(agent)
const list = fakeAgentDisposers.get(ctx) ?? []
list.push(dispose)