test(webui): trim redundant browser coverage
This commit is contained in:
1 parent
8857d4f9c8
commit
960bfa9a83
10 files changed
+187
-260
No files matched your search
@@ -6,10 +6,20 @@ import type { ThreadProjectionEvent } from "../src/lib/types";
|
||||
const reasons = ["idle", "context_pressure", "manual", "provider_native"] as const;
|
||||
const phases = ["started", "succeeded", "failed", "cancelled"] as const;
|
||||
|
||||
// Synthetic HTTP history and WebSocket delivery through the production client,
|
||||
// projection, cache, and thread. No model/provider execution is involved.
|
||||
const legacy: ThreadProjectionEvent = { event: "context_compaction", chat_id: "answer-order",
|
||||
compaction_id: "legacy", phase: "succeeded", created_at_ms: 100,
|
||||
projection_id: "legacy", turn_id: "legacy-turn", turn_seq: 1 };
|
||||
const samples = reasons.map((reason, index) => {
|
||||
const start: ThreadProjectionEvent = { event: "context_compaction", chat_id: "answer-order",
|
||||
compaction_id: reason, phase: "started", reason,
|
||||
projection_id: `${reason}-start`, turn_id: `${reason}-turn`, turn_seq: 1 };
|
||||
const phase = phases[index === 3 ? 1 : index + 1]!;
|
||||
return { reason, start, finish: { ...start, phase, projection_id: `${reason}-finish`, turn_seq: 2 } };
|
||||
});
|
||||
|
||||
for (const { code } of supportedLocales) {
|
||||
test(`compaction reasons survive live updates and session reentry in ${code}`, async ({ page }, info) => {
|
||||
const lifecycle = code === "en";
|
||||
test(`${lifecycle ? "compaction reasons survive live updates and session reentry" : "localized compaction history fits the thread"} in ${code}`, async ({ page }, info) => {
|
||||
await page.setViewportSize({ width: 390, height: 900 });
|
||||
const messages: typeof import("../src/i18n/locales/en/common.json") = JSON.parse(
|
||||
readFileSync(new URL(`../src/i18n/locales/${code}/common.json`, import.meta.url), "utf8"),
|
||||
@@ -18,9 +28,8 @@ for (const { code } of supportedLocales) {
|
||||
await page.addInitScript((locale) => localStorage.setItem("nanobot.locale", locale), code);
|
||||
const errors: string[] = [];
|
||||
page.on("pageerror", (error) => errors.push(error.message));
|
||||
let history: ThreadProjectionEvent[] = [{ event: "context_compaction", chat_id: "answer-order",
|
||||
compaction_id: "legacy", phase: "succeeded", created_at_ms: 100,
|
||||
projection_id: "legacy", turn_id: "legacy-turn", turn_seq: 1 }];
|
||||
const history: ThreadProjectionEvent[] = [legacy,
|
||||
...(lifecycle ? [] : samples.flatMap(({ start, finish }) => [start, finish]))];
|
||||
await page.route("**/api/**", (route) => route.fulfill({ status: 404, json: {} }));
|
||||
await page.route("**/api/commands", (route) => route.fulfill({ json: { commands: [] } }));
|
||||
await page.route("**/api/sessions/*/webui-thread?*", (route) => route.fulfill({ json: {
|
||||
@@ -42,34 +51,33 @@ for (const { code } of supportedLocales) {
|
||||
await page.goto("/browser/fixture.html?case=answer-order");
|
||||
await expect.poll(() => attached.has("answer-order")).toBe(true);
|
||||
const notices = page.locator("[data-context-compaction]");
|
||||
await expect(notices).toHaveCount(1);
|
||||
await expect(notices.first()).toHaveText(copy.succeeded);
|
||||
await expect(notices.first()).not.toHaveAttribute("role", "status");
|
||||
for (const [index, reason] of reasons.entries()) {
|
||||
const start: ThreadProjectionEvent = { event: "context_compaction", chat_id: "answer-order",
|
||||
compaction_id: reason, phase: "started", reason,
|
||||
projection_id: `${reason}-start`, turn_id: `${reason}-turn`, turn_seq: 1 };
|
||||
socket.send(JSON.stringify(start));
|
||||
const notice = notices.nth(index + 1);
|
||||
await expect(notices).toHaveCount(index + 2);
|
||||
await expect(notice).toHaveText(copy.reasons[reason].started);
|
||||
await expect(notice).toHaveAttribute("aria-busy", "true");
|
||||
const handle = await notice.elementHandle();
|
||||
const phase = phases[index === 3 ? 1 : index + 1]!;
|
||||
const finish = { ...start, phase, projection_id: `${reason}-finish`, turn_seq: 2 };
|
||||
socket.send(JSON.stringify(finish));
|
||||
await expect(notice).toHaveText(copy.reasons[reason][phase]);
|
||||
await expect(notice).toHaveAttribute("aria-busy", "false");
|
||||
expect(await notice.evaluate((node, original) => node === original, handle)).toBe(true);
|
||||
await expect(notices).toHaveCount(index + 2);
|
||||
history = [...history, start, finish];
|
||||
if (lifecycle) {
|
||||
await expect(notices).toHaveCount(1);
|
||||
await expect(notices.first()).toHaveText(copy.succeeded);
|
||||
await expect(notices.first()).not.toHaveAttribute("role", "status");
|
||||
for (const [index, { reason, start, finish }] of samples.entries()) {
|
||||
socket.send(JSON.stringify(start));
|
||||
const notice = notices.nth(index + 1);
|
||||
await expect(notices).toHaveCount(index + 2);
|
||||
await expect(notice).toHaveText(copy.reasons[reason].started);
|
||||
await expect(notice).toHaveAttribute("aria-busy", "true");
|
||||
const handle = await notice.elementHandle();
|
||||
socket.send(JSON.stringify(finish));
|
||||
await expect(notice).toHaveText(copy.reasons[reason][finish.phase]);
|
||||
await expect(notice).toHaveAttribute("aria-busy", "false");
|
||||
expect(await notice.evaluate((node, original) => node === original, handle)).toBe(true);
|
||||
await expect(notices).toHaveCount(index + 2);
|
||||
history.push(start, finish);
|
||||
}
|
||||
const text = await notices.allTextContents();
|
||||
await page.getByRole("button", { name: "Switch topic" }).click();
|
||||
await expect(notices).toHaveCount(0);
|
||||
await page.getByRole("button", { name: "Switch topic" }).click();
|
||||
await expect(notices).toHaveText(text);
|
||||
await page.reload();
|
||||
await expect(notices).toHaveText(text);
|
||||
}
|
||||
const text = await notices.allTextContents();
|
||||
await page.getByRole("button", { name: "Switch topic" }).click();
|
||||
await expect(notices).toHaveCount(0);
|
||||
await page.getByRole("button", { name: "Switch topic" }).click();
|
||||
await expect(notices).toHaveText(text);
|
||||
await page.reload();
|
||||
const text = [copy.succeeded, ...samples.map(({ reason, finish }) => copy.reasons[reason][finish.phase])];
|
||||
await expect(notices).toHaveText(text);
|
||||
await expect(page.locator('[data-context-compaction][role="status"]')).toHaveCount(0);
|
||||
for (const theme of ["light", "dark"]) {
|
||||
|
||||
Reference in new issue
Block a user