forked from longtao.wu/droboticflow
46 lines
1.8 KiB
JavaScript
46 lines
1.8 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { annotationEditorPhase } from "../../src/lib/annotation-workspace.js";
|
|
|
|
const draft = (workflow, processingJob) => ({
|
|
humanItem: {
|
|
processingJob,
|
|
subject: { payload: { sliceWorkflow: workflow, annotationDraft: { segments: [{ id: "a", source: "human" }] } } },
|
|
},
|
|
revisions: [{ revision: 1, segments: [{ id: "a", source: "human" }] }],
|
|
});
|
|
test("server readiness overrides restored annotations and requested editor state", () => {
|
|
for (const phase of ["slice", "materializing", "annotate"]) {
|
|
assert.equal(
|
|
annotationEditorPhase({ ...draft({ status: "completed", phase: "annotate" }), editorState: { phase } }),
|
|
phase,
|
|
);
|
|
}
|
|
});
|
|
test("known unfinished or failed workflows never infer annotation readiness from drafts", () => {
|
|
for (const workflow of [
|
|
{ status: "failed" },
|
|
{ status: "failed", phase: "annotate" },
|
|
{ status: "editing", phase: "annotate" },
|
|
{ status: "completed", phase: "slice" },
|
|
]) {
|
|
assert.equal(annotationEditorPhase(draft(workflow)), "slice");
|
|
}
|
|
assert.equal(annotationEditorPhase(draft({ status: "completed", phase: "annotate" }, { status: "failed" })), "slice");
|
|
assert.equal(
|
|
annotationEditorPhase(draft({ status: "completed", phase: "annotate" }, { status: "queued" })),
|
|
"materializing",
|
|
);
|
|
});
|
|
test("legacy API responses retain confirmed history but not draft-only readiness", () => {
|
|
assert.equal(annotationEditorPhase(draft(undefined)), "annotate");
|
|
assert.equal(annotationEditorPhase({ humanItem: draft(undefined).humanItem }), "slice");
|
|
assert.equal(
|
|
annotationEditorPhase({
|
|
humanItem: draft(undefined).humanItem,
|
|
sliceRevisions: [{ revision: 0, segments: [{ id: "s" }] }],
|
|
}),
|
|
"slice",
|
|
);
|
|
});
|