fix(coding-agent/acp): narrow CreateElicitationRequest variant before reading sessionId in live-getter test
`CreateElicitationRequest` is a discriminated union — even after
narrowing on `mode === "form"`, both `ElicitationRequestScope` (no
`sessionId`) and `ElicitationSessionScope` (with `sessionId`)
remain in the union. The new live-getter regression test was reading
`calls[N]!.sessionId` directly, which CI tsgo rejected with TS2339.
Per-element `if (!call || call.mode !== "form" || !("sessionId"
in call))` narrows to the session-scoped variant. Spelled three times
because loop-style narrows don't propagate to the assertions below.
Matches the discriminator pattern used in the older 'translates select'
test at line ~927.
Co-Authored-By: omp <noreply@oh-my-pi.dev>
This commit is contained in:
@@ -1170,12 +1170,21 @@ describe("ACP agent", () => {
|
||||
await ctx.input("Name?");
|
||||
|
||||
expect(calls).toHaveLength(3);
|
||||
if (calls[0]!.mode !== "form" || calls[1]!.mode !== "form" || calls[2]!.mode !== "form") {
|
||||
throw new Error("expected form-mode elicitations");
|
||||
}
|
||||
expect(calls[0]!.sessionId).toBe("session-before-switch");
|
||||
expect(calls[1]!.sessionId).toBe("session-after-switch");
|
||||
expect(calls[2]!.sessionId).toBe("session-after-switch");
|
||||
// Each call must be a session-scoped form elicitation. Spelled as three
|
||||
// separate narrows because `mode === "form"` alone leaves both
|
||||
// `ElicitationRequestScope` and `ElicitationSessionScope` in the union —
|
||||
// only `"sessionId" in call` picks the session-scoped variant — and
|
||||
// loop-style narrows don't propagate to the assertions below.
|
||||
const [first, second, third] = calls;
|
||||
if (!first || first.mode !== "form" || !("sessionId" in first))
|
||||
throw new Error("first call missing sessionId");
|
||||
if (!second || second.mode !== "form" || !("sessionId" in second))
|
||||
throw new Error("second call missing sessionId");
|
||||
if (!third || third.mode !== "form" || !("sessionId" in third))
|
||||
throw new Error("third call missing sessionId");
|
||||
expect(first.sessionId).toBe("session-before-switch");
|
||||
expect(second.sessionId).toBe("session-after-switch");
|
||||
expect(third.sessionId).toBe("session-after-switch");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user