test: dedupe pi failover warning mock reads

This commit is contained in:
Peter Steinberger
2026-05-12 21:30:49 +01:00
parent 178a50e017
commit 188bbe92e5

View File

@@ -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");
});
});