From 1a0b9c8b0f05f8b6d7d0b892efa39e0ef76e9a2c Mon Sep 17 00:00:00 2001 From: Said Turksever Date: Wed, 14 Oct 2026 13:08:35 +0100 Subject: [PATCH 1/9] fix(qa-cctv-v2): keep long headful waits under puppeteer's protocolTimeout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The headful drain budget is uncapped (camCount * 800 + 30000 ms, ~50 min at N≈3,700), but each page.waitForFunction is one CDP call that puppeteer aborts after its 180 s default protocolTimeout. The .catch then recorded "timed out waiting for drain on the real-GPU sign-off path" after ~3 min. - Poll the drain in <=120 s slices (waitForFunctionSliced) so no single CDP call outlives protocolTimeout, whatever the catalog size. - Launch with protocolTimeout 240 s, headroom above the largest slice and the 60 s fixed waits. - Bound the sibling-owner 3-frame postRender wait at 10 s and report the frame count, so a renderer that stops producing frames fails with evidence instead of hanging the evaluate. - List --disable-backgrounding-occluded-windows explicitly. Puppeteer 25.10 already passes it by default, so this documents the headful contract rather than changing behaviour. Co-Authored-By: Claude Opus 5.5 --- scripts/qa-cctv-v2.mjs | 76 +++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/scripts/qa-cctv-v2.mjs b/scripts/qa-cctv-v2.mjs index 08995603fa..9234093bef 100644 --- a/scripts/qa-cctv-v2.mjs +++ b/scripts/qa-cctv-v2.mjs @@ -139,6 +139,41 @@ function record(name, ok, detail) { const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); +// Every page.waitForFunction / page.evaluate is a single CDP call that +// puppeteer aborts after `protocolTimeout` (default 180s). The headful drain +// budget is uncapped and reaches ~50 minutes on the full ~3,900-camera +// catalog, so long waits are polled in slices of at most WAIT_SLICE_MS and +// protocolTimeout is set with headroom above the largest slice. +const WAIT_SLICE_MS = 120000; +const PROTOCOL_TIMEOUT_MS = 2 * WAIT_SLICE_MS; + +/** + * page.waitForFunction with an overall budget that may exceed + * protocolTimeout: waits in WAIT_SLICE_MS slices until the predicate holds or + * the budget runs out. + * @param {import('puppeteer').Page} page + * @param {Function} predicate - In-page predicate. + * @param {number} budgetMs - Overall budget. + * @returns {Promise} True if the predicate held within the budget. + */ +async function waitForFunctionSliced(page, predicate, budgetMs) { + const deadline = Date.now() + budgetMs; + for (;;) { + const remaining = deadline - Date.now(); + if (remaining <= 0) return false; + const ok = await page + .waitForFunction(predicate, { + timeout: Math.min(remaining, WAIT_SLICE_MS), + }) + .then(() => true) + .catch((err) => { + if (err?.name === 'TimeoutError') return false; + throw err; + }); + if (ok) return true; + } +} + // SwiftShader can spend tens of seconds servicing the hover drillPick emitted // by page.mouse.move(), before the LEFT_DOWN under test even runs. Position the // pointer while ADJUST is disabled, then re-enable it and explicitly render a @@ -364,6 +399,7 @@ async function main() { const chromeExecutable = findChromeExecutable(); const browser = await puppeteer.launch({ headless: HEADFUL ? false : 'new', + protocolTimeout: PROTOCOL_TIMEOUT_MS, ...(chromeExecutable ? { executablePath: chromeExecutable } : {}), args: [ '--no-sandbox', @@ -373,6 +409,9 @@ async function main() { '--disable-web-security', '--disable-background-timer-throttling', '--disable-renderer-backgrounding', + // Puppeteer's defaults already include this; listed so the headful + // run keeps rendering when covered even if those defaults change. + '--disable-backgrounding-occluded-windows', '--window-size=1280,800', ], }); @@ -475,18 +514,15 @@ async function main() { console.log( `Waiting for geometry-load queue to drain (N=${camCount}, budget ${Math.round(drainBudgetMs / 1000)}s)...`, ); - const drained = await page - .waitForFunction( - () => { - const mod = - window.__godsEyeView.dataManager.layers.get('cctv').module; - const ui = mod.getUIState(); - return ui.loading && ui.loading.active === false; - }, - { timeout: drainBudgetMs }, - ) - .then(() => true) - .catch(() => false); + const drained = await waitForFunctionSliced( + page, + () => { + const mod = window.__godsEyeView.dataManager.layers.get('cctv').module; + const ui = mod.getUIState(); + return ui.loading && ui.loading.active === false; + }, + drainBudgetMs, + ); record( `geometry-load queue drains within ${Math.round(drainBudgetMs / 1000)}s (N=${camCount})`, drained ? true : HEADFUL ? false : null, @@ -1358,16 +1394,23 @@ async function main() { }, }); window.__qaCctvSiblingOwner = owner; - await new Promise((resolve) => { + // Bounded: if the browser stops producing frames (headful window + // asleep or hidden), report it instead of hanging the CDP call. + const framesRendered = await new Promise((resolve) => { let frames = 0; + const finish = () => { + clearTimeout(timer); + remove(); + resolve(frames); + }; const remove = scene.postRender.addEventListener(() => { if (++frames < 3) { scene.requestRender(); return; } - remove(); - resolve(); + finish(); }); + const timer = setTimeout(finish, 10000); scene.requestRender(); }); const rect = scene.canvas.getBoundingClientRect(); @@ -1382,6 +1425,7 @@ async function main() { typeof pickedId === 'string' ? pickedId : (pickedId?.id ?? null), ownerId: owner.id, ownsExactObject: picked?.id === owner, + framesRendered, projectionDelta: Math.hypot( projected.x - canvasPoint.x, projected.y - canvasPoint.y, @@ -1395,7 +1439,7 @@ async function main() { siblingTarget.ownsExactObject : null, siblingTarget - ? `picked=${siblingTarget.pickedId} exactOwner=${siblingTarget.ownsExactObject} projectionΔ=${siblingTarget.projectionDelta}` + ? `picked=${siblingTarget.pickedId} exactOwner=${siblingTarget.ownsExactObject} projectionΔ=${siblingTarget.projectionDelta} frames=${siblingTarget.framesRendered}/3` : 'no previously verified empty canvas ray was available', ); if ( From 7cdaf40fd036c2cf43ce5d7f89fd1583c0816538 Mon Sep 17 00:00:00 2001 From: Said Date: Mon, 19 Oct 2026 14:00:35 +0100 Subject: [PATCH 2/9] docs(cctv): retain Ontario licence attribution in batch candidate --- src/data/dataCredits.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/data/dataCredits.js b/src/data/dataCredits.js index 23f317e669..747ed18d18 100644 --- a/src/data/dataCredits.js +++ b/src/data/dataCredits.js @@ -238,9 +238,9 @@ export const DATA_CREDITS = [ key: 'ontario-511-cctv', html: 'CCTV cameras & frames (Ontario): ' + - 'Ontario 511 ' + - '(Open Government Licence - Ontario) ' + - '· provided as is, without warranty; actual road conditions may differ', + 'Ontario 511. ' + + 'Contains information licensed under the Open Government Licence – Ontario. ' + + 'Provided as is, without warranty; actual road conditions may differ.', }, { key: 'fintraffic-cctv', From 5b4f5ed4a0caa1941ba97a62edb4f6f7e2e4dcf6 Mon Sep 17 00:00:00 2001 From: Said Date: Mon, 19 Oct 2026 23:05:37 +0100 Subject: [PATCH 3/9] Fix CCTV provider cancellation and credential-safe errors --- changelog.d/1228-cctv-ontario-511-key.md | 2 + .../1233-tarktee-datex-catalog-hardening.md | 3 +- docs/CURRENT-STATE.md | 7 +- server/providers/cctv/ontario511.test.mjs | 40 +++++++ server/providers/cctv/sources.js | 107 ++++++++--------- src/data/cctvEstonia.test.mjs | 113 +++++++++++++++++- src/layers/cctv/frames.test.mjs | 31 +++++ src/layers/cctv/rendering.test.mjs | 53 ++++++++ 8 files changed, 293 insertions(+), 63 deletions(-) diff --git a/changelog.d/1228-cctv-ontario-511-key.md b/changelog.d/1228-cctv-ontario-511-key.md index d9dc7986f7..cbc3194d41 100644 --- a/changelog.d/1228-cctv-ontario-511-key.md +++ b/changelog.d/1228-cctv-ontario-511-key.md @@ -2,3 +2,5 @@ free developer key; set `ONTARIO_511_API_KEY` to enable the pack, which is otherwise skipped with one log line saying where to get a key (quanticsoul4772, #1228). +- Refuse Ontario catalog redirects and keep credential-bearing URLs and provider + exception text out of failure logs; retain the Ontario licence attribution. diff --git a/changelog.d/1233-tarktee-datex-catalog-hardening.md b/changelog.d/1233-tarktee-datex-catalog-hardening.md index e8fec8b34e..f2b2781af9 100644 --- a/changelog.d/1233-tarktee-datex-catalog-hardening.md +++ b/changelog.d/1233-tarktee-datex-catalog-hardening.md @@ -1,4 +1,5 @@ - Harden the Tarktee (Estonia) DATEX2 camera catalog fetches: refuse redirects, - cancel both response streams when either request fails or overflows the 4 MB + abort pending siblings and cancel received or late response streams when either + request fails before headers or overflows the 4 MB byte cap, retain the shared 30 s dual-XML fetch deadline, and deduplicate camera IDs before per-pack prioritization (yaka0007, #1233). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index e9b6c1df5e..a7ed660912 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -4446,7 +4446,7 @@ silently demoting every later lookup for the session. requires a developer key, so the pack needs `ONTARIO_511_API_KEY` and is skipped without one (#1228). All sources are RAW PRIOR poses, and the layer is stills-first. - sources. Fintraffic Finland road weather cameras (2026-09-13; cap 300, `CCTV_FINTRAFFIC_MAX_SOURCES`, + Fintraffic Finland road weather cameras (2026-09-13; cap 300, `CCTV_FINTRAFFIC_MAX_SOURCES`, kill switch `CCTV_FINTRAFFIC_ENABLED=0`) are the fourth pack: one keyless GeoJSON station list covering the whole country, where one _preset_ (a station's fixed view) is one camera — 806 GATHERING stations carry 2,256 in-collection presets, prioritized to 300 against seven anchors @@ -4459,6 +4459,11 @@ silently demoting every later lookup for the session. empty keeps the old catalog and is retried after another 15 minutes, not on the next request. Estonia's Tarktee DATEX feeds, which answer in 2 to 16.6 s, get 30 s (`TARKTEE_FETCH_TIMEOUT_MS`) where other packs get 15 s. + Ontario catalog requests refuse redirects and log only a fixed diagnostic for + transport/JSON failures, so reflected request URLs or keys cannot reach logs. + Tarktee owns both XML requests with one 30-second deadline and shared abort; + a failed header or body read cancels its sibling, including a response arriving + after cleanup. - **CCTV v3 UX — viewshed + calibration gizmo** (built 2026-07-05 and field validated 2026-07-21): the COVERAGE toggle is a tri-state cycle `OFF → ON → VIEWSHED`; viewshed mode renders each visible camera's frustum diff --git a/server/providers/cctv/ontario511.test.mjs b/server/providers/cctv/ontario511.test.mjs index 51334b3cba..9a8ba0e643 100644 --- a/server/providers/cctv/ontario511.test.mjs +++ b/server/providers/cctv/ontario511.test.mjs @@ -127,3 +127,43 @@ for (const status of [429, 500, 503]) { assert.doesNotMatch(lines[0], /secret-key-value/); }); } + +for (const failure of ['transport', 'invalid-json']) { + test(`Ontario ${failure} failures cannot log reflected keys or request URLs`, async (t) => { + const lines = captureConsole(t); + const key = 'synthetic secret&/=%value'; + t.mock.method(globalThis, 'fetch', async (url) => { + if (failure === 'transport') + throw new Error(`request failed: ${url} ${key}`); + return new Response(`not JSON: ${url} ${key}`); + }); + assert.deepEqual( + await loadOntarioSourcesFromOpenData({}, { ONTARIO_511_API_KEY: key }), + [], + ); + assert.equal(lines.length, 1); + assert.match(lines[0], /Ontario 511 camera download error/); + assert.equal(lines[0].includes(key), false); + assert.equal(lines[0].includes('synthetic'), false); + assert.equal(lines[0].includes('https://'), false); + }); +} + +test('Ontario encodes reserved key characters and refuses credential-bearing redirects', async (t) => { + const lines = captureConsole(t); + const key = 'synthetic &/=% value'; + let request; + t.mock.method(globalThis, 'fetch', async (url, init) => { + request = { url: new URL(url), init }; + return Response.json([ROW]); + }); + const cameras = await loadOntarioSourcesFromOpenData( + {}, + { ONTARIO_511_API_KEY: key }, + ); + assert.equal(request.url.searchParams.get('key'), key); + assert.equal(request.init.redirect, 'error'); + assert.equal(cameras.length, 1); + assert.equal(JSON.stringify(cameras).includes('synthetic'), false); + assert.equal(lines.join(' ').includes('synthetic'), false); +}); diff --git a/server/providers/cctv/sources.js b/server/providers/cctv/sources.js index 56d712898b..9681c63620 100644 --- a/server/providers/cctv/sources.js +++ b/server/providers/cctv/sources.js @@ -563,6 +563,7 @@ export async function loadOntarioSourcesFromOpenData( url.searchParams.set('key', key); const resp = await fetch(url, { headers: { Accept: 'application/json' }, + redirect: 'error', signal: AbortSignal.timeout(CCTV_SOURCE_FETCH_TIMEOUT_MS), }); if (!resp.ok) { @@ -646,10 +647,11 @@ export async function loadOntarioSourcesFromOpenData( `[CCTV] Loaded Ontario 511 camera sources: ${unique.length} enabled (using nearest ${prioritized.length})`, ); return prioritized; - } catch (error) { + } catch { + // Transport and JSON errors may reflect the credential-bearing request. + // Do not log upstream exception text, response bodies or URLs. console.warn( - '[CCTV] Ontario 511 camera download error:', - error?.message || error, + '[CCTV] Ontario 511 camera download error (network or invalid response)', ); return []; } @@ -1246,66 +1248,50 @@ export function parseTarkteeDatexImages(xml) { * @returns {Promise>} Normalized camera source objects. */ export async function loadTarkteeSourcesFromDatex() { + // Own both transports before either can reject. A response that arrives + // after cleanup must also be discarded instead of escaping Promise.all. + const abort = new AbortController(); + const signal = AbortSignal.any([ + abort.signal, + AbortSignal.timeout(TARKTEE_FETCH_TIMEOUT_MS), + ]); + const responses = []; + const discardBoth = async () => { + abort.abort(); + await Promise.allSettled( + responses.map((response) => response.body?.cancel()), + ); + return []; + }; + const fetchXml = async (url) => { + const response = await fetch(url, { + headers: { Accept: 'application/xml,text/xml,*/*' }, + redirect: 'manual', + signal, + }); + if (signal.aborted) { + await Promise.allSettled([response.body?.cancel()]); + signal.throwIfAborted(); + } + responses.push(response); + if (!response.ok) { + throw new Error( + response.status >= 300 && response.status < 400 + ? 'catalog redirected; redirects are not followed' + : `catalog HTTP ${response.status}`, + ); + } + return response; + }; try { const [locResp, imgResp] = await Promise.all([ - fetch(TARKTEE_LOCATIONS_URL, { - headers: { Accept: 'application/xml,text/xml,*/*' }, - redirect: 'manual', - signal: AbortSignal.timeout(TARKTEE_FETCH_TIMEOUT_MS), - }), - fetch(TARKTEE_IMAGES_URL, { - headers: { Accept: 'application/xml,text/xml,*/*' }, - redirect: 'manual', - signal: AbortSignal.timeout(TARKTEE_FETCH_TIMEOUT_MS), - }), + fetchXml(TARKTEE_LOCATIONS_URL), + fetchXml(TARKTEE_IMAGES_URL), + ]); + const [locXml, imgXml] = await Promise.all([ + readResponseTextCapped(locResp, TARKTEE_MAX_CATALOG_BYTES, signal), + readResponseTextCapped(imgResp, TARKTEE_MAX_CATALOG_BYTES, signal), ]); - // Both responses are fetched in parallel; if either is rejected or overflows - // its byte cap, both bodies must be released so neither transport leaks. - const discardBoth = async () => { - await Promise.allSettled([ - locResp?.body?.cancel(), - imgResp?.body?.cancel(), - ]); - return []; - }; - if ( - (locResp.status >= 300 && locResp.status < 400) || - (imgResp.status >= 300 && imgResp.status < 400) - ) { - console.warn( - '[CCTV] Tarktee DATEX catalog redirected; redirects are not followed', - ); - return discardBoth(); - } - if (!locResp.ok) { - console.warn('[CCTV] Tarktee locations download failed:', locResp.status); - return discardBoth(); - } - if (!imgResp.ok) { - console.warn('[CCTV] Tarktee images download failed:', imgResp.status); - return discardBoth(); - } - let locXml; - let imgXml; - const readAbort = new AbortController(); - try { - [locXml, imgXml] = await Promise.all([ - readResponseTextCapped( - locResp, - TARKTEE_MAX_CATALOG_BYTES, - readAbort.signal, - ), - readResponseTextCapped( - imgResp, - TARKTEE_MAX_CATALOG_BYTES, - readAbort.signal, - ), - ]); - } catch (error) { - readAbort.abort(); - await discardBoth(); - throw error; - } const locations = parseTarkteeDatexLocations(locXml); const images = parseTarkteeDatexImages(imgXml); if (!locations.size || !images.size) { @@ -1366,6 +1352,7 @@ export async function loadTarkteeSourcesFromDatex() { ); return prioritized; } catch (error) { + await discardBoth(); console.warn( '[CCTV] Tarktee DATEX download error:', error?.message || error, diff --git a/src/data/cctvEstonia.test.mjs b/src/data/cctvEstonia.test.mjs index 9ffeb6744b..7ded2cc66e 100644 --- a/src/data/cctvEstonia.test.mjs +++ b/src/data/cctvEstonia.test.mjs @@ -4,6 +4,7 @@ import { TARKTEE_IMAGES_URL, TARKTEE_LOCATIONS_URL, TARKTEE_MAX_CATALOG_BYTES, + TARKTEE_FETCH_TIMEOUT_MS, } from '../../server/providers/cctv/constants.js'; import { loadTallinnSourcesFromCatalog, @@ -116,7 +117,7 @@ test('Tarktee DATEX requests wait 30 s, past the slow answers measured live', as ), ); const cameras = await loadTarkteeSourcesFromDatex(); - assert.deepEqual(timeouts, [30_000, 30_000]); + assert.deepEqual(timeouts, [30_000]); assert.equal(cameras.length, 1); }); @@ -246,3 +247,113 @@ test('Tarktee loader cancels the sibling body when one feed fails or overflows t 'sibling stream is cancelled when the other feed exceeds the byte cap', ); }); + +for (const failingUrl of [TARKTEE_LOCATIONS_URL, TARKTEE_IMAGES_URL]) { + for (const lateSibling of [false, true]) { + test(`Tarktee cancels a ${lateSibling ? 'late' : 'received'} sibling when ${failingUrl} rejects before headers`, async (t) => { + quiet(t); + let cancelled = false; + let siblingSignal; + let release; + const gate = new Promise((resolve) => { + release = resolve; + }); + t.mock.method(globalThis, 'fetch', async (url, init) => { + if (String(url) === failingUrl) throw new Error('headers unavailable'); + siblingSignal = init.signal; + if (lateSibling) await gate; + return new Response( + new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode('')); + }, + cancel() { + cancelled = true; + }, + }), + ); + }); + assert.deepEqual(await loadTarkteeSourcesFromDatex(), []); + // Also exercise a response arriving after abort, as a queued transport + // completion can race the rejection owner even when fetch honors abort. + if (lateSibling) { + release(); + await new Promise((resolve) => setImmediate(resolve)); + } + assert.equal(cancelled, true, 'every obtained body must be cancelled'); + assert.equal( + siblingSignal.aborted, + true, + 'a pending transport is aborted immediately', + ); + }); + } + test(`Tarktee aborts a pending sibling when ${failingUrl} rejects`, async (t) => { + quiet(t); + let aborted = false; + t.mock.method(globalThis, 'fetch', async (url, init) => { + if (String(url) === failingUrl) throw new Error('headers unavailable'); + return new Promise((resolve, reject) => { + init.signal.addEventListener( + 'abort', + () => { + aborted = true; + reject(init.signal.reason); + }, + { once: true }, + ); + }); + }); + assert.deepEqual(await loadTarkteeSourcesFromDatex(), []); + assert.equal(aborted, true, 'do not wait for the 30-second deadline'); + }); +} + +test('Tarktee cancels both lengthless streams when one exceeds the byte cap', async (t) => { + quiet(t); + const cancelled = []; + t.mock.method( + globalThis, + 'fetch', + async (url) => + new Response( + new ReadableStream({ + start(controller) { + const oversized = String(url) === TARKTEE_LOCATIONS_URL; + controller.enqueue( + new Uint8Array(oversized ? TARKTEE_MAX_CATALOG_BYTES + 1 : 1), + ); + }, + cancel() { + cancelled.push(String(url)); + }, + }), + ), + ); + assert.deepEqual(await loadTarkteeSourcesFromDatex(), []); + assert.deepEqual( + cancelled.sort(), + [TARKTEE_LOCATIONS_URL, TARKTEE_IMAGES_URL].sort(), + ); +}); + +test('Tarktee aborts pending headers as soon as its sibling returns an HTTP error', async (t) => { + quiet(t); + let aborted = false; + t.mock.method(globalThis, 'fetch', async (url, init) => { + if (String(url) === TARKTEE_LOCATIONS_URL) + return new Response('unavailable', { status: 503 }); + return new Promise((resolve, reject) => { + init.signal.addEventListener( + 'abort', + () => { + aborted = true; + reject(init.signal.reason); + }, + { once: true }, + ); + }); + }); + assert.deepEqual(await loadTarkteeSourcesFromDatex(), []); + assert.equal(aborted, true); +}); diff --git a/src/layers/cctv/frames.test.mjs b/src/layers/cctv/frames.test.mjs index 0d03e94576..a0f14169e8 100644 --- a/src/layers/cctv/frames.test.mjs +++ b/src/layers/cctv/frames.test.mjs @@ -139,3 +139,34 @@ test('same pixels at a new aspect redraw at the new fit', () => { ]); assert.equal(runtime.canvasStamp, 2); }); + +test('same pixels at a new resolution with the same fit skip the redraw', () => { + const { runtime, load } = stillHarness(); + load(640, 480); + assert.deepEqual(load(1280, 960), []); + assert.equal(runtime.canvasStamp, 1); + assert.equal(runtime.drawnImageStamp, 2); +}); + +test('changed pixels redraw even when the fitted rectangle is unchanged', () => { + const { runtime, load } = stillHarness(); + load(640, 480); + const changedPixels = new Uint8ClampedArray( + FRAME_SIGNATURE_W * FRAME_SIGNATURE_H * 4, + ).fill(90); + runtime.signatureCtx.getImageData = () => ({ data: changedPixels }); + const calls = load(640, 480); + assert.equal(calls[0][0], 'fillRect'); + assert.deepEqual(calls[1], ['drawImage', 240, 0, 1440, 1080]); + assert.equal(runtime.canvasStamp, 2); +}); + +test('a failed pixel signature redraws rather than assuming equal content', () => { + const { runtime, load } = stillHarness(); + load(640, 480); + runtime.signatureCtx.getImageData = () => { + throw new Error('tainted canvas'); + }; + assert.deepEqual(load(640, 480).at(-1), ['drawImage', 240, 0, 1440, 1080]); + assert.equal(runtime.canvasStamp, 2); +}); diff --git a/src/layers/cctv/rendering.test.mjs b/src/layers/cctv/rendering.test.mjs index c4b490dd2b..e82650c4b2 100644 --- a/src/layers/cctv/rendering.test.mjs +++ b/src/layers/cctv/rendering.test.mjs @@ -71,3 +71,56 @@ test('focus de-emphasis fades each icon from its own color', () => { ); assert.equal(state._activeFocusStyleCount, 3); }); + +test('focus release restores video hue and alpha after the style throttle', () => { + let target = {}; + const records = ['mp4', 'webm'].map((feedType) => ({ + camera: { id: feedType, feedType }, + billboard: { show: true, color: LIVE_CAMERA_COLOR }, + })); + const state = { + _enabled: true, + _viewer: { scene: {}, camera: {} }, + _records: records, + _activeCameraId: null, + _activeFocusStyleCount: 0, + _lastFocusStyleAt: -Infinity, + }; + const focus = { + focusNowMs: (nowMs) => nowMs, + getFocusTarget: () => target, + focusPassIsNeeded: (value, count) => !!value || count > 0, + advanceSpriteFocus: () => ({ + factor: target ? FOCUS_FACTOR : 1, + active: !!target, + transitioning: false, + }), + focusAlphaNeedsWrite: (before, after) => before !== after, + }; + const { refreshCctvFocusStyles } = createRendering({ + state, + services: { focus }, + parts: { model: { isVideoFeedType } }, + source: {}, + }); + + refreshCctvFocusStyles(1000); + for (const record of records) { + assertFadedFrom( + record.billboard.color, + LIVE_CAMERA_COLOR, + record.camera.id, + ); + } + const dimmed = records.map((record) => record.billboard.color); + target = null; + refreshCctvFocusStyles(1050); + for (let i = 0; i < records.length; i += 1) { + assert.equal(records[i].billboard.color, dimmed[i]); + } + refreshCctvFocusStyles(1100); + for (const record of records) { + assert.deepEqual(record.billboard.color, LIVE_CAMERA_COLOR); + } + assert.equal(state._activeFocusStyleCount, 0); +}); From ea09a59877f1c7627f342c6928f6dcd92e698c78 Mon Sep 17 00:00:00 2001 From: Said Date: Mon, 19 Oct 2026 23:05:38 +0100 Subject: [PATCH 4/9] Validate CCTV terrain regime and frame calibration drag fixture --- .../1133-cctv-qa-terrain-drag-fixture.md | 3 + scripts/qa-cctv-v2.mjs | 75 +++++++++++++++---- 2 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 changelog.d/1133-cctv-qa-terrain-drag-fixture.md diff --git a/changelog.d/1133-cctv-qa-terrain-drag-fixture.md b/changelog.d/1133-cctv-qa-terrain-drag-fixture.md new file mode 100644 index 0000000000..e997fc1fbb --- /dev/null +++ b/changelog.d/1133-cctv-qa-terrain-drag-fixture.md @@ -0,0 +1,3 @@ +- Make CCTV QA ground-sampling checks respect the active terrain regime and + frame the actual calibration gizmo for the drag regression, preserving the + photoreal completion floor and all drag invariants. diff --git a/scripts/qa-cctv-v2.mjs b/scripts/qa-cctv-v2.mjs index 2c121e0d6b..8b69ac83db 100644 --- a/scripts/qa-cctv-v2.mjs +++ b/scripts/qa-cctv-v2.mjs @@ -658,24 +658,39 @@ async function main() { // (existence, not just ceiling). The wait below tolerates the update-tick // latency of the completion pass (update interval is 10s). // ----------------------------------------------------------------------- - console.log('Waiting for tiles + the one-shot completion pass...'); - const tilesSeenLoaded = await waitForTilesLoaded(page, 45000); - let sampleFloorOk = false; - if (tilesSeenLoaded) { - sampleFloorOk = await waitForPredicate( - page, - (base) => window.__qaCounters.sampleHeight - base >= 1, - { timeoutMs: 30000, args: [c0.sampleHeight] }, + // Globe terrain uses the cached DEM/prior and intentionally never calls + // scene.sampleHeight. Only the photoreal regime owns a one-shot mesh snap. + // Keep the mesh completion floor strict when that regime is active. + const photorealRegime = await page.evaluate( + () => window.__godsEyeView.viewer.scene.globe?.show === false, + ); + if (photorealRegime) { + console.log('Waiting for tiles + the one-shot completion pass...'); + const tilesSeenLoaded = await waitForTilesLoaded(page, 45000); + let sampleFloorOk = false; + if (tilesSeenLoaded) { + sampleFloorOk = await waitForPredicate( + page, + (base) => window.__qaCounters.sampleHeight - base >= 1, + { timeoutMs: 30000, args: [c0.sampleHeight] }, + ); + } + const cFloor = await readCounters(); + record( + '>=1 real ground sample once tilesLoaded observed (one-shot snap completed)', + tilesSeenLoaded ? sampleFloorOk : null, + tilesSeenLoaded + ? `total real samples since enable=${cFloor.sampleHeight - c0.sampleHeight}` + : 'tilesLoaded never observed within 45s — floor not assessable this run', + ); + } else { + const cFloor = await readCounters(); + record( + 'terrain-globe uses its DEM/prior without photoreal mesh sampling', + cFloor.sampleHeight === c0.sampleHeight, + `mesh samples since enable=${cFloor.sampleHeight - c0.sampleHeight}`, ); } - const cFloor = await readCounters(); - record( - '>=1 real ground sample once tilesLoaded observed (one-shot snap completed)', - tilesSeenLoaded ? sampleFloorOk : null, - tilesSeenLoaded - ? `total real samples since enable=${cFloor.sampleHeight - c0.sampleHeight}` - : 'tilesLoaded never observed within 45s — floor not assessable this run', - ); // Let the completion pass finish before the steady-state window: require // the sampleHeight counter quiet for 12s (> the 10s update interval, so @@ -1732,6 +1747,34 @@ async function main() { gizmoStates.map((s, i) => `${GIZMO_PARTS[i]}=${s}`).join(' '), ); + // Frame the actual gizmo for the drag fixture. Default autofocus can leave + // its shaft below the 10px interaction threshold; that distant view is not + // the drag-usability scenario this regression exercises. + const dragFraming = await page.evaluate(async () => { + const viewer = window.__godsEyeView.viewer; + const e = viewer.entities.getById('cctv-gizmo-move-east'); + if (!e) return null; + const pts = e.polyline.positions.getValue(viewer.clock.currentTime); + const target = pts?.[0]; + if (!target) return null; + const measure = () => { + const a = viewer.scene.cartesianToCanvasCoordinates(pts[0]); + const b = viewer.scene.cartesianToCanvasCoordinates(pts[pts.length - 1]); + return { + shaftPx: a && b ? Math.hypot(b.x - a.x, b.y - a.y) : null, + rangeM: target.constructor.distance(viewer.camera.positionWC, target), + }; + }; + const before = measure(); + viewer.camera.cancelFlight(); + viewer.camera.lookAt(target, new target.constructor(0, -200, 180)); + viewer.camera.lookAtTransform(viewer.camera.transform.constructor.IDENTITY); + viewer.scene.requestRender(); + const frames = await window.__qaRenderFrames(3, 10000); + return { before, after: measure(), frames }; + }); + console.log('Drag fixture framing:', JSON.stringify(dragFraming)); + // Synthetic CDP drag on the EAST arrow — the owner's field-test // regression. Sample effective elevation after every mouse move: it must // stay frozen until release, with no transient sampleHeight calls. From f927ef288a28a37fe99235b1dbed2826dcc6c279 Mon Sep 17 00:00:00 2001 From: Said Date: Mon, 19 Oct 2026 23:16:02 +0100 Subject: [PATCH 5/9] Check tracking rotation on the first visible frame within fleet cadence --- .../1133-cctv-qa-terrain-drag-fixture.md | 3 + scripts/track-regression.mjs | 79 +++++++++++++------ 2 files changed, 56 insertions(+), 26 deletions(-) diff --git a/changelog.d/1133-cctv-qa-terrain-drag-fixture.md b/changelog.d/1133-cctv-qa-terrain-drag-fixture.md index e997fc1fbb..789df9291c 100644 --- a/changelog.d/1133-cctv-qa-terrain-drag-fixture.md +++ b/changelog.d/1133-cctv-qa-terrain-drag-fixture.md @@ -1,3 +1,6 @@ - Make CCTV QA ground-sampling checks respect the active terrain regime and frame the actual calibration gizmo for the drag regression, preserving the photoreal completion floor and all drag invariants. +- Measure the tracking arrival regression on the first visible frame within + 250 ms, accounting for the 80 ms fleet cadence while rejecting a stale + first-visible orientation instead of retrying until it is correct. diff --git a/scripts/track-regression.mjs b/scripts/track-regression.mjs index 756daccfc3..e05309efaf 100644 --- a/scripts/track-regression.mjs +++ b/scripts/track-regression.mjs @@ -2696,9 +2696,9 @@ async function main() { // Staged deterministically: park the camera nadir over the synthetic // cluster, let rotations settle, TAMPER a billboard's rotation, then // trigger each path with the camera idle. The idle-drift catch-up - // (ROTATION_REFRESH_MS = 1 s) can coincidentally mask a regression in a - // ~300 ms SwiftShader frame window, so a regression shows as an - // intermittent (not guaranteed) failure — never a false failure. + // (ROTATION_REFRESH_MS = 1 s) must not repair a stale first-visible nose + // before we inspect it: capture that first postRender, with a 250 ms + // deadline that admits the 80 ms fleet cadence without waiting a second. // ============================================================ console.log('\nChange 4 — arrival rotation: moveEnd settle pass + horizon-reveal pass'); const arrival = await evalPage(async () => { @@ -2762,6 +2762,43 @@ async function main() { }); await nextFrames(3); const angDiff = (a, b) => Math.abs(Math.atan2(Math.sin(a - b), Math.cos(a - b))); + // Render frames are not fleet ticks: at 60/120 Hz four frames can + // precede the next 80 ms fleet pass. Observe elapsed time instead, and + // freeze the angle on the FIRST visible frame, even when it is wrong. + const observeFirstReveal = (bb, course, budgetMs = 250) => new Promise((resolve) => { + const startedAt = performance.now(); + let frames = 0; + let settled = false; + const finish = (shown, elapsedMs) => { + if (settled) return; + settled = true; + clearTimeout(timer); + remove(); + const expected = shown + ? screenProjectedRotation(v.scene, bb.position, course, null) + : null; + resolve({ + shown, + flipFrame: shown ? frames : -1, + revealElapsedMs: elapsedMs, + revealWithinBudget: shown && elapsedMs <= budgetMs, + dReveal: shown && Number.isFinite(expected) ? angDiff(bb.rotation, expected) : null, + }); + }; + const remove = v.scene.postRender.addEventListener(() => { + frames += 1; + const elapsedMs = performance.now() - startedAt; + if (bb.show) { + finish(true, elapsedMs); + } else if (elapsedMs >= budgetMs) { + finish(false, elapsedMs); + } else { + v.scene.requestRender(); + } + }); + const timer = setTimeout(() => finish(false, performance.now() - startedAt), budgetMs); + v.scene.requestRender(); + }); const probe = async (id, course) => { const bb = findBB(id); if (!bb || !bb.show) return { error: `${id} missing/hidden` }; @@ -2779,25 +2816,17 @@ async function main() { const expectedMoveEnd = screenProjectedRotation(v.scene, bb.position, course, null); // (b) reveal pass: tamper + hide — the next fleet tick must flip it // visible AND correct the nose in that same tick (camera still idle, - // no moveEnd raised). Diagnostic fields (round 5): record WHICH frame - // the flip landed on (flipFrame; -1 = never within the extended - // window) and whether a 3D model owns this id — distinguishes "tick - // slow under load" from "occluder says hidden" from "model handoff". + // no moveEnd raised). Record frame count as diagnostics only: the + // first visible postRender must already have the corrected rotation. bb.rotation = r0 + 1.5; bb.show = false; - let flipFrame = -1; - for (let f = 1; f <= 6; f++) { - await nextFrames(1); - if (bb.show && flipFrame === -1) flipFrame = f; - if (f >= 2 && flipFrame !== -1) break; - } - const expectedReveal = screenProjectedRotation(v.scene, bb.position, course, null); + const reveal = await observeFirstReveal(bb, course); const hasModel = !!(window.__g3dFindModel && window.__g3dFindModel(id)); return { r0, dMoveEnd: angDiff(afterMoveEnd, expectedMoveEnd), - dReveal: angDiff(bb.rotation, expectedReveal), - shown: bb.show, flipFrame, hasModel, + ...reveal, + hasModel, }; }; const flightCourse = window.__SYNTH.flights.find((f) => f.icao === 'aaa002')?.track ?? 0; @@ -2808,20 +2837,18 @@ async function main() { }; }); const fmtArr = (a) => (!a ? `no result (${arrival?.error || 'phase error'})` : a.error ? a.error - : `settle-err=${(a.dMoveEnd * 180 / Math.PI).toFixed(1)}° reveal-err=${(a.dReveal * 180 / Math.PI).toFixed(1)}° shown=${a.shown} flipFrame=${a.flipFrame} hasModel=${a.hasModel}`); + : `settle-err=${(a.dMoveEnd * 180 / Math.PI).toFixed(1)}° reveal-err=${a.dReveal === null ? 'unobserved' : (a.dReveal * 180 / Math.PI).toFixed(1) + '°'} shown=${a.shown} flipFrame=${a.flipFrame} revealMs=${a.revealElapsedMs.toFixed(1)} hasModel=${a.hasModel}`); const TAMPER_DEG = 1.5 * 180 / Math.PI; // ≈ 86° — an uncorrected nose stays this far off - // Reveal budget re-pinned 2 → 4 frames (round 5): the diagnostic probe - // shows the military flip consistently lands on frame 2 — the exact edge - // of the old budget — so any load hiccup flaked it (flights lands frame - // 1). The regression this protects against is a reveal that waits for - // the 1 s idle catch-up (~30-60 frames) or never re-aims; 4 frames still - // catches that with a wide margin, with zero-headroom flakes gone. + // 250 ms spans multiple 80 ms fleet opportunities while remaining well + // below the 1 s idle catch-up. Never retry until the angle becomes correct: + // dReveal is the immutable first-visible-frame observation above. const arrOk = (a) => !!a && !a.error && a.shown - && (a.flipFrame === -1 ? false : a.flipFrame <= 4) + && a.revealWithinBudget && a.revealElapsedMs <= 250 + && a.dReveal !== null && a.dMoveEnd * 180 / Math.PI < 10 && a.dReveal * 180 / Math.PI < 10; - record(`arrival: moveEnd + reveal both re-aim within 4 frames, flights (tamper was ${TAMPER_DEG.toFixed(0)}°)`, + record(`arrival: moveEnd re-aims and first reveal is correct within 250 ms, flights (tamper was ${TAMPER_DEG.toFixed(0)}°)`, arrOk(arrival.flights), fmtArr(arrival.flights)); - record(`arrival: moveEnd + reveal both re-aim within 4 frames, military (tamper was ${TAMPER_DEG.toFixed(0)}°)`, + record(`arrival: moveEnd re-aims and first reveal is correct within 250 ms, military (tamper was ${TAMPER_DEG.toFixed(0)}°)`, arrOk(arrival.military), fmtArr(arrival.military)); // ============================================================ From bdd92663d63ce0a56aa6776b8905da6e0eafb70e Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Thu, 19 Nov 2026 18:59:04 +0400 Subject: [PATCH 6/9] Cancel the Tarktee sibling on a body failure and settle review notes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each Tarktee DATEX feed now reads its body as soon as its headers arrive, so a failed or oversized body aborts the other request at once instead of waiting for its headers up to the shared 30 s deadline. Status and redirect errors name the feed again. Ontario failures log the error class and system code, never the key-bearing URL or upstream text. DATA_SOURCES.md and the camera licence field use the Open Government Licence – Ontario statement the credit shows, and a test pins that credit. The focus-release rendering test now uses main's icon renderer and its isVideoFeedCamera contract. The Tarktee cancellation tests disable the 30 s deadline and time out after 2 s, so a regression fails fast instead of passing late or hanging; a duplicated older test and an unused import are gone. This PR's notes move into changelog.d/1266-cctv-shared-fix-batch.md: the 1133 fragment described main's tracking probe and terrain check, not this branch. --- DATA_SOURCES.md | 4 +- .../1133-cctv-qa-terrain-drag-fixture.md | 6 - changelog.d/1266-cctv-shared-fix-batch.md | 11 + docs/CURRENT-STATE.md | 18 +- server/providers/cctv/sources.js | 92 ++++---- src/data/cctvEstonia.test.mjs | 214 +++++++++--------- src/data/cctvEstoniaBodyPhase.test.mjs | 92 ++++++++ src/data/dataCredits.test.mjs | 12 + src/layers/cctv/rendering.test.mjs | 73 +++--- 9 files changed, 325 insertions(+), 197 deletions(-) delete mode 100644 changelog.d/1133-cctv-qa-terrain-drag-fixture.md create mode 100644 changelog.d/1266-cctv-shared-fix-batch.md create mode 100644 src/data/cctvEstoniaBodyPhase.test.mjs diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index f8da1e26c7..79ca2646f5 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -68,7 +68,7 @@ How to read this: | **Caltrans (cwwp2.dot.ca.gov)** | CCTV camera catalogs + frames, California districts | Public Caltrans traffic camera data | "Caltrans — cwwp2.dot.ca.gov" (courtesy) | | **DelDOT (video.deldot.gov)** | CCTV camera catalog (`tmc.deldot.gov/json/videocamera.json`, cached for 15 minutes) + live HTTPS HLS video, Delaware. Keyless | Public DelDOT traffic camera streams via the [DelDOT traffic map](https://deldot.gov/map/) | "DelDOT — Delaware Department of Transportation" (courtesy) | | **TfL Open Data (JamCams)** | CCTV camera catalog + frames, London | [TfL Open Data terms](https://tfl.gov.uk/info-for/open-data-users/) — attribution REQUIRED | "Powered by TfL Open Data. Contains OS data © Crown copyright and database rights" | -| **Ontario 511** | CCTV camera catalog + frames, Ontario highways including Kitchener-area routes | [Open Government Licence – Ontario](https://www.ontario.ca/page/open-government-licence-ontario) | "Ontario 511" plus Open Government Licence - Ontario | +| **Ontario 511** | CCTV camera catalog + frames, Ontario highways including Kitchener-area routes | [Open Government Licence – Ontario](https://www.ontario.ca/page/open-government-licence-ontario) | "Ontario 511. Contains information licensed under the Open Government Licence – Ontario" | | **Fintraffic / Digitraffic (weathercams)** | CCTV camera catalog + frames, Finland | [CC BY 4.0](https://www.digitraffic.fi/en/terms-of-service/) — attribution REQUIRED | "Fintraffic / digitraffic.fi, license CC BY 4.0" | | **DriveBC** (Government of British Columbia) | CCTV camera catalog + frames, British Columbia highways | [Open Government Licence – British Columbia](https://www2.gov.bc.ca/gov/content/data/open-data/open-government-licence-bc) — attribution REQUIRED | "DriveBC. Contains information licensed under the Open Government Licence – British Columbia" | | **Open Calgary** (`data.calgary.ca`) | CCTV camera catalog + frames, Calgary | [Open Government Licence – City of Calgary](https://data.calgary.ca/stories/s/Open-Calgary-Terms-of-Use/u45n-7awa) — attribution REQUIRED | "Contains information licensed under the Open Government Licence – City of Calgary" | @@ -247,7 +247,7 @@ The optional Local ADS-B layer and the broadcast-FM receiver use radio you recei - **Open Vessel Photos.** When you select a vessel with a nine-digit MMSI, the browser asks `https://openvesselphotos.org/v1/mmsi/{mmsi}` directly (the API is keyless and answers cross-origin, so no key and no server proxy are involved; account credentials are never sent) for that vessel only, once per MMSI per session, with an 8-second timeout. A miss (a 404 or a vessel without photos) is remembered for the session; a failed request may be asked again after five minutes. The first photo whose image is an `https://openvesselphotos.org` URL and which names a licence is shown, at the 800 px size, in the CONTEXT panel's CONTACTS view under the vessel's name and MMSI (`src/ui/views/panels/AwarenessPanel.vue`), and nowhere else (`src/data/openVesselPhoto.js`, `src/layers/vessels/photos.js`). The image is hotlinked from the URL the API gives (never copied or re-hosted); the photographer and licence are visible text next to it ("Photo: {photographer} · {licence}", or "Photo · {licence}" when the answer names no one), and the photo and credit link to the vessel's Open Vessel Photos page with `target="_blank" rel="noopener"`. If the image fails to load, the photo and its credit are hidden. - **Launch Library 2.** `/api/launches` makes a server-side rolling-30-day query against the supported v2.3 detailed launch endpoint, caches successful responses for 15 minutes in memory and on disk, and serves the last successful response during a throttle or transient outage. Anonymous access is limited to 15 calls/hour; deployments can provide `LL2_API_TOKEN` for authenticated access. The Space Devs' published terms permit using and sharing the API data in any form, ask users not to forward it without adding value, disclaim complete accuracy, and encourage—but do not require—attribution. This app keeps a courtesy credit. Payload and stage/recovery records are shown only when supplied. Failed launches expose their source status and never receive fallback orbit geometry or a live/estimated marker. LL2 supplies launch context and event timing, not continuous ascent telemetry or live orbital state. - **TfL JamCams.** The camera list comes from the keyless `api.tfl.gov.uk` endpoint (an optional `TFL_APP_KEY` raises its rate limit); frames come from TfL's public S3 bucket. The "Powered by TfL Open Data" attribution is required by TfL's terms and is registered in the Data attribution popover. -- **Ontario 511 CCTV.** The camera list comes from the `511on.ca/api/v2/get/cameras` endpoint, which now requires a free developer key (`ONTARIO_511_API_KEY`: sign up at 511on.ca/my511/register, then request it while logged in at 511on.ca/developers/doc; throttled to 10 calls a minute). Without the key the pack is skipped. Frames are server-registered still images under `511on.ca/map/Cctv/`. The source is live-fetched at runtime and attributed under the Open Government Licence - Ontario. Access is governed by Ontario 511's Developer's Access Agreement (511on.ca/developers/resources): the data stays under the Open Government Licence - Ontario unless otherwise specified; key requests are reviewed case by case and ask for the intended use and any third parties that will receive the data; attribution by link to 511on.ca is encouraged, and the Ontario 511 logo may not be altered or used to imply endorsement (this app links and shows no logo); and the data is provided "as is", a disclaimer distributors should pass on, which the credit does. +- **Ontario 511 CCTV.** The camera list comes from the `511on.ca/api/v2/get/cameras` endpoint, which now requires a free developer key (`ONTARIO_511_API_KEY`: sign up at 511on.ca/my511/register, then request it while logged in at 511on.ca/developers/doc; throttled to 10 calls a minute). Without the key the pack is skipped. Frames are server-registered still images under `511on.ca/map/Cctv/`. The source is live-fetched at runtime and attributed under the Open Government Licence – Ontario. Access is governed by Ontario 511's Developer's Access Agreement (511on.ca/developers/resources): the data stays under the Open Government Licence – Ontario unless otherwise specified; key requests are reviewed case by case and ask for the intended use and any third parties that will receive the data; attribution by link to 511on.ca is encouraged, and the Ontario 511 logo may not be altered or used to imply endorsement (this app links and shows no logo); and the data is provided "as is", a disclaimer distributors should pass on, which the credit does. - **DelDOT live video cameras.** The keyless `tmc.deldot.gov/json/videocamera.json` catalog supplies active cameras and official `https://video.deldot.gov/live/…/playlist.m3u8` links. The local server transiently buffers bounded MPEG-TS segments in memory and deletes them on session release or idle expiry. No recordings are retained. `CCTV_DELDOT_ENABLED=0` disables the pack. Public availability is not a blanket redistribution license; deployment beyond personal local viewing needs confirmation of applicable DelDOT terms. - **Fintraffic weathercams.** The camera list is one keyless GeoJSON request to `tie.digitraffic.fi/api/weathercam/v1/stations` (809 stations / 2,275 presets), sent with the `Digitraffic-User: gods-eye-view` header the service asks clients to identify themselves with and with gzip; frames are stills on `weathercam.digitraffic.fi`, refreshed on each station's 600 s collection interval, which is also the client's ambient-still refresh cadence for this pack (the active camera keeps the usual 10-second refresh). One preset (a fixed camera view) is one camera; stations not `GATHERING` and presets not `inCollection` are dropped. Attribution is required by the CC BY 4.0 licence and is registered in the Data attribution popover. `CCTV_FINTRAFFIC_ENABLED=0` is the kill switch. - **DriveBC highway cameras.** The camera list comes from the keyless `https://www.drivebc.ca/api/webcams/` endpoint served by the DriveBC.ca site ([bcgov/DriveBC.ca](https://github.com/bcgov/DriveBC.ca)); frames come from `https://www.drivebc.ca/images/.jpg`, built from the numeric camera id. DataBC's [DriveBC HighwayCams](https://catalogue.data.gov.bc.ca/dataset/bc-highwaycams) catalogue entry publishes the same cameras under the Open Government Licence – British Columbia, but its CSV still lists the retired `images.drivebc.ca` frame URLs, which now return a placeholder. The licence's attribution statement is required and is registered in the Data attribution popover. By default the 250 cameras nearest Vancouver and Victoria load; `CCTV_DRIVEBC_MAX_SOURCES` changes the cap and `CCTV_DRIVEBC_ENABLED=0` turns the pack off. Some cameras in the feed are supplied by partners (TransLink, the City of Vancouver, the City of Surrey, Parks Canada / Alberta Motor Association and others); the feed's per-camera credit is carried onto the camera record and shown beside the provider in the CCTV panel. diff --git a/changelog.d/1133-cctv-qa-terrain-drag-fixture.md b/changelog.d/1133-cctv-qa-terrain-drag-fixture.md deleted file mode 100644 index 789df9291c..0000000000 --- a/changelog.d/1133-cctv-qa-terrain-drag-fixture.md +++ /dev/null @@ -1,6 +0,0 @@ -- Make CCTV QA ground-sampling checks respect the active terrain regime and - frame the actual calibration gizmo for the drag regression, preserving the - photoreal completion floor and all drag invariants. -- Measure the tracking arrival regression on the first visible frame within - 250 ms, accounting for the 80 ms fleet cadence while rejecting a stale - first-visible orientation instead of retrying until it is correct. diff --git a/changelog.d/1266-cctv-shared-fix-batch.md b/changelog.d/1266-cctv-shared-fix-batch.md new file mode 100644 index 0000000000..898606fafd --- /dev/null +++ b/changelog.d/1266-cctv-shared-fix-batch.md @@ -0,0 +1,11 @@ +- Refuse Ontario 511 catalog redirects and keep the key-bearing request URL + and upstream error text out of failure logs, which now name only the error + class and system code. Credit Ontario 511 with the Open Government + Licence – Ontario attribution statement (asturksever, #1266). +- Abort the other Tarktee (Estonia) DATEX request as soon as one fails, before + its headers or while its body is read, instead of waiting out the shared + 30 s deadline; a response that arrives after the failure is released too + (asturksever, #1266). +- Frame the calibration gizmo before the CCTV QA drag regression drags it; + default autofocus could leave the arrow shorter than the 10 px grab + threshold (asturksever, #1266). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 91c0d7bd0e..661e962e15 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -7540,16 +7540,14 @@ silently demoting every later lookup for the session. empty keeps the old catalog and is retried after another 15 minutes, not on the next request. Estonia's Tarktee DATEX feeds, which answer in 2 to 16.6 s, get 30 s (`TARKTEE_FETCH_TIMEOUT_MS`) where other packs get 15 s. - Ontario catalog requests refuse redirects and log only a fixed diagnostic for - transport/JSON failures, so reflected request URLs or keys cannot reach logs. - Tarktee owns both XML requests with one 30-second deadline and shared abort; - a failed header or body read cancels its sibling, including a response arriving - after cleanup. - Both Tarktee XML catalogs refuse redirects and have a 4 MiB per-document - limit, enforced against declared length and streamed bytes. A rejected fetch, - unsuccessful response, or body-read failure releases both available response - bodies; read failures also cancel an active sibling reader. Cameras sharing - an image number are deduplicated before the Tarktee pack cap is applied. + Ontario catalog requests refuse redirects and log only the error class and + system code for transport/JSON failures, never the request URL or key. + Both Tarktee XML catalogs share that 30 s deadline, refuse redirects and + have a 4 MiB per-document limit, enforced against declared length and + streamed bytes. A failed request, unsuccessful response or body read aborts + the other feed at once and releases every response body, including one that + arrives after the failure. Cameras sharing an image number are deduplicated + before the Tarktee pack cap is applied. - **CCTV v3 UX — viewshed + calibration gizmo** (built 2026-07-05 and field validated 2026-07-21): the COVERAGE toggle is a tri-state cycle `OFF → ON → VIEWSHED`; viewshed mode renders each visible camera's frustum diff --git a/server/providers/cctv/sources.js b/server/providers/cctv/sources.js index 86e8aa2ea9..43cd0f1f3f 100644 --- a/server/providers/cctv/sources.js +++ b/server/providers/cctv/sources.js @@ -561,6 +561,22 @@ export function _resetOntarioKeyWarningForTest() { ontarioKeyMissingLogged = false; } +/** + * What failed in an Ontario download, without upstream text: the error class, + * plus the system code (`ENOTFOUND`) or a refused redirect when there is one. + * @param {unknown} error + * @returns {string} + */ +function ontarioFailureKind(error) { + const name = /^[A-Za-z]{1,40}$/.test(error?.name) ? error.name : 'Error'; + if (error?.cause?.message === 'unexpected redirect') + return `${name}, redirect refused`; + const code = error?.cause?.code; + return typeof code === 'string' && /^[A-Z][A-Z0-9_]{1,40}$/.test(code) + ? `${name} ${code}` + : name; +} + /** * Fetch Ontario 511 CCTV cameras. The camera list comes from the 511 API, * which now requires a free developer key (511on.ca/developers/doc, "Requires a @@ -659,7 +675,7 @@ export async function loadOntarioSourcesFromOpenData( url: view.url, snapshotUrl: view.url, sourceKind: 'ontario-511-open-data', - license: 'Open Government Licence - Ontario', + license: 'Open Government Licence – Ontario', }); } @@ -677,11 +693,11 @@ export async function loadOntarioSourcesFromOpenData( `[CCTV] Loaded Ontario 511 camera sources: ${unique.length} enabled (using nearest ${prioritized.length})`, ); return prioritized; - } catch { - // Transport and JSON errors may reflect the credential-bearing request. - // Do not log upstream exception text, response bodies or URLs. + } catch (error) { + // Transport and JSON errors may reflect the credential-bearing request, + // so only the error class and a system code are logged, never the text. console.warn( - '[CCTV] Ontario 511 camera download error (network or invalid response)', + `[CCTV] Ontario 511 camera download error (${ontarioFailureKind(error)})`, ); return []; } @@ -1280,49 +1296,46 @@ export function parseTarkteeDatexImages(xml) { * @returns {Promise>} Normalized camera source objects. */ export async function loadTarkteeSourcesFromDatex() { - // Own both transports before either can reject. A response that arrives - // after cleanup must also be discarded instead of escaping Promise.all. - const abort = new AbortController(); + // One deadline for both feeds. Whichever read fails first aborts the other, + // so a stalled sibling is not waited on until the deadline. + const sibling = new AbortController(); const signal = AbortSignal.any([ - abort.signal, + sibling.signal, AbortSignal.timeout(TARKTEE_FETCH_TIMEOUT_MS), ]); - const responses = []; - const discardBoth = async () => { - abort.abort(); - await Promise.allSettled( - responses.map((response) => response.body?.cancel()), - ); - return []; - }; - const fetchXml = async (url) => { - const response = await fetch(url, { - headers: { Accept: 'application/xml,text/xml,*/*' }, - redirect: 'manual', - signal, - }); - if (signal.aborted) { - await Promise.allSettled([response.body?.cancel()]); + const readXml = async (url, feed) => { + let response; + try { + response = await fetch(url, { + headers: { Accept: 'application/xml,text/xml,*/*' }, + redirect: 'manual', + signal, + }); signal.throwIfAborted(); - } - responses.push(response); - if (!response.ok) { - throw new Error( - response.status >= 300 && response.status < 400 - ? 'catalog redirected; redirects are not followed' - : `catalog HTTP ${response.status}`, + if (!response.ok) { + throw new Error( + response.status >= 300 && response.status < 400 + ? `${feed} catalog redirected; redirects are not followed` + : `${feed} download failed: ${response.status}`, + ); + } + return await readResponseTextCapped( + response, + TARKTEE_MAX_CATALOG_BYTES, + signal, ); + } catch (error) { + // The join needs both feeds: stop the other one now, and release this + // body, including a response that arrived after the other failed. + sibling.abort(); + await response?.body?.cancel().catch(() => {}); + throw error; } - return response; }; try { - const [locResp, imgResp] = await Promise.all([ - fetchXml(TARKTEE_LOCATIONS_URL), - fetchXml(TARKTEE_IMAGES_URL), - ]); const [locXml, imgXml] = await Promise.all([ - readResponseTextCapped(locResp, TARKTEE_MAX_CATALOG_BYTES, signal), - readResponseTextCapped(imgResp, TARKTEE_MAX_CATALOG_BYTES, signal), + readXml(TARKTEE_LOCATIONS_URL, 'locations'), + readXml(TARKTEE_IMAGES_URL, 'images'), ]); const locations = parseTarkteeDatexLocations(locXml); const images = parseTarkteeDatexImages(imgXml); @@ -1384,7 +1397,6 @@ export async function loadTarkteeSourcesFromDatex() { ); return prioritized; } catch (error) { - await discardBoth(); console.warn( '[CCTV] Tarktee DATEX download error:', error?.message || error, diff --git a/src/data/cctvEstonia.test.mjs b/src/data/cctvEstonia.test.mjs index 945cf189f8..91ca74b898 100644 --- a/src/data/cctvEstonia.test.mjs +++ b/src/data/cctvEstonia.test.mjs @@ -4,7 +4,6 @@ import { TARKTEE_IMAGES_URL, TARKTEE_LOCATIONS_URL, TARKTEE_MAX_CATALOG_BYTES, - TARKTEE_FETCH_TIMEOUT_MS, } from '../../server/providers/cctv/constants.js'; import { loadTallinnSourcesFromCatalog, @@ -13,6 +12,14 @@ import { parseTarkteeDatexLocations, } from '../../server/providers/cctv/sources.js'; +/** + * Disarm the 30 s deadline, so a loader that only stops at that deadline + * fails at the test timeout instead of passing late. + */ +function withoutDeadline(t) { + t.mock.method(AbortSignal, 'timeout', () => new AbortController().signal); +} + /** Silence the loaders' progress and failure logging. */ function quiet(t) { t.mock.method(console, 'log', () => {}); @@ -192,48 +199,6 @@ test('Tarktee loader refuses a redirect and cancels both response bodies', async assert.equal(cancelled.images, true, 'sibling 200 body is also cancelled'); }); -test('Tarktee loader cancels fulfilled bodies when either fetch rejects', async (t) => { - for (const failedUrl of [TARKTEE_LOCATIONS_URL, TARKTEE_IMAGES_URL]) { - for (const delayedSibling of [false, true]) { - await t.test( - `${failedUrl}, delayed sibling: ${delayedSibling}`, - async (t) => { - quiet(t); - let cancelled = false; - const response = new Response( - new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode('')); - }, - cancel() { - cancelled = true; - }, - }), - ); - t.mock.method(globalThis, 'fetch', async (url) => { - if (String(url) === failedUrl) throw new TypeError('fetch failed'); - if (delayedSibling) await new Promise(setImmediate); - return response; - }); - - try { - assert.deepEqual(await loadTarkteeSourcesFromDatex(), []); - // An aborted mock transport may still deliver its queued response. - if (delayedSibling) await new Promise(setImmediate); - assert.equal( - cancelled, - true, - 'fulfilled sibling body is cancelled', - ); - } finally { - await response.body.cancel(); - } - }, - ); - } - } -}); - test('Tarktee loader cancels the sibling body when one feed fails or overflows the byte cap', async (t) => { quiet(t); let siblingCancelled = false; @@ -292,63 +257,81 @@ test('Tarktee loader cancels the sibling body when one feed fails or overflows t for (const failingUrl of [TARKTEE_LOCATIONS_URL, TARKTEE_IMAGES_URL]) { for (const lateSibling of [false, true]) { - test(`Tarktee cancels a ${lateSibling ? 'late' : 'received'} sibling when ${failingUrl} rejects before headers`, async (t) => { + test( + `Tarktee cancels a ${lateSibling ? 'late' : 'received'} sibling when ${failingUrl} rejects before headers`, + { timeout: 2000 }, + async (t) => { + quiet(t); + withoutDeadline(t); + let cancelled = false; + let siblingSignal; + let release; + const gate = new Promise((resolve) => { + release = resolve; + }); + t.mock.method(globalThis, 'fetch', async (url, init) => { + if (String(url) === failingUrl) + throw new Error('headers unavailable'); + siblingSignal = init.signal; + // A late transport answers once the sibling is aborted, or on release. + if (lateSibling) + await Promise.race([ + gate, + new Promise((resolve) => + init.signal.addEventListener('abort', resolve, { once: true }), + ), + ]); + return new Response( + new ReadableStream({ + start(controller) { + controller.enqueue(new TextEncoder().encode('')); + }, + cancel() { + cancelled = true; + }, + }), + ); + }); + assert.deepEqual(await loadTarkteeSourcesFromDatex(), []); + // Also exercise a response arriving after abort, as a queued transport + // completion can race the rejection owner even when fetch honors abort. + if (lateSibling) { + release(); + await new Promise((resolve) => setImmediate(resolve)); + } + assert.equal(cancelled, true, 'every obtained body must be cancelled'); + assert.equal( + siblingSignal.aborted, + true, + 'a pending transport is aborted immediately', + ); + }, + ); + } + test( + `Tarktee aborts a pending sibling when ${failingUrl} rejects`, + { timeout: 2000 }, + async (t) => { quiet(t); - let cancelled = false; - let siblingSignal; - let release; - const gate = new Promise((resolve) => { - release = resolve; - }); + withoutDeadline(t); + let aborted = false; t.mock.method(globalThis, 'fetch', async (url, init) => { if (String(url) === failingUrl) throw new Error('headers unavailable'); - siblingSignal = init.signal; - if (lateSibling) await gate; - return new Response( - new ReadableStream({ - start(controller) { - controller.enqueue(new TextEncoder().encode('')); + return new Promise((resolve, reject) => { + init.signal.addEventListener( + 'abort', + () => { + aborted = true; + reject(init.signal.reason); }, - cancel() { - cancelled = true; - }, - }), - ); + { once: true }, + ); + }); }); assert.deepEqual(await loadTarkteeSourcesFromDatex(), []); - // Also exercise a response arriving after abort, as a queued transport - // completion can race the rejection owner even when fetch honors abort. - if (lateSibling) { - release(); - await new Promise((resolve) => setImmediate(resolve)); - } - assert.equal(cancelled, true, 'every obtained body must be cancelled'); - assert.equal( - siblingSignal.aborted, - true, - 'a pending transport is aborted immediately', - ); - }); - } - test(`Tarktee aborts a pending sibling when ${failingUrl} rejects`, async (t) => { - quiet(t); - let aborted = false; - t.mock.method(globalThis, 'fetch', async (url, init) => { - if (String(url) === failingUrl) throw new Error('headers unavailable'); - return new Promise((resolve, reject) => { - init.signal.addEventListener( - 'abort', - () => { - aborted = true; - reject(init.signal.reason); - }, - { once: true }, - ); - }); - }); - assert.deepEqual(await loadTarkteeSourcesFromDatex(), []); - assert.equal(aborted, true, 'do not wait for the 30-second deadline'); - }); + assert.equal(aborted, true, 'do not wait for the 30-second deadline'); + }, + ); } test('Tarktee cancels both lengthless streams when one exceeds the byte cap', async (t) => { @@ -379,23 +362,28 @@ test('Tarktee cancels both lengthless streams when one exceeds the byte cap', as ); }); -test('Tarktee aborts pending headers as soon as its sibling returns an HTTP error', async (t) => { - quiet(t); - let aborted = false; - t.mock.method(globalThis, 'fetch', async (url, init) => { - if (String(url) === TARKTEE_LOCATIONS_URL) - return new Response('unavailable', { status: 503 }); - return new Promise((resolve, reject) => { - init.signal.addEventListener( - 'abort', - () => { - aborted = true; - reject(init.signal.reason); - }, - { once: true }, - ); +test( + 'Tarktee aborts pending headers as soon as its sibling returns an HTTP error', + { timeout: 2000 }, + async (t) => { + quiet(t); + withoutDeadline(t); + let aborted = false; + t.mock.method(globalThis, 'fetch', async (url, init) => { + if (String(url) === TARKTEE_LOCATIONS_URL) + return new Response('unavailable', { status: 503 }); + return new Promise((resolve, reject) => { + init.signal.addEventListener( + 'abort', + () => { + aborted = true; + reject(init.signal.reason); + }, + { once: true }, + ); + }); }); - }); - assert.deepEqual(await loadTarkteeSourcesFromDatex(), []); - assert.equal(aborted, true); -}); + assert.deepEqual(await loadTarkteeSourcesFromDatex(), []); + assert.equal(aborted, true); + }, +); diff --git a/src/data/cctvEstoniaBodyPhase.test.mjs b/src/data/cctvEstoniaBodyPhase.test.mjs new file mode 100644 index 0000000000..92c3c80d8a --- /dev/null +++ b/src/data/cctvEstoniaBodyPhase.test.mjs @@ -0,0 +1,92 @@ +// A body-phase failure of one Tarktee DATEX feed must abort the sibling that is +// still waiting for headers instead of leaving it until the 30 s deadline. +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import http from 'node:http'; +import { + TARKTEE_IMAGES_URL, + TARKTEE_LOCATIONS_URL, + TARKTEE_MAX_CATALOG_BYTES, +} from '../../server/providers/cctv/constants.js'; +import { loadTarkteeSourcesFromDatex } from '../../server/providers/cctv/sources.js'; + +/** The sibling sends its headers this late; the loader must not wait for it. */ +const SIBLING_HEADER_DELAY_MS = 2000; +/** Generous bound for "at once" on a loaded CI machine. */ +const FAIL_FAST_MS = 1000; + +function startServer(handlers) { + const server = http.createServer((req, res) => handlers[req.url](req, res)); + return new Promise((resolve) => { + server.listen(0, '127.0.0.1', () => resolve(server)); + }); +} + +/** Send the two DATEX URLs to the local server through the real fetch. */ +function routeFetchTo(t, port) { + const realFetch = globalThis.fetch; + t.mock.method(globalThis, 'fetch', (url, init) => { + const path = + String(url) === TARKTEE_LOCATIONS_URL + ? '/loc' + : String(url) === TARKTEE_IMAGES_URL + ? '/img' + : null; + assert.ok(path, `unexpected url ${url}`); + return realFetch(`http://127.0.0.1:${port}${path}`, init); + }); +} + +const slowHeaders = (req, res) => { + const timer = setTimeout(() => { + res.writeHead(200, { 'content-type': 'application/xml' }); + res.end(''); + }, SIBLING_HEADER_DELAY_MS); + res.on('close', () => clearTimeout(timer)); +}; + +const failingBodies = { + 'declares a body over the byte cap': (req, res) => { + res.writeHead(200, { + 'content-type': 'application/xml', + 'content-length': String(TARKTEE_MAX_CATALOG_BYTES + 1), + }); + res.write(''); + }, + 'resets the connection mid-body': (req, res) => { + res.writeHead(200, { 'content-type': 'application/xml' }); + res.write(''); + setTimeout(() => res.socket.destroy(), 20); + }, +}; + +for (const [label, failingFeed] of Object.entries(failingBodies)) { + for (const [failing, pending] of [ + ['/loc', '/img'], + ['/img', '/loc'], + ]) { + test(`Tarktee aborts ${pending} pending headers when ${failing} ${label}`, { timeout: 10_000 }, async (t) => { + t.mock.method(console, 'log', () => {}); + t.mock.method(console, 'warn', () => {}); + const server = await startServer({ + [failing]: failingFeed, + [pending]: slowHeaders, + }); + t.after(() => { + server.closeAllConnections(); + server.close(); + }); + routeFetchTo(t, server.address().port); + + const started = Date.now(); + const cameras = await loadTarkteeSourcesFromDatex(); + const elapsed = Date.now() - started; + + assert.deepEqual(cameras, []); + assert.ok( + elapsed < FAIL_FAST_MS, + `loader waited ${elapsed} ms for the sibling's headers instead of aborting it`, + ); + }); + } +} diff --git a/src/data/dataCredits.test.mjs b/src/data/dataCredits.test.mjs index 8036413793..56fdffc6db 100644 --- a/src/data/dataCredits.test.mjs +++ b/src/data/dataCredits.test.mjs @@ -173,6 +173,18 @@ test('the NYC camera credit carries NYC DOT’s requested disclaimer', () => { assert.match(credit.html, /observe posted signage/); }); +test('the Ontario 511 camera credit carries the licence attribution statement', () => { + const credit = DATA_CREDITS.find((entry) => entry.key === 'ontario-511-cctv'); + assert.ok(credit, 'Ontario 511 camera frames must be credited'); + assert.ok( + credit.html.includes( + 'Contains information licensed under the Open Government Licence – Ontario<\/a>/); + assert.match(credit.html, /Provided as is, without warranty/); +}); + test("the Houston camera credit names TranStar's terms and the permission they require", () => { const credit = DATA_CREDITS.find((entry) => entry.key === 'houston-cctv'); assert.ok(credit, 'Houston TranStar camera frames must be credited'); diff --git a/src/layers/cctv/rendering.test.mjs b/src/layers/cctv/rendering.test.mjs index 307d05050c..7bd0a84d7c 100644 --- a/src/layers/cctv/rendering.test.mjs +++ b/src/layers/cctv/rendering.test.mjs @@ -378,14 +378,22 @@ test('a pose with no perspective field of view is projected by the renderer', () }); test('focus release restores video hue and alpha after the style throttle', () => { + const viewer = {}; + const camera = fakeCameraPort({ + pose: { position: { x: 6378137 + 1000, y: 0, z: 0 } }, + }); + const { unbind } = bindFakeDraw(viewer, { + camera: camera.port, + query: { project: () => ({ x: 10, y: 20 }) }, + }); let target = {}; const records = ['mp4', 'webm'].map((feedType) => ({ camera: { id: feedType, feedType }, - billboard: { show: true, color: LIVE_CAMERA_COLOR }, + position: { x: 6378137, y: 0, z: 0 }, })); const state = { _enabled: true, - _viewer: { scene: {}, camera: {} }, + _viewer: viewer, _records: records, _activeCameraId: null, _activeFocusStyleCount: 0, @@ -402,30 +410,43 @@ test('focus release restores video hue and alpha after the style throttle', () = }), focusAlphaNeedsWrite: (before, after) => before !== after, }; - const { refreshCctvFocusStyles } = createRendering({ - state, - services: { focus }, - parts: { model: { isVideoFeedType } }, - source: {}, - }); + const { createCameraIcons, addCameraIcon, refreshCctvFocusStyles } = + createRendering({ + state, + services: { focus }, + parts: { + model: { + isVideoFeedCamera: (camera) => isVideoFeedType(camera.feedType), + }, + }, + source: {}, + }); + try { + createCameraIcons(viewer); + for (const record of records) addCameraIcon(record); + const icons = state._icons; - refreshCctvFocusStyles(1000); - for (const record of records) { - assertFadedFrom( - record.billboard.color, - LIVE_CAMERA_COLOR, - record.camera.id, - ); + refreshCctvFocusStyles(1000); + for (const record of records) { + assertKeepsColor( + icons, + record.camera.id, + LIVE_CAMERA_COLOR, + record.camera.id, + ); + } + target = null; + refreshCctvFocusStyles(1050); + for (const record of records) { + assert.equal(icons.focus(record.camera.id), FOCUS_FACTOR, 'throttled'); + } + refreshCctvFocusStyles(1100); + for (const record of records) { + assert.deepEqual(icons.item(record.camera.id).color, LIVE_CAMERA_COLOR); + assert.equal(icons.focus(record.camera.id), 1); + } + assert.equal(state._activeFocusStyleCount, 0); + } finally { + unbind(); } - const dimmed = records.map((record) => record.billboard.color); - target = null; - refreshCctvFocusStyles(1050); - for (let i = 0; i < records.length; i += 1) { - assert.equal(records[i].billboard.color, dimmed[i]); - } - refreshCctvFocusStyles(1100); - for (const record of records) { - assert.deepEqual(record.billboard.color, LIVE_CAMERA_COLOR); - } - assert.equal(state._activeFocusStyleCount, 0); }); From 75f1a3c1814903d022980dd165e6789d006005f1 Mon Sep 17 00:00:00 2001 From: Said Turksever Date: Thu, 19 Nov 2026 18:06:58 +0000 Subject: [PATCH 7/9] Frame the port-drawn gizmo in the CCTV QA drag fixture and share the catalog-pair reader The drag-fixture framing looked the gizmo up in viewer.entities, which main no longer populates, so it did nothing and five drag checks stayed inconclusive. It now reads the arrow from the layer's drawn state and records the framed shaft length as a check. Tarktee and Lithuania read their two catalogs through one helper, readCatalogsTogether, so both get the shared deadline, sibling abort and the release of a response that arrives after the other feed failed. An Ontario error response has its body released, and tests pin the refused redirect and system-code log labels. --- changelog.d/1266-cctv-shared-fix-batch.md | 8 ++-- docs/CURRENT-STATE.md | 7 ++- scripts/format-scope.json | 1 + scripts/package-boundaries.json | 1 + scripts/qa-cctv-v2.mjs | 27 ++++++++---- server/providers/cctv/catalogPair.js | 51 ++++++++++++++++++++++ server/providers/cctv/lithuania.js | 52 ++++++---------------- server/providers/cctv/ontario511.test.mjs | 52 ++++++++++++++++++++++ server/providers/cctv/sources.js | 53 ++++++----------------- 9 files changed, 160 insertions(+), 92 deletions(-) create mode 100644 server/providers/cctv/catalogPair.js diff --git a/changelog.d/1266-cctv-shared-fix-batch.md b/changelog.d/1266-cctv-shared-fix-batch.md index 898606fafd..f35f3ac82c 100644 --- a/changelog.d/1266-cctv-shared-fix-batch.md +++ b/changelog.d/1266-cctv-shared-fix-batch.md @@ -1,10 +1,12 @@ - Refuse Ontario 511 catalog redirects and keep the key-bearing request URL and upstream error text out of failure logs, which now name only the error - class and system code. Credit Ontario 511 with the Open Government - Licence – Ontario attribution statement (asturksever, #1266). + class and system code; release the body of an error response. Credit + Ontario 511 with the Open Government Licence – Ontario attribution statement + (asturksever, #1266). - Abort the other Tarktee (Estonia) DATEX request as soon as one fails, before its headers or while its body is read, instead of waiting out the shared - 30 s deadline; a response that arrives after the failure is released too + 30 s deadline; a response that arrives after the failure is released too. + The Lithuania pack reads its two catalogs through the same helper (asturksever, #1266). - Frame the calibration gizmo before the CCTV QA drag regression drags it; default autofocus could leave the arrow shorter than the 10 px grab diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 661e962e15..d0c06f38c8 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -7546,8 +7546,11 @@ silently demoting every later lookup for the session. have a 4 MiB per-document limit, enforced against declared length and streamed bytes. A failed request, unsuccessful response or body read aborts the other feed at once and releases every response body, including one that - arrives after the failure. Cameras sharing an image number are deduplicated - before the Tarktee pack cap is applied. + arrives after the failure. The Lithuania pack reads its two catalogs + through the same helper (`readCatalogsTogether`, + `server/providers/cctv/catalogPair.js`) with its 15 s deadline. An Ontario + error response has its body released. Cameras sharing an image number are + deduplicated before the Tarktee pack cap is applied. - **CCTV v3 UX — viewshed + calibration gizmo** (built 2026-07-05 and field validated 2026-07-21): the COVERAGE toggle is a tri-state cycle `OFF → ON → VIEWSHED`; viewshed mode renders each visible camera's frustum diff --git a/scripts/format-scope.json b/scripts/format-scope.json index e86ae6c4ea..3c846d449b 100644 --- a/scripts/format-scope.json +++ b/scripts/format-scope.json @@ -148,6 +148,7 @@ "server/providers/cctv/groundHeights.js", "server/providers/cctv/catalog.js", "server/providers/cctv/lithuania.js", + "server/providers/cctv/catalogPair.js", "src/data/cctvLithuania.test.mjs", "server/providers/cctv/taiwan.js", "src/data/cctvTaiwan.test.mjs", diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index 31245c7cf2..d600ec7446 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -563,6 +563,7 @@ "server/providers/cctv/groundHeights.js", "server/providers/cctv/catalog.js", "server/providers/cctv/lithuania.js", + "server/providers/cctv/catalogPair.js", "server/providers/cctv/taiwan.js", "server/providers/cctv/quebec.js", "server/providers/cctv/ottawa.js", diff --git a/scripts/qa-cctv-v2.mjs b/scripts/qa-cctv-v2.mjs index 734fb98fd6..652de38b7d 100644 --- a/scripts/qa-cctv-v2.mjs +++ b/scripts/qa-cctv-v2.mjs @@ -1792,31 +1792,40 @@ async function main() { // Frame the actual gizmo for the drag fixture. Default autofocus can leave // its shaft below the 10px interaction threshold; that distant view is not - // the drag-usability scenario this regression exercises. + // the drag-usability scenario this regression exercises. The gizmo is drawn + // through the renderer ports, so its arrow is read from the layer's drawn + // state (plain {x,y,z} points), not from viewer.entities. const dragFraming = await page.evaluate(async () => { const viewer = window.__godsEyeView.viewer; - const e = viewer.entities.getById('cctv-gizmo-move-east'); - if (!e) return null; - const pts = e.polyline.positions.getValue(viewer.clock.currentTime); - const target = pts?.[0]; - if (!target) return null; + const mod = window.__godsEyeView.dataManager.layers.get('cctv').module; + const arrow = () => + mod._cctvDrawnForTest().gizmo['cctv-gizmo-move-east']?.positions; + if (!arrow()?.length) return null; + const Cartesian3 = viewer.camera.positionWC.constructor; const measure = () => { + const pts = arrow(); + if (!pts?.length) return { shaftPx: null, rangeM: null }; const a = viewer.scene.cartesianToCanvasCoordinates(pts[0]); const b = viewer.scene.cartesianToCanvasCoordinates(pts[pts.length - 1]); return { shaftPx: a && b ? Math.hypot(b.x - a.x, b.y - a.y) : null, - rangeM: target.constructor.distance(viewer.camera.positionWC, target), + rangeM: Cartesian3.distance(viewer.camera.positionWC, pts[0]), }; }; const before = measure(); + const target = Cartesian3.clone(arrow()[0]); viewer.camera.cancelFlight(); - viewer.camera.lookAt(target, new target.constructor(0, -200, 180)); + viewer.camera.lookAt(target, new Cartesian3(0, -200, 180)); viewer.camera.lookAtTransform(viewer.camera.transform.constructor.IDENTITY); viewer.scene.requestRender(); const frames = await window.__qaRenderFrames(3, 10000); return { before, after: measure(), frames }; }); - console.log('Drag fixture framing:', JSON.stringify(dragFraming)); + record( + 'drag fixture frames the east arrow above the 10px grab threshold', + dragFraming?.after?.shaftPx >= 10, + JSON.stringify(dragFraming), + ); // Synthetic CDP drag on the EAST arrow — the owner's field-test // regression. Sample effective elevation after every mouse move: it must diff --git a/server/providers/cctv/catalogPair.js b/server/providers/cctv/catalogPair.js new file mode 100644 index 0000000000..b6f0ffa901 --- /dev/null +++ b/server/providers/cctv/catalogPair.js @@ -0,0 +1,51 @@ +import { readResponseTextCapped } from '../common/http.js'; + +/** + * Read catalogs that are only useful together, because the pack joins them. + * + * The requests share one deadline and refuse redirects. Whichever fails first + * (before its headers, on its status, or while its capped body is read) aborts + * the others at once, so a stalled feed is not waited on until the deadline. + * Every response body is released, including one that arrives after another + * feed has already failed. + * + * @param {Array<{url: string, label: string}>} feeds `label` names the feed + * in the error ("locations download failed: 503"). + * @param {{accept: string, maxBytes: number, timeoutMs: number}} options + * @returns {Promise} The body texts, in feed order. + */ +export async function readCatalogsTogether( + feeds, + { accept, maxBytes, timeoutMs }, +) { + const sibling = new AbortController(); + const signal = AbortSignal.any([ + sibling.signal, + AbortSignal.timeout(timeoutMs), + ]); + return Promise.all( + feeds.map(async ({ url, label }) => { + let response; + try { + response = await fetch(url, { + headers: { Accept: accept }, + redirect: 'manual', + signal, + }); + signal.throwIfAborted(); + if (!response.ok) { + throw new Error( + response.status >= 300 && response.status < 400 + ? `${label} catalog redirected; redirects are not followed` + : `${label} download failed: ${response.status}`, + ); + } + return await readResponseTextCapped(response, maxBytes, signal); + } catch (error) { + sibling.abort(); + await response?.body?.cancel().catch(() => {}); + throw error; + } + }), + ); +} diff --git a/server/providers/cctv/lithuania.js b/server/providers/cctv/lithuania.js index 840e68c6cf..5ce67d411b 100644 --- a/server/providers/cctv/lithuania.js +++ b/server/providers/cctv/lithuania.js @@ -4,7 +4,7 @@ import { fallbackHeadingFromId, prioritizeSources, } from './normalize.js'; -import { readResponseJsonCapped } from '../common/http.js'; +import { readCatalogsTogether } from './catalogPair.js'; const BASE = 'https://eismoinfo.lt/eismoinfo-backend'; export const LITHUANIA_CAMERAS_URL = `${BASE}/camera-info-table`; @@ -81,46 +81,22 @@ export function lithuaniaCameraToSource(row, feature) { }; } -async function readCatalog(url, sibling) { - const signal = AbortSignal.any([ - AbortSignal.timeout(CCTV_SOURCE_FETCH_TIMEOUT_MS), - sibling.signal, - ]); - try { - const response = await fetch(url, { - headers: { Accept: 'application/json' }, - redirect: 'manual', - signal, - }); - if (!response.ok) { - await response.body?.cancel().catch(() => {}); - throw new Error( - response.status >= 300 && response.status < 400 - ? 'catalog redirected; redirects are not followed' - : `Catalog HTTP ${response.status}`, - ); - } - return await readResponseJsonCapped( - response, - LITHUANIA_MAX_CATALOG_BYTES, - signal, - ); - } catch (error) { - // The join needs both catalogs; release the other request at once - // rather than leaving its body open until the timeout. - sibling.abort(); - throw error; - } -} - /** Two bounded requests per shared catalog refresh, no API key required. */ export async function loadLithuaniaSources() { try { - const sibling = new AbortController(); - const [rows, layers] = await Promise.all([ - readCatalog(LITHUANIA_CAMERAS_URL, sibling), - readCatalog(LITHUANIA_LOCATIONS_URL, sibling), - ]); + const [rows, layers] = ( + await readCatalogsTogether( + [ + { url: LITHUANIA_CAMERAS_URL, label: 'cameras' }, + { url: LITHUANIA_LOCATIONS_URL, label: 'locations' }, + ], + { + accept: 'application/json', + maxBytes: LITHUANIA_MAX_CATALOG_BYTES, + timeoutMs: CCTV_SOURCE_FETCH_TIMEOUT_MS, + }, + ) + ).map((text) => JSON.parse(text)); if (!Array.isArray(rows) || !Array.isArray(layers)) return []; const features = layers.find((layer) => layer?.layer === 'VKR')?.features; if (!Array.isArray(features)) return []; diff --git a/server/providers/cctv/ontario511.test.mjs b/server/providers/cctv/ontario511.test.mjs index 9a8ba0e643..2f24388df9 100644 --- a/server/providers/cctv/ontario511.test.mjs +++ b/server/providers/cctv/ontario511.test.mjs @@ -167,3 +167,55 @@ test('Ontario encodes reserved key characters and refuses credential-bearing red assert.equal(JSON.stringify(cameras).includes('synthetic'), false); assert.equal(lines.join(' ').includes('synthetic'), false); }); + +test('Ontario names a refused redirect and a system code without the request text', async (t) => { + const lines = captureConsole(t); + const key = 'synthetic-secret'; + const failures = [ + // The shape Node's fetch gives a refused redirect and a DNS failure. + new TypeError('fetch failed', { + cause: new Error('unexpected redirect'), + }), + new TypeError('fetch failed', { + cause: Object.assign(new Error(`getaddrinfo ENOTFOUND ${key}`), { + code: 'ENOTFOUND', + }), + }), + ]; + t.mock.method(globalThis, 'fetch', async () => { + throw failures.shift(); + }); + for (let i = 0; i < 2; i++) { + assert.deepEqual( + await loadOntarioSourcesFromOpenData({}, { ONTARIO_511_API_KEY: key }), + [], + ); + } + assert.deepEqual(lines, [ + '[CCTV] Ontario 511 camera download error (TypeError, redirect refused)', + '[CCTV] Ontario 511 camera download error (TypeError ENOTFOUND)', + ]); +}); + +test('Ontario releases the body of an error response', async (t) => { + captureConsole(t); + let cancelled = false; + t.mock.method( + globalThis, + 'fetch', + async () => + new Response( + new ReadableStream({ + cancel() { + cancelled = true; + }, + }), + { status: 503 }, + ), + ); + assert.deepEqual( + await loadOntarioSourcesFromOpenData({}, { ONTARIO_511_API_KEY: 'k' }), + [], + ); + assert.equal(cancelled, true); +}); diff --git a/server/providers/cctv/sources.js b/server/providers/cctv/sources.js index 43cd0f1f3f..d7df49530a 100644 --- a/server/providers/cctv/sources.js +++ b/server/providers/cctv/sources.js @@ -172,6 +172,7 @@ import { pinnedCameraUrl, } from './normalize.js'; import { directionToHeading } from '../../../src/data/directionText.js'; +import { readCatalogsTogether } from './catalogPair.js'; import { readResponseBytesCapped, readResponseJsonCapped, @@ -621,6 +622,7 @@ export async function loadOntarioSourcesFromOpenData( console.warn( `[CCTV] Ontario 511 camera download failed: ${resp.status}${keyHint}`, ); + await resp.body?.cancel().catch(() => {}); return []; } const rows = await resp.json(); @@ -1296,47 +1298,18 @@ export function parseTarkteeDatexImages(xml) { * @returns {Promise>} Normalized camera source objects. */ export async function loadTarkteeSourcesFromDatex() { - // One deadline for both feeds. Whichever read fails first aborts the other, - // so a stalled sibling is not waited on until the deadline. - const sibling = new AbortController(); - const signal = AbortSignal.any([ - sibling.signal, - AbortSignal.timeout(TARKTEE_FETCH_TIMEOUT_MS), - ]); - const readXml = async (url, feed) => { - let response; - try { - response = await fetch(url, { - headers: { Accept: 'application/xml,text/xml,*/*' }, - redirect: 'manual', - signal, - }); - signal.throwIfAborted(); - if (!response.ok) { - throw new Error( - response.status >= 300 && response.status < 400 - ? `${feed} catalog redirected; redirects are not followed` - : `${feed} download failed: ${response.status}`, - ); - } - return await readResponseTextCapped( - response, - TARKTEE_MAX_CATALOG_BYTES, - signal, - ); - } catch (error) { - // The join needs both feeds: stop the other one now, and release this - // body, including a response that arrived after the other failed. - sibling.abort(); - await response?.body?.cancel().catch(() => {}); - throw error; - } - }; try { - const [locXml, imgXml] = await Promise.all([ - readXml(TARKTEE_LOCATIONS_URL, 'locations'), - readXml(TARKTEE_IMAGES_URL, 'images'), - ]); + const [locXml, imgXml] = await readCatalogsTogether( + [ + { url: TARKTEE_LOCATIONS_URL, label: 'locations' }, + { url: TARKTEE_IMAGES_URL, label: 'images' }, + ], + { + accept: 'application/xml,text/xml,*/*', + maxBytes: TARKTEE_MAX_CATALOG_BYTES, + timeoutMs: TARKTEE_FETCH_TIMEOUT_MS, + }, + ); const locations = parseTarkteeDatexLocations(locXml); const images = parseTarkteeDatexImages(imgXml); if (!locations.size || !images.size) { From b6d5d7373fbf8faaee18fba613bd8bf570bce80d Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 20 Nov 2026 03:39:06 +0400 Subject: [PATCH 8/9] Check that the Tarktee body-failure tests close the sibling request --- src/data/cctvEstoniaBodyPhase.test.mjs | 38 ++++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/data/cctvEstoniaBodyPhase.test.mjs b/src/data/cctvEstoniaBodyPhase.test.mjs index 92c3c80d8a..dfc4782e2a 100644 --- a/src/data/cctvEstoniaBodyPhase.test.mjs +++ b/src/data/cctvEstoniaBodyPhase.test.mjs @@ -37,13 +37,26 @@ function routeFetchTo(t, port) { }); } -const slowHeaders = (req, res) => { - const timer = setTimeout(() => { - res.writeHead(200, { 'content-type': 'application/xml' }); - res.end(''); - }, SIBLING_HEADER_DELAY_MS); - res.on('close', () => clearTimeout(timer)); -}; +/** The sibling answers late and reports whether it was cut off before headers. */ +function slowSibling() { + const arrived = Promise.withResolvers(); + const closed = Promise.withResolvers(); + return { + arrived: arrived.promise, + closed: closed.promise, + handler(req, res) { + arrived.resolve(); + const timer = setTimeout(() => { + res.writeHead(200, { 'content-type': 'application/xml' }); + res.end(''); + }, SIBLING_HEADER_DELAY_MS); + res.on('close', () => { + clearTimeout(timer); + closed.resolve({ beforeHeaders: !res.headersSent }); + }); + }, + }; +} const failingBodies = { 'declares a body over the byte cap': (req, res) => { @@ -68,9 +81,11 @@ for (const [label, failingFeed] of Object.entries(failingBodies)) { test(`Tarktee aborts ${pending} pending headers when ${failing} ${label}`, { timeout: 10_000 }, async (t) => { t.mock.method(console, 'log', () => {}); t.mock.method(console, 'warn', () => {}); + const sibling = slowSibling(); const server = await startServer({ - [failing]: failingFeed, - [pending]: slowHeaders, + [failing]: (req, res) => + sibling.arrived.then(() => failingFeed(req, res)), + [pending]: sibling.handler, }); t.after(() => { server.closeAllConnections(); @@ -87,6 +102,11 @@ for (const [label, failingFeed] of Object.entries(failingBodies)) { elapsed < FAIL_FAST_MS, `loader waited ${elapsed} ms for the sibling's headers instead of aborting it`, ); + assert.deepEqual( + await sibling.closed, + { beforeHeaders: true }, + `${pending} was not aborted`, + ); }); } } From 247452c202cc0992aaf4e1ddcfb5c128097d4341 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 20 Nov 2026 03:39:07 +0400 Subject: [PATCH 9/9] Parse Lithuania catalogs inside the shared reader so bad JSON cancels the sibling --- server/providers/cctv/catalogPair.js | 18 ++++++++------ server/providers/cctv/lithuania.js | 25 +++++++++---------- src/data/cctvLithuania.test.mjs | 37 +++++++++++++++------------- 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/server/providers/cctv/catalogPair.js b/server/providers/cctv/catalogPair.js index b6f0ffa901..d52ab75969 100644 --- a/server/providers/cctv/catalogPair.js +++ b/server/providers/cctv/catalogPair.js @@ -4,19 +4,21 @@ import { readResponseTextCapped } from '../common/http.js'; * Read catalogs that are only useful together, because the pack joins them. * * The requests share one deadline and refuse redirects. Whichever fails first - * (before its headers, on its status, or while its capped body is read) aborts - * the others at once, so a stalled feed is not waited on until the deadline. - * Every response body is released, including one that arrives after another - * feed has already failed. + * (before its headers, on its status, or while its capped body is read or + * parsed) aborts the others at once, so a stalled feed is not waited on until + * the deadline. Every response body is released, including one that arrives + * after another feed has already failed. * * @param {Array<{url: string, label: string}>} feeds `label` names the feed * in the error ("locations download failed: 503"). - * @param {{accept: string, maxBytes: number, timeoutMs: number}} options - * @returns {Promise} The body texts, in feed order. + * @param {{accept: string, maxBytes: number, timeoutMs: number, + * parse?: (text: string) => unknown}} options + * @returns {Promise} The parsed bodies (texts without `parse`), in + * feed order. */ export async function readCatalogsTogether( feeds, - { accept, maxBytes, timeoutMs }, + { accept, maxBytes, timeoutMs, parse = (text) => text }, ) { const sibling = new AbortController(); const signal = AbortSignal.any([ @@ -40,7 +42,7 @@ export async function readCatalogsTogether( : `${label} download failed: ${response.status}`, ); } - return await readResponseTextCapped(response, maxBytes, signal); + return parse(await readResponseTextCapped(response, maxBytes, signal)); } catch (error) { sibling.abort(); await response?.body?.cancel().catch(() => {}); diff --git a/server/providers/cctv/lithuania.js b/server/providers/cctv/lithuania.js index 5ce67d411b..c977749a20 100644 --- a/server/providers/cctv/lithuania.js +++ b/server/providers/cctv/lithuania.js @@ -84,19 +84,18 @@ export function lithuaniaCameraToSource(row, feature) { /** Two bounded requests per shared catalog refresh, no API key required. */ export async function loadLithuaniaSources() { try { - const [rows, layers] = ( - await readCatalogsTogether( - [ - { url: LITHUANIA_CAMERAS_URL, label: 'cameras' }, - { url: LITHUANIA_LOCATIONS_URL, label: 'locations' }, - ], - { - accept: 'application/json', - maxBytes: LITHUANIA_MAX_CATALOG_BYTES, - timeoutMs: CCTV_SOURCE_FETCH_TIMEOUT_MS, - }, - ) - ).map((text) => JSON.parse(text)); + const [rows, layers] = await readCatalogsTogether( + [ + { url: LITHUANIA_CAMERAS_URL, label: 'cameras' }, + { url: LITHUANIA_LOCATIONS_URL, label: 'locations' }, + ], + { + accept: 'application/json', + maxBytes: LITHUANIA_MAX_CATALOG_BYTES, + timeoutMs: CCTV_SOURCE_FETCH_TIMEOUT_MS, + parse: JSON.parse, + }, + ); if (!Array.isArray(rows) || !Array.isArray(layers)) return []; const features = layers.find((layer) => layer?.layer === 'VKR')?.features; if (!Array.isArray(features)) return []; diff --git a/src/data/cctvLithuania.test.mjs b/src/data/cctvLithuania.test.mjs index af28a51f60..a59cea16b0 100644 --- a/src/data/cctvLithuania.test.mjs +++ b/src/data/cctvLithuania.test.mjs @@ -140,25 +140,28 @@ for (const [label, flag] of [ }); } -test('a failed catalog cancels the sibling request instead of waiting for the timeout', async (t) => { - t.mock.method(console, 'warn', () => {}); - let siblingSignal; - t.mock.method(globalThis, 'fetch', async (url, options) => { - if (url === LITHUANIA_CAMERAS_URL) { - return new Response('', { status: 503 }); - } - siblingSignal = options.signal; - // Never settles on its own; only an abort ends it. - return new Promise((_, reject) => { - options.signal.addEventListener('abort', () => - reject(options.signal.reason), - ); +for (const [failure, camerasResponse] of [ + ['failed', () => new Response('', { status: 503 })], + ['malformed', () => new Response('error page')], +]) { + test(`a ${failure} catalog cancels the sibling request instead of waiting for the timeout`, async (t) => { + t.mock.method(console, 'warn', () => {}); + let siblingSignal; + t.mock.method(globalThis, 'fetch', async (url, options) => { + if (url === LITHUANIA_CAMERAS_URL) return camerasResponse(); + siblingSignal = options.signal; + // Never settles on its own; only an abort ends it. + return new Promise((_, reject) => { + options.signal.addEventListener('abort', () => + reject(options.signal.reason), + ); + }); }); + assert.deepEqual(await loadLithuaniaSources(), []); + assert.equal(siblingSignal?.aborted, true); + assert.notEqual(siblingSignal.reason?.name, 'TimeoutError'); }); - assert.deepEqual(await loadLithuaniaSources(), []); - assert.equal(siblingSignal?.aborted, true); - assert.notEqual(siblingSignal.reason?.name, 'TimeoutError'); -}); +} test('a redirected catalog is reported as not followed', async (t) => { const warnings = [];