droboticflow/tests/frontend/capture-annotation-workbench.test.mjs

522 lines
31 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.

import assert from "node:assert/strict";
import fs from "node:fs";
import test from "node:test";
import { freezeSliceEditSession, sliceEditWorkspaceChanged } from "../../src/lib/slice-edit-session.js";
import { CAPTURE_PLAYBACK_RATES } from "../../src/lib/annotation-workbench.js";
const workbench = fs.readFileSync(
new URL("../../src/components/CaptureAnnotationWorkbench.tsx", import.meta.url),
"utf8",
);
const preview = fs.readFileSync(
new URL("../../src/dev/CaptureAnnotationWorkbenchPreview.tsx", import.meta.url),
"utf8",
);
const main = fs.readFileSync(new URL("../../src/main.tsx", import.meta.url), "utf8");
const app = fs.readFileSync(new URL("../../src/App.tsx", import.meta.url), "utf8");
const layout = fs.readFileSync(new URL("../../src/components/Layout.tsx", import.meta.url), "utf8");
const sidebar = fs.readFileSync(new URL("../../src/components/Sidebar.tsx", import.meta.url), "utf8");
const theme = fs.readFileSync(new URL("../../src/context/ThemeContext.tsx", import.meta.url), "utf8");
const annotationOperations = fs.readFileSync(
new URL("../../src/pages/AnnotationOperations.tsx", import.meta.url),
"utf8",
);
const css = fs.readFileSync(new URL("../../src/index.css", import.meta.url), "utf8");
const transport = fs.readFileSync(new URL("../../src/hooks/useCaptureVideoTransport.ts", import.meta.url), "utf8");
const sliceEditPanel = fs.readFileSync(new URL("../../src/components/SliceEditPanel.tsx", import.meta.url), "utf8");
const sliceEditConflictList = fs.readFileSync(
new URL("../../src/components/SliceEditConflictList.tsx", import.meta.url),
"utf8",
);
test("playback rates share the same menu and validation without seeking (movi cap 4x)", () => {
// 6x/8x removed 2026-10-12: the vendored movi-player host clamps playbackRate
// to getMaxAllowedRate() (patched 2 → 4 in public/vendor/movi-player-0.4.1),
// so options above 4x were silently dead in the movi branch.
assert.deepEqual(CAPTURE_PLAYBACK_RATES, [0.5, 1, 1.5, 2, 4]);
assert.ok(Object.isFrozen(CAPTURE_PLAYBACK_RATES));
assert.match(workbench, /CAPTURE_PLAYBACK_RATES\.map/);
const changeRate = workbench.slice(
workbench.indexOf("const changePlaybackRate ="),
workbench.indexOf("const closeDescriptionDictionary ="),
);
assert.match(changeRate, /!CAPTURE_PLAYBACK_RATES\.includes\(rate\)/);
assert.match(changeRate, /leftVideoRef\.current\.playbackRate = rate/);
assert.match(changeRate, /rightVideoRef\.current\.playbackRate = rate/);
assert.doesNotMatch(changeRate, /\bseek\(|currentTime\s*=/);
});
test("speed shortcuts keep their old meaning and frame stepping never scales by playback rate", () => {
assert.match(workbench, /changePlaybackRate\(action === "slow" \? 0\.5 : 1\)/);
const step = workbench.slice(workbench.indexOf("const step ="), workbench.indexOf("const updateSliceBoundaryAt ="));
assert.match(step, /stepFrameBoundary\(frameBoundaries, currentTime, direction\)/);
assert.match(step, /stepFrameBoundary\(frameBoundaries, selection\.end, direction\)/);
assert.doesNotMatch(step, /playbackRate/);
});
test("frame shortcuts are scoped to the workbench and preserve text editing", () => {
assert.match(workbench, /aria-keyshortcuts="ArrowLeft"/);
assert.match(workbench, /aria-keyshortcuts="ArrowRight"/);
assert.match(workbench, /event\.nativeEvent\.isComposing/);
// Input/IME isolation is verified by annotation-editing-revision.mjs;
// readonly names and sliders must not be treated as text editors.
assert.match(workbench, /step\(event\.key === "ArrowLeft" \? -1 : 1\)/);
assert.match(workbench, /pausePlayback\(\)/);
assert.match(transport, /leftRef\.current\?\.pause\(\)/);
});
test("both playhead sliders use latest-only pointer previews and exact final commits", () => {
assert.equal((workbench.match(/\{\.\.\.sliderEvents\}/g) || []).length, 2);
assert.match(workbench, /if \(sliderDragging\.current\) previewSeek\(next\)/);
assert.match(workbench, /else seek\(next\)/);
for (const event of ["onPointerUp", "onPointerCancel", "onLostPointerCapture", "onBlur"]) {
assert.match(workbench, new RegExp(`${event}: [\\s\\S]{0,120}transport\\.finishScrub\\(\\)`));
}
assert.match(workbench, /定位中,时间为目标位置/);
});
test("hidden sources detach and right-only playback maps back to the canonical frame clock", () => {
// Real focused-camera resource lifetime is exercised by
// tests/browser/video-playback-recovery.mjs (hidden camera issues no request).
assert.match(workbench, /src=\{effectiveShowLeft \? source : undefined\}/);
assert.match(workbench, /src=\{effectiveShowRight \? rightSource : undefined\}/);
assert.match(
workbench,
/mapCameraBoundaryTime\(rightMediaBoundaries, frameBoundaries, time - \(mediaSourceOffsets\?\.right \|\| 0\)\)/,
);
assert.match(transport, /return c\.showLeft \? c\.leftRef\.current : c\.rightRef\.current/);
assert.match(transport, /video\.load\(\)/);
assert.match(transport, /queue\.isPending\(\) \|\| scrubbing\.current \|\| video\.seeking/);
});
test("annotation playback remains visible when opening the description editor", () => {
assert.match(workbench, /md:sticky md:top-0 z-30/);
assert.match(workbench, /clamp\(100px,24vh,240px\)/);
assert.match(workbench, /ref=\{descriptionEditorRef\}/);
assert.match(workbench, /scrollIntoView\(\{ block: "end"/);
assert.doesNotMatch(workbench, /capture-workbench overflow-hidden/);
});
test("Capture workbench follows the confirmed two-phase interaction", () => {
assert.match(workbench, /切片/);
assert.match(workbench, /逐片标注/);
assert.match(workbench, /上一帧/);
assert.match(workbench, /下一帧/);
assert.match(workbench, /左相机/);
assert.match(workbench, /右相机/);
assert.match(workbench, /insertSlice\(splitPreview\.sliceIndex, splitPreview\.time\)/);
assert.match(workbench, /top-20[^\n]*-translate-y-1\/2/);
assert.match(workbench, /onPointerDown=\{\(event\) => beginSliceBoundaryDrag\(event, index\)\}/);
assert.doesNotMatch(workbench, /切片可用性/);
assert.match(workbench, /从字典选择/);
assert.match(workbench, /确认保存描述/);
assert.match(workbench, /重新切片/);
assert.match(workbench, /完成任务并提交质检/);
assert.doesNotMatch(workbench, /自动保存|高级模式|使用手别/);
});
test("single-slice E opens the panel directly; the constant slot keeps only the lock notice (tickets 01+06, rua 04 D1)", () => {
// 批 0 I2a 的恒定占位槽保留(票 06 后承载面板锁定提示),旧 slice-edit-mode-banner
// 横幅随模式整体删除——提示出现/消失轨道零位移。rework-ux-adjust 04(D1):单切片
// 按 E 的 toast 提示整体删除(面板内可加边界,直开即解决),槽内只剩锁定提示。
const slotStart = workbench.indexOf('data-testid="slice-edit-banner-slot"');
const bannerSlot = workbench.slice(slotStart, workbench.indexOf('data-testid="capture-slice-timeline"'));
assert.ok(slotStart >= 0, "annotate 阶段恒定挂载提示槽位");
assert.match(workbench, /\{phase === "annotate" \?\s*\(\s*<div data-testid="slice-edit-banner-slot"/);
assert.match(bannerSlot, /relative z-10 mb-1 h-8/);
assert.doesNotMatch(bannerSlot, /slice-edit-mode-banner/, "旧模式横幅已删除");
assert.match(bannerSlot, /absolute inset-x-0 top-0/);
assert.doesNotMatch(bannerSlot, /slice-edit-unavailable-notice/, "单切片 E 提示已随 D1 删除");
assert.match(bannerSlot, /data-testid="slice-edit-locked-notice"/);
// D1:E 入口守卫只剩活跃编辑会话;单切片守卫删除(openSliceEditPanel 直开)。
const open = workbench.slice(
workbench.indexOf("const openSliceEditPanel ="),
workbench.indexOf("const openSliceEditPanelForJump ="),
);
assert.doesNotMatch(open, /slices\.length < 2/, "单切片守卫已删除");
assert.match(open, /!continuousActions && editingAnnotation/, "活跃编辑会话守卫保留");
assert.doesNotMatch(workbench, /sliceEditEntry: slices\.length > 1/, "sliceEditEntry 分叉已删除");
});
test("slice reconfig panel: E opens the preview panel with Enter/Esc, locks bypasses, and renders pending structure", () => {
// 票 04(spec §2 R1-Q1/R1-Q3/R1-Q4/R2-Q5):E 改派切片重设面板——预览不落库、
// Enter 应用(冲突走清单)、Esc 整体回退;旁路锁定 + 轨道实时渲染预览结构。
assert.match(
workbench,
/action === "toggle-slice-edit" && phase === "annotate" && !readOnly && !isQualityReview && !mediaOnly\)\s*openSliceEditPanel\(\)/,
);
const open = workbench.slice(
workbench.indexOf("const openSliceEditPanel ="),
workbench.indexOf("const openSliceEditPanelForJump ="),
);
assert.doesNotMatch(open, /slices\.length < 2/, "D1:单切片直开面板");
assert.match(open, /editSession\.freeze\(\{/);
assert.match(open, /restoreSliceEditWorkspace\(snapshot\)\.slices/);
const cancel = workbench.slice(
workbench.indexOf("const cancelSliceEditPanel ="),
workbench.indexOf("const sliceEditPanelOpen ="),
);
assert.match(cancel, /setSliceEditPanel\(null\)/, "Esc 丢弃预览即回退到打开时快照");
// Enter:先 03 引擎扫描,无冲突直落库、有冲突弹清单;落库前跑 T3 钉死自检。
const apply = workbench.slice(
workbench.indexOf("const applySliceEditPanel ="),
workbench.indexOf("const insertSlice ="),
);
assert.match(apply, /scanSliceEditConflicts\(/);
assert.match(apply, /scan\.clean[\s\S]*commitSliceEditPanel\(\{\}\)/);
// 工单 02:播种调用带上贴边跟随集合(prettier 折行,空白弹性匹配)。
assert.match(
apply,
/setSliceEditConflictList\(\{\s*entries: scan\.entries,\s*autoFollows: scan\.autoFollows,\s*decisions: \{\},\s*focus: 0,\s*source: "panel",?\s*\}\);/,
);
const commit = workbench.slice(
workbench.indexOf("const commitSliceEditPanel = async"),
workbench.indexOf("const applySliceEditPanel ="),
);
assert.match(commit, /resolveSliceEditConflicts\(/);
assert.match(commit, /checkSliceEditResolution\(resolution, \{ baseSlices: panel\.snapshot\.slices \}\)/);
assert.match(commit, /editSession\.commit\(panel\.frozen/);
assert.match(commit, /onApplySliceEdit\(/, "应用经页面侧原子落库回调");
// 面板与清单组件、常显提示、红块高亮、播放族放行(seam ③ 表 + 分发)。
assert.match(sliceEditPanel, /data-testid="slice-edit-panel-hint"/);
assert.match(sliceEditPanel, /onClick=\{onApply\}/);
assert.match(sliceEditPanel, /onClick=\{onCancel\}/);
assert.match(sliceEditPanel, /SliceNameDictionaryPicker/, "字典描述复用既有选择器");
assert.match(sliceEditPanel, /DiscardReasonFields/, "舍弃复用既有原因字典");
assert.match(workbench, /data-testid="slice-edit-panel-boundary-highlight"/);
assert.match(sliceEditConflictList, /data-testid="slice-edit-conflict-list"/);
assert.match(sliceEditConflictList, /sliceEditChoiceLabels/, "处置文案与引擎选项值同源");
assert.match(workbench, /sliceEditPanelShortcut\(/);
assert.match(workbench, /sliceEditConflictListShortcut\(/);
assert.match(workbench, /command === "pass"/, "播放族放行到全局表");
// rua 04(D6):J/K 在面板打开期间放行给返工跳转分支——面板分支不再有 locked
// 处理;冲突清单分支保留 locked + 提示(动过开始/结束时间必须先决断)。
const conflictDispatch = workbench.slice(
workbench.indexOf("if (sliceEditConflictList && showSliceEditConflict) {"),
workbench.indexOf('else if (sliceEditPanel && phase === "annotate") {'),
);
assert.match(conflictDispatch, /command === "locked"[\s\S]{0,80}notifySliceEditLocked/, "冲突清单 J/K 锁定有提示");
// R2-Q5 旁路锁定:拖手柄、垃圾桶、悬停+、点其它切片。
const drag = workbench.slice(
workbench.indexOf("const beginSliceBoundaryDrag ="),
workbench.indexOf("const updateSliceDrag ="),
);
assert.match(drag, /sliceEditPanelOpen[\s\S]{0,60}notifySliceEditLocked/);
const select = workbench.slice(workbench.indexOf("const selectSlice ="), workbench.indexOf("const navigateSlice ="));
assert.match(select, /sliceEditPanel && slice\.id !== sliceEditPanel\.sliceId[\s\S]{0,60}notifySliceEditLocked/);
const insert = workbench.slice(
workbench.indexOf("const insertSlice ="),
workbench.indexOf("const annotationEditState ="),
);
assert.match(insert, /sliceEditPanelOpen[\s\S]{0,60}notifySliceEditLocked/);
assert.match(workbench, /disabled=\{!canDeleteSliceAtIndex\(index\) \|\| sliceEditPanelOpen\}/);
assert.match(workbench, /disabled=\{readOnly \|\| saving \|\| sliceEditPanelOpen\}/, "拖手柄禁用");
// 轨道在面板打开期间渲染预览结构(R1-Q1 轨道实时可见)。
assert.match(workbench, /sliceEditPanel \? sliceEditPanel\.pendingSlices : visibleSlices/);
// R2-Q5 锁定提示复用恒定占位槽。
assert.match(workbench, /data-testid="slice-edit-locked-notice"/);
assert.match(workbench, /面板期间已锁定该操作/);
// 页面侧:Enter 应用经 applySliceChange 原子落库(一条可撤销历史)。
assert.match(annotationOperations, /onApplySliceEdit=\{/);
assert.match(annotationOperations, /await persistSliceEditApplication\(/);
});
test("drag quick path: releases route through the 03 engine into the 04 conflict list (ticket 05)", () => {
// 票 05(spec §2 R2-Q3 拖动确认时机):拖动释放/悬停+拆分先过 03 引擎——无冲突
// 立即生效(与 04 Enter 同一管线),有冲突弹 04 同款冲突清单(同一键盘模型),
// Esc 回退本次拖动;拖动来源不再进旧三选卡(06 删旧卡与非拖动调用方)。
const finish = annotationOperations.slice(
annotationOperations.indexOf("const finishSliceBoundaryEdit ="),
annotationOperations.indexOf("const recordSliceDragEdit ="),
);
assert.match(finish, /planSliceEditDragRelease\(/, "释放点跑 03 引擎扫描");
assert.doesNotMatch(finish, /classifyBoundaryMove|setSliceTriage/, "拖动释放不再进旧三选卡");
assert.match(finish, /sliceDragEditRef\.current = edit/, "清单落定继续并入拖动历史 + Esc 回退基线");
assert.match(finish, /applySliceEditQuickResolution\(/, "无冲突直落库");
const quickHelpers = annotationOperations.slice(
annotationOperations.indexOf("const applySliceEditQuickResolution ="),
annotationOperations.indexOf("const adjustSlice ="),
);
assert.ok(quickHelpers.indexOf("const applySliceEditQuickResolution =") >= 0, "落库原语存在");
assert.match(quickHelpers, /checkSliceEditResolution\(/, "落库前 Go 守卫前端镜像自检(T3)");
assert.match(quickHelpers, /persistSliceEditApplication\(/, "服务端原子归档及一条可撤销历史");
assert.match(quickHelpers, /sliceEditSessionRef\.current\.commit\(prompt\.frozen/, "与面板共享会话校验与提交锁");
assert.match(quickHelpers, /resolveSliceEditConflicts\(/, "清单 Enter 未决按默认落定");
const cancel = quickHelpers.slice(
quickHelpers.indexOf("const handleSliceEditQuickConflictCancel ="),
quickHelpers.indexOf("const applySliceChange =") >= 0 ? quickHelpers.length : quickHelpers.length,
);
assert.match(cancel, /setSliceSegments\(before\.slices\)/, "Esc 回退拖动前切片几何");
assert.match(cancel, /setSegments\(before\.segments\)/);
assert.match(cancel, /setSliceStatuses\(before\.statuses\)/);
// 悬停+拆分与垃圾桶合并同样路由(单一处置入口,票 05 范围 4)。
const split = annotationOperations.slice(
annotationOperations.indexOf("const splitSlice ="),
annotationOperations.indexOf("const mergeSlice ="),
);
assert.match(split, /planSliceEditDragRelease\(/, "拆分点先过引擎");
assert.match(split, /applySliceEditQuickResolution\(/);
const del = annotationOperations.slice(
annotationOperations.indexOf("const deleteSlice ="),
annotationOperations.indexOf("const updateSliceName ="),
);
assert.match(del, /planSliceEditDragRelease\(/, "垃圾桶合并走同一管线");
// 待决期间冻结其它边界改动(快照不被打穿)。
const begin = annotationOperations.slice(
annotationOperations.indexOf("const beginSliceBoundaryEdit ="),
annotationOperations.indexOf("const finishSliceBoundaryEdit ="),
);
assert.match(begin, /sliceEditQuickConflict/);
const adjust = annotationOperations.slice(
annotationOperations.indexOf("const adjustSlice ="),
annotationOperations.indexOf("const splitSlice ="),
);
assert.match(adjust, /sliceEditQuickConflict/);
// 票 06:旧三选卡与非拖动调用方收口——提交式挪动也走同一条冲突管线。
assert.doesNotMatch(annotationOperations, /const applySliceTriage =/);
assert.doesNotMatch(adjust, /classifyBoundaryMove\(/);
assert.match(adjust, /planSliceEditDragRelease\(/, "提交式挪动与拖动释放同管线");
// 页面把清单条目交给工作台(04 同款组件/键盘模型的宿主)。
assert.match(annotationOperations, /sliceEditQuickConflict=\{/);
assert.match(annotationOperations, /onSliceEditQuickConflictApply=\{handleSliceEditQuickConflictApply\}/);
assert.match(annotationOperations, /onSliceEditQuickConflictCancel=\{handleSliceEditQuickConflictCancel\}/);
// 工作台:同一 SliceEditConflictList,source 分流 Enter/Esc;清单开着锁拖手柄/悬停+/
// 垃圾桶;阶段/只读化时经回调整体取消;快路径清单水平锚在释放分界处。
// 工单 02:prop 额外携带 autoFollows(贴边无效动作静默跟随集合 → 折叠提示行)。
assert.match(
workbench,
/sliceEditQuickConflict\?: \{\s*entries: SliceEditConflictEntry\[\];\s*anchorTime: number;\s*autoFollows\?: SliceEditAutoFollow\[\];\s*beforeSlices\?: SliceSegment\[\];\s*afterSlices\?: SliceSegment\[\];\s*\} \| null;/,
);
assert.match(workbench, /onSliceEditQuickConflictApply\?:/);
assert.match(workbench, /onSliceEditQuickConflictCancel\?:/);
const seed = workbench.slice(
workbench.indexOf("票 05:拖动/悬停+释放撞出的冲突条目"),
workbench.indexOf("const playbackBounds ="),
);
assert.match(seed, /source: "quick"/, "释放条目播种进同一清单状态");
assert.match(seed, /autoFollows: sliceEditQuickConflict\.autoFollows \?\? \[\]/, "工单 02:快路径播种贴边跟随集合");
assert.match(seed, /list\?\.source === "quick" \? null : list/, "条目清空只收 quick 来源");
assert.match(
workbench,
/sliceEditConflictList\.source === "quick"\) onSliceEditQuickConflictCancel\?\.\(\)/,
"阶段/只读化经页面回退",
);
const dispatchApply = workbench.slice(
workbench.indexOf("const applySliceEditConflictList ="),
workbench.indexOf("const insertSlice ="),
);
assert.ok(dispatchApply.indexOf("const applySliceEditConflictList =") >= 0, "Enter/Esc 按来源分发的助手存在");
assert.match(dispatchApply, /source === "quick"/);
assert.match(dispatchApply, /onSliceEditQuickConflictApply\?\.\(decisions\)/);
assert.match(dispatchApply, /commitSliceEditPanel\(decisions\)/, "面板来源维持 04 自己的流");
assert.match(dispatchApply, /onSliceEditQuickConflictCancel\?\.\(\)/);
assert.match(dispatchApply, /cancelSliceEditPanel\(\)/);
// 工单 02:面板 Enter 撞出的清单同样播种 autoFollows;渲染处把集合交给清单组件
// (折叠提示行「N 个贴边无效动作自动跟随」)。
assert.match(
workbench,
/setSliceEditConflictList\(\{\s*entries: scan\.entries,\s*autoFollows: scan\.autoFollows,\s*decisions: \{\},\s*focus: 0,\s*source: "panel",?\s*\}\);/,
);
assert.match(workbench, /autoFollows=\{sliceEditConflictList\.autoFollows\}/);
// 键盘分发与渲染共用同一组助手。
assert.match(workbench, /applySliceEditConflictList\(sliceEditConflictList\.decisions\)/);
assert.match(workbench, /if \(command === "cancel"\) \{\s*cancelSliceEditConflictList\(\);/);
// R2-Q5/R2-Q3 锁定:清单开着不接受新的拖动/悬停+/垃圾桶。
const drag = workbench.slice(
workbench.indexOf("const beginSliceBoundaryDrag ="),
workbench.indexOf("const updateSliceDrag ="),
);
assert.match(drag, /if \(sliceEditConflictList \|\| sliceEditPanelOpen\)[\s\S]{0,60}notifySliceEditLocked/);
const insert = workbench.slice(
workbench.indexOf("const insertSlice ="),
workbench.indexOf("const annotationEditState ="),
);
assert.match(insert, /if \(sliceEditConflictList \|\| sliceEditPanelOpen\)[\s\S]{0,60}notifySliceEditLocked/);
const trash = workbench.slice(
workbench.indexOf("const deleteSliceAtIndex ="),
workbench.indexOf("const sliceBoundaryIssue ="),
);
assert.match(trash, /if \(sliceEditConflictList \|\| sliceEditPanelOpen\)[\s\S]{0,60}notifySliceEditLocked/);
// October 16: conflict controls use the reserved rail; geometry is checked in the browser fixture.
assert.match(workbench, /onApply=\{\(\) => applySliceEditConflictList\(sliceEditConflictList\.decisions\)\}/);
assert.match(workbench, /onCancel=\{cancelSliceEditConflictList\}/);
});
test("ticket 06: replaced triage card and slice-edit mode are deleted outright (R3-Q2)", () => {
// R3-Q2 全删不留开关旗:04/05 新动线(E 面板 + 冲突清单)落地后,旧三选卡
// (引擎/状态/键表/UI/CSS)与旧切片编辑模式(sliceEditActive 框架/横幅/键表)
// 整体移除,git 历史可回溯。
const shortcuts = fs.readFileSync(new URL("../../src/lib/annotation-shortcuts.js", import.meta.url), "utf8");
const workspaceCss = fs.readFileSync(new URL("../../src/styles/capture-workspace.css", import.meta.url), "utf8");
for (const source of [workbench, annotationOperations, shortcuts]) {
for (const legacy of [
"sliceEditActive",
"sliceEditShortcut",
"slice-edit-mode-banner",
"triageCardShortcut",
"triageCardAnchor",
"SliceTriageCard",
"sliceTriage",
"onSliceTriageChoose",
"onSliceTriageDismiss",
"classifyBoundaryMove",
"applyBoundaryMove",
"applySliceTriage",
"slice-boundary-triage",
"slice-triage-card",
])
assert.ok(!source.includes(legacy), `${legacy} 已随旧卡/旧模式删除`);
}
assert.ok(!workspaceCss.includes("slice-triage-"), "处置卡 CSS 随卡删除");
for (const removed of [
"src/lib/slice-boundary-triage.js",
"src/lib/slice-triage-card.js",
"src/lib/slice-triage-card-types.ts",
"src/components/SliceTriageCard.tsx",
])
assert.ok(!fs.existsSync(new URL(`../../${removed}`, import.meta.url)), `${removed} 文件已删除`);
// 提交式挪动(slice 相 ←/→ 与 Shift+←/→)与拖动释放/拆分/垃圾桶同走 03 引擎
// 冲突管线:无冲突直落库,有冲突弹 04 同款清单(单一处置入口)。
const adjust = annotationOperations.slice(
annotationOperations.indexOf("const adjustSlice ="),
annotationOperations.indexOf("const splitSlice ="),
);
assert.doesNotMatch(adjust, /setSliceTriage|classifyBoundaryMove|triageCardModel/);
assert.match(adjust, /planSliceEditDragRelease\(/, "提交式挪动走同一条冲突管线");
// 单切片 E 守卫与提示随 rua 04(D1)删除(面板内可加边界,直开即解决);
// 提示槽保留(锁定提示仍在原槽渲染,零位移结构不变)。
assert.match(workbench, /data-testid="slice-edit-banner-slot"/);
assert.doesNotMatch(workbench, /slice-edit-unavailable-notice/);
assert.doesNotMatch(workbench, /仅一个切片,无可调边界/);
assert.doesNotMatch(workbench, /sliceEditEntry/);
});
test("acceptance fix C: E opens despite parked drafts; autosave pauses for the panel session and flushes on release", () => {
// 验收修复(票 04 设计变更):停泊草稿是标注常态,E 不再被「先保存草稿」拦死——
// 面板打开即暂停自动保存(草稿留在本地态、快照引用稳定),关闭(Enter/Esc)立即补存。
// 保留守卫:非连续模式的活跃编辑会话(!continuousActions && editingAnnotation)照旧
// 拦下,提示文案不变;单切片守卫随 rua 04(D1)删除(面板内可加边界)。
const open = workbench.slice(
workbench.indexOf("const openSliceEditPanel ="),
workbench.indexOf("const openSliceEditPanelForJump ="),
);
assert.doesNotMatch(open, /slices\.length < 2/, "单切片守卫已删除(D1 直开)");
assert.match(open, /!continuousActions && editingAnnotation/, "活跃编辑会话守卫保留");
assert.match(open, /请先保存或取消当前描述,再进入切片重设面板/, "活跃编辑提示文案不变");
assert.match(
open,
/editSession\.freeze\([\s\S]*includeDrafts: continuousActions/,
"停泊草稿进入共享会话快照,不拦 E",
);
// 会话通道:打开/关闭都通知页面,页面据此暂停与补存自动保存。
assert.match(workbench, /onSliceEditSessionChange/);
assert.match(open, /onSliceEditSessionChange\?\.\(true\)/);
const cancel = workbench.slice(
workbench.indexOf("const cancelSliceEditPanel ="),
workbench.indexOf("const sliceEditPanelOpen ="),
);
assert.match(cancel, /onSliceEditSessionChange\?\.\(false\)/);
const commit = workbench.slice(
workbench.indexOf("const commitSliceEditPanel = async"),
workbench.indexOf("const applySliceEditPanel ="),
);
assert.match(commit, /onSliceEditSessionChange\?\.\(false\)/, "Enter 应用后释放会话");
// 页面侧:面板会话或任一冲突清单打开 → isBlocked 暂停;释放下降沿立即补存;
// 换任务复位会话标记(workbench 按 key 重挂载,防残留 true 冻结自动保存)。
assert.match(annotationOperations, /onSliceEditSessionChange=\{setSliceEditSessionOpen\}/);
assert.match(annotationOperations, /sliceEditSessionOpen \|\| Boolean\(sliceEditQuickConflict\)/);
assert.match(annotationOperations, /sliceEditSessionFlushEdge\(/);
assert.match(annotationOperations, /flushNow\("slice-edit-close"\)/);
assert.match(annotationOperations, /setSliceEditSessionOpen\(false\)/);
// Enter 一律被拒的既有缺陷(E 走查实测):快照经 snapshotSliceEditWorkspace 深拷贝,
// 引用比较恒不相等——外部改动守卫改按值比较(真实外部改写仍被拦)。rua 04(D6)
// 后该口径抽成 workspaceDiffersFromSnapshot,供 Enter 守卫与驻留重开复用。
const apply = workbench.slice(
workbench.indexOf("const applySliceEditPanel ="),
workbench.indexOf("const insertSlice ="),
);
assert.doesNotMatch(apply, /slices !== panel\.snapshot\.slices/, "不再用引用比较快照");
assert.match(apply, /workspaceDiffersFromSnapshot\(panel\.baseSnapshot\)/);
assert.match(workbench, /sliceEditWorkspaceChanged\(snapshot, slices, segments\)/);
const slices = [{ id: "s", start: 0, end: 2 }];
const actions = [{ id: "a", start: 0, end: 2, description: "保留描述" }];
const frozen = freezeSliceEditSession({ taskId: "task", slices, actions, drafts: [] });
assert.equal(
sliceEditWorkspaceChanged(frozen.baseSnapshot, structuredClone(slices), structuredClone(actions)),
false,
);
assert.equal(
sliceEditWorkspaceChanged(frozen.baseSnapshot, slices, [{ ...actions[0], description: "外部改动" }]),
true,
);
});
test("production shell keeps real users, collapsible navigation, and a persisted light-default theme", () => {
assert.match(app, /<UserProvider>/);
assert.match(app, /<ThemeProvider>/);
assert.match(layout, /toggleTheme/);
assert.match(layout, /切换到深色主题/);
assert.match(sidebar, /onToggle/);
assert.match(sidebar, /isCollapsed \? "w-20" : "w-64"/);
assert.match(theme, /droboticflow\.theme/);
assert.match(theme, /return "light"/);
assert.match(theme, /localStorage\.setItem/);
assert.match(annotationOperations, /annotation-operations-page/);
assert.match(css, /html:not\(\.dark\) \.annotation-operations-page/);
assert.match(annotationOperations, /claimTask\(task, humanItem\)/);
assert.match(annotationOperations, /annotationTaskAction/);
assert.doesNotMatch(annotationOperations, /领取标注任务|领取剪切任务/);
assert.match(css, /capture-media-controls/);
assert.match(annotationOperations, /requireSliceCompletion: !detail\.task\.continuousActions/);
assert.doesNotMatch(annotationOperations, /sliceProgress\.pending > 0/);
assert.match(workbench, /已完整标注/);
assert.match(workbench, /annotationCoverageGaps\(slice, segments\)\.length/);
assert.doesNotMatch(workbench, /语义留空合法/);
assert.doesNotMatch(workbench, /个切片已完成标注/);
});
test("local mock preview is guarded by Vite development mode", () => {
assert.match(main, /import\.meta\.env\.DEV/);
assert.match(main, /\/__capture-workbench/);
assert.match(preview, /__capture-workbench-mock\.mp4/);
assert.match(preview, /CaptureAnnotationWorkbench/);
assert.match(preview, /data-testid="mock-capture-task-pool"/);
assert.match(preview, /领取并开始切片/);
assert.match(preview, /我的任务/);
assert.match(preview, /href=\{href\}/);
assert.match(preview, /onReturnToPool=\{\(\) => setView\("pool"\)\}/);
});
test("a read-only quality review keeps its own footer instead of the annotator slice bar", () => {
const footer = workbench.slice(workbench.indexOf("<footer"), workbench.indexOf("</footer>"));
// Slice phase only routes to the annotator's confirmation bar outside quality review.
assert.match(footer, /\) : phase === "slice" && !isQualityReview \? \(/);
const readOnlyFooter = footer.slice(footer.indexOf(") : readOnly ? ("));
assert.match(readOnlyFooter, /isQualityReview && reviewReadOnlyNotice \?/);
assert.match(readOnlyFooter, /质检审核模式(只读查看)/);
// The hint appears exactly when the page offers the takeover button.
assert.match(
annotationOperations,
/reviewReadOnlyNotice=\{\s*reviewSessionEnabled && !reviewSession\.writable\s*\? "本页只读,点上方「在本页接管审查」后可审核"/,
);
assert.match(
annotationOperations,
/reviewSessionEnabled && !reviewSession\.writable && \(\s*<button[\s\S]{0,200}在本页接管审查/,
);
});
test("task connection diagnostics joins each layout's top row instead of taking its own line", () => {
assert.equal(annotationOperations.match(/当前任务连接诊断/g)?.length, 1);
assert.doesNotMatch(annotationOperations, /<div className="flex justify-end text-xs">\s*<a/);
const focusHeading = annotationOperations.slice(
annotationOperations.indexOf('<div className="review-focus-heading">'),
annotationOperations.indexOf('<div className="annotation-workspace-heading'),
);
assert.match(focusHeading, /返回任务池\s*<\/button>\s*\{taskDiagnosticsLink\}/);
assert.match(annotationOperations, /\{!reviewFocused && taskDiagnosticsLink\}\s*<Link/);
assert.match(
annotationOperations,
/<PageSubnav compact items=\{annotationStageTabs\}[^>]*\/>\s*<\/div>\s*\{!reviewFocused && \(\s*<div[^>]*>\s*\{taskDiagnosticsLink\}/,
);
});