Files
NODEDC_MISSION_CORE/apps/control-station/test/e29Evidence.test.mjs
T

219 lines
5.9 KiB
JavaScript

import assert from "node:assert/strict";
import { after, before, test } from "node:test";
import { createServer } from "vite";
let server;
let parseE29EvidenceCatalog;
let parseE29EvidenceFrame;
let fetchE29EvidenceCatalog;
let fetchE29EvidenceFrame;
let E29EvidenceContractError;
const resultId = `e29-camera-geometry-${"a".repeat(64)}`;
function result(overrides = {}) {
return {
result_id: resultId,
created_at_utc: "2026-07-26T00:00:00Z",
status: "diagnostic-replay-complete",
identity: {
frame_count: 4489,
timeline_start_seconds: 35.4,
timeline_end_seconds: 484.0,
},
metrics: {
frames: {
total: 4489,
source_available: 3928,
local_surface_valid: 3928,
},
semantic_observations: {
total: 20513,
current: 19625,
agreement_fraction_of_current: 0.3231,
geometry_status: {
agree: 6341,
"single-source-camera": 13246,
conflict: 38,
unknown: 888,
},
},
geometry_only_occupied: {
cluster_count: 21321,
point_count: 2021343,
},
runtime: {
build_elapsed_ms: 8466.6,
frame_processing_ms: { p95: 2.517 },
},
},
decision: {
camera_first_contract_implemented: true,
parallel_geometry_only_layer_implemented: true,
production_promotion: false,
next_gate: "operator review",
},
limitations: ["not ground truth"],
authority: {
commands_enabled: false,
navigation_or_safety_accepted: false,
},
review_frames: [{
frame_index: 343,
source_frame_index: 343,
session_seconds: 69.799,
conflict_count: 1,
semantic_observation_count: 6,
geometry_only_cluster_count: 5,
}],
linked_evidence: {
source_session_id: "20260720T065719Z_viewer_live",
local_surface_model_id: `k1-local-surface-${"b".repeat(64)}`,
source_pack_id: `e10-lidar-pack-${"c".repeat(64)}`,
source_result_id: `e10-integrated-perception-${"d".repeat(64)}`,
published_on_control_plane: true,
worker_copy_required: false,
},
ground_truth: false,
access: "read-only",
...overrides,
};
}
function catalog(overrides = {}) {
return {
schema_version: "missioncore.laboratory-e29-catalog/v1",
configured: true,
items: [result()],
candidate_total: 3,
invalid_total: 0,
access: "read-only",
...overrides,
};
}
function frame(overrides = {}) {
return {
schema_version: "missioncore.laboratory-e29-frame/v1",
result_id: resultId,
frame: {
schema_version: "missioncore.e29-camera-geometry-frame/v1",
frame_index: 343,
source_frame_index: 343,
session_seconds: 69.799,
semantic_observations: [{
track_id: 240042,
label: "car",
geometry_status: "conflict",
geometry_reason: "camera-object-region-observed-as-local-surface",
range_m: null,
score: 0.76,
support: {
classified_points_in_bbox: 8,
occupied_points_in_bbox: 0,
surface_points_in_bbox: 7,
},
}],
geometry_only_occupied: [{
nearest_range_m: 3.71,
point_count: 7,
voxel_count: 5,
height_range_m: [1.61, 1.86],
}],
},
access: "read-only",
...overrides,
};
}
before(async () => {
server = await createServer({
appType: "custom",
logLevel: "silent",
server: { middlewareMode: true },
});
({
parseE29EvidenceCatalog,
parseE29EvidenceFrame,
fetchE29EvidenceCatalog,
fetchE29EvidenceFrame,
E29EvidenceContractError,
} = await server.ssrLoadModule("/src/core/laboratory/e29Evidence.ts"));
});
after(async () => {
await server?.close();
});
test("decodes only verified non-authoritative E29 evidence", () => {
const decoded = parseE29EvidenceCatalog(catalog());
assert.equal(decoded.items.length, 1);
assert.equal(decoded.candidateTotal, 3);
assert.equal(decoded.items[0].metrics.semanticObservations.geometryStatus.conflict, 38);
assert.equal(decoded.items[0].linkedEvidence.publishedOnControlPlane, true);
const decodedFrame = parseE29EvidenceFrame(frame());
assert.equal(decodedFrame.semanticObservations[0].geometryStatus, "conflict");
assert.equal(decodedFrame.geometryOnlyOccupied[0].pointCount, 7);
});
test("rejects command authority and unverified publication", () => {
assert.throws(
() => parseE29EvidenceCatalog(catalog({
items: [result({
authority: {
commands_enabled: true,
navigation_or_safety_accepted: false,
},
})],
})),
E29EvidenceContractError,
);
assert.throws(
() => parseE29EvidenceCatalog(catalog({
items: [result({
linked_evidence: {
...result().linked_evidence,
published_on_control_plane: false,
},
})],
})),
E29EvidenceContractError,
);
});
test("fetches canonical catalog and exact review frame read-only", async () => {
const requests = [];
const fetchedCatalog = await fetchE29EvidenceCatalog({
fetcher: async (input, init) => {
requests.push({ input: String(input), method: init?.method });
return new Response(JSON.stringify(catalog()), {
status: 200,
headers: { "Content-Type": "application/json" },
});
},
});
const fetchedFrame = await fetchE29EvidenceFrame(resultId, 343, {
fetcher: async (input, init) => {
requests.push({ input: String(input), method: init?.method });
return new Response(JSON.stringify(frame()), {
status: 200,
headers: { "Content-Type": "application/json" },
});
},
});
assert.equal(fetchedCatalog.items[0].identity.frameCount, 4489);
assert.equal(fetchedFrame.sourceFrameIndex, 343);
assert.deepEqual(requests, [
{
input: "/api/v1/laboratory/e29/results?limit=1",
method: "GET",
},
{
input: `/api/v1/laboratory/e29/results/${resultId}/frames/343`,
method: "GET",
},
]);
});