droboticflow/tests/browser/review-problem-workflow.mjs

660 lines
32 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Real authenticated application, decoded videos and public API; isolated review fixtures only.
// Contract: .scratch/review-problem-flow/spec.md — F→scope→Enter→text→Ctrl/⌘+Enter, Esc per stage,
// Ctrl+↑/↓ recall (no auto-edit), Enter edits, Shift+Delete with confirm, same-target multiple
// independent problems, task viewAnchor bookmarks, unsaved-text viewing freedom, serial writes.
// Accessible names confirmed by reviewer from ticket-02 UI: region 审查问题草稿, radiogroup 问题范围
// (radio 动作/切片/整体), textbox 审查问题说明, listbox 已保存问题 (option[data-problem-id]),
// buttons 保存批注 / 删除选中问题, dialog 确认删除问题, hint 恢复未保存内容.
// STATUS: prepared for the integrated build (tickets 02+03); not yet executed — see
// docs/review-problem-flow-validation-2026-09-23.md.
import { chromium } from "playwright";
import fs from "node:fs/promises";
import assert from "node:assert/strict";
const dir = process.env.REVIEW_FIXTURES || "local-data/verification/review-focused-20260922";
const base = process.env.REVIEW_TEST_URL || "http://review-session.test:5178";
const hostname = new URL(base).hostname;
const fixtures = JSON.parse(await fs.readFile(`${dir}/fixture-index.json`, "utf8"));
const browser = await chromium.launch({
executablePath: process.env.BROWSER_EXECUTABLE || "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
headless: true,
args: [`--host-resolver-rules=MAP ${hostname} 127.0.0.1`, "--no-proxy-server"],
});
const reports = [];
try {
for (const mode of process.env.REVIEW_PROBLEM_MODE ? [process.env.REVIEW_PROBLEM_MODE] : ["quality", "acceptance"]) {
const auth = JSON.parse(
await fs.readFile(`${dir}/fixture-${mode === "quality" ? "qc" : "acceptance"}-auth.json`, "utf8"),
);
auth.cookies = auth.cookies.map((c) => ({ ...c, domain: hostname }));
for (const focused of [false, true]) {
const context = await browser.newContext({
storageState: auth,
viewport: { width: 1413, height: focused ? 615 : 1000 },
});
const page = await context.newPage();
page.setDefaultTimeout(25000);
const errors = [],
formalRequests = [];
page.on("pageerror", (e) => errors.push(e.stack || e.message));
page.on("request", (r) => {
if (r.method() === "POST" && /\/(?:review|decisions)$/.test(new URL(r.url()).pathname))
formalRequests.push(r.url());
});
const fixture = fixtures[mode][0];
const url = `${base}/plugins/annotation-qa/workflows/all/${mode}?projectId=${fixtures.projectId}${fixture.taskId ? `&taskId=${fixture.taskId}` : ""}`;
const open = async () => {
await page.goto(url);
await page.getByRole("button", { name: /^我的任务/ }).click();
if (mode === "acceptance")
await page
.getByTestId("acceptance-task-card")
.first()
.getByRole("button", { name: /^预览 / })
.click();
await page
.getByRole("status")
.filter({ hasText: /本页可编辑审查意见|本页只读/ })
.waitFor();
const takeover = page.getByRole("button", { name: "在本页接管审查", exact: true });
if (await takeover.count()) await takeover.click();
await page.getByText("本页可编辑审查意见", { exact: true }).waitFor();
await page.getByRole("button", { name: "保存批注", exact: true }).waitFor();
if (focused) await page.getByRole("button", { name: "进入专注审查", exact: true }).click();
};
await open();
const bench = page.getByTestId("capture-annotation-workbench").first();
const range = bench.getByRole("slider", { name: "Capture 播放位置", exact: true });
const panel = page.getByRole("region", { name: "审查问题草稿" });
const input = page.getByRole("textbox", { name: "审查问题说明", exact: true });
const scope = panel.getByRole("radiogroup", { name: "问题范围" });
const scopeRadio = (name) => scope.getByRole("radio", { name, exact: true });
const list = panel.getByRole("listbox", { name: "已保存问题" });
const option = (text) => list.getByRole("option").filter({ hasText: text });
const deleteDialog = page.getByRole("alertdialog", { name: "确认删除问题" });
const read = (suffix = "review-draft") =>
page.evaluate(
async ({ id, suffix }) => {
const r = await fetch(`/api/human-items/${id}${suffix ? `/${suffix}` : ""}`);
if (!r.ok) throw Error(`read ${r.status}`);
return r.json();
},
{ id: fixture.humanItemId, suffix },
);
const problems = async () => (await read()).draft.problems;
const before = await read("");
const settle = async () =>
page.waitForFunction(() => {
const videos = [...document.querySelectorAll("video")].filter((v) => v.getBoundingClientRect().width > 0);
const step = [...document.querySelectorAll("button")].find((button) => button.textContent.trim() === "上一帧");
return step && !step.disabled && videos.length && videos.every((v) => v.readyState >= 2 && !v.seeking);
});
const seek = async (time) => {
const b = await range.boundingBox();
const min = Number(await range.getAttribute("min")),
max = Number(await range.getAttribute("max"));
await range.click({ position: { x: 8 + ((b.width - 16) * (time - min)) / (max - min), y: b.height / 2 } });
await settle();
};
const videoState = () =>
page
.locator("video")
.evaluateAll((vs) =>
vs.filter((v) => v.getBoundingClientRect().width > 0).map((v) => ({ time: v.currentTime, paused: v.paused })),
);
const workbenchFocused = () =>
page.waitForFunction(
() => document.activeElement && document.activeElement.getAttribute("aria-label") !== "审查问题说明",
);
// Confirming delete saves immediately; wait for that write before any further F (gated while saving).
const confirmDelete = async () => {
await Promise.all([
page.waitForResponse(
(r) => r.request().method() === "PUT" && r.url().endsWith("/review-draft") && r.ok(),
),
deleteDialog.getByRole("button", { name: /^确认/ }).click(),
]);
await deleteDialog.waitFor({ state: "detached" });
};
// Focus a non-activating control inside the workbench so keydown bubbles to its handler.
const focusBench = () => bench.getByRole("button", { name: "上一帧", exact: true }).focus();
// Known product bugs under repair must fail loudly but not block the rest of the matrix.
const failures = [];
const expose = async (name, fn) => {
try {
await fn();
} catch (cause) {
failures.push({ name, error: String(cause).slice(0, 400) });
console.log("EXPOSED", name, String(cause).split("\n")[0]);
await open().catch(() => {});
await settle().catch(() => {});
}
};
// F from the workbench: pauses, fixes the ready frame, opens scope selection.
const pressF = async () => {
await focusBench();
await page.keyboard.press("f");
await scope.waitFor();
};
const startText = async (scopeName) => {
// Clicking a radio confirms that scope directly; Enter on the focused default confirms 动作.
if (scopeName) await scopeRadio(scopeName).click();
else await scopeRadio("动作").press("Enter");
await page.waitForFunction(() => document.activeElement?.getAttribute("aria-label") === "审查问题说明");
};
const saveCurrent = async () => {
await Promise.all([
page.waitForResponse(
(r) => r.request().method() === "PUT" && r.url().endsWith("/review-draft") && r.ok(),
),
input.press("Control+Enter"),
]);
// After save the editor is gone: input empty, readonly, focus back on the workbench.
await page.waitForFunction(() => {
const el = document.querySelector('[aria-label="审查问题说明"]');
return el && el.value === "" && el.readOnly;
});
await workbenchFocused();
};
const create = async (text, scopeName) => {
await pressF();
await startText(scopeName);
await input.fill(text);
await saveCurrent();
};
await settle();
const stamp = Date.now();
const tag = `${mode}/${focused ? "focus" : "ordinary"}`;
// S1 — F creates an action problem on the actual ready frame; save clears input and returns focus.
const actionBlocks =
mode === "quality"
? bench.getByTestId("annotation-description-block")
: page.getByTestId("acceptance-action-timeline").getByRole("button", { name: /^动作 / });
await actionBlocks.first().click();
await seek(18);
await pressF();
assert.ok((await videoState()).every((v) => v.paused), "F pauses all visible videos");
assert.equal(await scopeRadio("动作").getAttribute("aria-checked"), "true", "default scope is current action");
await startText();
const noteA = `${tag} 同一动作第一条 ${stamp}`;
await input.fill(noteA);
await saveCurrent();
assert.equal(await input.inputValue(), "", "save clears the input");
await page.keyboard.press(" ");
await page.waitForFunction(
() => [...document.querySelectorAll("video")].some((v) => v.getBoundingClientRect().width > 0 && !v.paused),
);
await page.keyboard.press(" ");
const first = (await problems()).find((p) => p.text === noteA);
assert.ok(first?.id);
assert.equal(first.actionId, "review-action-1-2");
assert.equal(first.sliceId, "review-slice-1");
assert.ok(first.atSeconds > 13 && first.atSeconds < 24.3);
if (mode === "acceptance") assert.ok(first.sourceItemId);
// S2 — second F on the same target creates an independent problem; order = first-save order; refresh keeps both.
await seek(18); // pin the same frame so both captures share the target
const noteB = `${tag} 同一动作第二条 ${stamp}`;
await create(noteB);
const pair = (ps) => ps.filter((p) => p.text === noteA || p.text === noteB);
let pairNow = pair(await problems());
assert.equal(pairNow.length, 2, "same target keeps two independent problems");
assert.notEqual(pairNow[0].id, pairNow[1].id);
assert.equal(pairNow[0].actionId, pairNow[1].actionId);
assert.deepEqual(pairNow.map((p) => p.text), [noteA, noteB], "list order follows first-save order");
await open();
await settle();
assert.deepEqual(
pair(await problems()).map((p) => p.text),
[noteA, noteB],
"refresh keeps both problems and their order",
);
// S3 — recall never auto-edits (mouse and Ctrl+↑/↓); Enter edits only the selected entry, in place.
await option(noteB).click();
await settle();
assert.equal(await input.inputValue(), "", "mouse click recalls only, never edits");
await page.keyboard.press("Control+ArrowUp");
await settle();
assert.ok(
Math.abs(Number(await range.inputValue()) - first.atSeconds) < 0.07,
"Ctrl+↑ recalls the previous problem's picture",
);
assert.equal(await input.inputValue(), "", "selection does not start editing");
await page.keyboard.press("Enter");
await page.waitForFunction(() => document.activeElement?.getAttribute("aria-label") === "审查问题说明");
assert.equal(await input.inputValue(), noteA);
const noteA2 = `${noteA}(改)`;
await input.fill(noteA2);
await saveCurrent();
const afterEdit = await problems();
const edited = afterEdit.find((p) => p.text === noteA2);
const sibling = afterEdit.find((p) => p.text === noteB);
assert.ok(edited && sibling, "edit does not overwrite the same-target sibling");
assert.equal(edited.id, first.id, "edit keeps identity");
assert.equal(
afterEdit.findIndex((p) => p.id === sibling.id) - afterEdit.findIndex((p) => p.id === edited.id),
1,
"edit keeps list position",
);
// S4 — inside the textbox, Ctrl+↑/↓ stays text navigation and Shift+Delete never deletes.
await option(noteA2).click();
await page.keyboard.press("Enter");
await page.waitForFunction(() => document.activeElement?.getAttribute("aria-label") === "审查问题说明");
await input.press("Control+ArrowDown");
assert.equal(await input.inputValue(), noteA2, "Ctrl+↓ inside text keeps native behavior");
await input.press("Shift+Delete");
assert.equal(await deleteDialog.count(), 0, "Shift+Delete inside text never opens delete confirm");
assert.equal((await problems()).filter((p) => p.text === noteB).length, 1);
await input.press("Escape");
await workbenchFocused();
assert.equal(
(await problems()).find((p) => p.id === first.id).text,
noteA2,
"Esc while editing keeps saved content",
);
// S5 — Shift+Delete: Esc cancels; confirm deletes exactly one; the mouse button is the same path.
await option(noteB).click();
await page.keyboard.press("Shift+Delete");
await deleteDialog.waitFor();
await deleteDialog.press("Escape");
await deleteDialog.waitFor({ state: "detached" });
assert.equal((await problems()).filter((p) => p.text === noteB).length, 1, "cancelled delete changes nothing");
await page.keyboard.press("Shift+Delete");
await confirmDelete();
assert.equal((await problems()).filter((p) => p.text === noteB).length, 0, "confirmed delete removes one");
assert.ok((await problems()).some((p) => p.id === first.id), "sibling survives delete");
const noteC = `${tag} 鼠标删除 ${stamp}`;
await create(noteC);
await option(noteC).click();
await panel.getByRole("button", { name: "删除选中问题", exact: true }).click();
await confirmDelete();
assert.equal((await problems()).filter((p) => p.text === noteC).length, 0, "mouse delete follows the same path");
// S6 — Esc exits scope stage and fresh input without saving; F with dirty text guards then continues.
await pressF();
await page.keyboard.press("Escape");
await workbenchFocused();
assert.equal(await input.inputValue(), "", "Esc at scope stage leaves no input");
const countBefore = (await problems()).length;
await pressF();
await startText();
await input.fill(`${tag} 放弃的新增 ${stamp}`);
await page.keyboard.press("Escape");
await workbenchFocused();
assert.equal((await problems()).length, countBefore, "Esc never saves");
await expose("dirty-discard continues into the new F capture", async () => {
await pressF();
await startText();
await input.fill(`${tag} 被替换的脏文字 ${stamp}`);
await focusBench(); // F is a workbench shortcut; inside the textbox it would just type
await page.keyboard.press("f");
const guard = panel.getByRole("alert").filter({ hasText: "当前批注文字尚未保存" });
await guard.waitFor();
await guard.getByRole("button", { name: "继续编辑", exact: true }).click();
assert.equal(await input.inputValue(), `${tag} 被替换的脏文字 ${stamp}`, "guard cancel keeps editing");
await focusBench();
await page.keyboard.press("f");
await guard.getByRole("button", { name: "放弃文字", exact: true }).click();
await scope.waitFor(); // discard must actually continue into the new F capture
await page.keyboard.press("Escape");
assert.equal((await problems()).length, countBefore, "discarded drafts never reach the server");
});
// S7 — unsaved text survives viewing; the saved target stays the captured frame's action.
await pressF();
const capturedAt = Number(await range.inputValue());
await startText();
const dirty = `${tag} 未保存仍可观看 ${stamp}`;
await input.fill(dirty);
await bench.getByRole("button", { name: "播放", exact: true }).click();
await page.waitForFunction(
() => [...document.querySelectorAll("video")].some((v) => v.getBoundingClientRect().width > 0 && !v.paused),
);
await bench.getByRole("button", { name: "暂停", exact: true }).click();
await seek(28);
if (mode === "quality") await bench.getByRole("button", { name: "下一片", exact: true }).click();
else await page.locator('[aria-label="验收切片选择"]').getByRole("button").nth(1).click();
await settle();
assert.ok(
Math.abs(Number(await range.inputValue()) - capturedAt) > 0.2,
"viewing actually moved away from the captured frame",
);
assert.equal(await input.inputValue(), dirty, "slice/action navigation keeps unsaved text");
await option(noteA2).click();
await settle();
assert.equal(await input.inputValue(), dirty, "viewing never clears unsaved text");
await saveCurrent();
const dirtySaved = (await problems()).find((p) => p.text === dirty);
assert.ok(
Math.abs(dirtySaved.atSeconds - capturedAt) < 0.07,
"target stays the frame captured by F, not the viewing spot",
);
await option(dirty).click();
await page.keyboard.press("Shift+Delete");
await confirmDelete();
// S8 — empty input cannot save or delete; IME-composing and auto-repeat Ctrl+Enter send nothing.
const versionBefore = (await read()).draft.version;
let puts = 0;
page.on("request", (r) => {
if (r.method() === "PUT" && r.url().endsWith("/review-draft")) puts++;
});
await pressF();
await startText();
await input.press("Control+Enter");
await input.evaluate((el) => {
el.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", ctrlKey: true, repeat: true, bubbles: true }));
el.dispatchEvent(
new KeyboardEvent("keydown", { key: "Enter", ctrlKey: true, isComposing: true, bubbles: true }),
);
});
await page.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))));
assert.equal(puts, 0, "empty/IME/repeat Ctrl+Enter sends no write");
assert.equal((await read()).draft.version, versionBefore);
await page.keyboard.press("Escape");
// S9 — late writes: Esc works mid-save, no second PUT while pending, late success never steals focus;
// failure offers 恢复未保存内容; an identical retry of an unknown write never duplicates.
let releaseSave;
const saveGate = new Promise((resolve) => (releaseSave = resolve));
await page.route("**/review-draft", async (route) => {
if (route.request().method() !== "PUT") return route.continue();
const response = await route.fetch();
await saveGate;
return route.fulfill({ response });
});
const late = `${tag} 迟到保存 ${stamp}`;
await pressF();
await startText();
await input.fill(late);
await Promise.all([
page.waitForRequest((r) => r.method() === "PUT" && r.url().endsWith("/review-draft")),
input.press("Control+Enter"),
]);
await page.keyboard.press("Escape");
await workbenchFocused();
await page.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))));
assert.equal(puts, 1, "serial writes: no second PUT while one is pending");
releaseSave();
await panel
.getByRole("status")
.filter({ hasText: /^已保存$/ })
.waitFor();
assert.notEqual(
await page.evaluate(() => document.activeElement?.getAttribute("aria-label")),
"审查问题说明",
"late success never pulls focus back to the input",
);
assert.equal((await problems()).filter((p) => p.text === late).length, 1);
await page.unroute("**/review-draft");
// Late failure after leaving the input: recovery is offered, focus is never forced.
let releaseFail;
const failGate = new Promise((resolve) => (releaseFail = resolve));
await page.route("**/review-draft", async (route) => {
if (route.request().method() !== "PUT") return route.continue();
await failGate;
return route.abort("failed");
});
const failed = `${tag} 迟到失败 ${stamp}`;
await pressF();
await startText();
await input.fill(failed);
await Promise.all([
page.waitForRequest((r) => r.method() === "PUT" && r.url().endsWith("/review-draft")),
input.press("Control+Enter"),
]);
await page.keyboard.press("Escape"); // leave the input while the save is unresolved
await workbenchFocused();
releaseFail();
const recover = panel.getByRole("button", { name: "恢复未保存内容", exact: true });
await recover.waitFor();
assert.notEqual(
await page.evaluate(() => document.activeElement?.getAttribute("aria-label")),
"审查问题说明",
"late failure never forces focus",
);
await page.unroute("**/review-draft");
await recover.click();
assert.equal(await input.inputValue(), failed, "recovery restores the exact text");
await panel.getByRole("button", { name: "保存批注", exact: true }).click();
await panel
.getByRole("status")
.filter({ hasText: /^已保存$/ })
.waitFor();
assert.equal((await problems()).filter((p) => p.text === failed).length, 1, "recovered retry saves once");
// Unknown result: replay the identical operation through the public API — same-operation
// receipt (200), never a second create. Session/CSRF headers stay in memory only.
const dup = `${tag} 结果未知 ${stamp}`;
await pressF();
await startText();
await input.fill(dup);
const [sent] = await Promise.all([
page.waitForRequest((r) => r.method() === "PUT" && r.url().endsWith("/review-draft")),
input.press("Control+Enter"),
]);
await panel
.getByRole("status")
.filter({ hasText: /^已保存$/ })
.waitFor();
const sentHeaders = await sent.allHeaders();
const replayHeaders = Object.fromEntries(
Object.entries(sentHeaders).filter(([name]) =>
["content-type", "x-review-page", "x-review-generation", "x-droboticflow-csrf-token"].includes(name),
),
);
const replay = await page.evaluate(
async ({ url, body, headers }) => {
const r = await fetch(url, { method: "PUT", headers, body });
return r.status;
},
{ url: sent.url(), body: sent.postData(), headers: replayHeaders },
);
assert.equal(replay, 200, "identical authorized retry returns the same-operation receipt");
assert.equal((await problems()).filter((p) => p.text === dup).length, 1, "identical retry never duplicates");
// S10 — task problems carry a viewAnchor bookmark; aggregate anchors stay isolated per source.
const sliceButtons = mode === "acceptance" ? page.locator('[aria-label="验收切片选择"]').getByRole("button") : null;
if (sliceButtons) {
await sliceButtons.nth(0).click();
await settle();
}
await seek(18);
const taskNote = `${tag} 整体问题 ${stamp}`;
await create(taskNote, "整体");
const taskProblem = (await problems()).find((p) => p.text === taskNote);
assert.equal(taskProblem.scope, "task");
assert.ok(!taskProblem.actionId && !taskProblem.sliceId, "task target stays global");
assert.ok(taskProblem.viewAnchor?.sliceId, "task problem keeps the capture-time viewAnchor");
assert.ok(Number.isFinite(taskProblem.viewAnchor.atSeconds));
assert.equal(
taskProblem.viewAnchor.timeBasis,
mode === "quality" ? "capture-seconds" : "slice-seconds",
"anchor basis follows the evidence",
);
if (mode === "acceptance") {
assert.ok(taskProblem.viewAnchor.sourceItemId);
await sliceButtons.nth(3).click();
await settle();
const otherTaskNote = `${tag} 第二来源整体 ${stamp}`;
await create(otherTaskNote, "整体");
const otherTask = (await problems()).find((p) => p.text === otherTaskNote);
assert.ok(otherTask.viewAnchor?.sourceItemId);
assert.notEqual(
otherTask.viewAnchor.sourceItemId,
taskProblem.viewAnchor.sourceItemId,
"aggregate viewAnchors stay isolated per source",
);
// Recalling the first member's task bookmark from the second member must restore its slice and picture.
await expose("cross-member task viewAnchor recall", async () => {
await option(taskNote).click();
await settle();
assert.equal(
await sliceButtons.nth(0).getAttribute("aria-pressed"),
"true",
"task recall follows viewAnchor back to the original member",
);
assert.ok(
Math.abs(Number(await range.inputValue()) - taskProblem.viewAnchor.atSeconds) < 0.5,
"task recall lands on the anchored picture",
);
});
await sliceButtons.nth(3).click();
await settle();
await seek(18);
const otherAction = `${tag} 第二来源动作 ${stamp}`;
await create(otherAction);
const oa = (await problems()).find((p) => p.text === otherAction);
assert.equal(oa.actionId, first.actionId, "same display action id");
assert.notEqual(oa.sourceItemId, first.sourceItemId, "aggregate source identity stays separate");
}
// S11 — no raw JSON entry; invalid segment wording is 无效片段 everywhere.
assert.equal(await page.getByText("原始记录 JSON", { exact: true }).count(), 0);
assert.equal(await page.getByText("无效动作", { exact: true }).count(), 0, "old wording is gone");
// S12 — screenshots for K3 review: 1413×615 left/right/dual in focus, ordinary otherwise.
// Move to a text-bearing frame so every visible camera renders its own caption.
await actionBlocks.first().click();
await settle();
// Wait for the camera relayout to settle: the expected cameras are visible and each has its own caption.
const captionsSettled = async (cameras) => {
const visibleVideos = () =>
[...document.querySelectorAll("video")].filter(
(v) => v.checkVisibility() && v.getBoundingClientRect().width > 0,
);
try {
await page.waitForFunction(
(count) =>
[...document.querySelectorAll("video")].filter(
(v) => v.checkVisibility() && v.getBoundingClientRect().width > 0,
).length === count &&
document.querySelectorAll(".review-picture-caption-text").length === count,
cameras.length,
);
} catch (cause) {
console.log(
"CAPTION_DEBUG",
JSON.stringify(
await page.evaluate(() => ({
videos: [...document.querySelectorAll("video")].map((v) => ({
w: Math.round(v.getBoundingClientRect().width),
visible: v.checkVisibility(),
})),
captions: [...document.querySelectorAll("[data-camera-caption]")].map((c) =>
c.getAttribute("data-camera-caption"),
),
})),
),
);
throw cause;
}
await page.waitForFunction(
() =>
new Promise((resolve) => {
const key = () =>
[...document.querySelectorAll("video,.review-picture-caption-text")]
.map((el) => {
const r = el.getBoundingClientRect();
return `${Math.round(r.x)},${Math.round(r.y)},${Math.round(r.width)},${Math.round(r.height)}`;
})
.join("|");
const firstKey = key();
requestAnimationFrame(() => requestAnimationFrame(() => resolve(key() === firstKey)));
}),
);
const layout = await page.evaluate(() => {
const rect = (el) => {
const r = el.getBoundingClientRect();
return { x: r.x, y: r.y, w: r.width, h: r.height, bottom: r.bottom };
};
return {
videos: [...document.querySelectorAll("video")]
.filter((v) => v.checkVisibility() && v.getBoundingClientRect().width > 0)
.map(rect),
captions: [...document.querySelectorAll("[data-camera-caption]")].map((c) => ({
camera: c.getAttribute("data-camera-caption"),
...rect(c),
})),
};
});
assert.equal(layout.videos.length, cameras.length, "visible cameras match the selection");
assert.deepEqual(
layout.captions.map((c) => c.camera).sort(),
[...cameras].sort(),
"visible captions belong to the selected cameras",
);
for (const caption of layout.captions) {
const owner = layout.videos.find(
(v) => caption.x + caption.w / 2 >= v.x && caption.x + caption.w / 2 <= v.x + v.w,
);
assert.ok(owner, "caption sits inside its own camera image horizontally");
assert.ok(
Math.abs(caption.x + caption.w / 2 - (owner.x + owner.w / 2)) < owner.w * 0.2,
"caption is horizontally centered on its own camera image",
);
assert.ok(
caption.bottom <= owner.bottom + 2 && caption.bottom > owner.bottom - owner.h * 0.6,
"caption stays near the bottom of its own camera image",
);
}
};
if (focused) {
for (const [camera, label, cameras] of [
["left", "放大左相机", ["left"]],
["right", "放大右相机", ["right"]],
["both", "恢复双画面", ["left", "right"]],
]) {
await page.getByRole("button", { name: label, exact: true }).click();
await settle();
await captionsSettled(cameras);
await page.screenshot({ path: `${dir}/problem-workflow-${mode}-focus-${camera}.png`, fullPage: true });
}
} else {
await captionsSettled(["left", "right"]); // ordinary layout keeps both cameras visible
await page.screenshot({ path: `${dir}/problem-workflow-${mode}-ordinary.png`, fullPage: true });
}
// No formal decision may ever fire from problem editing.
const after = await read("");
assert.equal(after.item.status, before.item.status);
assert.equal(after.item.currentRevision, before.item.currentRevision);
assert.equal(after.acceptanceReviews?.length, before.acceptanceReviews?.length);
assert.equal(formalRequests.length, 0);
assert.deepEqual(errors, []);
reports.push({
mode,
focused,
fFlow: true,
sameTargetMultiple: true,
orderAndRefresh: true,
recallNoAutoEdit: true,
editInPlace: true,
textInputExclusions: true,
deleteConfirmAndMousePath: true,
escStages: true,
viewingWhileUnsaved: true,
emptyImeRepeatGuard: true,
lateWriteRecovery: true,
idempotentRetry: true,
viewAnchor: true,
aggregateSourceIsolation: mode === "acceptance",
noJsonCaptionsUnified: true,
noFormalDecision: true,
knownProductFailures: failures,
});
if (failures.length) process.exitCode = 1;
console.log("PASS", mode, focused ? "focus" : "ordinary", failures.length ? `(${failures.length} exposed)` : "");
await context.close();
}
}
await fs.writeFile(
`${dir}/review-problem-workflow-${process.env.REVIEW_PROBLEM_MODE || "all"}-20260923.json`,
JSON.stringify(reports, null, 2),
);
} finally {
await browser.close();
}