60 lines
2.6 KiB
JavaScript
60 lines
2.6 KiB
JavaScript
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',
|
|
});
|
|
}
|
|
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);
|
|
await page.getByText("這是會留下來的回覆", { exact: true }).waitFor();
|
|
await page.waitForFunction(() => document.body.innerText.includes("這是會留下來的回覆"));
|
|
assert.equal(await page.getByText("這是會留下來的回覆", { exact: true }).count(), 1);
|
|
assert.equal(await page.getByText("這段 scratchpad 不該出現在聊天裡").count(), 0);
|
|
await page.reload();
|
|
await page.getByText("這是會留下來的回覆", { exact: true }).waitFor();
|
|
assert.equal(await page.getByText("這是會留下來的回覆", { exact: true }).count(), 1);
|
|
assert.equal(await page.getByText("這段 scratchpad 不該出現在聊天裡").count(), 0);
|
|
console.log("PASS transcript stays the public snapshot across events and reload");
|
|
} finally {
|
|
await browser.close();
|
|
}
|