Files
pikasTech-HWLAB/web/hwlab-cloud-web/tests/workbench-e2e/specs/event-replay.spec.ts
T

78 lines
4.3 KiB
TypeScript

import { expect, gotoWorkbench, saveScreenshot, test } from "../fixtures/test";
import { selectors, sessionTab } from "../fixtures/selectors";
test.use({ scenarioId: "event-replay" });
test("SSE terminal event and REST gap fill replay to the same terminal UI", async ({ page }, testInfo) => {
await gotoWorkbench(page);
await expect(page.locator(`${selectors.messageCard}[data-role="agent"][data-status="running"]`)).toBeVisible();
await expect(page.locator(`${selectors.traceTimeline}[data-status="running"]`)).toBeVisible();
await expect(page.locator(`${selectors.messageCard}[data-role="agent"][data-status="completed"]`)).toContainText("事件重放后完成");
await expect(page.locator(`${selectors.traceTimeline}[data-status="completed"]`)).toBeVisible();
await expect(page.locator(selectors.commandSend)).toHaveAttribute("data-action", "turn");
await saveScreenshot(page, testInfo, "event-replay-terminal");
await page.reload();
await expect(page.locator(`${selectors.messageCard}[data-role="agent"][data-status="completed"]`)).toContainText("事件重放后完成");
await expect(page.locator(`${selectors.traceTimeline}[data-status="completed"]`)).toBeVisible();
});
test.describe("terminal completed without final response", () => {
test.use({ scenarioId: "terminal-completed-no-final-response" });
test("keeps the assistant final response area empty", async ({ page }, testInfo) => {
await gotoWorkbench(page);
const agentCard = page.locator(`${selectors.messageCard}[data-role="agent"]`).last();
await expect(agentCard).toHaveAttribute("data-status", "running");
await expect(agentCard).toHaveAttribute("data-status", "completed");
await expect(page.locator(`${selectors.traceTimeline}[data-status="completed"]`)).toBeVisible();
const snapshot = await agentCard.evaluate((element) => {
const placeholder = "Code Agent 已完成,但没有返回可展示的 final response。";
return {
status: element.getAttribute("data-status"),
messageTexts: Array.from(element.querySelectorAll(".message-markdown.message-text")).map((item) => (item.textContent ?? "").trim()),
bodyHasPlaceholder: document.body.textContent?.includes(placeholder) === true
};
});
expect(snapshot.status).toBe("completed");
expect(snapshot.messageTexts.filter(Boolean)).toEqual([]);
expect(snapshot.bodyHasPlaceholder).toBe(false);
await saveScreenshot(page, testInfo, "terminal-completed-no-final-response");
});
});
test("fresh deep link replays completed turn from the session authority", async ({ page }, testInfo) => {
const detail = await page.request.get("/v1/workbench/sessions/ses_completed");
expect(detail.status()).toBe(200);
const detailBody = await detail.json();
expect(detailBody.session.sessionId).toBe("ses_completed");
const turn = await page.request.get("/v1/workbench/turns/trc_completed");
expect(turn.status()).toBe(200);
expect((await turn.json()).turn.status).toBe("completed");
const trace = await page.request.get("/v1/workbench/traces/trc_completed/events");
expect(trace.status()).toBe(200);
expect((await trace.json()).traceStatus).toBe("completed");
await gotoWorkbench(page, "/workbench/sessions/ses_completed");
await expect(page.locator(sessionTab("ses_completed"))).toHaveAttribute("data-active", "true");
await expect(page.locator(`${selectors.messageCard}[data-role="agent"][data-status="completed"]`)).toContainText("构建和 Trace 渲染检查完成");
await expect(page.locator(`${selectors.traceTimeline}[data-status="completed"]`)).toBeVisible();
await expect.poll(async () => await page.locator(selectors.traceRow).count()).toBeGreaterThan(0);
await saveScreenshot(page, testInfo, "completed-deeplink-authority");
});
test.describe("completed replay unavailable", () => {
test.use({ scenarioId: "completed-replay-detail-404" });
test("detail or turn 404 renders diagnostic state instead of an empty conversation", async ({ page }) => {
await gotoWorkbench(page, "/workbench/sessions/ses_completed");
await expect(page.locator(".conversation-error-hint")).toContainText(/session URL not found|replay|unavailable/u);
await expect(page.locator(selectors.messageCard)).toHaveCount(0);
await expect(page.locator(selectors.sessionTabs)).not.toHaveAttribute("data-loading", "true");
});
});