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/); });