feat(perception): add lossless lidar replay v2
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { after, before, test } from "node:test";
|
||||
|
||||
import { createServer } from "vite";
|
||||
|
||||
let server;
|
||||
let parseLidarReplayCatalog;
|
||||
let parseLidarReplayDetail;
|
||||
let fetchLidarReplayCatalog;
|
||||
let fetchLidarReplayDetail;
|
||||
let LidarReplayContractError;
|
||||
let workspaceById;
|
||||
|
||||
before(async () => {
|
||||
server = await createServer({
|
||||
appType: "custom",
|
||||
logLevel: "silent",
|
||||
server: { middlewareMode: true },
|
||||
});
|
||||
({
|
||||
parseLidarReplayCatalog,
|
||||
parseLidarReplayDetail,
|
||||
fetchLidarReplayCatalog,
|
||||
fetchLidarReplayDetail,
|
||||
LidarReplayContractError,
|
||||
} = await server.ssrLoadModule("/src/core/lidar/replayQuality.ts"));
|
||||
({ workspaceById } = await server.ssrLoadModule("/src/productModel.ts"));
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await server?.close();
|
||||
});
|
||||
|
||||
const packId = `lidar-replay-pack-${"a".repeat(64)}`;
|
||||
|
||||
function summary(overrides = {}) {
|
||||
return {
|
||||
pack_id: packId,
|
||||
session_id: "20260719T220917Z_viewer_live",
|
||||
profile_id: "xgrids-k1-lidar-replay-pack/v2",
|
||||
point_frames: 10,
|
||||
pose_frames: 12,
|
||||
points: 1234,
|
||||
mean_points_per_frame: 123.4,
|
||||
p95_frame_interval_ms: 98.7,
|
||||
pose_coverage_fraction: 0.9,
|
||||
equivalence_status: "passed",
|
||||
logical_content_sha256: "b".repeat(64),
|
||||
created_at_utc: "2026-07-25T00:00:00Z",
|
||||
authority: {
|
||||
commands_enabled: false,
|
||||
navigation_or_safety_accepted: false,
|
||||
},
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function distribution() {
|
||||
return {
|
||||
sample_count: 10,
|
||||
minimum: 1,
|
||||
mean: 2,
|
||||
p50: 2,
|
||||
p95: 3,
|
||||
maximum: 4,
|
||||
};
|
||||
}
|
||||
|
||||
function catalog(overrides = {}) {
|
||||
return {
|
||||
schema_version: "missioncore.lidar-replay-pack-catalog/v1",
|
||||
configured: true,
|
||||
items: [summary()],
|
||||
valid_total: 1,
|
||||
invalid_total: 0,
|
||||
duplicate_total: 0,
|
||||
access: "read-only",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function detail() {
|
||||
return {
|
||||
schema_version: "missioncore.lidar-replay-pack-detail/v1",
|
||||
access: "read-only",
|
||||
pack: summary({ created_at_utc: undefined }),
|
||||
quality: {
|
||||
schema_version: "missioncore.lidar-quality-report/v1",
|
||||
field_retention: {
|
||||
xyz_map: true,
|
||||
raw_xyz: true,
|
||||
raw_rgbi: true,
|
||||
intensity_low_byte: true,
|
||||
source_sequence: true,
|
||||
header_seq_stamp_scaler: true,
|
||||
host_epoch_ns: true,
|
||||
host_monotonic_ns: true,
|
||||
},
|
||||
point_count_per_frame: distribution(),
|
||||
point_frame_interval_ms: distribution(),
|
||||
intensity_0_255: distribution(),
|
||||
pose_binding: {
|
||||
threshold_ms: 100,
|
||||
covered_point_frames: 9,
|
||||
coverage_fraction: 0.9,
|
||||
nearest_delta_ms: distribution(),
|
||||
},
|
||||
limitations: ["vendor-mapped increment"],
|
||||
},
|
||||
equivalence: {
|
||||
schema_version: "missioncore.lidar-live-replay-equivalence/v1",
|
||||
status: "passed",
|
||||
arrays_compared: 24,
|
||||
array_mismatches: 0,
|
||||
},
|
||||
readiness: {
|
||||
stages: [
|
||||
{
|
||||
stage: "lidar-3d-detection",
|
||||
readiness: "degraded",
|
||||
reasons: ["pretrained-domain-expects-sensor-scan"],
|
||||
},
|
||||
{
|
||||
stage: "lidar-inertial-slam",
|
||||
readiness: "blocked",
|
||||
reasons: ["lio-requires-unregistered-sensor-scans"],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function jsonResponse(payload, status = 200) {
|
||||
return new Response(JSON.stringify(payload), {
|
||||
status,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
}
|
||||
|
||||
test("LiDAR catalog and detail decode only passed, path-free evidence", () => {
|
||||
const parsedCatalog = parseLidarReplayCatalog(catalog());
|
||||
const parsedDetail = parseLidarReplayDetail(detail());
|
||||
|
||||
assert.equal(parsedCatalog.items[0].packId, packId);
|
||||
assert.equal(parsedDetail.quality.fieldRetention.raw_rgbi, true);
|
||||
assert.equal(parsedDetail.equivalence.arrayMismatches, 0);
|
||||
assert.equal(parsedDetail.stages[0].readiness, "degraded");
|
||||
assert.equal("path" in parsedCatalog.items[0], false);
|
||||
});
|
||||
|
||||
test("LiDAR contract refuses replay that did not pass equivalence", () => {
|
||||
assert.throws(
|
||||
() => parseLidarReplayCatalog(catalog({
|
||||
items: [summary({ equivalence_status: "failed" })],
|
||||
})),
|
||||
LidarReplayContractError,
|
||||
);
|
||||
});
|
||||
|
||||
test("LiDAR fetchers use read-only endpoints and workspace is registered", async () => {
|
||||
const calls = [];
|
||||
const fetcher = async (input, init) => {
|
||||
calls.push({ input: String(input), method: init?.method });
|
||||
return String(input).includes(packId)
|
||||
? jsonResponse(detail())
|
||||
: jsonResponse(catalog());
|
||||
};
|
||||
const parsedCatalog = await fetchLidarReplayCatalog({ fetcher });
|
||||
const parsedDetail = await fetchLidarReplayDetail(packId, { fetcher });
|
||||
|
||||
assert.equal(parsedCatalog.validTotal, 1);
|
||||
assert.equal(parsedDetail.pack.packId, packId);
|
||||
assert.deepEqual(calls, [
|
||||
{ input: "/api/v1/lidar/replay-packs?limit=50", method: "GET" },
|
||||
{ input: `/api/v1/lidar/replay-packs/${packId}`, method: "GET" },
|
||||
]);
|
||||
assert.equal(workspaceById("lidar-quality").root, "data");
|
||||
assert.equal(workspaceById("lidar-quality").kind, "lidar-quality");
|
||||
});
|
||||
Reference in New Issue
Block a user