LazyBoy2/tests/transcript_ui.mjs

63 lines
2.8 KiB
JavaScript
Raw Normal View History

2026-09-15 09:07:16 +00:00
import { chromium } from "../tools/playwright/node_modules/playwright/index.mjs";
import assert from "node:assert/strict";
const transcript = [
{ role: "user", content: "你好", at: "2026-09-15T10:00:00Z" },
{ role: "assistant", content: "這是會留下來的回覆", at: "2026-09-15T10:00:01Z" },
];
const browser = await chromium.launch({ headless: true });
try {
const page = await browser.newPage();
page.setDefaultTimeout(8000);
await page.addInitScript(() => localStorage.setItem("lazyboy.locale", "zh-Hant"));
page.on("pageerror", (e) => console.error(e.message));
await page.route("**/api/**", async (route) => {
const path = new URL(route.request().url()).pathname;
if (path.endsWith("/activity")) {
return route.fulfill({
json: { state: "idle", running: false, queued: false, active_task_ids: [], observed_at_ms: Date.now() },
});
}
if (path.endsWith("/events")) {
return route.fulfill({
contentType: "text/event-stream",
body: 'data: {"events":[{"id":9,"kind":"reply","payload":{"verdict":"answer","message":"這段 scratchpad 不該出現在聊天裡"}}]}\n\n',
});
}
2026-09-16 06:40:00 +00:00
if (path.endsWith("/computer")) {
return route.fulfill({ json: { ready: true, state: "ready", viewer_url: "/fixture-viewer" } });
}
2026-09-15 09:07:16 +00:00
if (path === "/api/agents") {
return route.fulfill({ json: { agents: [{ id: "owner", name: "測試", running: false }] } });
}
if (path === "/api/agents/owner") {
return route.fulfill({
json: {
id: "owner",
name: "測試",
expertise: "",
preview: "這是會留下來的回覆",
transcript,
running: false,
activity: { state: "idle", running: false, queued: false, active_task_ids: [], observed_at_ms: Date.now() },
},
});
}
return route.fulfill({ json: {} });
});
const url = process.env.LAZYBOY_TEST_UI_URL || "http://127.0.0.1:5173";
await page.goto(url);
2026-09-16 08:17:38 +00:00
await page.locator(".messages").getByText("這是會留下來的回覆", { exact: true }).waitFor();
2026-09-15 09:07:16 +00:00
await page.waitForFunction(() => document.body.innerText.includes("這是會留下來的回覆"));
2026-09-16 08:17:38 +00:00
assert.equal(await page.locator(".messages").getByText("這是會留下來的回覆", { exact: true }).count(), 1);
2026-09-15 09:07:16 +00:00
assert.equal(await page.getByText("這段 scratchpad 不該出現在聊天裡").count(), 0);
await page.reload();
2026-09-16 08:17:38 +00:00
await page.locator(".messages").getByText("這是會留下來的回覆", { exact: true }).waitFor();
assert.equal(await page.locator(".messages").getByText("這是會留下來的回覆", { exact: true }).count(), 1);
2026-09-15 09:07:16 +00:00
assert.equal(await page.getByText("這段 scratchpad 不該出現在聊天裡").count(), 0);
console.log("PASS transcript stays the public snapshot across events and reload");
} finally {
await browser.close();
}