forked from longtao.wu/droboticflow
38 lines
1.8 KiB
JavaScript
38 lines
1.8 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import { newAnnotationClaimRequestID } from "../../src/lib/annotation-random-claim.js";
|
|
const page = fs.readFileSync(new URL("../../src/pages/AnnotationOperations.tsx", import.meta.url), "utf8");
|
|
const workbench = fs.readFileSync(
|
|
new URL("../../src/components/CaptureAnnotationWorkbench.tsx", import.meta.url),
|
|
"utf8",
|
|
);
|
|
test("claim request IDs work on HTTP without crypto.randomUUID", () => {
|
|
const id = newAnnotationClaimRequestID({
|
|
getRandomValues(bytes) {
|
|
bytes.fill(1);
|
|
return bytes;
|
|
},
|
|
});
|
|
assert.equal(id, "01".repeat(16));
|
|
assert.match(newAnnotationClaimRequestID(), /^[0-9a-f]{32}$/);
|
|
assert.notEqual(newAnnotationClaimRequestID(), newAnnotationClaimRequestID());
|
|
});
|
|
test("annotator claims require a project, retain ambiguous request IDs and ignore stale account responses", () => {
|
|
assert.match(page, /!projectId \|\| !currentUser \|\| randomClaimFlight.current/);
|
|
assert.match(page, /sessionStorage.getItem\(key\)/);
|
|
assert.match(page, /sessionStorage.setItem\(key, requestId\)/);
|
|
assert.match(page, /claimContextRef.current.userId !== actorID/);
|
|
assert.match(page, /newAnnotationClaimRequestID\(\)/);
|
|
assert.doesNotMatch(page, /crypto.randomUUID\(\)/);
|
|
});
|
|
test("random acquisition hides unclaimed cards and leaves named claiming for other roles", () => {
|
|
assert.match(page, /role === "annotator" && \(workspaceMode === "annotate" \|\| workspaceMode === "clip"\)/);
|
|
assert.match(page, /!blindAnnotator \|\| taskPoolView === "mine"/);
|
|
assert.match(page, /随机领取任务/);
|
|
assert.match(page, /claimTask\(task, humanItem\)/);
|
|
assert.match(page, /releaseLocked \|\| !selectedClaimedByMe/);
|
|
assert.match(workbench, /onReleaseTask &&/);
|
|
assert.match(workbench, /claimLocked \? "返回我的任务"/);
|
|
});
|