refactor(lab): canonicalize recorded spatial replay
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { after, before, test } from "node:test";
|
||||
|
||||
import { createServer } from "vite";
|
||||
|
||||
let server;
|
||||
let canonicalMapGravityLocalPointToBodyGround;
|
||||
let canonicalRecordedLabPackedTgsCells;
|
||||
let canonicalRecordedLabTgsIsCurrent;
|
||||
|
||||
before(async () => {
|
||||
server = await createServer({
|
||||
appType: "custom",
|
||||
logLevel: "silent",
|
||||
server: { middlewareMode: true },
|
||||
});
|
||||
({
|
||||
canonicalMapGravityLocalPointToBodyGround,
|
||||
canonicalRecordedLabPackedTgsCells,
|
||||
canonicalRecordedLabTgsIsCurrent,
|
||||
} = await server.ssrLoadModule("/src/core/laboratory/canonicalRecordedLab.ts"));
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await server?.close();
|
||||
});
|
||||
|
||||
const identity = [
|
||||
[1, 0, 0],
|
||||
[0, 1, 0],
|
||||
[0, 0, 1],
|
||||
];
|
||||
|
||||
test("canonical TGS validity never retains a sparse anchor beyond its sealed history", () => {
|
||||
assert.equal(canonicalRecordedLabTgsIsCurrent(2_000_000_000, 1_000_000_000), true);
|
||||
assert.equal(canonicalRecordedLabTgsIsCurrent(2_000_000_001, 1_000_000_000), false);
|
||||
assert.equal(canonicalRecordedLabTgsIsCurrent(999_999_999, 1_000_000_000), false);
|
||||
});
|
||||
|
||||
test("map-gravity-local TGS uses sensor translation and current ground body exactly once", () => {
|
||||
const anchor = {
|
||||
originMapXyzM: [10, 20, 0.68],
|
||||
sensorOriginMapXyzM: [10, 20, 1],
|
||||
basisMapFromBody: identity,
|
||||
};
|
||||
const current = {
|
||||
originMapXyzM: [8, 20, 0],
|
||||
sensorOriginMapXyzM: [8, 20, 0.32],
|
||||
basisMapFromBody: identity,
|
||||
};
|
||||
assert.deepEqual(
|
||||
canonicalMapGravityLocalPointToBodyGround([1, 2, -1], anchor, current),
|
||||
[3, 2, 0],
|
||||
);
|
||||
const packed = canonicalRecordedLabPackedTgsCells({
|
||||
centersXyM: [[1, 2]],
|
||||
stateCodes: [2],
|
||||
zBoundsM: [[-1, 0]],
|
||||
}, anchor, current);
|
||||
assert.deepEqual([...packed.centersBodyXyM], [3, 2]);
|
||||
assert.deepEqual([...packed.zBoundsM], [0, 1]);
|
||||
assert.deepEqual([...packed.stateCodes], [2]);
|
||||
});
|
||||
|
||||
test("recorded LAB spatial loading is shared, profile-bound and experiment-neutral", async () => {
|
||||
const [contract, scheduler, vegetation] = await Promise.all([
|
||||
readFile(new URL("../src/core/laboratory/canonicalRecordedLabSpatial.ts", import.meta.url), "utf8"),
|
||||
readFile(new URL("../src/components/laboratory/useCanonicalRecordedLabSpatialFrame.ts", import.meta.url), "utf8"),
|
||||
readFile(new URL("../src/core/laboratory/vegetationShadow.ts", import.meta.url), "utf8"),
|
||||
]);
|
||||
assert.match(contract, /CANONICAL_RECORDED_LAB_SPATIAL_PROFILE/);
|
||||
assert.match(contract, /profile: CANONICAL_RECORDED_LAB_SPATIAL_PROFILE/);
|
||||
assert.match(scheduler, /Shared latest-request-wins scheduler/);
|
||||
assert.match(scheduler, /identityRef\.current !== requestIdentity/);
|
||||
assert.doesNotMatch(scheduler, /RAVNOVES|vegetation|DDRNet/);
|
||||
assert.doesNotMatch(vegetation, /fetchCanonicalRecordedLabSpatialFrame|CanonicalRecordedLabSpatialFrame/);
|
||||
});
|
||||
@@ -19,13 +19,15 @@ before(async () => {
|
||||
});
|
||||
({
|
||||
fetchVegetationBenchmarkResult,
|
||||
fetchCanonicalRecordedLabSpatialFrame,
|
||||
fetchVegetationShadowResult,
|
||||
fetchVegetationRouteTgsAnchor,
|
||||
vegetationFullRouteMaskUrl,
|
||||
} = await server.ssrLoadModule(
|
||||
"/src/core/laboratory/vegetationShadow.ts",
|
||||
));
|
||||
({ fetchCanonicalRecordedLabSpatialFrame } = await server.ssrLoadModule(
|
||||
"/src/core/laboratory/canonicalRecordedLabSpatial.ts",
|
||||
));
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
@@ -405,16 +407,35 @@ test("canonical recorded LAB spatial frame keeps source, SLAM and body identity
|
||||
fetcher: async (url) => {
|
||||
requestedUrl = String(url);
|
||||
return new Response(JSON.stringify({
|
||||
schema_version: "missioncore.canonical-recorded-lab-spatial-frame/v1",
|
||||
schema_version: "missioncore.canonical-recorded-lab-spatial-frame/v2",
|
||||
target_time_ns: 82_770_000_000,
|
||||
source_time_ns: 82_769_535_708,
|
||||
pose_time_ns: 82_769_535_708,
|
||||
trajectory_time_ns: 82_700_000_000,
|
||||
coordinate_frame: "body-ground",
|
||||
sensor_height: {
|
||||
meters: 0.32,
|
||||
source: "initial-source-cloud-lower-quantile-median",
|
||||
sample_count: 20,
|
||||
mad_m: 0.03,
|
||||
authority: "visual-derived",
|
||||
},
|
||||
spatial_profile: {
|
||||
profile_id: "source-paced-ground-v2",
|
||||
local_slam_history_seconds: 5,
|
||||
local_slam_radius_m: 30,
|
||||
local_slam_voxel_size_m: 0.12,
|
||||
local_slam_point_limit: 27000,
|
||||
},
|
||||
source_point_count: 2,
|
||||
source_points_body_xyz_m: [[1, 2, 3], [4, 5, 6]],
|
||||
local_slam_source_frame_count: 2,
|
||||
local_slam_source_point_count: 4,
|
||||
local_slam_point_count: 2,
|
||||
local_slam_body_xyz_m: [[0, 0, 0], [1, 0, 0]],
|
||||
body_frame: {
|
||||
origin_map_xyz_m: [33, 4, 1],
|
||||
sensor_origin_map_xyz_m: [33, 4, 1.32],
|
||||
basis_map_from_body: [[1, 0, 0], [0, 1, 0], [0, 0, 1]],
|
||||
},
|
||||
}), { status: 200, headers: { "Content-Type": "application/json" } });
|
||||
@@ -422,10 +443,11 @@ test("canonical recorded LAB spatial frame keeps source, SLAM and body identity
|
||||
});
|
||||
assert.equal(
|
||||
requestedUrl,
|
||||
`/api/v1/observation-sessions/session-004/canonical-lab/spatial-frame?generation=${generation}&time_ns=82770000000`,
|
||||
`/api/v1/observation-sessions/session-004/canonical-lab/spatial-frame?generation=${generation}&time_ns=82770000000&profile=source-paced-ground-v2`,
|
||||
);
|
||||
assert.equal(frame.sourcePointCount, 2);
|
||||
assert.equal(frame.localSlamBodyXyzM.length, 2);
|
||||
assert.equal(frame.sensorHeight.meters, 0.32);
|
||||
assert.deepEqual(frame.bodyFrame.originMapXyzM, [33, 4, 1]);
|
||||
});
|
||||
|
||||
@@ -461,11 +483,13 @@ test("vegetation realtime LAB and archival benchmark use separate admitted instr
|
||||
assert.match(resultSource, /RecordedEvidenceVideoScene/);
|
||||
assert.match(resultSource, /LaboratoryMetricEvidenceScene/);
|
||||
assert.doesNotMatch(resultSource, /RerunViewport/);
|
||||
assert.match(resultSource, /fetchCanonicalRecordedLabSpatialFrame/);
|
||||
assert.match(resultSource, /useCanonicalRecordedLabSpatialFrame/);
|
||||
assert.doesNotMatch(resultSource, /cacheRef|pumpRef|desiredRef/);
|
||||
assert.match(resultSource, /useCanonicalRecordedLabReplayState/);
|
||||
assert.match(resultSource, /playbackTransport="epoch-stream"/);
|
||||
assert.match(resultSource, /causalTgsCase/);
|
||||
assert.match(resultSource, /latest causal of 10 sealed anchors/);
|
||||
assert.match(resultSource, /TGS visible only inside sealed 1 s evidence window/);
|
||||
assert.match(resultSource, /canonicalRecordedLabPackedTgsCells/);
|
||||
assert.doesNotMatch(resultSource, /LaboratoryRecordedClipPlayer|M48EvidenceModeRail/);
|
||||
assert.doesNotMatch(resultSource, /assets\.tgs|<img/);
|
||||
assert.match(resultSource, /SOURCE POINTS/);
|
||||
|
||||
Reference in New Issue
Block a user