mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Navara now matches Cesium where the review found it diverging: a flight holds the camera inputs, camera.changed counts turns as Cesium does, render requests made during a frame survive it, follow pinches zoom, ground widths follow the pixel ratio and Cyber sonar reaches glyph caches and models. On Cesium, a staged imagery swap keeps loading tiles, setView replaces a running flight, and a cleared weather detail goes away. The contract gains MoverSet.failed, maps.terrainRevision, render.maxTextureSize and surface.sampleTerrainMostDetailed on every engine, so layers retry failed models, key road heights by terrain, size weather textures to the GPU and place Bhote Koshi cards on detailed terrain. Engine switches keep the live view, follows, focus, layer options and cards: a pick hands over the exact pose, applies no address options and pans no carried-over card; a history visit still applies its entry. Layers put GhostMaps pins, cable landings, OSM Places and directions on the measured surface without per-frame sampling, draw the Cockpit contact dot, hide disabled CCTV on attach, and keep ALPR running outside secure contexts. KML imports draw raised polygon fills, rotated and coloured ground overlays and north-referenced icon headings, and report files with nothing to draw. QA scripts read the contract instead of Cesium internals (test:track is 109/109 again), wait for the camera to rest before clicking, and give cold switches and parked engines realistic time. Docs follow the code.
355 lines
12 KiB
JavaScript
355 lines
12 KiB
JavaScript
/** Camera-jump regression against an existing server; never starts a server. */
|
|
import puppeteer from 'puppeteer';
|
|
import { chromeExecutablePath, captureQaScreenshot } from './qa-chrome.mjs';
|
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
import { reduceTrailPixels } from '../src/layers/transit/qaMetrics.js';
|
|
import { blockPaidQaMaps } from './qa-map-policy.mjs';
|
|
import { transitQaBase } from './qa-transit-browser.mjs';
|
|
|
|
const base = transitQaBase(process.env.QA_BASE_URL);
|
|
const shots = process.env.QA_SHOTS || 'qa-shots/transit-recovery';
|
|
await mkdir(shots, { recursive: true });
|
|
const browser = await puppeteer.launch({
|
|
headless: true,
|
|
executablePath: chromeExecutablePath(),
|
|
args: [
|
|
...(process.platform === 'darwin' ? ['--use-angle=metal'] : []),
|
|
'--enable-gpu',
|
|
'--disable-background-timer-throttling',
|
|
'--disable-renderer-backgrounding',
|
|
],
|
|
});
|
|
try {
|
|
const page = await browser.newPage();
|
|
await blockPaidQaMaps(page);
|
|
await page.setViewport({ width: 1920, height: 1080 });
|
|
const errors = [];
|
|
page.on('pageerror', (error) => errors.push(error.message));
|
|
await page.goto(
|
|
`${base}/?welcome=0#lat=30.271&lon=-97.7431&alt=600&heading=0&pitch=-60`,
|
|
);
|
|
await page.waitForFunction(() =>
|
|
window.__godsEyeView?.dataManager?.layers.has('transit'),
|
|
);
|
|
await page.evaluate(async () => {
|
|
const app = window.__godsEyeView;
|
|
await app.dataManager.setEnabled('transit', true, { source: 'qa' });
|
|
});
|
|
await page.waitForFunction(
|
|
() => {
|
|
const scene = window.__godsEyeView.viewer.scene;
|
|
return scene.globe.tilesLoaded && scene.globe.show;
|
|
},
|
|
{ timeout: 60000 },
|
|
);
|
|
await page.waitForFunction(
|
|
() => {
|
|
const cover = document.getElementById('loading-screen');
|
|
return !cover || cover.classList.contains('hidden');
|
|
},
|
|
{ timeout: 60000 },
|
|
);
|
|
await page.evaluate(() => {
|
|
const app = window.__godsEyeView,
|
|
camera = app.viewer.camera;
|
|
const C = camera.positionCartographic.constructor,
|
|
lat = 30.267 + 90 / 111320;
|
|
const floor =
|
|
app.viewer.scene.globe.getHeight(C.fromDegrees(-97.7431, lat)) || 0;
|
|
camera.setView({
|
|
destination: C.toCartesian(
|
|
C.fromDegrees(
|
|
-97.7431,
|
|
lat - 600 / Math.tan(Math.PI / 3) / 111320,
|
|
floor + 600,
|
|
),
|
|
),
|
|
orientation: { heading: 0, pitch: -Math.PI / 3, roll: 0 },
|
|
});
|
|
});
|
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
await page.waitForFunction(
|
|
() => window.__godsEyeView.viewer.scene.globe.tilesLoaded,
|
|
{ timeout: 60000 },
|
|
);
|
|
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
const result = await page.evaluate(async () => {
|
|
const app = window.__godsEyeView,
|
|
scene = app.viewer.scene,
|
|
camera = app.viewer.camera;
|
|
const layer = app.dataManager.layers.get('transit').module;
|
|
const state = layer._transitStateForTest(),
|
|
parts = layer._transitPartsForTest();
|
|
const { getRegisteredTransitFeed } =
|
|
await import('/src/data/transitFeeds.js');
|
|
const { setRate } = await import('/src/data/contactPlayback.js');
|
|
const C = camera.positionCartographic.constructor;
|
|
const feed = {
|
|
...getRegisteredTransitFeed('capmetro-austin'),
|
|
id: 'qa-camera-recovery',
|
|
};
|
|
const aim = (lat, height = 600) =>
|
|
camera.setView({
|
|
destination: C.toCartesian(
|
|
C.fromDegrees(
|
|
-97.7431,
|
|
lat - 600 / Math.tan(Math.PI / 3) / 111320,
|
|
height,
|
|
),
|
|
),
|
|
orientation: { heading: 0, pitch: -Math.PI / 3, roll: 0 },
|
|
});
|
|
// The trail draws through engine.ground (render/display.js); its renderer
|
|
// is the handle that shows and hides the whole trail. Keep the one the
|
|
// selection below creates.
|
|
let trailRenderer = null;
|
|
const createTrailRenderer = parts.renderer.createTrailRenderer;
|
|
parts.renderer.createTrailRenderer = (...args) =>
|
|
(trailRenderer = createTrailRenderer.apply(parts.renderer, args));
|
|
parts.selection.clearSelection();
|
|
parts.ingestion.abortAllInFlight();
|
|
state._activeFeeds.clear();
|
|
for (const key of state._vehicles.keys())
|
|
parts.ingestion.removeVehicle(key);
|
|
// Model an outstanding floor lookup while reports arrive off screen.
|
|
// Only acquisition is controlled; selection, visibility, paths and rendering
|
|
// use their real owners. Release to the loaded terrain at the camera jump.
|
|
const requestHeight = parts.height.requestHeight;
|
|
parts.height.requestHeight = (lat, lon) => ({
|
|
cell: `${lat},${lon}`,
|
|
height: null,
|
|
prior: null,
|
|
});
|
|
aim(30.28);
|
|
const now = Date.now();
|
|
for (let i = 0; i < 9; i++) {
|
|
const timestamp = now - 135000 + i * 15000;
|
|
parts.ingestion.applySnapshot(
|
|
feed,
|
|
{
|
|
fetchedAt: timestamp,
|
|
vehicles: [
|
|
{
|
|
id: 'moving-bus',
|
|
routeId: '1',
|
|
tripId: 'qa',
|
|
lat: 30.267 + (i * 90) / 111320,
|
|
lon: -97.7431,
|
|
timestamp: timestamp / 1000,
|
|
timestampSource: 'vehicle',
|
|
bearing: 0,
|
|
},
|
|
],
|
|
},
|
|
{ stale: false },
|
|
);
|
|
}
|
|
const entry = state._vehicles.get(`${feed.id}:moving-bus`);
|
|
entry.qaFixture = true; // Protect this disclosed fixture from live feed eviction.
|
|
parts.rendering.sampleIdle(entry);
|
|
const before = {
|
|
shown: entry.marker.show,
|
|
heightPending: entry.heightPending,
|
|
phase: entry.sample.phase,
|
|
fixes: entry.track.count,
|
|
};
|
|
clearTimeout(state._floorTimer);
|
|
state._floorTimer = null;
|
|
const started = performance.now();
|
|
parts.selection.selectVehicle(entry.key);
|
|
parts.renderer.createTrailRenderer = createTrailRenderer;
|
|
const preparedAtSelection = !!parts.trails.diagnostics()?.body;
|
|
parts.height.requestHeight = requestHeight;
|
|
const floor =
|
|
scene.globe.getHeight(
|
|
C.fromDegrees(entry.sample.lon, entry.sample.lat),
|
|
) || 0;
|
|
aim(entry.sample.lat, floor + 600);
|
|
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
let trail;
|
|
while (performance.now() - started < 1400) {
|
|
trail = parts.trails.diagnostics();
|
|
if (entry.marker.show && trail?.body?.show && trail.body.ready) break;
|
|
scene.requestRender();
|
|
await wait(25);
|
|
}
|
|
const status = {
|
|
before,
|
|
preparedAtSelection,
|
|
markerShow: entry.marker.show,
|
|
body: !!trail?.body,
|
|
bodyShow: trail?.body?.show === true,
|
|
visibility: layer
|
|
._transitVisibilityForTest()
|
|
.find((e) => e.key === entry.key),
|
|
recoveryMs: performance.now() - started,
|
|
};
|
|
if (!trailRenderer)
|
|
return { ...status, reason: 'the selection created no trail renderer' };
|
|
if (!entry.marker.show || !trail?.body?.show || !trail.body.ready)
|
|
return {
|
|
...status,
|
|
reason: 'marker or body did not recover before pixel deadline',
|
|
};
|
|
setRate(entry.track, 0, {
|
|
wallNowMs: Date.now(),
|
|
monoNowMs: performance.now(),
|
|
});
|
|
parts.rendering.sampleIdle(entry);
|
|
parts.rendering.schedulePlayback(entry);
|
|
// Marker positions are plain { x, y, z } now (the display's handles), not
|
|
// Cesium Cartesian3 instances with static helpers.
|
|
const V = {
|
|
distance: (a, b) => Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z),
|
|
lerp: (a, b, t) => ({
|
|
x: a.x + (b.x - a.x) * t,
|
|
y: a.y + (b.y - a.y) * t,
|
|
z: a.z + (b.z - a.z) * t,
|
|
}),
|
|
};
|
|
const points = entry.trailSegments
|
|
.filter((s) => s.toT <= entry.sample.displayT)
|
|
.flatMap((s) => s.positions);
|
|
const lengths = [0];
|
|
for (let i = 1; i < points.length; i++)
|
|
lengths.push(lengths.at(-1) + V.distance(points[i - 1], points[i]));
|
|
const canvas = scene.canvas,
|
|
gl = scene.context._gl,
|
|
scale = canvas.width / canvas.clientWidth;
|
|
const mul = (m, v) =>
|
|
[0, 1, 2, 3].map(
|
|
(i) =>
|
|
m[i] * v[0] + m[i + 4] * v[1] + m[i + 8] * v[2] + m[i + 12] * v[3],
|
|
);
|
|
const project = (p) => {
|
|
const q = mul(
|
|
camera.frustum.projectionMatrix,
|
|
mul(camera.viewMatrix, [p.x, p.y, p.z, 1]),
|
|
);
|
|
return {
|
|
x: ((q[0] / q[3]) * 0.5 + 0.5) * canvas.clientWidth,
|
|
y: (0.5 - (q[1] / q[3]) * 0.5) * canvas.clientHeight,
|
|
inFront: q[3] > 0,
|
|
};
|
|
};
|
|
const samples = Array.from({ length: 8 }, (_, i) => {
|
|
const d = (lengths.at(-1) * (i + 1)) / 9;
|
|
let j = 1;
|
|
while (j < lengths.length - 1 && lengths[j] < d) j++;
|
|
const p = V.lerp(
|
|
points[j - 1],
|
|
points[j],
|
|
(d - lengths[j - 1]) / Math.max(0.001, lengths[j] - lengths[j - 1]),
|
|
);
|
|
const cart = C.fromCartesian(p);
|
|
cart.height = scene.globe.getHeight(cart) || 0;
|
|
return {
|
|
...project(C.toCartesian(cart)),
|
|
radius: (Math.SQRT2 * Math.ceil(3 * scale)) / scale,
|
|
};
|
|
});
|
|
const sprite = {
|
|
...project(entry.marker.position),
|
|
radius: Math.hypot(entry.marker.width, entry.marker.height) / 2 + 4,
|
|
};
|
|
const read = () =>
|
|
samples.map(({ x, y }) => {
|
|
const r = Math.ceil(3 * scale),
|
|
px = Math.round(x * scale),
|
|
py = Math.round(canvas.height - 1 - y * scale);
|
|
if (
|
|
px < r ||
|
|
py < r ||
|
|
px + r >= canvas.width ||
|
|
py + r >= canvas.height
|
|
)
|
|
return null;
|
|
const data = new Uint8Array((2 * r + 1) ** 2 * 4);
|
|
gl.readPixels(
|
|
px - r,
|
|
py - r,
|
|
2 * r + 1,
|
|
2 * r + 1,
|
|
gl.RGBA,
|
|
gl.UNSIGNED_BYTE,
|
|
data,
|
|
);
|
|
return Array.from(data);
|
|
});
|
|
const frame = () =>
|
|
new Promise((resolve, reject) => {
|
|
const timer = setTimeout(() => {
|
|
remove();
|
|
reject(new Error('No recovery frame'));
|
|
}, 500);
|
|
const remove = scene.postRender.addEventListener(() => {
|
|
remove();
|
|
clearTimeout(timer);
|
|
resolve(read());
|
|
});
|
|
scene.requestRender();
|
|
});
|
|
let visible = true;
|
|
// Body and head together, as the trail's own visibility switch does.
|
|
const remove = scene.preRender.addEventListener(() =>
|
|
trailRenderer.setVisible(visible),
|
|
);
|
|
const captures = [];
|
|
try {
|
|
for (const show of [false, true, false, true]) {
|
|
visible = show;
|
|
await frame();
|
|
captures.push(await frame());
|
|
}
|
|
} finally {
|
|
remove();
|
|
trailRenderer.setVisible(true);
|
|
parts.trails.update();
|
|
}
|
|
const [off, on, offAgain, onAgain] = captures;
|
|
return {
|
|
...status,
|
|
samples,
|
|
sprite,
|
|
off,
|
|
on,
|
|
offAgain,
|
|
onAgain,
|
|
tilesReady:
|
|
scene.globe.tilesLoaded &&
|
|
parts.trails.diagnostics().body === trail.body,
|
|
elapsedMs: performance.now() - started,
|
|
// The trail's ground corridors (age bands and head, each with a backing).
|
|
lines: app.engine.ground
|
|
.list()
|
|
.filter(({ id }) => id.startsWith('transit-trail-')),
|
|
};
|
|
});
|
|
const pixels = reduceTrailPixels(result.on, result.off, result);
|
|
result.present = pixels.present;
|
|
result.pixelPass = pixels.pass;
|
|
result.pixelDetails = pixels;
|
|
result.errors = errors;
|
|
await captureQaScreenshot(page, { path: `${shots}/recovery.png` });
|
|
await writeFile(`${shots}/recovery.json`, JSON.stringify(result, null, 2));
|
|
for (const key of ['on', 'off', 'onAgain', 'offAgain']) delete result[key];
|
|
const pass =
|
|
result.before?.shown === false &&
|
|
result.before?.phase === 'playing' &&
|
|
// Ground history is prepared even while marker floors are unresolved.
|
|
result.preparedAtSelection &&
|
|
result.markerShow &&
|
|
result.body &&
|
|
result.bodyShow &&
|
|
result.elapsedMs <= 2000 &&
|
|
pixels.pass &&
|
|
!errors.length;
|
|
console.log(
|
|
`${pass ? 'PASS' : 'FAIL'} select moving bus, setView, marker + body + >=6/8 trail pixels within 2 s`,
|
|
);
|
|
console.log(JSON.stringify(result));
|
|
process.exitCode = pass ? 0 : 1;
|
|
} finally {
|
|
await browser.close();
|
|
}
|