import assert from "node:assert/strict"; import { existsSync, readFileSync } from "node:fs"; import { after, before, test } from "node:test"; import { createServer } from "vite"; let server; let fetchM48SmallStaticRegression; let fetchM48SmallStaticRegressionCases; let fetchM48SmallStaticRegressionCase; const resultId = `m48-small-static-passage-regression-${"a".repeat(64)}`; const packId = `m48-object-quality-pack-${"b".repeat(64)}`; const referenceGraphLabResultId = `m47-reference-graph-lab-${"d".repeat(64)}`; const anchorId = `anchor-${"c".repeat(24)}`; const authority = { mode: "replay-simulated", physical_live: false, commands_enabled: false, actuation_allowed: false, navigation_or_safety_accepted: false, }; before(async () => { server = await createServer({ appType: "custom", logLevel: "silent", server: { middlewareMode: true } }); ({ fetchM48SmallStaticRegression, fetchM48SmallStaticRegressionCases, fetchM48SmallStaticRegressionCase, } = await server.ssrLoadModule("/src/core/laboratory/m48SmallStaticRegression.ts")); }); after(async () => server?.close()); function response(value) { return { ok: true, status: 200, json: async () => value }; } test("M4.8R1 keeps pipeline identity and assisted evidence authority explicit", async () => { const summary = await fetchM48SmallStaticRegression(resultId, { fetcher: async () => response({ schema_version: "missioncore.m48-small-static-passage-regression-result-view/v1", result_id: resultId, pack_id: packId, reference_graph_lab_result_id: referenceGraphLabResultId, created_at_utc: "2026-08-24T12:00:00Z", run_label: "M4.8R1", pipeline_id: "m48-class-free-object-quality/v1", experiment_id: "m48-small-static-passage-regression/v1", accepted: false, metrics: { assisted_anchor_count: 14, assisted_tracklet_count: 14, anchor_clip_count: 8, requires_avoidance_or_clearance_count: 12, worker_recalled_anchor_count: 0, worker_missed_anchor_count: 14, assisted_anchor_recall: 0, extent_iou_threshold: 0.5, minimum_assisted_anchor_recall: 0.9, }, gates: { anchor_set_non_empty: true, development_anchor_recall_target: false, independent_truth_available: false, }, decision: { state: "failed-development-regression-baseline", summary: "Worker 006 matched 0/14.", next_action: "Publish another immutable run.", }, ground_truth: false, independent_truth: false, authority, }), }); assert.equal(summary.pipelineId, "m48-class-free-object-quality/v1"); assert.equal(summary.experimentId, "m48-small-static-passage-regression/v1"); assert.equal(summary.referenceGraphLabResultId, referenceGraphLabResultId); assert.equal(summary.metrics.workerMissedAnchorCount, 14); assert.equal(summary.independentTruth, false); }); test("M4.8R1 bounded case binds one exact assisted anchor and frozen objects", async () => { const cases = await fetchM48SmallStaticRegressionCases(resultId, { fetcher: async () => response({ schema_version: "missioncore.m48-small-static-passage-regression-case-catalog/v1", result_id: resultId, cases: [{ anchor_id: anchorId, clip_id: "m48-clip-03", sequence: 256, anchor_extent_xyxy: [0.2, 0.3, 0.4, 0.7], requires_avoidance_or_clearance: true, worker_candidate_count: 1, best_iou: 0.01, matched_at_threshold: false, outcome: "missed-assisted-anchor", }], case_count: 1, ground_truth: false, authority, }), }); assert.equal(cases[0].outcome, "missed-assisted-anchor"); assert.deepEqual(cases[0].anchorExtentXyxy, [0.2, 0.3, 0.4, 0.7]); const item = await fetchM48SmallStaticRegressionCase(resultId, anchorId, { fetcher: async () => response({ schema_version: "missioncore.m48-small-static-passage-regression-case-view/v1", result_id: resultId, pack_id: packId, anchor: { anchor_id: anchorId, clip_id: "m48-clip-03", object_id: "object-01", sequence: 256, extent_xyxy: [0.2, 0.3, 0.4, 0.7], visibility: "visible", geometry_association: "unknown", freshness: "current", motion: "static", threat: "not-threat", requires_avoidance_or_clearance: true, }, comparison: { anchor_id: anchorId, clip_id: "m48-clip-03", sequence: 256, requires_avoidance_or_clearance: true, worker_candidate_count: 1, best_iou: 0.01, matched_at_threshold: false, outcome: "missed-assisted-anchor", source_time_ns: 25_600_000_000, anchor_extent_xyxy: [0.2, 0.3, 0.4, 0.7], worker_objects: [{ prediction_id: "proposal-256-0", extent_xyxy: [0.7, 0.2, 0.9, 0.6], geometry_association: "associated", freshness: "current", motion: "static", threat: "not-threat", }], best_prediction_id: "proposal-256-0", extent_iou_threshold: 0.5, }, camera_url: `/api/v1/laboratory/m48/packs/${packId}/source/clips/m48-clip-03/frames/256/camera`, spatial_url: `/api/v1/laboratory/m48/packs/${packId}/source/clips/m48-clip-03/frames/256/spatial`, ground_truth: false, authority, }), }); assert.equal(item.anchor.sequence, 256); assert.equal(item.comparison.workerObjects[0].predictionId, "proposal-256-0"); assert.equal(item.groundTruth, false); }); test("M4.8R1 deletes the third viewer and projects anchors through the canonical graph", () => { const deletedVisual = new URL( "../src/workspaces/laboratory/M48SmallStaticRegressionVisual.tsx", import.meta.url, ); assert.equal(existsSync(deletedVisual), false); const evidence = readFileSync( new URL("../src/workspaces/laboratory/M48SmallStaticRegressionEvidence.tsx", import.meta.url), "utf8", ); const canonicalVisual = readFileSync( new URL("../src/workspaces/laboratory/M4ReplayThreatVisual.tsx", import.meta.url), "utf8", ); assert.match(evidence, /fetchM47ReferenceGraphLab/); assert.match(evidence, /