forked from longtao.wu/droboticflow
681 lines
32 KiB
JavaScript
681 lines
32 KiB
JavaScript
import { browserExecutableOptions } from "../../scripts/lib/browser-executable.mjs";
|
||
// Actual acceptance component and media reloads; API responses/media and review-draft writes are isolated synthetic fixtures.
|
||
import { closeBrowserFixture } from "../../scripts/lib/browser-test-lifecycle.mjs";
|
||
import { createServer } from "vite";
|
||
import { chromium } from "playwright";
|
||
import assert from "node:assert/strict";
|
||
import fs from "node:fs/promises";
|
||
import { execFileSync } from "node:child_process";
|
||
|
||
let base = process.env.REVIEW_TEST_URL;
|
||
if (base) {
|
||
const url = new URL(base);
|
||
assert(
|
||
url.protocol === "http:" && ["localhost", "127.0.0.1"].includes(url.hostname) && !url.username && !url.password,
|
||
);
|
||
}
|
||
const out = process.env.REVIEW_TEST_OUTPUT || "local-data/test-results/acceptance-playback-rate";
|
||
await fs.mkdir(out, { recursive: true });
|
||
execFileSync("ffmpeg", [
|
||
"-nostdin",
|
||
"-hide_banner",
|
||
"-loglevel",
|
||
"error",
|
||
"-y",
|
||
"-f",
|
||
"lavfi",
|
||
"-i",
|
||
"testsrc2=s=320x240:r=30:d=8",
|
||
"-c:v",
|
||
"libx264",
|
||
"-pix_fmt",
|
||
"yuv420p",
|
||
"-movflags",
|
||
"+faststart",
|
||
`${out}/synthetic.mp4`,
|
||
]);
|
||
const media = await fs.readFile(`${out}/synthetic.mp4`);
|
||
execFileSync("ffmpeg", [
|
||
"-nostdin",
|
||
"-hide_banner",
|
||
"-loglevel",
|
||
"error",
|
||
"-y",
|
||
"-f",
|
||
"lavfi",
|
||
"-i",
|
||
"testsrc2=s=320x240:r=30:d=25",
|
||
"-c:v",
|
||
"libx264",
|
||
"-pix_fmt",
|
||
"yuv420p",
|
||
"-movflags",
|
||
"+faststart",
|
||
`${out}/source.mp4`,
|
||
]);
|
||
const sourceMedia = await fs.readFile(`${out}/source.mp4`);
|
||
let browser, server, diagnosticPage;
|
||
const launchBrowser = () =>
|
||
chromium.launch({ ...browserExecutableOptions(), headless: true, args: ["--no-proxy-server"] });
|
||
const cases = [];
|
||
try {
|
||
if (!base) {
|
||
server = await createServer({
|
||
configFile: "tests/browser/vite.platform-feedback.config.ts",
|
||
cacheDir: `${out}/vite-cache`,
|
||
optimizeDeps: { entries: ["tests/browser/fixtures/acceptance-playback-rate.tsx"] },
|
||
plugins: process.env.REVIEW_NOTE_BASELINE
|
||
? [
|
||
{
|
||
name: "baseline-note-hook",
|
||
enforce: "pre",
|
||
load(id) {
|
||
if (id.endsWith("/src/hooks/useReviewDraft.ts"))
|
||
return execFileSync("git", ["show", "6d8b011c:src/hooks/useReviewDraft.ts"], { encoding: "utf8" });
|
||
},
|
||
},
|
||
]
|
||
: [],
|
||
server: { host: "127.0.0.1", port: 0 },
|
||
});
|
||
await server.listen();
|
||
base = server.resolvedUrls.local[0].replace(/\/$/, "");
|
||
}
|
||
for (const engine of process.env.REVIEW_NOTE_BASELINE ? ["native"] : ["native", "movi", "movi-fractional"]) {
|
||
// Decoder modes have independent browser-process lifetimes as well as
|
||
// isolated API fixtures; close each owned process before the next mode.
|
||
browser = await launchBrowser();
|
||
const sourceIndex = engine !== "native";
|
||
const fractionalOffset = engine === "movi-fractional" ? 0.023333333 : 0;
|
||
const context = await browser.newContext({ viewport: { width: 1500, height: 1000 } });
|
||
const page = await context.newPage();
|
||
diagnosticPage = page;
|
||
const errors = [];
|
||
page.on("pageerror", (e) => errors.push(e.message));
|
||
await page.addInitScript((engine) => {
|
||
if (engine === "native") localStorage.setItem("droboticflow.movi.force", "native");
|
||
else localStorage.removeItem("droboticflow.movi.force");
|
||
}, engine);
|
||
let draft = {
|
||
itemId: "acceptance-rate-synthetic",
|
||
stageId: "final_acceptance",
|
||
reviewRound: 1,
|
||
resultVersion: "result",
|
||
modelVersion: 2,
|
||
version: 0,
|
||
problems: [],
|
||
updatedAt: "",
|
||
};
|
||
let draftError = false;
|
||
let actionMode = "ready";
|
||
await page.route("**/api/**", async (route) => {
|
||
const url = new URL(route.request().url());
|
||
if (!url.pathname.startsWith("/api/")) return route.continue();
|
||
if (url.pathname.endsWith("/review-draft")) {
|
||
if (route.request().method() === "PUT") {
|
||
const payload = route.request().postDataJSON();
|
||
assert.equal(payload.version, draft.version);
|
||
assert.equal(payload.resultVersion, draft.resultVersion);
|
||
draft = { ...draft, ...payload, version: payload.version + 1 };
|
||
} else {
|
||
assert.equal(route.request().method(), "GET");
|
||
if (draftError) return route.fulfill({ status: 503, json: { error: "Synthetic draft read failure" } });
|
||
}
|
||
return route.fulfill({ json: { draft } });
|
||
}
|
||
assert.match(route.request().method(), /^(GET|HEAD)$/, "fixture must not claim or submit decisions");
|
||
if (url.pathname.endsWith("/members")) {
|
||
const items = Array.from({ length: 3 }, (_, i) => {
|
||
const slice = `slice-${String(i + 1).padStart(6, "0")}`;
|
||
return [
|
||
"left.mp4",
|
||
"right.mp4",
|
||
"annotation.json",
|
||
"synchronized-slice.json",
|
||
"left_pts.csv",
|
||
"right_pts.csv",
|
||
...(sourceIndex ? ["source-index.json"] : []),
|
||
].map((name) => ({
|
||
id: `${slice}-${name}`,
|
||
name,
|
||
group: `slices/${slice}`,
|
||
sizeBytes: 100,
|
||
contentAvailable: true,
|
||
}));
|
||
}).flat();
|
||
return route.fulfill({
|
||
json: { items, total: items.length, limit: 200, offset: 0, recognized: true, truncated: false },
|
||
});
|
||
}
|
||
if (url.pathname.endsWith("/content")) {
|
||
if (url.pathname.includes(".mp4/")) {
|
||
const bytes = sourceIndex ? sourceMedia : media;
|
||
const range = /bytes=(\d+)-(\d*)/.exec(route.request().headers().range || "");
|
||
const start = range ? Number(range[1]) : 0;
|
||
const end = range?.[2] ? Math.min(Number(range[2]), bytes.length - 1) : bytes.length - 1;
|
||
return route.fulfill({
|
||
status: range ? 206 : 200,
|
||
contentType: "video/mp4",
|
||
body: route.request().method() === "HEAD" ? undefined : bytes.subarray(start, end + 1),
|
||
headers: {
|
||
"Accept-Ranges": "bytes",
|
||
"Content-Length": String(end - start + 1),
|
||
...(range ? { "Content-Range": `bytes ${start}-${end}/${bytes.length}` } : {}),
|
||
},
|
||
});
|
||
}
|
||
if (url.pathname.includes("annotation.json") && actionMode === "loading")
|
||
await new Promise((resolve) => setTimeout(resolve, 1500));
|
||
if (url.pathname.includes("annotation.json") && actionMode === "error")
|
||
return route.fulfill({ status: 503, json: { error: "合成动作读取失败" } });
|
||
if (url.pathname.includes("annotation.json") && actionMode === "dense")
|
||
return route.fulfill({
|
||
json: {
|
||
descriptions: Array.from({ length: 24 }, (_, i) => ({
|
||
id: `dense-${i}`,
|
||
clipStartMs: (i * 8000) / 24,
|
||
clipEndMs: ((i + 1) * 8000) / 24,
|
||
description: `密集动作 ${i + 1}`,
|
||
})),
|
||
},
|
||
});
|
||
if (url.pathname.includes("annotation.json") && actionMode === "empty")
|
||
return route.fulfill({ json: { descriptions: [] } });
|
||
if (url.pathname.includes("annotation.json"))
|
||
return route.fulfill({
|
||
json: {
|
||
descriptions: [
|
||
{ id: "invalid-before", clipStartMs: 0, clipEndMs: 2000, isInvalid: true, description: "无效片段" },
|
||
{ id: "brief", clipStartMs: 2000, clipEndMs: 2500, description: "短暂有效动作" },
|
||
{ id: "invalid-after", clipStartMs: 2500, clipEndMs: 7000, isInvalid: true, description: "无效片段" },
|
||
{ id: "blank", clipStartMs: 7000, clipEndMs: 8000 },
|
||
],
|
||
},
|
||
});
|
||
if (url.pathname.includes("synchronized-slice.json")) {
|
||
const index = Number(/slice-(\d+)/.exec(url.pathname)?.[1] || 1) - 1;
|
||
return route.fulfill({
|
||
json: {
|
||
window: { startTimestampUs: index * 8000000, endTimestampUs: (index + 1) * 8000000 },
|
||
boundaryContract: "hardware-frame-v1",
|
||
boundarySeconds: Array.from({ length: 241 }, (_, i) => i / 30),
|
||
left: { pts: { rowCount: 240 } },
|
||
...(sourceIndex
|
||
? {
|
||
sourceIndexSchema: "droboticflow.source-slice-index/v1",
|
||
sourceMediaOffsets: { left: index * 8 + fractionalOffset, right: index * 8 + fractionalOffset },
|
||
rightBoundarySeconds: Array.from({ length: 241 }, (_, i) => i / 30),
|
||
}
|
||
: {}),
|
||
},
|
||
});
|
||
}
|
||
return route.fulfill({
|
||
contentType: "text/csv",
|
||
body: "clip_time_ms\n" + Array.from({ length: 240 }, (_, i) => (i * 1000) / 30).join("\n"),
|
||
});
|
||
}
|
||
return route.fulfill({ json: { items: [] } });
|
||
});
|
||
await page.route("**/__acceptance_playback_rate*", (route) =>
|
||
route.fulfill({
|
||
contentType: "text/html",
|
||
body: `<!doctype html><html><body><div id="root"></div><script type="module">
|
||
import F from '/@react-refresh';F.injectIntoGlobalHook(window);window.$RefreshReg$=()=>{};window.$RefreshSig$=()=>x=>x;window.__vite_plugin_react_preamble_installed__=true;
|
||
await import('/tests/browser/fixtures/acceptance-playback-rate.tsx');</script></body></html>`,
|
||
}),
|
||
);
|
||
await page.goto(`${base}/__acceptance_playback_rate`);
|
||
await page.getByLabel("播放速度").waitFor();
|
||
assert(
|
||
!/SUPPLIER_IDENTITY_MUST_STAY_HIDDEN|ANNOTATOR_IDENTITY_MUST_STAY_HIDDEN/.test(
|
||
await page.locator("body").innerText(),
|
||
),
|
||
"acceptance does not import quality personnel identities",
|
||
);
|
||
const actionList = page.getByRole("listbox", { name: "动作区间", exact: true });
|
||
await actionList.getByRole("option").nth(3).waitFor();
|
||
assert.match(
|
||
await actionList.getByRole("option").first().innerText(),
|
||
/片内 00:00.000–00:02.000.*原视频 00:00.000–00:02.000/s,
|
||
);
|
||
assert(
|
||
await actionList.locator("..").evaluate((el) => el.classList.contains("review-action-list")),
|
||
"acceptance uses the quality review action rail",
|
||
);
|
||
assert.equal(await page.getByRole("combobox", { name: "切片列表", exact: true }).locator("option").count(), 3);
|
||
const brief = actionList.getByRole("option").nth(1);
|
||
assert.match(await brief.innerText(), /0.500 秒.*短区间/s);
|
||
assert.match(await actionList.getByRole("option").nth(3).innerText(), /待标注/);
|
||
assert((await brief.boundingBox()).height >= 82, "brief actions must have a full-sized row");
|
||
await brief.click();
|
||
await page.waitForFunction(() =>
|
||
document.querySelector('.acceptance-action-list [aria-selected="true"]')?.textContent.includes("短暂有效动作"),
|
||
);
|
||
assert.match(
|
||
await page.getByTestId("review-action-times").innerText(),
|
||
/片内 00:02.000–00:02.500.*原视频 00:02.000–00:02.500/s,
|
||
);
|
||
const assertActionTime = async (value) => {
|
||
await page.waitForFunction(
|
||
({ value, offset }) => {
|
||
const player = document.querySelector('[data-camera="left"]');
|
||
return player?.paused && !player.seeking && Math.abs(player.currentTime - offset - value) < 0.06;
|
||
},
|
||
{ value, offset: sourceIndex ? fractionalOffset : 0 },
|
||
);
|
||
};
|
||
await assertActionTime(2);
|
||
// Navigation follows the selected row and never skips a sub-three-second action.
|
||
await page.keyboard.press("ArrowDown");
|
||
await assertActionTime(2.5);
|
||
await page.keyboard.press("ArrowUp");
|
||
await assertActionTime(2);
|
||
await page.keyboard.press("ArrowUp");
|
||
await assertActionTime(0);
|
||
await page.keyboard.press("ArrowUp");
|
||
await assertActionTime(0);
|
||
await actionList.getByRole("option").last().click();
|
||
await assertActionTime(7);
|
||
await page.keyboard.press("ArrowDown");
|
||
await assertActionTime(7);
|
||
await brief.click();
|
||
await assertActionTime(2);
|
||
await page.screenshot({ path: `${out}/${engine}-short-action-list.png`, fullPage: true });
|
||
const listBox = await actionList.boundingBox();
|
||
const videoBox = await page.locator('[data-testid="capture-video-panel"]').boundingBox();
|
||
assert(listBox.x + listBox.width <= videoBox.x, "action list stays left of the video");
|
||
await page.getByRole("button", { name: "快捷键帮助", exact: true }).click();
|
||
await page.keyboard.press("ArrowDown");
|
||
await page.keyboard.press("Escape");
|
||
await assertActionTime(2);
|
||
// Read-only viewing still permits list navigation; IME/text entry is tested
|
||
// below using the actual review problem editor.
|
||
// Keep the same single-camera source player across keep -> discard -> keep.
|
||
// Caption DOM must recover without toggling captions or resizing the window.
|
||
const sliceChoices = page.locator('[aria-label="验收切片选择"]');
|
||
const leftCaption = page.locator('[data-camera-caption="left"]');
|
||
await leftCaption.waitFor();
|
||
assert.match(await leftCaption.innerText(), /第一片/);
|
||
await sliceChoices.getByRole("button", { name: /已舍弃/ }).click();
|
||
await page.getByTestId("acceptance-discard-evidence").waitFor();
|
||
await page.waitForFunction(() => {
|
||
const p = document.querySelector('[data-camera="left"]');
|
||
return p?.readyState >= 2 && !p.seeking;
|
||
});
|
||
await page.getByRole("combobox", { name: "切片列表", exact: true }).selectOption("0:2");
|
||
await page.waitForFunction(
|
||
() => document.querySelector('[data-testid="review-current-slice"]')?.textContent === "第二片",
|
||
);
|
||
await page.waitForFunction(() => {
|
||
const p = document.querySelector('[data-camera="left"]');
|
||
return p?.readyState >= 2 && !p.seeking;
|
||
});
|
||
await leftCaption.waitFor({ timeout: 8000 });
|
||
assert.match(await leftCaption.innerText(), /第二片/);
|
||
assert.match(await actionList.getByRole("option").first().innerText(), /原视频 00:08.000–00:10.000/);
|
||
await page.waitForFunction(
|
||
() => document.querySelector('[data-testid="original-video-position"]')?.textContent === "原视频 00:08.000",
|
||
);
|
||
await page.getByRole("button", { name: "播放", exact: true }).click();
|
||
await page.waitForFunction(
|
||
(offset) => {
|
||
const p = document.querySelector('[data-camera="left"]');
|
||
return p && !p.paused && p.currentTime > offset + 0.3;
|
||
},
|
||
sourceIndex ? 8 + fractionalOffset : 0,
|
||
);
|
||
assert.match(await leftCaption.innerText(), /第二片/);
|
||
await page.getByRole("button", { name: "暂停", exact: true }).click();
|
||
await page.screenshot({ path: `${out}/${engine}-caption-after-discard.png`, fullPage: true });
|
||
await sliceChoices.getByRole("button", { name: /^第一片/ }).click();
|
||
await page.waitForFunction(
|
||
() => document.querySelector('[data-testid="review-current-slice"]')?.textContent === "第一片",
|
||
);
|
||
await page.getByRole("button", { name: "恢复双画面", exact: true }).click();
|
||
async function assertRate(rate) {
|
||
assert.equal(await page.getByLabel("播放速度").inputValue(), String(rate));
|
||
await page.waitForFunction(
|
||
({ rate, tag }) => {
|
||
const players = [...document.querySelectorAll("[data-camera]")].filter((p) =>
|
||
["VIDEO", "MOVI-PLAYER"].includes(p.tagName),
|
||
);
|
||
return (
|
||
players.length === 2 &&
|
||
players.every((p) => p.tagName === tag && p.readyState >= 2 && Math.abs(p.playbackRate - rate) < 0.001)
|
||
);
|
||
},
|
||
{ rate, tag: sourceIndex ? "MOVI-PLAYER" : "VIDEO" },
|
||
{ timeout: 20000 },
|
||
);
|
||
}
|
||
await page.getByLabel("播放速度").selectOption("2");
|
||
await assertRate(2);
|
||
await page.getByRole("button", { name: "下一片", exact: true }).click();
|
||
await page.waitForFunction(
|
||
() => document.querySelector('[data-testid="review-current-slice"]')?.textContent === "第二片",
|
||
);
|
||
await assertRate(2);
|
||
await page.getByRole("button", { name: "播放", exact: true }).click();
|
||
await page.waitForFunction(
|
||
(offset) =>
|
||
[...document.querySelectorAll("[data-camera]")].some(
|
||
(p) => ["VIDEO", "MOVI-PLAYER"].includes(p.tagName) && !p.paused && p.currentTime > offset + 0.3,
|
||
),
|
||
sourceIndex ? 8 + fractionalOffset : 0,
|
||
);
|
||
await page.getByRole("button", { name: "暂停", exact: true }).click();
|
||
await assertRate(2);
|
||
await page.getByLabel("播放速度").selectOption("1.5");
|
||
await page.getByRole("button", { name: "下一片", exact: true }).click();
|
||
await page.waitForFunction(
|
||
() => document.querySelector('[data-testid="review-current-slice"]')?.textContent === "已舍弃:手部动作太少",
|
||
);
|
||
await assertRate(1.5);
|
||
await page.getByRole("button", { name: "上一片", exact: true }).click();
|
||
await page.waitForFunction(
|
||
() => document.querySelector('[data-testid="review-current-slice"]')?.textContent === "第二片",
|
||
);
|
||
await assertRate(1.5);
|
||
// Actual keyboard events, immediately followed by play: do not wait for
|
||
// canplay/seeked first. Older Movi state flags could strand this sequence
|
||
// in positioning, or let an old pause event cancel the new play request.
|
||
const shortcutChanges = process.env.REVIEW_NOTE_BASELINE ? 0 : 12;
|
||
for (let iteration = 0; iteration < shortcutChanges; iteration++) {
|
||
const forward = iteration % 2 === 0;
|
||
await page.getByTestId("final-acceptance-workspace").focus();
|
||
await page.keyboard.press(forward ? "Control+ArrowRight" : "Control+ArrowLeft");
|
||
await page.waitForFunction(
|
||
(name) => document.querySelector('[data-testid="review-current-slice"]')?.textContent === name,
|
||
forward ? "已舍弃:手部动作太少" : "第二片",
|
||
);
|
||
await page.keyboard.press("Space");
|
||
const offset = sourceIndex ? (forward ? 16 : 8) + fractionalOffset : 0;
|
||
await page.waitForFunction(
|
||
(offset) => {
|
||
const players = [...document.querySelectorAll("[data-camera]")].filter((p) =>
|
||
["VIDEO", "MOVI-PLAYER"].includes(p.tagName),
|
||
);
|
||
return (
|
||
players.length === 2 &&
|
||
players.every((p) => !p.paused && !p.seeking && p.readyState >= 2 && p.currentTime > offset + 0.35)
|
||
);
|
||
},
|
||
offset,
|
||
{ timeout: 8000 },
|
||
);
|
||
await page.keyboard.press("Space");
|
||
}
|
||
const timestampCard = page.getByRole("button", { name: /^当前时间点意见/ });
|
||
const sliceCard = page.getByRole("button", { name: /^当前切片意见/ });
|
||
// Real playback must freeze at mouse-entry time, just like the F shortcut.
|
||
await page.getByRole("button", { name: "播放", exact: true }).click();
|
||
await page.waitForFunction(() =>
|
||
[...document.querySelectorAll("[data-camera]")].some(
|
||
(p) => ["VIDEO", "MOVI-PLAYER"].includes(p.tagName) && !p.paused,
|
||
),
|
||
);
|
||
await timestampCard.click();
|
||
assert(
|
||
await page.evaluate(() =>
|
||
[...document.querySelectorAll("[data-camera]")]
|
||
.filter((p) => ["VIDEO", "MOVI-PLAYER"].includes(p.tagName))
|
||
.every((p) => p.paused),
|
||
),
|
||
"mouse timestamp entry must pause actual media",
|
||
);
|
||
const firstAnchor = await page.getByLabel("批注对象").textContent();
|
||
await page.waitForTimeout(350);
|
||
assert.equal(
|
||
await page.getByLabel("批注对象").textContent(),
|
||
firstAnchor,
|
||
"typing target must not drift with playback",
|
||
);
|
||
const noteInput = page.getByRole("textbox", { name: "审查问题说明" });
|
||
await noteInput.fill("时间点固定在当前画面");
|
||
const frozenSelection = await actionList.locator('[aria-selected="true"]').textContent();
|
||
await page.keyboard.press("ArrowDown");
|
||
await page.keyboard.press("Control+ArrowRight");
|
||
assert.equal(await actionList.locator('[aria-selected="true"]').textContent(), frozenSelection);
|
||
assert.equal(await noteInput.inputValue(), "时间点固定在当前画面");
|
||
await page.getByRole("button", { name: "保存批注", exact: true }).click();
|
||
await page.getByRole("button", { name: "保存批注", exact: true }).waitFor({ state: "hidden" });
|
||
assert.equal(draft.problems.length, 1);
|
||
const problem = draft.problems[0];
|
||
assert.equal(problem.scope, "timestamp");
|
||
await page.getByLabel("时间点意见标记", { exact: true }).waitFor();
|
||
assert.equal(await page.getByRole("button", { name: "时间点意见 时间点固定在当前画面", exact: true }).count(), 1);
|
||
assert.equal(problem.timeBasis, "slice-seconds");
|
||
assert.equal(problem.sourceItemId, "synthetic-source");
|
||
assert.equal(problem.sliceId, "slice-000002");
|
||
assert(firstAnchor.includes(problem.atSeconds.toFixed(3)), "saved timestamp must equal frozen editor anchor");
|
||
const marker = page.getByRole("button", { name: "时间点意见 时间点固定在当前画面", exact: true });
|
||
const geometry = await marker.evaluate((button) => {
|
||
const timeline = button.closest(".acceptance-total-timeline");
|
||
if (!timeline) throw new Error("The timestamp marker must share the total timeline with the slider and slices");
|
||
const rect = (selector) => timeline.querySelector(selector).getBoundingClientRect();
|
||
const noteRow = rect('[aria-label="时间点意见标记"]');
|
||
const slider = rect('[aria-label="总视频播放位置"]');
|
||
const slices = rect('[aria-label="验收切片选择"]');
|
||
const selected = rect('[aria-label="验收切片选择"] button[aria-pressed="true"]');
|
||
const marker = button.getBoundingClientRect();
|
||
return {
|
||
startsAligned: Math.abs(noteRow.left - slices.left) < 1 && Math.abs(slider.left + 8 - slices.left) < 1,
|
||
endsAligned: Math.abs(noteRow.right - slices.right) < 1 && Math.abs(slider.right - 8 - slices.right) < 1,
|
||
rowsSeparated: marker.bottom <= noteRow.bottom && noteRow.bottom <= slider.top && slider.bottom <= slices.top,
|
||
selectedSliceStart: (selected.left - slices.left) / slices.width,
|
||
markerPosition: (marker.x + marker.width / 2 - slices.left) / slices.width,
|
||
};
|
||
});
|
||
assert(geometry.startsAligned && geometry.endsAligned, "timeline rows must share one horizontal scale");
|
||
assert(geometry.rowsSeparated, "timestamp markers, slider and slice buttons must occupy separate rows");
|
||
assert(Math.abs(geometry.selectedSliceStart - 8 / 24) < 0.001, "slice boundary must match its cumulative time");
|
||
assert(
|
||
Math.abs(geometry.markerPosition - (8 + problem.atSeconds) / 24) < 0.001,
|
||
"marker must match its total time",
|
||
);
|
||
await marker.click();
|
||
await page.waitForFunction((value) => {
|
||
const slider = document.querySelector('input[aria-label="总视频播放位置"]');
|
||
return slider && Math.abs(Number(slider.value) - (8 + value)) < 0.15;
|
||
}, problem.atSeconds);
|
||
await page.screenshot({ path: `${out}/${engine}-timestamp-marker.png`, fullPage: true });
|
||
await page.getByLabel("字幕位置").selectOption("top");
|
||
await page.waitForFunction(() => document.querySelectorAll('[data-caption-placement="top"]').length === 2);
|
||
await page.getByRole("button", { name: "下一片", exact: true }).click();
|
||
await page.getByTestId("acceptance-discard-evidence").waitFor();
|
||
assert.equal(
|
||
await page.getByLabel("时间点意见标记", { exact: true }).count(),
|
||
0,
|
||
"another slice must not inherit markers",
|
||
);
|
||
await assertRate(1.5);
|
||
await page.waitForFunction(
|
||
(offset) =>
|
||
[...document.querySelectorAll("[data-camera]")]
|
||
.filter((p) => ["VIDEO", "MOVI-PLAYER"].includes(p.tagName))
|
||
.every((p) => p.readyState >= 2 && !p.seeking && Math.abs(p.currentTime - offset) < 0.1),
|
||
sourceIndex ? 16 + fractionalOffset : 0,
|
||
);
|
||
await page.getByText("定位中,时间为目标位置…", { exact: true }).waitFor({ state: "hidden" });
|
||
assert(await timestampCard.isDisabled(), "discarded timestamp must not offer a server-rejected target");
|
||
assert(await page.getByRole("button", { name: /^当前动作意见/ }).isDisabled());
|
||
await sliceCard.click();
|
||
await page.getByRole("textbox", { name: "审查问题说明" }).fill("舍弃原因需要修改");
|
||
await page.getByRole("button", { name: "保存批注", exact: true }).click();
|
||
await page.getByRole("button", { name: "保存批注", exact: true }).waitFor({ state: "hidden" });
|
||
assert(
|
||
draft.problems.some((p) => p.scope === "slice" && p.sliceId === "slice-000003" && p.text === "舍弃原因需要修改"),
|
||
);
|
||
await page.screenshot({ path: `${out}/${engine}-discard-note-top.png`, fullPage: true });
|
||
await page.reload();
|
||
await page.getByLabel("字幕位置").waitFor();
|
||
assert.equal(
|
||
await page.getByLabel("字幕位置").inputValue(),
|
||
"top",
|
||
"caption placement persists across remount/reload",
|
||
);
|
||
await page.getByRole("button", { name: "下一片", exact: true }).click();
|
||
await page.getByLabel("时间点意见标记", { exact: true }).waitFor();
|
||
assert.equal(
|
||
await page.getByRole("button", { name: "时间点意见 时间点固定在当前画面", exact: true }).count(),
|
||
1,
|
||
"saved marker survives reload and slice navigation",
|
||
);
|
||
await page.goto(`${base}/__acceptance_playback_rate?readonly=1`);
|
||
await sliceCard.waitFor();
|
||
assert(await sliceCard.isDisabled(), "read-only viewers cannot enter edit mode");
|
||
assert(
|
||
!(await page.getByRole("combobox", { name: "切片列表", exact: true }).isDisabled()),
|
||
"read-only slice navigation remains available",
|
||
);
|
||
assert(await page.getByRole("button", { name: "验收通过", exact: true }).isDisabled());
|
||
assert(await page.getByRole("button", { name: "打回质检", exact: true }).isDisabled());
|
||
await brief.click();
|
||
await assertActionTime(2);
|
||
await page.keyboard.press("ArrowDown");
|
||
await assertActionTime(2.5);
|
||
await page.screenshot({ path: `${out}/${engine}-readonly.png`, fullPage: true });
|
||
draftError = true;
|
||
await page.reload();
|
||
await page.getByRole("alert").first().waitFor();
|
||
assert(await sliceCard.isDisabled(), "failed draft loading keeps edit locked");
|
||
await page.screenshot({ path: `${out}/${engine}-draft-error.png`, fullPage: true });
|
||
if (engine === "native") {
|
||
draftError = false;
|
||
await page.goto(`${base}/__acceptance_playback_rate?normal=1`);
|
||
await brief.waitFor();
|
||
await brief.click();
|
||
await assertActionTime(2);
|
||
await page.screenshot({ path: `${out}/normal-action-list.png`, fullPage: true });
|
||
await page.setViewportSize({ width: 1000, height: 800 });
|
||
await page.evaluate(() => document.documentElement.classList.add("dark"));
|
||
await page.screenshot({ path: `${out}/dark-narrow-action-list.png`, fullPage: true });
|
||
assert(await brief.isVisible());
|
||
assert(
|
||
await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth),
|
||
"list must not widen the page",
|
||
);
|
||
await page.setViewportSize({ width: 1500, height: 1000 });
|
||
actionMode = "empty";
|
||
await page.reload();
|
||
await actionList.getByText("暂无动作区间", { exact: true }).waitFor();
|
||
assert.equal(await actionList.getByRole("option").count(), 0);
|
||
await page.screenshot({ path: `${out}/empty-action-list.png`, fullPage: true });
|
||
actionMode = "error";
|
||
await page.reload();
|
||
await actionList.getByRole("alert").waitFor();
|
||
assert.equal(await actionList.getByRole("option").count(), 0);
|
||
await page.screenshot({ path: `${out}/error-action-list.png`, fullPage: true });
|
||
actionMode = "loading";
|
||
await page.reload();
|
||
await actionList.getByRole("status").waitFor();
|
||
await page.screenshot({ path: `${out}/loading-action-list.png`, fullPage: true });
|
||
await brief.waitFor();
|
||
actionMode = "dense";
|
||
await page.goto(`${base}/__acceptance_playback_rate`);
|
||
await actionList.getByRole("option").nth(23).waitFor();
|
||
const horizontalScroll = page.getByLabel("动作时间轴横向滚动", { exact: true });
|
||
await horizontalScroll.waitFor();
|
||
await actionList.getByRole("option").nth(22).click();
|
||
await assertActionTime(22 / 3);
|
||
await page.waitForFunction(
|
||
() => document.querySelector('[data-testid="acceptance-action-viewport"]').scrollLeft > 1000,
|
||
);
|
||
const anchor = await actionList.locator('[aria-selected="true"]').textContent();
|
||
await horizontalScroll.focus();
|
||
await page.keyboard.press("Home");
|
||
await page.keyboard.press("ArrowRight");
|
||
await page.keyboard.press("End");
|
||
await assertActionTime(22 / 3);
|
||
assert.equal(
|
||
await actionList.locator('[aria-selected="true"]').textContent(),
|
||
anchor,
|
||
"scroll keys must not navigate review actions or frames",
|
||
);
|
||
const scrollBox = await horizontalScroll.boundingBox();
|
||
const footerBox = await page.locator('[data-testid="final-acceptance-workspace"] > footer').boundingBox();
|
||
assert(scrollBox.y + scrollBox.height <= footerBox.y, "scrollbar stays above decision buttons");
|
||
assert(scrollBox.y + scrollBox.height < 1000, "dense actions must stay inside the viewport");
|
||
assert(
|
||
await actionList.evaluate((el) => el.scrollHeight > el.clientHeight),
|
||
"dense left list scrolls instead of expanding the video row",
|
||
);
|
||
await page.screenshot({ path: `${out}/dense-focused-scrollbar.png`, fullPage: true });
|
||
|
||
actionMode = "ready";
|
||
draft.problems = Array.from({ length: 160 }, (_, index) => ({
|
||
id: `dense-note-${index}`,
|
||
sourceItemId: "synthetic-source",
|
||
sliceId: index < 158 ? "slice-000001" : "slice-000003",
|
||
timeBasis: "slice-seconds",
|
||
scope: "timestamp",
|
||
atSeconds: index < 158 ? index * 0.045 : index === 158 ? 7.7 : 7.8,
|
||
text: `时间点样例 ${index + 1}`,
|
||
}));
|
||
await page.setViewportSize({ width: 850, height: 800 });
|
||
await page.goto(`${base}/__acceptance_playback_rate?readonly=1`);
|
||
const layer = page.getByLabel("时间点意见标记", { exact: true });
|
||
const badges = layer.getByRole("button", { name: /^时间点意见 \d+ 条$/ });
|
||
await badges.first().waitFor();
|
||
assert(
|
||
await badges.evaluateAll((buttons) =>
|
||
buttons.every(
|
||
(button, index) =>
|
||
index === 0 || buttons[index - 1].getBoundingClientRect().right <= button.getBoundingClientRect().left,
|
||
),
|
||
),
|
||
"dense markers in a narrow viewport must stay individually clickable",
|
||
);
|
||
await page.getByRole("combobox", { name: "切片列表", exact: true }).selectOption({ index: 2 });
|
||
const group = layer.getByRole("button", { name: "时间点意见 2 条", exact: true });
|
||
await group.click();
|
||
const endNote = layer.getByRole("button", { name: /时间点样例 160$/ });
|
||
const popup = await endNote.evaluate((button) => {
|
||
const menu = button.parentElement.getBoundingClientRect();
|
||
const layer = button.closest('[aria-label="时间点意见标记"]').getBoundingClientRect();
|
||
return { offset: menu.left - layer.left, rightGap: layer.right - menu.right };
|
||
});
|
||
assert(popup.offset >= 0 && popup.rightGap >= -1 && popup.rightGap < 2, "end menu must fit inside the axis");
|
||
await endNote.click();
|
||
await page.waitForFunction(() => {
|
||
const slider = document.querySelector('[aria-label="总视频播放位置"]');
|
||
return Math.abs(Number(slider.value) - 23.8) < 0.04;
|
||
});
|
||
}
|
||
assert.deepEqual(errors, []);
|
||
await page.screenshot({ path: `${out}/${engine}.png`, fullPage: true });
|
||
cases.push({ engine, sliceChanges: 3 + shortcutChanges, retainedRates: [2, 1.5, 1.5], errors });
|
||
await context.close();
|
||
await closeBrowserFixture({ browser });
|
||
browser = undefined;
|
||
}
|
||
await fs.writeFile(`${out}/report.json`, JSON.stringify({ passed: true, cases }, null, 2));
|
||
console.log(JSON.stringify({ passed: true, cases }));
|
||
} catch (error) {
|
||
console.error(error);
|
||
if (diagnosticPage) {
|
||
await diagnosticPage.screenshot({ path: `${out}/failure.png`, fullPage: true }).catch(() => {});
|
||
console.log(
|
||
await diagnosticPage
|
||
.evaluate(() => ({
|
||
captions: [...document.querySelectorAll("[data-camera-caption]")].map((p) => ({
|
||
placement: p.getAttribute("data-caption-placement"),
|
||
camera: p.getAttribute("data-camera-caption"),
|
||
})),
|
||
media: [...document.querySelectorAll("[data-camera]")].map((p) => ({
|
||
tag: p.tagName,
|
||
width: p.clientWidth,
|
||
height: p.clientHeight,
|
||
ready: p.readyState,
|
||
paused: p.paused,
|
||
})),
|
||
}))
|
||
.catch(() => null),
|
||
);
|
||
}
|
||
throw error;
|
||
} finally {
|
||
await closeBrowserFixture({ browser, vite: server });
|
||
}
|