forked from longtao.wu/droboticflow
- server: handleSliceResetCreate splits on submission history using the established isRework signals (task revision fence, rework status, human annotation revision via fanyuV5CombinedSubmissionIsRework); first pass runs the original reset write path with sliceResetHistory audit, history keeps 409 slice_reset_disabled with in-place guidance (spec D1 revised) - table tests pin both classes incl. the system-suggestion edge; the four retired-contract test files flip to split-flow assertions - frontend: restore the reslice button, warning dialog with both reset modes, and authoritative reconciliation from f980696f~1; entry is gated client-side by the same signals (resliceEligible), normal and focused layouts share the restored footer entry; E-mode changes untouched - dev preview regains the entry; two retirement-era nail assertions flip back with the gate asserted in their place
235 lines
9.3 KiB
JavaScript
235 lines
9.3 KiB
JavaScript
import assert from "node:assert/strict";
|
||
import fs from "node:fs";
|
||
import test from "node:test";
|
||
|
||
import {
|
||
analyzeSliceCoverage,
|
||
annotationStageNavigationPath,
|
||
annotationSegmentPosition,
|
||
annotationSliceEditorReadOnly,
|
||
editAnnotationSegment,
|
||
humanEditableAnnotationSegments,
|
||
normalizeAnnotationSegments,
|
||
scopedHumanQueueEmptyMessage,
|
||
summarizeAnnotationWorkload,
|
||
} from "../../src/lib/annotation-operations.js";
|
||
|
||
test("annotation stage navigation preserves the exact workflow and run scope", () => {
|
||
assert.equal(
|
||
annotationStageNavigationPath("/plugins/annotation-qa/workflows/workflow-1/quality", {
|
||
projectId: "project-1",
|
||
workflowId: "workflow-1",
|
||
runId: "run-1",
|
||
captureDirectory: "capture-000001",
|
||
}),
|
||
"/plugins/annotation-qa/workflows/workflow-1/quality?projectId=project-1&workflowId=workflow-1&runId=run-1&capture=capture-000001",
|
||
);
|
||
});
|
||
|
||
test("scoped human queue explains that an automatic run has not reached the human stage", () => {
|
||
assert.equal(
|
||
scopedHumanQueueEmptyMessage({
|
||
runId: "run-1",
|
||
runStatus: "running",
|
||
currentNodeId: "undistort",
|
||
stageLabel: "最终验收",
|
||
}),
|
||
"当前执行记录正在自动处理,当前节点 undistort,尚未生成最终验收任务",
|
||
);
|
||
});
|
||
|
||
test("annotation timeline normalization rejects invalid ranges and sorts segments", () => {
|
||
const segments = normalizeAnnotationSegments(
|
||
[
|
||
{ id: "late", labelId: "steady", label: "平稳活动", start: 10, end: 20 },
|
||
{ id: "invalid", labelId: "bad", label: "bad", start: -1, end: 2 },
|
||
{ id: "early", labelId: "static", label: "静止观察", start: 0, end: 10 },
|
||
],
|
||
0,
|
||
20,
|
||
);
|
||
assert.deepEqual(
|
||
segments.map((item) => item.id),
|
||
["early", "late"],
|
||
);
|
||
assert.deepEqual(annotationSegmentPosition(segments[1], 0, 20), { left: 50, width: 50 });
|
||
});
|
||
|
||
test("combined JSON descriptions need no handedness or task label", () => {
|
||
const segments = normalizeAnnotationSegments([{ id: "event", description: "拿取商品", start: 1, end: 2 }], 0, 5);
|
||
assert.equal(segments.length, 1);
|
||
assert.equal(segments[0].description, "拿取商品");
|
||
assert.equal(segments[0].handedness, "");
|
||
});
|
||
|
||
test("model prelabels stay on the suggestion track instead of entering the human submission", () => {
|
||
const segments = humanEditableAnnotationSegments([
|
||
{
|
||
revision: 0,
|
||
segments: [
|
||
{ id: "qwen", labelId: "free-form", label: "free form", source: "qwen", start: 0, end: 1 },
|
||
{ id: "manual", labelId: "01", label: "鲜食处理", source: "manual", start: 1, end: 2 },
|
||
],
|
||
},
|
||
]);
|
||
assert.deepEqual(
|
||
segments.map((item) => item.id),
|
||
["manual"],
|
||
);
|
||
});
|
||
|
||
test("annotation timeline supports snapped move and edge resize without overlap", () => {
|
||
const segments = [
|
||
{ id: "first", labelId: "steady", label: "平稳活动", start: 0, end: 5 },
|
||
{ id: "second", labelId: "fast", label: "快速移动", start: 6, end: 10 },
|
||
];
|
||
const moved = editAnnotationSegment(segments, "first", "move", 2.26, 0, 10, 0.1);
|
||
assert.equal(moved[0].start, 1);
|
||
assert.equal(moved[0].end, 6);
|
||
|
||
const resized = editAnnotationSegment(moved, "second", "resize-start", -0.44, 0, 10, 0.1);
|
||
assert.equal(resized[1].start, 6);
|
||
const shortened = editAnnotationSegment(resized, "second", "resize-end", -1.24, 0, 10, 0.1);
|
||
assert.equal(shortened[1].end, 8.8);
|
||
});
|
||
|
||
test("rework does not increase formal output count", () => {
|
||
const summary = summarizeAnnotationWorkload([
|
||
{ outputCount: 1, reworkCount: 0, qualityApproved: 1, acceptanceApproved: 0, durationSeconds: 60 },
|
||
{ outputCount: 0, reworkCount: 1, qualityRejected: 1, acceptanceRejected: 0, durationSeconds: 30 },
|
||
]);
|
||
assert.equal(summary.outputCount, 1);
|
||
assert.equal(summary.reworkCount, 1);
|
||
assert.equal(summary.durationSeconds, 90);
|
||
});
|
||
|
||
test("slice editing is locked for reviewers and unclaimed tasks", () => {
|
||
assert.equal(
|
||
annotationSliceEditorReadOnly({ workspaceMode: "quality", isCombinedQuality: true, claimedByMe: true }),
|
||
true,
|
||
);
|
||
assert.equal(
|
||
annotationSliceEditorReadOnly({ workspaceMode: "clip", isCombinedQuality: false, claimedByMe: false }),
|
||
true,
|
||
);
|
||
assert.equal(
|
||
annotationSliceEditorReadOnly({ workspaceMode: "annotate", isCombinedQuality: false, claimedByMe: true }),
|
||
false,
|
||
);
|
||
});
|
||
|
||
test("slice coverage requires a gap-free full-video partition", () => {
|
||
const complete = analyzeSliceCoverage(
|
||
[
|
||
{ id: "a", start: 0, end: 2 },
|
||
{ id: "b", start: 2, end: 7 },
|
||
{ id: "c", start: 7, end: 10 },
|
||
],
|
||
0,
|
||
10,
|
||
);
|
||
assert.equal(complete.complete, true);
|
||
assert.equal(complete.coverageRatio, 1);
|
||
assert.deepEqual(complete.gaps, []);
|
||
assert.deepEqual(complete.overlaps, []);
|
||
|
||
const gap = analyzeSliceCoverage(
|
||
[
|
||
{ id: "a", start: 0, end: 4 },
|
||
{ id: "b", start: 5, end: 10 },
|
||
],
|
||
0,
|
||
10,
|
||
);
|
||
assert.equal(gap.complete, false);
|
||
assert.deepEqual(gap.gaps, [{ start: 4, end: 5 }]);
|
||
|
||
const overlap = analyzeSliceCoverage(
|
||
[
|
||
{ id: "a", start: 0, end: 6 },
|
||
{ id: "b", start: 5, end: 10 },
|
||
],
|
||
0,
|
||
10,
|
||
);
|
||
assert.equal(overlap.complete, false);
|
||
assert.deepEqual(overlap.overlaps, [{ start: 5, end: 6 }]);
|
||
});
|
||
|
||
test("annotation operations uses the draggable video timeline and workflow deep links", () => {
|
||
const page = fs.readFileSync(new URL("../../src/pages/AnnotationOperations.tsx", import.meta.url), "utf8");
|
||
const client = fs.readFileSync(new URL("../../src/services/api/annotation-operations.ts", import.meta.url), "utf8");
|
||
const materialized = fs.readFileSync(
|
||
new URL("../../src/components/MaterializedSliceWorkbench.tsx", import.meta.url),
|
||
"utf8",
|
||
);
|
||
const captureWorkbench = fs.readFileSync(
|
||
new URL("../../src/components/CaptureAnnotationWorkbench.tsx", import.meta.url),
|
||
"utf8",
|
||
);
|
||
assert.doesNotMatch(page, /AnnotationTimelineEditor/);
|
||
assert.doesNotMatch(page, /AnnotationWorkbenchEditor/);
|
||
assert.match(page, /requestedRunId/);
|
||
assert.match(page, /annotationStageNavigationPath/);
|
||
assert.match(page, /BusinessExecutionPath/);
|
||
assert.match(page, /3\. Capture 子目录/);
|
||
assert.match(page, /captureDirectoriesFromHumanTask/);
|
||
assert.doesNotMatch(page, /默认仅显示待处理任务/);
|
||
assert.match(page, /runId: requestedRunId \|\| undefined/);
|
||
assert.match(page, /status: projectPoolView === "all" \? undefined : "pending_acceptance"/);
|
||
assert.match(page, /acceptanceWorkspace && item.status !== "pending_acceptance"/);
|
||
assert.match(page, /!isManager && current === "all" \? "available" : current/);
|
||
assert.doesNotMatch(page, /current === "available" \? "all"/);
|
||
assert.match(page, /visibleDeliveryPackages/);
|
||
assert.match(page, /Run \{detail\.task\.runId\}/);
|
||
assert.match(page, /sourceIsFullVideo=\{detail\.task\.sourceIsFullVideo\}/);
|
||
assert.match(page, /humanEditableAnnotationSegments\(next\.revisions\)/);
|
||
assert.match(page, /humanLoopApi\.subjectContentURL\(selectedHumanItem\.id\)/);
|
||
assert.match(page, /rightVideoSource=\{selectedRightVideoSource\}/);
|
||
assert.match(page, /subjectContentURL\(selectedHumanItem\.id, "right"\)/);
|
||
assert.match(page, /projectLoadRecoveryAttempts/);
|
||
assert.match(page, /loadProject\(\)/);
|
||
assert.match(page, /selectTask\(task\.id\)/);
|
||
assert.match(page, /selectedVideoSource/);
|
||
assert.match(page, /taskPoolView/);
|
||
assert.match(page, /taskSearch/);
|
||
assert.match(page, /taskStatusFilter/);
|
||
assert.match(page, /可领取/);
|
||
assert.match(page, /我的任务/);
|
||
assert.match(page, /全部任务/);
|
||
assert.match(page, /待标注\/剪切/);
|
||
assert.match(page, /待质检/);
|
||
assert.match(page, /已通过/);
|
||
assert.match(page, /返工中/);
|
||
assert.match(captureWorkbench, /切片名称/);
|
||
// 票 06(D1 修订版):首标「重新切片」警告弹窗恢复(resliceEligible 闸门控入口)。
|
||
assert.match(page, /清空标注并重新切片/);
|
||
assert.match(page, /重新切片警告/);
|
||
assert.match(page, /resliceEligible/);
|
||
assert.match(captureWorkbench, /切片编辑模式/);
|
||
assert.match(client, /slice-confirmations/);
|
||
assert.match(client, /slice-reset/);
|
||
assert.doesNotMatch(page, /workgroup/i);
|
||
assert.doesNotMatch(client, /workgroup/i);
|
||
assert.match(page, /selectedMaterialization/);
|
||
assert.match(page, /slices=\{sliceSegments\}/);
|
||
assert.match(captureWorkbench, /nearestFrameBoundaryIndex\(frameBoundaries, currentTime\)/);
|
||
assert.match(captureWorkbench, /stepFrameBoundary\(frameBoundaries, currentTime, direction\)/);
|
||
assert.doesNotMatch(page, /\(current\.start \+ current\.end\) \/ 2/);
|
||
assert.match(captureWorkbench, /aria-label="在此新增切片"/);
|
||
assert.match(page, /canCurrentUserClaimItem/);
|
||
assert.match(page, /claimTask\(task, humanItem\)/);
|
||
assert.doesNotMatch(page, /管理员不能代替生产角色领取|canCurrentUserClaimSelected/);
|
||
assert.match(captureWorkbench, /切片/);
|
||
assert.match(captureWorkbench, /逐片标注/);
|
||
assert.match(materialized, /真实双目切片检查/);
|
||
assert.match(materialized, /aria-pressed=\{showLeftCamera\}/);
|
||
assert.match(materialized, /aria-pressed=\{showRightCamera\}/);
|
||
assert.doesNotMatch(materialized, /CameraMode/);
|
||
assert.match(materialized, /播完自动下一条/);
|
||
assert.match(materialized, /synchronized-slice\.json/);
|
||
assert.match(materialized, /left_pts\.csv/);
|
||
assert.match(materialized, /right_pts\.csv/);
|
||
assert.match(materialized, /时间戳标注/);
|
||
});
|