test: tighten failover recovery assertions

This commit is contained in:
Peter Steinberger
2026-05-09 15:05:16 +01:00
parent 2f73f423c7
commit 0a8c98e7cb
3 changed files with 35 additions and 39 deletions

View File

@@ -843,13 +843,13 @@ describe("failover-error", () => {
"400 The following tools cannot be used with reasoning.effort 'minimal': web_search.",
});
expect(describeFailoverError(err)).toMatchObject({
message: "LLM request failed: provider rejected the request schema.",
rawError:
"400 The following tools cannot be used with reasoning.effort 'minimal': web_search.",
reason: "format",
status: 400,
});
const description = describeFailoverError(err);
expect(description.message).toBe("LLM request failed: provider rejected the request schema.");
expect(description.rawError).toBe(
"400 The following tools cannot be used with reasoning.effort 'minimal': web_search.",
);
expect(description.reason).toBe("format");
expect(description.status).toBe(400);
});
it("coerces JSON-wrapped OpenRouter stealth-model 404s into FailoverError", () => {
@@ -985,15 +985,14 @@ describe("failover-error", () => {
});
expect(err.sessionId).toBe("session:browser-abcd");
expect(err.lane).toBe("answer");
expect(describeFailoverError(err)).toMatchObject({
provider: "anthropic",
model: "claude-opus-4-6",
profileId: "profile-2",
sessionId: "session:browser-abcd",
lane: "answer",
reason: "rate_limit",
status: 429,
});
const description = describeFailoverError(err);
expect(description.provider).toBe("anthropic");
expect(description.model).toBe("claude-opus-4-6");
expect(description.profileId).toBe("profile-2");
expect(description.sessionId).toBe("session:browser-abcd");
expect(description.lane).toBe("answer");
expect(description.reason).toBe("rate_limit");
expect(description.status).toBe(429);
});
it("coerceToFailoverError carries sessionId/lane from context (#42713)", () => {

View File

@@ -64,16 +64,14 @@ describe("resolveCopilotApiToken", () => {
fetchImpl: fetchImpl as unknown as typeof fetch,
});
expect(fetchImpl).toHaveBeenCalledWith(
"https://api.github.com/copilot_internal/v2/token",
expect.objectContaining({
method: "GET",
headers: expect.objectContaining({
Accept: "application/json",
Authorization: "Bearer github-token",
...buildCopilotIdeHeaders({ includeApiVersion: true }),
}),
}),
);
expect(fetchImpl).toHaveBeenCalledTimes(1);
const [url, init] = fetchImpl.mock.calls[0] as unknown as [string, RequestInit];
expect(url).toBe("https://api.github.com/copilot_internal/v2/token");
expect(init.method).toBe("GET");
expect(init.headers).toEqual({
Accept: "application/json",
Authorization: "Bearer github-token",
...buildCopilotIdeHeaders({ includeApiVersion: true }),
});
});
});

View File

@@ -235,11 +235,12 @@ describe("main-session-restart-recovery", () => {
expect(result).toEqual({ recovered: 1, failed: 0, skipped: 0 });
expect(callGateway).toHaveBeenCalledOnce();
expect(vi.mocked(callGateway).mock.calls[0]?.[0].params).toMatchObject({
sessionKey: "agent:main:main",
deliver: false,
lane: "main",
});
const resumeParams = vi.mocked(callGateway).mock.calls[0]?.[0].params as
| { sessionKey?: string; deliver?: boolean; lane?: string }
| undefined;
expect(resumeParams?.sessionKey).toBe("agent:main:main");
expect(resumeParams?.deliver).toBe(false);
expect(resumeParams?.lane).toBe("main");
const store = loadSessionStore(path.join(sessionsDir, "sessions.json"));
expect(store["agent:main:main"]?.abortedLastRun).toBe(false);
});
@@ -308,13 +309,11 @@ describe("main-session-restart-recovery", () => {
const beforeStoreRead = Date.now();
const store = loadSessionStore(path.join(sessionsDir, "sessions.json"));
const entry = store["agent:main:main"];
expect(entry).toMatchObject({
abortedLastRun: false,
pendingFinalDelivery: true,
pendingFinalDeliveryText: pendingPayload,
pendingFinalDeliveryAttemptCount: 1,
pendingFinalDeliveryLastError: null,
});
expect(entry?.abortedLastRun).toBe(false);
expect(entry?.pendingFinalDelivery).toBe(true);
expect(entry?.pendingFinalDeliveryText).toBe(pendingPayload);
expect(entry?.pendingFinalDeliveryAttemptCount).toBe(1);
expect(entry?.pendingFinalDeliveryLastError).toBeNull();
expect(entry?.pendingFinalDeliveryCreatedAt).toBeLessThanOrEqual(beforeStoreRead);
expect(entry?.pendingFinalDeliveryLastAttemptAt).toBeLessThanOrEqual(beforeStoreRead);
expect(entry?.pendingFinalDeliveryLastAttemptAt ?? 0).toBeGreaterThanOrEqual(