feat(rerun): retain live playback and recover isolated viewer resources
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import {before,after,test} from 'node:test';
|
||||
import {createServer} from './support/vite-server.mjs';
|
||||
let server,create;
|
||||
before(async()=>{server=await createServer({appType:'custom',logLevel:'silent'});({liveRerunPlayback:create}=await server.ssrLoadModule('../../packages/sensor-ui/src/liveRerunPlayback.ts'));});
|
||||
after(async()=>{await server?.close();});
|
||||
function fixture(){
|
||||
const data={id:'a',range:{min:0,max:10e9},time:10e9,playing:false,calls:[]};
|
||||
const viewer={get_active_recording_id:()=>data.id,get_time_range:()=>({...data.range}),get_current_time:()=>data.time,get_playing:()=>data.playing,set_current_time:(_id,_timeline,time)=>{data.calls.push(['time',time]);data.time=time;},set_playing:(_id,playing)=>{data.calls.push(['play',playing]);data.playing=playing;}};
|
||||
return {data,controller:create(viewer)};
|
||||
}
|
||||
test('rewind pauses only the playhead, retains new data and returns to the latest received frame',()=>{
|
||||
const {data,controller:c}=fixture();assert.equal(c.read().live,true);
|
||||
const count=data.calls.length;c.read();assert.equal(data.calls.length,count,'an unchanged range must not enqueue native commands');
|
||||
c.seek(3e9);assert.equal(data.time,3e9);assert.equal(data.playing,false);
|
||||
data.range.max=20e9;const paused=c.read();assert.equal(paused.currentNs,3e9);assert.equal(paused.rangeNs.max,20e9);assert.equal(paused.live,false);
|
||||
c.setPlaying(true);assert.equal(data.time,3e9);assert.equal(data.playing,true);
|
||||
data.time=4e9;assert.equal(c.read().currentNs,4e9);
|
||||
assert.equal(c.jumpToLive().currentNs,20e9);data.range.max=21e9;assert.equal(c.read().currentNs,21e9);
|
||||
});
|
||||
test('native retention and acquisition changes cannot expose an expired history cursor',()=>{
|
||||
const {data,controller:c}=fixture();c.read();c.seek(-1);assert.equal(data.time,0);
|
||||
data.range.min=5e9;assert.equal(c.read().currentNs,5e9);
|
||||
c.seek(Infinity);assert.equal(data.time,5e9);
|
||||
data.id='b';data.range={min:50e9,max:51e9};assert.equal(c.read().live,true);assert.equal(data.time,51e9);
|
||||
});
|
||||
@@ -3,11 +3,11 @@ import { readFileSync } from "node:fs";
|
||||
import { after, before, test } from "node:test";
|
||||
import { createServer } from "./support/vite-server.mjs";
|
||||
|
||||
let server, readNativeRerunCameraEye;
|
||||
let server, readNativeRerunCameraEye, selectRecordedRerunCameraEye;
|
||||
before(async () => {
|
||||
server = await createServer({ appType: "custom", logLevel: "silent",
|
||||
server: { middlewareMode: true } });
|
||||
({ readNativeRerunCameraEye } = await server.ssrLoadModule(
|
||||
({ readNativeRerunCameraEye, selectRecordedRerunCameraEye } = await server.ssrLoadModule(
|
||||
"/src/components/rerun/recordedRerunCameraJournal.ts"));
|
||||
});
|
||||
after(async () => { await server?.close(); });
|
||||
@@ -34,9 +34,22 @@ test("iframe owner reads the native camera and installs no shadow input listener
|
||||
assert.doesNotMatch(owner + camera, /createRecordedRerunCameraJournal|addEventListener|Math\.exp/);
|
||||
});
|
||||
|
||||
test("display blueprint activation carries the current native eye, not the embedded preset", () => {
|
||||
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, /!enablingFollow \? active\.getCameraEye\?\.\(\) \?\? undefined : undefined/);
|
||||
assert.match(viewport, /requestBlueprint\(\s*firstEye,\s*firstEyeIsTrackingRelative,/);
|
||||
assert.match(viewport, /currentTimeNs: eyeRelativeToTracking \? currentTimeNs : undefined/);
|
||||
assert.match(viewport, /selectRecordedRerunCameraEye\(\s*cameraContractChanged, recordedPlanView, active\.getCameraEye/);
|
||||
assert.match(viewport, /eyeRelativeToTracking: false/);
|
||||
assert.doesNotMatch(viewport, /pendingFollowCameraEye|stabilizedPayload|firstEyeIsTrackingRelative/);
|
||||
});
|
||||
|
||||
@@ -26,6 +26,7 @@ function fixture(t, { stopFails = false } = {}) {
|
||||
timers.set(++timerId, fn); return timerId;
|
||||
});
|
||||
t.mock.method(globalThis, "clearTimeout", (id) => timers.delete(id));
|
||||
t.mock.method(globalThis, "fetch", async () => ({ok: true, text: async () => "<!doctype html><div id=viewer></div>"}));
|
||||
const listeners = new Map();
|
||||
const viewer = { stop() { stops++; if (stopFails) throw new Error("partial start"); } };
|
||||
const mount = {};
|
||||
@@ -39,7 +40,10 @@ function fixture(t, { stopFails = false } = {}) {
|
||||
};
|
||||
const host = { dataset: {}, ownerDocument: { createElement(name) {
|
||||
assert.equal(name, "iframe"); return frame;
|
||||
} }, append(child) { assert.equal(child, frame); } };
|
||||
} }, append(child) {
|
||||
assert.equal(child, frame);
|
||||
assert.equal(child.src, '/rerun-runtime.html', 'URL must precede browsing-context insertion');
|
||||
} };
|
||||
return { host, frame, viewer, mount, timers, listeners,
|
||||
counts: () => ({ creates, stops, removals }) };
|
||||
}
|
||||
@@ -87,6 +91,27 @@ test("recorded realm terminates on close even if upstream stop throws", async (t
|
||||
assert.equal(ready.viewer.ready, false);
|
||||
});
|
||||
|
||||
test("playback poll publishes only the latest native eye and removes it on disposal", async (t) => {
|
||||
const f = fixture(t);
|
||||
let time = 1;
|
||||
let position = [300, 7, 8];
|
||||
f.viewer.get_current_time = () => time;
|
||||
f.viewer.get_camera_eye = () => ({ position, lookTarget: [298, 9, 0], eyeUp: [0, 0, 1] });
|
||||
const scope = createIsolatedRerunHost(f.host);
|
||||
f.frame.onload();
|
||||
const { viewer } = await scope.ready;
|
||||
assert.equal(viewer.get_current_time("recording", "session_time"), 1);
|
||||
assert.deepEqual(JSON.parse(f.host.dataset.rerunCamera).eye.position, [300, 7, 8]);
|
||||
time = 2;
|
||||
position = [310, 9, 8];
|
||||
assert.equal(viewer.get_current_time("recording", "session_time"), 2);
|
||||
const latest = JSON.parse(f.host.dataset.rerunCamera);
|
||||
assert.equal(latest.timeNs, 2);
|
||||
assert.deepEqual(latest.eye.position, position);
|
||||
scope.dispose();
|
||||
assert.equal(f.host.dataset.rerunCamera, undefined);
|
||||
});
|
||||
|
||||
test("native frame input relays Escape and leaves pointer ownership inside Rerun", () => {
|
||||
const listeners = new Map(), events = [];
|
||||
class ParentEvent { constructor(type, init) { this.type = type; Object.assign(this, init); } }
|
||||
@@ -146,6 +171,95 @@ test("close before frame load cancels startup and cannot reopen", async (t) => {
|
||||
assert.equal(f.timers.size, 0);
|
||||
});
|
||||
|
||||
test("detached observation portal navigates only after attachment and cancels pending navigation", async (t) => {
|
||||
const f = fixture(t), frames = new Map(); let sequence = 0;
|
||||
f.host.isConnected = f.frame.isConnected = false;
|
||||
f.host.ownerDocument.defaultView = {
|
||||
requestAnimationFrame() { throw new Error('Background tab does not paint'); },
|
||||
setTimeout(fn) { frames.set(++sequence, fn); return sequence; },
|
||||
clearTimeout(id) { frames.delete(id); },
|
||||
};
|
||||
const tick = () => { const [id, fn] = frames.entries().next().value; frames.delete(id); fn(); };
|
||||
const scope = createIsolatedRerunHost(f.host);
|
||||
tick(); tick();
|
||||
assert.equal(f.frame.src, undefined);
|
||||
f.host.isConnected = f.frame.isConnected = true;
|
||||
tick(); assert.equal(f.frame.src, '/rerun-runtime.html');
|
||||
f.frame.onload(); await scope.ready; scope.dispose();
|
||||
assert.equal(frames.size, 0);
|
||||
|
||||
f.host.isConnected = f.frame.isConnected = false;
|
||||
const pending = createIsolatedRerunHost(f.host);
|
||||
const rejection = assert.rejects(pending.ready, /disposed/);
|
||||
pending.dispose(); await rejection;
|
||||
assert.equal(frames.size, 0);
|
||||
});
|
||||
|
||||
test("initial blank load is ignored while the bundled document is fetched within its deadline", async (t) => {
|
||||
const f = fixture(t), navigations = new Map(); let sequence = 0;
|
||||
f.host.ownerDocument.defaultView = {
|
||||
setTimeout(fn) { navigations.set(++sequence, fn); return sequence; },
|
||||
clearTimeout(id) { navigations.delete(id); },
|
||||
};
|
||||
const tick = () => { const [id, fn] = navigations.entries().next().value; navigations.delete(id); fn(); };
|
||||
const scope = createIsolatedRerunHost(f.host);
|
||||
const deadline = [...f.timers.keys()];
|
||||
tick();
|
||||
const api = f.frame.contentWindow.missionCoreRerun;
|
||||
delete f.frame.contentWindow.missionCoreRerun;
|
||||
f.frame.contentDocument = {URL: "about:blank"};
|
||||
f.frame.onload(); f.frame.onload();
|
||||
assert.equal(navigations.size, 0);
|
||||
assert.deepEqual([...f.timers.keys()], deadline);
|
||||
assert.equal(f.frame.src, "/rerun-runtime.html");
|
||||
f.frame.contentWindow.missionCoreRerun = api;
|
||||
f.frame.contentDocument.URL = "http://localhost/rerun-runtime.html";
|
||||
f.frame.onload(); await scope.ready;
|
||||
assert.equal(navigations.size, 0);
|
||||
scope.dispose();
|
||||
assert.equal(f.timers.size, 0);
|
||||
});
|
||||
|
||||
test("bundled document is fetched once and installed before the isolated realm is attached", async (t) => {
|
||||
const f = fixture(t); let requests = 0, attached = 0;
|
||||
t.mock.method(globalThis, 'fetch', async (url, options) => {
|
||||
assert.equal(url, '/rerun-runtime.html');
|
||||
assert.equal(options.redirect, 'error'); requests++;
|
||||
return {ok:true, text:async()=>'<html>runtime</html>'};
|
||||
});
|
||||
f.host.append = frame => { assert.equal(frame.srcdoc, '<html>runtime</html>'); attached++; };
|
||||
const scope = createIsolatedRerunHost(f.host);
|
||||
await new Promise(setImmediate);
|
||||
assert.equal(requests, 1); assert.equal(attached, 1);
|
||||
f.frame.onload(); await scope.ready; scope.dispose();
|
||||
assert.equal(f.timers.size, 0);
|
||||
});
|
||||
|
||||
test("closing during document fetch cancels it and late content cannot attach a frame", async (t) => {
|
||||
const f = fixture(t); let finish, signal, attached = 0;
|
||||
t.mock.method(globalThis, 'fetch', (_url, options) => {
|
||||
signal=options.signal; return new Promise(resolve=>{finish=resolve;});
|
||||
});
|
||||
f.host.append = () => attached++;
|
||||
const scope = createIsolatedRerunHost(f.host);
|
||||
const rejected = assert.rejects(scope.ready, /disposed/);
|
||||
scope.dispose(); await rejected;
|
||||
assert.equal(signal.aborted, true);
|
||||
finish({ok:true,text:async()=>'<html>late</html>'});
|
||||
await new Promise(setImmediate);
|
||||
assert.equal(attached, 0); assert.equal(f.counts().creates, 0);
|
||||
assert.equal(f.timers.size, 0);
|
||||
});
|
||||
|
||||
test("document fetch failure releases the empty realm and its deadline", async (t) => {
|
||||
const f = fixture(t);
|
||||
t.mock.method(globalThis, 'fetch', async()=>({ok:false}));
|
||||
const scope = createIsolatedRerunHost(f.host);
|
||||
await assert.rejects(scope.ready, /failed to load/);
|
||||
assert.equal(f.counts().removals, 1);
|
||||
assert.equal(f.timers.size, 0);
|
||||
});
|
||||
|
||||
test("closing during SDK startup also releases a late successful start", async () => {
|
||||
let finish, stops = 0;
|
||||
const owner = bridge({
|
||||
|
||||
@@ -252,9 +252,9 @@ test("recorded RRD bytes are never split across LogChannel.send_rrd calls", asyn
|
||||
assert.match(source, /recordedPerceptionLayers\.costmap !== undefined && status !== "ready"/);
|
||||
assert.match(source, /perceptionLayers\.costmap === undefined \? \{\} : \{\s*show_costmap: perceptionLayers\.costmap,\s*reactivate_updates: true/s);
|
||||
// Ordinary archives need activation too, not only the LAB costmap path.
|
||||
assert.match(source, /requestBlueprint\(\s*firstEye,\s*firstEyeIsTrackingRelative,[\s\S]*?\n\s*true,\s*\);/);
|
||||
assert.match(source, /cameraEye,\s*[\s\S]*?eyeRelativeToTracking: false,\s*reactivateUpdates: true,/);
|
||||
// Display changes must not trigger a full-file camera-bounds scan.
|
||||
assert.match(source, /currentTimeNs: eyeRelativeToTracking \? currentTimeNs : undefined/);
|
||||
assert.doesNotMatch(source, /currentTimeNs: eyeRelativeToTracking|Recorded tracking cursor is unavailable/);
|
||||
assert.match(source, /viewer\.start\(\s*rerunViewerInitialSource\(resolvedSource\)/s);
|
||||
assert.doesNotMatch(source, /rerunViewerOpenOptions/);
|
||||
assert.match(
|
||||
|
||||
@@ -37,6 +37,8 @@ test("generated JS and native WASM share one ABI including the camera snapshot",
|
||||
const wasm = new WebAssembly.Module(readFileSync(resolve(packageRoot, "re_viewer_bg.wasm")));
|
||||
const names = new Set(WebAssembly.Module.exports(wasm).map(item => item.name));
|
||||
assert.ok(names.has("webhandle_nodedc_camera_eye"));
|
||||
assert.ok(names.has("webhandle_nodedc_height_slice"));
|
||||
assert.ok(names.has("webhandle_nodedc_height_bounds"));
|
||||
for (const [, name] of glue.matchAll(/\bwasm\.([a-zA-Z_$][\w$]*)/g)) {
|
||||
assert.ok(names.has(name), `Missing WASM export: ${name}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user