NODEDC_MISSION_CORE/apps/control-station/test/groundQualification.test.mjs

135 lines
3.7 KiB
JavaScript

import assert from "node:assert/strict";
import { after, before, test } from "node:test";
import { createServer } from "vite";
let server;
let decodeGroundQualification;
let decodeGroundFailurePreview;
let fetchGroundQualification;
let GroundQualificationContractError;
const aggregate = {
micro: {
ground_iou: 0.75,
natural_ground_recall: 0.8,
obstacle_non_ground_recall: 0.92,
},
latency_ms: { p50: 12, p95: 18, maximum: 25 },
assigned_fraction: 1,
source_coverage: 1,
frame_count: 961,
};
const qualification = {
schema_version: "missioncore.polygon-ground-qualification/v1",
access: "read-only",
run_id: "goose-ground-abc",
identity_sha256: "a".repeat(64),
source_id: "goose-3d/v2025-08-22",
split: "validation",
frame_count: 961,
aggregates: {
current: { ...aggregate, micro: { ...aggregate.micro, ground_iou: 0.5 } },
patchworkpp: aggregate,
},
degradations: { "range-20m": { ...aggregate, source_coverage: 0.6 } },
checks: [{
check_id: "ground-iou-gain",
observed: 0.25,
operator: ">=",
threshold: 0.07,
passed: true,
}],
worst_frames: [{
frame_id: "2022-07-22_flight__0071_0001",
current_ground_iou: 0.6,
patchwork_ground_iou: 0.55,
ground_iou_delta: -0.05,
patchwork_natural_ground_recall: 0.7,
}],
decision: {
status: "shadow-candidate",
passed: true,
promoted_to_navigation_or_safety: false,
reason: "all gates passed",
},
safety: {
qualification_only: true,
actuator_authority: false,
navigation_or_safety_accepted: false,
},
};
before(async () => {
server = await createServer({
appType: "custom",
logLevel: "silent",
server: { middlewareMode: true },
});
({
decodeGroundQualification,
decodeGroundFailurePreview,
fetchGroundQualification,
GroundQualificationContractError,
} = await server.ssrLoadModule("/src/core/polygon/groundQualification.ts"));
});
after(async () => {
await server?.close();
});
test("decodes a bounded shadow-only qualification", () => {
const decoded = decodeGroundQualification(qualification);
assert.equal(decoded.frameCount, 961);
assert.equal(decoded.patchwork.micro.groundIou, 0.75);
assert.equal(decoded.degradations["range-20m"].sourceCoverage, 0.6);
assert.equal(decoded.decision.promotedToNavigationOrSafety, false);
});
test("rejects navigation or safety promotion", () => {
assert.throws(
() => decodeGroundQualification({
...qualification,
decision: {
...qualification.decision,
promoted_to_navigation_or_safety: true,
},
}),
GroundQualificationContractError,
);
});
test("decodes point-aligned failure preview", () => {
const decoded = decodeGroundFailurePreview({
schema_version: "missioncore.polygon-ground-failure-preview/v1",
access: "read-only",
run_id: "goose-ground-abc",
source_id: "goose-3d/v2025-08-22",
frame_id: "2022-07-22_flight__0071_0001",
source_point_count: 2,
point_count: 2,
sampling: "deterministic-even-index",
points_xyz_m: [[0, 0, 0], [1, 1, 1]],
ground_truth_ground: [1, 0],
evaluated: [1, 1],
current_ground: [0, 0],
patchwork_ground: [1, 0],
current_disagreement: [1, 0],
patchwork_disagreement: [0, 0],
safety: { navigation_or_safety_accepted: false },
});
assert.equal(decoded.pointCount, 2);
assert.deepEqual(decoded.patchworkGround, [1, 0]);
});
test("treats missing qualification as a generic run", async () => {
const result = await fetchGroundQualification("goose-ground-abc", {
fetcher: async () => new Response(
JSON.stringify({ detail: "not found" }),
{ status: 404, headers: { "content-type": "application/json" } },
),
});
assert.equal(result, null);
});