215 lines
6.7 KiB
JavaScript
215 lines
6.7 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { after, before, test } from "node:test";
|
|
|
|
import { createServer } from "vite";
|
|
|
|
let server;
|
|
let fetchM47ReferenceGraphLab;
|
|
|
|
const resultId = `m47-reference-graph-lab-${"a".repeat(64)}`;
|
|
const graphResultId = `m47-reference-graph-${"b".repeat(64)}`;
|
|
const visualResultId = `m4-threat-replay-${"c".repeat(64)}`;
|
|
|
|
before(async () => {
|
|
server = await createServer({
|
|
appType: "custom",
|
|
logLevel: "silent",
|
|
server: { middlewareMode: true },
|
|
});
|
|
({ fetchM47ReferenceGraphLab } = await server.ssrLoadModule(
|
|
"/src/core/laboratory/m47ReferenceGraph.ts",
|
|
));
|
|
});
|
|
|
|
after(async () => {
|
|
await server?.close();
|
|
});
|
|
|
|
function m4Result() {
|
|
return {
|
|
schema_version: "missioncore.m4-threat-replay-view/v1",
|
|
result_id: visualResultId,
|
|
created_at_utc: "2026-08-05T15:36:01.553Z",
|
|
status: "accepted",
|
|
profile_id: "m4-ravnoves00-virtual-corridor/v3",
|
|
rig_profile_id: "virtual-base-footprint-1000x600/v3",
|
|
corridor_profile_id: "ravnoves00-forward-corridor-8m/v3",
|
|
source_result_ids: {
|
|
detector: `m4-detector-replay-${"d".repeat(64)}`,
|
|
geometry: `m4-geometry-replay-${"e".repeat(64)}`,
|
|
temporal: `m4-temporal-replay-${"f".repeat(64)}`,
|
|
},
|
|
metrics: {
|
|
decisions: { threat: 7606, "not-threat": 10769, unknown: 128878 },
|
|
evidence: {
|
|
"camera-only": 10158,
|
|
"current-metric": 28081,
|
|
"rolling-map-retained": 70989,
|
|
"stale-or-held": 38025,
|
|
},
|
|
fixtures: { critical: 5, critical_false_not_threat: 0, passed: 10, total: 10 },
|
|
runtime: {
|
|
frames_per_second: 175.0,
|
|
provider_latency_p50_ms: 2.5,
|
|
provider_latency_p95_ms: 7.2,
|
|
provider_latency_max_ms: 26.6,
|
|
},
|
|
body_frame: {
|
|
available: 3928,
|
|
qualified: 3861,
|
|
rejected: 67,
|
|
camera_forward_alignment_deg: { p95: 8.439, maximum: 24.252 },
|
|
},
|
|
reason_counts: { "geometry-only-evidence": 87550 },
|
|
},
|
|
configuration: {
|
|
virtual_body_m: [1, 0.6],
|
|
nominal_sensor_height_m: 1.25,
|
|
forward_corridor_m: 8,
|
|
prediction_horizon_seconds: 5,
|
|
body_frame: {
|
|
origin: "local-surface-vertical-projection",
|
|
up: "vendor-slam-map-gravity-axis",
|
|
forward: "smoothed-slam-trajectory-validated-by-camera-axis",
|
|
},
|
|
},
|
|
limitations: ["replay only"],
|
|
accepted: true,
|
|
authority: "replay-simulated",
|
|
physical_collision_accepted: false,
|
|
actuation_allowed: false,
|
|
};
|
|
}
|
|
|
|
function evidenceReport() {
|
|
const mismatch = {
|
|
source_binding: 0,
|
|
current: 0,
|
|
rolling_retained: 0,
|
|
held: 0,
|
|
expired: 0,
|
|
camera_uncertainty: 0,
|
|
threat_assessments: 0,
|
|
};
|
|
const raw = {
|
|
schema_version: "missioncore.reference-perception-graph-lab-report/v1",
|
|
result_id: resultId,
|
|
source: { graph_result_id: graphResultId },
|
|
method: { graph_id: "reference-perception-graph/v2" },
|
|
execution: {
|
|
worker_id: "worker-006",
|
|
worker_node: "DESKTOP-OPJ8J04",
|
|
artifact_sha256: "1".repeat(64),
|
|
code_revision: "2".repeat(40),
|
|
elapsed_seconds: 198.126,
|
|
},
|
|
metrics: {
|
|
frames: { expected: 4489, admitted: 4489, delivered: 4489 },
|
|
parity_mismatch_counts: mismatch,
|
|
queue_high_watermarks: {
|
|
detector: 2,
|
|
geometry: 2,
|
|
temporal: 2,
|
|
rolling: 2,
|
|
threat: 2,
|
|
},
|
|
},
|
|
acceptance: { accepted: true },
|
|
authority: {
|
|
commands_enabled: false,
|
|
actuation_allowed: false,
|
|
navigation_or_safety_accepted: false,
|
|
},
|
|
visual_evidence: {
|
|
linked_result_id: visualResultId,
|
|
shared_recorded_clock: true,
|
|
video_camera_3d_plan_available: true,
|
|
},
|
|
limitations: ["recorded replay only"],
|
|
};
|
|
return {
|
|
schema_version: "missioncore.laboratory-evidence-report/v1",
|
|
work_id: "m47-reference-graph-shadow",
|
|
result_id: resultId,
|
|
created_at_utc: "2026-08-23T18:00:16.061Z",
|
|
access: "read-only",
|
|
proof: {
|
|
document_schema_version: "missioncore.reference-perception-graph-lab/v1",
|
|
document_sha256: "3".repeat(64),
|
|
identity_sha256: "a".repeat(64),
|
|
report_schema_version: raw.schema_version,
|
|
report_sha256: "4".repeat(64),
|
|
artifact_count: 6,
|
|
verified_artifact_count: 6,
|
|
},
|
|
completeness: { identity: "recorded" },
|
|
identity: { authority: raw.authority },
|
|
source: raw.source,
|
|
configuration: null,
|
|
method: raw.method,
|
|
execution: raw.execution,
|
|
resources: null,
|
|
metrics: raw.metrics,
|
|
gates: raw.acceptance,
|
|
decision: null,
|
|
limitations: raw.limitations,
|
|
authority: raw.authority,
|
|
artifacts: [],
|
|
visual_evidence: {},
|
|
raw_report: raw,
|
|
};
|
|
}
|
|
|
|
test("M4.7 binds exact Worker graph proof to the synchronized M4.6 visual", async () => {
|
|
const requests = [];
|
|
const result = await fetchM47ReferenceGraphLab({
|
|
resultId,
|
|
fetcher: async (input) => {
|
|
const path = String(input);
|
|
requests.push(path);
|
|
return new Response(JSON.stringify(
|
|
path.includes("/evidence-reports/") ? evidenceReport() : m4Result(),
|
|
), { status: 200 });
|
|
},
|
|
});
|
|
|
|
assert.equal(result.graphResultId, graphResultId);
|
|
assert.equal(result.visual.resultId, visualResultId);
|
|
assert.equal(result.worker.id, "worker-006");
|
|
assert.equal(result.frames.delivered, 4489);
|
|
assert.deepEqual(Object.values(result.parityMismatchCounts), Array(7).fill(0));
|
|
assert.equal(Math.max(...Object.values(result.queueHighWatermarks)), 2);
|
|
assert.deepEqual(requests, [
|
|
`/api/v1/laboratory/evidence-reports/m47-reference-graph-shadow/${resultId}`,
|
|
`/api/v1/laboratory/m4-threat/results/${visualResultId}`,
|
|
]);
|
|
});
|
|
|
|
test("M4.7 keeps exact visual binding during a rolling API deployment", async () => {
|
|
const requests = [];
|
|
const result = await fetchM47ReferenceGraphLab({
|
|
resultId,
|
|
fetcher: async (input) => {
|
|
const path = String(input);
|
|
requests.push(path);
|
|
if (path.includes("/evidence-reports/")) {
|
|
return new Response(JSON.stringify(evidenceReport()), { status: 200 });
|
|
}
|
|
if (path.endsWith(`/${visualResultId}`)) {
|
|
return new Response(null, { status: 404 });
|
|
}
|
|
return new Response(JSON.stringify({
|
|
schema_version: "missioncore.m4-threat-replay-catalog/v1",
|
|
items: [m4Result()],
|
|
}), { status: 200 });
|
|
},
|
|
});
|
|
|
|
assert.equal(result.visual.resultId, visualResultId);
|
|
assert.deepEqual(requests, [
|
|
`/api/v1/laboratory/evidence-reports/m47-reference-graph-shadow/${resultId}`,
|
|
`/api/v1/laboratory/m4-threat/results/${visualResultId}`,
|
|
"/api/v1/laboratory/m4-threat/results?limit=10",
|
|
]);
|
|
});
|