import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { after, before, test } from "node:test"; import { createServer } from "./support/vite-server.mjs"; let server, readNativeRerunCameraEye, selectRecordedRerunCameraEye; before(async () => { server = await createServer({ appType: "custom", logLevel: "silent", server: { middlewareMode: true } }); ({ readNativeRerunCameraEye, selectRecordedRerunCameraEye } = await server.ssrLoadModule( "/src/components/rerun/recordedRerunCameraJournal.ts")); }); after(async () => { await server?.close(); }); test("camera snapshot copies exact native pose, without approximating input", () => { const native = { position: [287, -74, 8], lookTarget: [286, -72, 0], eyeUp: [0, 0, 1] }; const eye = readNativeRerunCameraEye(native); assert.deepEqual(eye, native); native.position[0] = 999; assert.equal(eye.position[0], 287); assert.equal(readNativeRerunCameraEye(null), null); }); test("invalid native pose fails closed instead of substituting a guessed camera", () => { for (const value of [{}, "pose", { position: [NaN, 0, 1], lookTarget: [0, 0, 0], eyeUp: [0, 0, 1] }]) { assert.throws(() => readNativeRerunCameraEye(value), /Invalid native Rerun camera/); } }); test("iframe owner reads the native camera and installs no shadow input listeners", () => { const owner = readFileSync(new URL("../src/components/rerun/recordedRerunOwner.ts", import.meta.url), "utf8"); const camera = readFileSync(new URL("../src/components/rerun/recordedRerunCameraJournal.ts", import.meta.url), "utf8"); assert.match(owner, /get_camera_eye\?\.\(\)/); assert.doesNotMatch(owner + camera, /createRecordedRerunCameraJournal|addEventListener|Math\.exp/); }); test("follow and display changes preserve an off-centre world eye, including looking away", () => { const eye = { position: [120, 40, 25], lookTarget: [120, 40, 45], eyeUp: [0, 1, 0] }; assert.deepEqual(selectRecordedRerunCameraEye(false, false, eye), eye); assert.deepEqual(selectRecordedRerunCameraEye(false, true, eye), eye); assert.equal(selectRecordedRerunCameraEye(false, false, null), undefined); }); test("only explicit reset or plan/3D changes choose a camera preset", () => { const eye = { position: [120, 40, 25], lookTarget: [120, 40, 45], eyeUp: [0, 1, 0] }; assert.deepEqual(selectRecordedRerunCameraEye(true, false, eye).lookTarget, [0, 0, 0]); assert.deepEqual(selectRecordedRerunCameraEye(true, true, eye).position, [0, 0, 30]); }); test("recorded adapter preserves the native eye in one world-space activation", () => { const viewport = readFileSync(new URL("../src/components/RerunViewport.tsx", import.meta.url), "utf8"); assert.match(viewport, /selectRecordedRerunCameraEye\(\s*cameraContractChanged, recordedPlanView, active\.getCameraEye/); assert.match(viewport, /eyeRelativeToTracking: false/); assert.doesNotMatch(viewport, /pendingFollowCameraEye|stabilizedPayload|firstEyeIsTrackingRelative/); });