forked from longtao.wu/droboticflow
196 lines
8.1 KiB
JavaScript
196 lines
8.1 KiB
JavaScript
// Real acceptance workspace and styles, synthetic media only. Requires the local Vite server.
|
|
import { chromium } from "playwright";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs/promises";
|
|
import { execFileSync } from "node:child_process";
|
|
|
|
const base = process.env.REVIEW_TEST_URL || "http://127.0.0.1:5173";
|
|
const out = process.env.REVIEW_TEST_OUTPUT || "verification/acceptance-video-layout";
|
|
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",
|
|
out + "/mock.mp4",
|
|
]);
|
|
const media = await fs.readFile(out + "/mock.mp4");
|
|
const browser = await chromium.launch({
|
|
...(process.env.BROWSER_PATH ? { executablePath: process.env.BROWSER_PATH } : { channel: "chrome" }),
|
|
headless: true,
|
|
args: ["--no-proxy-server"],
|
|
timeout: 30000,
|
|
});
|
|
const cases = [],
|
|
errors = [];
|
|
try {
|
|
const page = await browser.newPage();
|
|
page.setDefaultTimeout(15000);
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
const names = [
|
|
"annotation.json",
|
|
"imu.csv",
|
|
"left.mp4",
|
|
"right.mp4",
|
|
"left_pts.csv",
|
|
"right_pts.csv",
|
|
"synchronized-slice.json",
|
|
];
|
|
await page.route("**/api/**", (route) => {
|
|
const p = new URL(route.request().url()).pathname;
|
|
if (!p.startsWith("/api/")) return route.continue();
|
|
if (p.endsWith("/members"))
|
|
return route.fulfill({
|
|
json: {
|
|
items: names.map((name) => ({
|
|
id: name,
|
|
name,
|
|
group: "slices/slice-000001",
|
|
sizeBytes: 100,
|
|
contentAvailable: true,
|
|
})),
|
|
offset: 0,
|
|
limit: 200,
|
|
total: names.length,
|
|
recognized: true,
|
|
runId: "run",
|
|
artifactId: "mat",
|
|
truncated: false,
|
|
},
|
|
});
|
|
if (p.endsWith("/content")) {
|
|
if (p.includes(".mp4/")) return route.fulfill({ contentType: "video/mp4", body: media });
|
|
if (p.includes("annotation.json")) return route.fulfill({ json: { actions: [] } });
|
|
if (p.includes("synchronized-slice.json"))
|
|
return route.fulfill({
|
|
json: {
|
|
window: { startTimestampUs: 0, endTimestampUs: 8000000 },
|
|
boundaryContract: "hardware-frame-v1",
|
|
boundarySeconds: Array.from({ length: 241 }, (_, i) => i / 30),
|
|
left: { pts: { rowCount: 240 } },
|
|
},
|
|
});
|
|
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_video_layout?*", (route) => {
|
|
const focused = new URL(route.request().url()).searchParams.get("focused") === "true";
|
|
return route.fulfill({
|
|
contentType: "text/html; charset=utf-8",
|
|
body: `<!doctype html><html><head><meta charset="utf-8"></head><body>
|
|
<main class="annotation-operations-page" ${focused ? 'data-review-focused="true"' : ""}>
|
|
<div id="root" style="height:calc(100dvh - 32px);padding:8px"></div>
|
|
</main><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('/src/index.css');await import('/src/styles/capture-workspace.css');await import('/src/styles/review-workspace.css');
|
|
const R=await import('/node_modules/.vite/deps/react.js');const React=R.default||R;const D=await import('/node_modules/.vite/deps/react-dom_client.js');
|
|
const {FinalAcceptanceWorkspace}=await import('/src/components/FinalAcceptanceWorkspace.tsx');
|
|
const item={id:'accept',version:1,status:'claimed',assignedUserId:'u',processingProfile:'raw_human',subject:{payload:{items:[{
|
|
materialization:{artifactId:'mat',revision:1,manifestSha256:'one',sliceCount:1,coverage:{contiguous:true,gapMicroseconds:0,overlapMicroseconds:0}},
|
|
finalSlices:[{id:'slice-1',name:'布局测试',start:0,end:8}]}]}}};
|
|
(D.createRoot||D.default.createRoot)(document.getElementById('root')).render(React.createElement(FinalAcceptanceWorkspace,{
|
|
item,mine:true,saving:false,focusedLayout:${focused},draft:{headpose:'include',handpose:'include',exclusionReason:''},comment:'',
|
|
onDraftChange:()=>{},onCommentChange:()=>{},onApprove:()=>{},onReject:()=>{}}));
|
|
</script></body></html>`,
|
|
});
|
|
});
|
|
for (const viewport of [
|
|
{ width: 3135, height: 1412 },
|
|
{ width: 1600, height: 1000 },
|
|
{ width: 1413, height: 615 },
|
|
]) {
|
|
await page.setViewportSize(viewport);
|
|
for (const focused of [false, true]) {
|
|
console.log(`Checking ${viewport.width}x${viewport.height}, focused=${focused}`);
|
|
await page.goto(base + "/__acceptance_video_layout?focused=" + focused);
|
|
await page.waitForFunction(() => [...document.querySelectorAll("video")].some((v) => v.readyState >= 2));
|
|
assert.equal(await page.getByTestId("review-current-slice").innerText(), "布局测试");
|
|
assert.equal(await page.getByTestId("review-current-slice").isVisible(), true);
|
|
for (const camera of focused ? ["left", "right", "both"] : ["left"]) {
|
|
if (focused)
|
|
await page
|
|
.getByRole("button", {
|
|
name: { left: "放大左相机", right: "放大右相机", both: "恢复双画面" }[camera],
|
|
exact: true,
|
|
})
|
|
.click();
|
|
await page.waitForFunction(() =>
|
|
[...document.querySelectorAll(".capture-video-surface > video")]
|
|
.filter((v) => v.getBoundingClientRect().width > 0)
|
|
.every((v) => v.readyState >= 2),
|
|
);
|
|
const sizes = await page.evaluate(() =>
|
|
[...document.querySelectorAll(".capture-video-surface > video")]
|
|
.filter((v) => v.getBoundingClientRect().width > 0)
|
|
.map((v) => ({
|
|
camera: v.dataset.camera,
|
|
height: v.getBoundingClientRect().height,
|
|
stageHeight: v.parentElement.getBoundingClientRect().height,
|
|
objectFit: getComputedStyle(v).objectFit,
|
|
error: v.error?.code ?? null,
|
|
})),
|
|
);
|
|
assert.equal(sizes.length, camera === "both" ? 2 : 1);
|
|
for (const size of sizes) {
|
|
assert.equal(size.error, null);
|
|
assert.equal(size.objectFit, "contain");
|
|
if (focused)
|
|
assert.ok(
|
|
Math.abs(size.height - size.stageHeight) < 2,
|
|
`${camera} video ${size.height}px must fill stage ${size.stageHeight}px`,
|
|
);
|
|
else assert.ok(size.height <= 200 && size.height >= 120, "normal preview remains compact");
|
|
}
|
|
cases.push({ viewport, focused, camera, sizes });
|
|
}
|
|
}
|
|
}
|
|
const playback = await page.evaluate(async () => {
|
|
const videos = [...document.querySelectorAll(".capture-video-surface > video")].filter(
|
|
(v) => v.getBoundingClientRect().width > 0,
|
|
);
|
|
const starts = videos.map((v) => v.currentTime);
|
|
await Promise.all(
|
|
videos.map((v) => {
|
|
v.muted = true;
|
|
return v.play();
|
|
}),
|
|
);
|
|
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
return videos.map((v, i) => {
|
|
v.pause();
|
|
return { camera: v.dataset.camera, advanced: v.currentTime - starts[i], error: v.error?.code ?? null };
|
|
});
|
|
});
|
|
assert.ok(
|
|
playback.every((v) => v.advanced > 1 && v.error === null),
|
|
"both cameras still play",
|
|
);
|
|
assert.deepEqual(errors, []);
|
|
await page.screenshot({ path: out + "/minimum-focused.png", fullPage: true });
|
|
await fs.writeFile(out + "/result.json", JSON.stringify({ cases, playback, errors }, null, 2));
|
|
console.log(`PASS ${cases.length} viewport/layout/camera cases and dual playback`);
|
|
} catch (error) {
|
|
const page = browser.contexts()[0]?.pages()[0];
|
|
if (page) {
|
|
await page.screenshot({ path: out + "/failure.png", fullPage: true });
|
|
console.error((await page.locator("body").innerText()).slice(0, 2500), errors);
|
|
}
|
|
throw error;
|
|
} finally {
|
|
await browser.close();
|
|
}
|