From 188bbe92e5e34e91901ac7a7fd90cbaae310d7e3 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 21:30:49 +0100 Subject: [PATCH] test: dedupe pi failover warning mock reads --- .../run/failover-observation.test.ts | 56 +++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/agents/pi-embedded-runner/run/failover-observation.test.ts b/src/agents/pi-embedded-runner/run/failover-observation.test.ts index b58529a6de2..0a72503b1db 100644 --- a/src/agents/pi-embedded-runner/run/failover-observation.test.ts +++ b/src/agents/pi-embedded-runner/run/failover-observation.test.ts @@ -24,6 +24,30 @@ function normalizeObservation( }); } +function firstWarnCall(warnSpy: { mock: { calls: unknown[][] } }): unknown[] { + const call = warnSpy.mock.calls[0]; + if (!call) { + throw new Error("Expected warning log"); + } + return call; +} + +function firstWarnDetails(warnSpy: { mock: { calls: unknown[][] } }): { + consoleMessage?: string; + model?: string; + provider?: string; + sourceModel?: string; + sourceProvider?: string; +} { + return firstWarnCall(warnSpy)[1] as { + consoleMessage?: string; + model?: string; + provider?: string; + sourceModel?: string; + sourceProvider?: string; + }; +} + describe("normalizeFailoverDecisionObservationBase", () => { it("fills timeout observation reasons for deadline timeouts without provider error text", () => { const observation = normalizeObservation({ @@ -75,23 +99,15 @@ describe("createFailoverDecisionLogger", () => { logDecision("fallback_model"); - const [message, details] = warnSpy.mock.calls.at(0) ?? []; + const [message] = firstWarnCall(warnSpy); expect(message).toBe("embedded run failover decision"); - const observation = details as - | { - sourceProvider?: string; - sourceModel?: string; - provider?: string; - model?: string; - consoleMessage?: string; - } - | undefined; - expect(observation?.sourceProvider).toBe("github-copilot"); - expect(observation?.sourceModel).toBe("gpt-5.4-mini"); - expect(observation?.provider).toBe("openai"); - expect(observation?.model).toBe("gpt-5.4"); - expect(observation?.consoleMessage).toContain("from=github-copilot/gpt-5.4-mini"); - expect(observation?.consoleMessage).toContain("to=openai/gpt-5.4"); + const observation = firstWarnDetails(warnSpy); + expect(observation.sourceProvider).toBe("github-copilot"); + expect(observation.sourceModel).toBe("gpt-5.4-mini"); + expect(observation.provider).toBe("openai"); + expect(observation.model).toBe("gpt-5.4"); + expect(observation.consoleMessage).toContain("from=github-copilot/gpt-5.4-mini"); + expect(observation.consoleMessage).toContain("to=openai/gpt-5.4"); }); it("omits to model refs when the source matches the selected target", () => { @@ -114,11 +130,7 @@ describe("createFailoverDecisionLogger", () => { logDecision("surface_error"); - expect( - (warnSpy.mock.calls.at(0)?.[1] as { consoleMessage?: string } | undefined)?.consoleMessage, - ).toContain("from=openai/gpt-5.4"); - expect( - (warnSpy.mock.calls.at(0)?.[1] as { consoleMessage?: string } | undefined)?.consoleMessage, - ).not.toContain("to=openai/gpt-5.4"); + expect(firstWarnDetails(warnSpy).consoleMessage).toContain("from=openai/gpt-5.4"); + expect(firstWarnDetails(warnSpy).consoleMessage).not.toContain("to=openai/gpt-5.4"); }); });