Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

test: isolate provider outage from coach history batches (#3779)

Amruth Pillai40b4bb4ed908
diff --git a/tests/e2e/specs/ai-provider-regressions.spec.ts b/tests/e2e/specs/ai-provider-regressions.spec.ts
index 288778613..0f888accc 100644
--- a/tests/e2e/specs/ai-provider-regressions.spec.ts
+++ b/tests/e2e/specs/ai-provider-regressions.spec.ts
@@ -256,21 +256,101 @@ test("application coach history survives provider-list failure", async ({ authPa
await composer.press("Enter");
await consent(page);
await expect(page.getByText("You left the document out.", { exact: true })).toBeVisible();
+ await expect
+ .poll(async () => {
+ const response = await page.request.post("/api/rpc/agent/threads/list", {
+ data: { json: {} },
+ });
+ expect(response.ok()).toBe(true);
+ const { json: allThreads } = await response.json();
+ const threads = allThreads.filter((thread: { applicationId: string | null }) => thread.applicationId === id);
+ if (threads.length !== 1 || threads[0].activeRunId) return false;
+ const history = await page.request.post("/api/rpc/agent/threads/get", { data: { json: { id: threads[0].id } } });
+ expect(history.ok()).toBe(true);
+ const { json: thread } = await history.json();
+ const hasText = (role: string, text: string) =>
+ thread.messages.some(
+ (message: { role: string; parts: { type: string; text?: string }[] }) =>
+ message.role === role && message.parts.some((part) => part.type === "text" && part.text?.includes(text)),
+ );
+ return (
+ !thread.thread.activeRunId &&
+ hasText("user", "Remember this fictional history") &&
+ hasText("assistant", "You left the document out.")
+ );
+ })
+ .toBe(true);
+ const count = stub.requests.length;
let blocked = 0;
await page.route("**/api/rpc/**", async (route) => {
const req = route.request();
- const body = req.postData() ?? "";
- if (req.url().includes("aiProviders/list") || body.includes("aiProviders")) {
- blocked++;
- await route.abort("failed");
- } else await route.continue();
+ const batched = new URL(req.url()).pathname.endsWith("/__batch__");
+ const entries: { url: string }[] = batched ? JSON.parse(req.postData() ?? "[]") : [{ url: req.url() }];
+ const providers = entries.flatMap((entry, index) =>
+ new URL(entry.url).pathname === "/api/rpc/aiProviders/list" ? [index] : [],
+ );
+ if (!providers.length) return route.continue();
+ blocked++;
+ const response = await route.fetch();
+ const error = {
+ json: { defined: false, code: "INTERNAL_SERVER_ERROR", status: 500, message: "Provider lookup unavailable" },
+ };
+ // A physical batch can also carry thread discovery: preserve every sibling's real response.
+ const body = batched
+ ? (await response.text())
+ .split("\n")
+ .map((line) => {
+ if (!line.startsWith("data: ")) return line;
+ const event = JSON.parse(line.slice(6));
+ return providers.includes(event.index)
+ ? `data: ${JSON.stringify({ ...event, status: 500, body: error })}`
+ : line;
+ })
+ .join("\n")
+ : JSON.stringify(error);
+ await route.fulfill({
+ response,
+ status: batched ? 207 : 500,
+ body,
+ headers: { ...response.headers(), "content-length": String(Buffer.byteLength(body)) },
+ });
});
+ const mixed = await page.evaluate(async () => {
+ const response = await fetch("/api/rpc/agent/threads/list/__batch__", {
+ method: "POST",
+ headers: { "content-type": "application/json", "x-orpc-batch": "streaming" },
+ body: JSON.stringify(
+ ["agent/threads/list", "aiProviders/list"].map((path) => ({
+ url: `${location.origin}/api/rpc/${path}`,
+ body: { json: {} },
+ })),
+ ),
+ });
+ return {
+ status: response.status,
+ events: (await response.text())
+ .split("\n")
+ .filter((line) => line.startsWith("data: "))
+ .map((line) => JSON.parse(line.slice(6))),
+ };
+ });
+ expect(mixed.status).toBe(207);
+ expect(mixed.events).toHaveLength(2);
+ expect(mixed.events.find((event: { index: number }) => event.index === 0)).toMatchObject({
+ status: 200,
+ body: { json: expect.arrayContaining([expect.objectContaining({ applicationId: id })]) },
+ });
+ expect(mixed.events.find((event: { index: number }) => event.index === 1)).toMatchObject({
+ status: 500,
+ body: { json: { code: "INTERNAL_SERVER_ERROR", message: "Provider lookup unavailable" } },
+ });
+ const beforeReload = blocked;
await page.reload();
- await expect.poll(() => blocked).toBeGreaterThan(0);
+ await expect.poll(() => blocked).toBeGreaterThan(beforeReload);
await expect(page.getByText("You left the document out.", { exact: true })).toBeVisible({ timeout: 12000 });
await expect(composer).toBeDisabled();
await page.screenshot({ path: info.outputPath("coach-history-provider-error.png") });
- const count = stub.requests.length;
+ expect(stub.requests.length).toBe(count);
await page.getByRole("button", { name: "Try again", exact: true }).first().click({ timeout: 10000 });
await page.unroute("**/api/rpc/**");
await expect(composer).toBeEnabled();