|
| 1 | +import { electronTest as test, electronExpect as expect } from "../electronTest"; |
| 2 | +import { LIST_PROGRAMMING_LANGUAGES } from "@/node/services/mock/scenarios/basicChat"; |
| 3 | +import { ERROR_PROMPTS, ERROR_MESSAGES } from "@/node/services/mock/scenarios/errorScenarios"; |
| 4 | + |
| 5 | +test.skip( |
| 6 | + ({ browserName }) => browserName !== "chromium", |
| 7 | + "Electron scenario runs on chromium only" |
| 8 | +); |
| 9 | + |
| 10 | +test.describe("streaming behavior", () => { |
| 11 | + test("stream continues after settings modal opens", async ({ ui, page }) => { |
| 12 | + await ui.projects.openFirstWorkspace(); |
| 13 | + |
| 14 | + const streamPromise = ui.chat.captureStreamTimeline(async () => { |
| 15 | + await ui.chat.sendMessage(LIST_PROGRAMMING_LANGUAGES); |
| 16 | + }); |
| 17 | + |
| 18 | + await page.waitForTimeout(50); |
| 19 | + await ui.settings.open(); |
| 20 | + const timeline = await streamPromise; |
| 21 | + await ui.settings.close(); |
| 22 | + |
| 23 | + expect(timeline.events.some((e) => e.type === "stream-end")).toBe(true); |
| 24 | + await ui.chat.expectTranscriptContains("Python"); |
| 25 | + }); |
| 26 | + |
| 27 | + test("mode switching doesn't break streaming", async ({ ui }) => { |
| 28 | + await ui.projects.openFirstWorkspace(); |
| 29 | + |
| 30 | + await ui.chat.setMode("Exec"); |
| 31 | + await ui.chat.setMode("Plan"); |
| 32 | + |
| 33 | + const timeline = await ui.chat.captureStreamTimeline(async () => { |
| 34 | + await ui.chat.sendMessage(LIST_PROGRAMMING_LANGUAGES); |
| 35 | + }); |
| 36 | + |
| 37 | + expect(timeline.events.some((e) => e.type === "stream-end")).toBe(true); |
| 38 | + await ui.chat.expectTranscriptContains("Python"); |
| 39 | + }); |
| 40 | + |
| 41 | + // Consolidate error tests using parameterization |
| 42 | + for (const [errorType, prompt, expectedMessage] of [ |
| 43 | + ["rate limit", ERROR_PROMPTS.TRIGGER_RATE_LIMIT, ERROR_MESSAGES.RATE_LIMIT], |
| 44 | + ["server", ERROR_PROMPTS.TRIGGER_API_ERROR, ERROR_MESSAGES.API_ERROR], |
| 45 | + ["network", ERROR_PROMPTS.TRIGGER_NETWORK_ERROR, ERROR_MESSAGES.NETWORK_ERROR], |
| 46 | + ] as const) { |
| 47 | + test(`${errorType} error displays in transcript`, async ({ ui, page }) => { |
| 48 | + await ui.projects.openFirstWorkspace(); |
| 49 | + await ui.chat.setMode("Exec"); |
| 50 | + |
| 51 | + const timeline = await ui.chat.captureStreamTimeline(async () => { |
| 52 | + await ui.chat.sendMessage(prompt); |
| 53 | + }); |
| 54 | + |
| 55 | + expect(timeline.events.some((e) => e.type === "stream-error")).toBe(true); |
| 56 | + const transcript = page.getByRole("log", { name: "Conversation transcript" }); |
| 57 | + await expect(transcript.getByText(expectedMessage)).toBeVisible(); |
| 58 | + }); |
| 59 | + } |
| 60 | + |
| 61 | + test("app recovers after error", async ({ ui }) => { |
| 62 | + await ui.projects.openFirstWorkspace(); |
| 63 | + await ui.chat.setMode("Exec"); |
| 64 | + |
| 65 | + await ui.chat.captureStreamTimeline(async () => { |
| 66 | + await ui.chat.sendMessage(ERROR_PROMPTS.TRIGGER_API_ERROR); |
| 67 | + }); |
| 68 | + |
| 69 | + await ui.chat.setMode("Plan"); |
| 70 | + const timeline = await ui.chat.captureStreamTimeline(async () => { |
| 71 | + await ui.chat.sendMessage(LIST_PROGRAMMING_LANGUAGES); |
| 72 | + }); |
| 73 | + |
| 74 | + expect(timeline.events.some((e) => e.type === "stream-end")).toBe(true); |
| 75 | + await ui.chat.expectTranscriptContains("Python"); |
| 76 | + }); |
| 77 | +}); |
0 commit comments