From d47f55c7fdd216ae6be35c666c4e623e981d26d3 Mon Sep 17 00:00:00 2001 From: David Marshall Date: Thu, 14 May 2026 10:24:21 -0500 Subject: [PATCH] fix(coding-agent/acp): narrow CreateElicitationRequest variant before reading sessionId in live-getter test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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 --- packages/coding-agent/test/acp-agent.test.ts | 21 ++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/coding-agent/test/acp-agent.test.ts b/packages/coding-agent/test/acp-agent.test.ts index 95448af19..d7ada16e9 100644 --- a/packages/coding-agent/test/acp-agent.test.ts +++ b/packages/coding-agent/test/acp-agent.test.ts @@ -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"); }); }); });