Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

fix: reconcile share-link token allocation with main

manjunath22466d0105f1e9d3e
diff --cc CHANGELOG.md
index 09e0bf056,29dbedfaa..8e0c5f754
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -1,18 -1,58 +1,71 @@@
# Changelog
+ - CCTV cameras whose bearing is a guess now say so. Packs mark bearings derived
+ from a hash of the camera id as `headingConfidence: 'low'`, but nothing read the
+ flag, so roughly 70% of a default catalog rendered like surveyed facings. The HUD
+ now reads `HDG n° (ESTIMATED)` and the coverage wireframe draws dashed; manual
+ calibrations and curated poses are never marked estimated (bassem chagra, #643).
+
+ - Report which upstream declined a Street Traffic road load. The layer row now
+ reads `Overpass rate-limited`, `Overpass timed out`, or
+ `Overpass refused the road query (HTTP 406)` instead of a general
+ "Road data temporarily unavailable", so a reader is not sent to check a
+ TomTom key when the public OpenStreetMap mirrors are the side that failed.
+ The proxy's own 502 (every mirror unreachable) and 503 (local limiter busy)
+ read `Overpass mirrors unreachable` and `Overpass temporarily unavailable`.
+ Failures the layer cannot classify keep the general line (daikaginza, #665).
+
+ - Bound the client terrain-height cache at 20 000 entries with least-recently-used eviction, so a long session no longer retains every coordinate it ever resolved. Consumer reads promote their entry and a batch still reports every point it resolved (Pedro Lobato, #594).
+
+ - Release CCTV media streams whose upstream falls silent after answering. The
+ 15-second media deadline covered only the wait for response headers, so a
+ camera that replied and then stopped sending held both the proxy connection
+ and its upstream socket open for as long as the camera host allowed; the
+ declared `Content-Length` ceiling was the only body bound, and a chunked or
+ length-less body had none. A 30-second idle deadline now bounds the gap
+ between upstream chunks and releases a body that has gone silent. It is
+ rescheduled while the response is still waiting to drain, so a viewer on a
+ slow link is not mistaken for a dead camera; live feeds are unaffected
+ (Ethan Stoner, #688).
+
+ - Aircraft track backfill (`/api/opensky-track`, `/api/adsblol/trace`) now
+ answers 502 when the upstream body exceeds the 5 MB cap, instead of a 200
+ whose error body the client read as an empty track. The failure is cached
+ like other upstream errors, so retries inside the 60 s window do not spend
+ OpenSky credits (Raushankumar0720, #720, #722).
+
+ - Saving a key from Provider Settings works again on Macs where Nix or
+ Homebrew coreutils sit ahead of `/bin` on `PATH`. The credential hardener
+ now spawns Apple's `/bin/chmod -N` by absolute path; GNU `chmod` has no `-N`,
+ so the ACL strip failed closed and every save was refused (Arthur Bogaart, #694).
+
+ - Render on iPad and iPhone instead of stopping with "An error occurred while
+ rendering." Cesium's per-vertex model atmosphere binds shader `out`
+ parameters directly to varyings, which Apple's Metal/ANGLE backend cannot
+ link, so the program failed and the render loop was torn down. The stage is
+ now kept out of the pipeline on affected devices by clearing
+ `scene.fog.renderable`, which leaves `fog.enabled` — and the fog density that
+ drives 3D Tiles refinement — untouched. Detection is a WebGL2 link probe of
+ the same pattern, so a future driver fix restores the effect with no code
+ change, with iOS/iPadOS detection as a backstop. Sky atmosphere and the
+ ground-atmosphere fragment path route through locals and are unaffected;
+ affected devices lose distance fog on 3D tiles and on the globe basemaps.
+ `src/app/atmosphereCompat.test.mjs` pins the probe, the platform matrix and
+ the `renderable`-not-`enabled` choice (KnottyDyes, #705).
+
+- Make share-link layer tokens durable allocations instead of ad hoc picks.
+ Existing one-character mappings are pinned permanently, while new layers use
+ the next free single-character digit, then two-character base-36 tokens.
+ Authors record each token in the permanent JSON ledger after running
+ `npm run layer-token:next -- <layer-id>` on a rebased branch.
+ `npm run layer-token:check -- --base-ref origin/main` guards published
+ assignments and allocation order in
+ pull-request CI. Existing v2 links keep their exact meaning.
+ Malformed enabled-layer lists now reject the whole layer payload instead of
+ restoring a partial list. A QA-only browser fixture exercises the future
+ two-character path after a fixture-only exhausted-digit scenario, without
+ reserving `00` in production.
+
- Region scopes in voice analyst queries ("in the Gulf of Mexico", "over
the Alps") work again in the dev server: the bundled Natural Earth and
neighborhood packs are fetched as JSON in the browser
diff --cc CONTRIBUTING.md
index 1957b66dd,c65efac10..cdfbb6547
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@@ -70,27 -70,6 +70,39 @@@ gate for the feature you changed
> and a browser. Include the applicable local run in your PR's validation
> evidence.
+## Share-link layer tokens
+
+Every shareable layer owns an immutable token in `LAYER_STATE_REGISTRY` and
+`src/data/layerStateTokenReservations.json`. Never change or reuse an existing
+token: published v2 links are authored state, and the reservation remains even
+if its layer is later removed.
+
+New layers first use the remaining unreserved single-character digits (`0`
+through `9`), then the two-character base-36 namespace (`00` through `zz`). On the
+current published ledger, `1` and `2` are already owned, so the next choices
+are `0`, `3` through `9`, then `00`. After rebasing onto the latest `main`, run
+`npm run layer-token:next -- <layer-id>`, add that result to both the permanent
+JSON reservation ledger and registry entry, and keep the exact registered-layer
+count assertion up to date. The token is assigned against the merge-time base, not
+claimed when a PR opens, so another merged layer may require rerunning the
+command after a rebase. Never repurpose a published or retired token.
+Run `npm run layer-token:check -- --base-ref origin/main` after the rebase;
+this checks that every published assignment remains reserved and that new
+assignments consume free digits before the two-character tokens, in order.
+Pull-request CI runs the same check against `main`.
+
++The helper reads the local ledger; it does not run during a rebase or edit files.
++If another PR publishes your provisional token first, keep every published
++registry entry and ledger reservation from the refreshed `main`. Temporarily
++remove only your still-unpublished layer's registry entry and ledger row so the
++local registry is valid again, then rerun `npm run layer-token:next -- <layer-id>`.
++For example, if PR A publishes `0` while PR B still provisionally uses `0`,
++PR B removes only its own provisional entry, reruns the helper, and receives
++`3`. Put `3` on PR B's registry entry and ledger row, update its pinned count
++and token tests, then rerun `npm run layer-token:check -- --base-ref origin/main`.
++An invalid duplicate ledger can fail during module import before the helper
++prints anything; never fix that by renaming or deleting PR A's published token.
++
## Good first contributions
The highest-leverage places to jump in:
diff --cc src/data/layerState.test.mjs
index af2cd6526,fb6d04a5d..1b504a439
--- a/src/data/layerState.test.mjs
+++ b/src/data/layerState.test.mjs
@@@ -456,6 -289,6 +456,25 @@@ test('v2 codec distinguishes absent fro
);
});
++test('all production layers and options round-trip through a v2 share URL', () => {
++ const allEnabled = normalizeLayerState({
++ enabledLayerIds: REGISTERED_LAYER_IDS,
++ options: {
++ cctv: { coverageMode: 'viewshed', showProjection: false, autoHop: true },
++ flights: { models3d: true, models3dMode: 'all' },
++ radio: { filter: 'news', volume: 0.37 },
++ },
++ });
++ const shareUrl = new URL('https://example.invalid/');
++ shareUrl.hash = encode(allEnabled);
++ const params = new URLSearchParams(shareUrl.hash.slice(1));
++ const restored = decodeLayerStateParams(params);
++
++ assert.equal(params.get('l')?.split('.').length, REGISTERED_LAYER_IDS.length);
++ assert.deepEqual(restored?.enabledLayerIds, REGISTERED_LAYER_IDS);
++ assert.deepEqual(restored?.options, allEnabled.options);
++});
++
test('unknown enabled-layer tokens reject the payload instead of becoming an empty set', () => {
assert.equal(
decodeLayerStateParams(new URLSearchParams('v=2&l=unknown')),
diff --cc src/data/layerStateTokenLedger.test.mjs
index 2cbefbace,000000000..7b0a9263c
mode 100644,000000..100644
--- a/src/data/layerStateTokenLedger.test.mjs
+++ b/src/data/layerStateTokenLedger.test.mjs
@@@ -1,272 -1,0 +1,419 @@@
+import assert from 'node:assert/strict';
+import { execFileSync, spawnSync } from 'node:child_process';
+import {
+ mkdtempSync,
+ mkdirSync,
+ readFileSync,
++ realpathSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
- import { fileURLToPath } from 'node:url';
++import { fileURLToPath, pathToFileURL } from 'node:url';
+import test from 'node:test';
+import {
+ LEGACY_LAYER_STATE_TOKENS,
+ LAYER_STATE_TOKEN_ALPHABET,
+ LAYER_STATE_TOKEN_RESERVATIONS,
+ nextLayerStateToken,
+ parseLayerStateTokenReservations,
+ validateLayerStateAllocations,
+} from './layerState.js';
+import {
+ PRE_LEDGER_LAYER_STATE_TOKENS,
+ checkLayerStateTokens,
+ readPublishedLayerStateReservations,
+} from '../../scripts/check-layer-state-tokens.mjs';
+
+const LEDGER_PATH = 'src/data/layerStateTokenReservations.json';
+const SOURCE_PATH = 'src/data/layerState.js';
++const CODEC_SOURCE_PATH = fileURLToPath(
++ new URL('./layerState.js', import.meta.url),
++);
+const CHECKER_PATH = fileURLToPath(
+ new URL('../../scripts/check-layer-state-tokens.mjs', import.meta.url),
+);
++const NEXT_PATH = fileURLToPath(
++ new URL('../../scripts/next-layer-state-token.mjs', import.meta.url),
++);
+const reservationRows = JSON.parse(
+ readFileSync(
+ new URL('./layerStateTokenReservations.json', import.meta.url),
+ 'utf8',
+ ),
+);
+
+test('pre-ledger published ownership is independent of the candidate mapping', () => {
+ assert.notStrictEqual(
+ PRE_LEDGER_LAYER_STATE_TOKENS,
+ LEGACY_LAYER_STATE_TOKENS,
+ );
+ assert.deepEqual(PRE_LEDGER_LAYER_STATE_TOKENS, LEGACY_LAYER_STATE_TOKENS);
+ assert.equal(Object.keys(PRE_LEDGER_LAYER_STATE_TOKENS).length, 28);
+ assert.equal(PRE_LEDGER_LAYER_STATE_TOKENS['recent-imagery'], '1');
+ assert.equal(PRE_LEDGER_LAYER_STATE_TOKENS['fire-perimeters'], '2');
+ assert.throws(
+ () =>
+ validateLayerStateAllocations(PRE_LEDGER_LAYER_STATE_TOKENS, {
+ ...LAYER_STATE_TOKEN_RESERVATIONS,
+ flights: '00',
+ }),
+ /Published layer-state token changed or removed: flights/,
+ );
+});
+
+function git(cwd, ...args) {
+ return execFileSync('git', args, { cwd, encoding: 'utf8' }).trim();
+}
+
+function withPublishedBase(
+ { rows, source = 'export const changed = true;\n' },
+ check,
+) {
+ const cwd = mkdtempSync(path.join(tmpdir(), 'gev-layer-token-ledger-'));
+ try {
+ git(cwd, 'init', '-q');
+ mkdirSync(path.join(cwd, 'src/data'), { recursive: true });
+ writeFileSync(path.join(cwd, SOURCE_PATH), source);
+ if (rows !== undefined) {
+ writeFileSync(path.join(cwd, LEDGER_PATH), JSON.stringify(rows));
+ }
+ git(cwd, 'add', 'src/data');
+ git(
+ cwd,
+ '-c',
+ 'user.name=Layer Token Test',
+ '-c',
+ 'commit',
+ '-q',
+ '-m',
+ 'published base',
+ );
+ check(cwd);
+ } finally {
+ rmSync(cwd, { recursive: true, force: true });
+ }
+}
+
++function writeCodecFixture(cwd, rows, entries) {
++ const source = readFileSync(CODEC_SOURCE_PATH, 'utf8');
++ const registryEnd = ']);\n\nexport const REGISTERED_LAYER_IDS';
++ assert.equal(source.split(registryEnd).length, 2);
++ const additions = entries
++ .map(
++ ({ id, token }) =>
++ ` Object.freeze({ id: '${id}', token: '${token}', disposition: 'enabled-only' }),`,
++ )
++ .join('\n');
++ mkdirSync(path.join(cwd, 'src/data'), { recursive: true });
++ writeFileSync(path.join(cwd, 'package.json'), '{"type":"module"}');
++ writeFileSync(
++ path.join(cwd, SOURCE_PATH),
++ source.replace(registryEnd, `${additions}\n${registryEnd}`),
++ );
++ writeFileSync(path.join(cwd, LEDGER_PATH), JSON.stringify(rows));
++ return path.join(cwd, SOURCE_PATH);
++}
++
+test('reservation ledger is complete, pinned, and rejects duplicate or malformed rows', () => {
+ assert.deepEqual(
+ { ...parseLayerStateTokenReservations(reservationRows) },
+ { ...LAYER_STATE_TOKEN_RESERVATIONS },
+ );
+ assert.equal(Object.keys(LAYER_STATE_TOKEN_RESERVATIONS).length, 28);
+ assert.deepEqual(
+ { ...LAYER_STATE_TOKEN_RESERVATIONS },
+ { ...LEGACY_LAYER_STATE_TOKENS },
+ );
+ assert.throws(
+ () => parseLayerStateTokenReservations(reservationRows.slice(1)),
+ /Missing or changed legacy/,
+ );
+ assert.throws(
+ () =>
+ parseLayerStateTokenReservations([
+ ...reservationRows,
+ reservationRows[0],
+ ]),
+ /Duplicate layer-state token reservation id/,
+ );
+ assert.throws(
+ () =>
+ parseLayerStateTokenReservations([...reservationRows, ['future', 'a']]),
+ /Duplicate layer-state token reservation/,
+ );
+ assert.equal(
+ parseLayerStateTokenReservations([...reservationRows, ['future', '0']])
+ .future,
+ '0',
+ );
+ assert.throws(
+ () =>
+ parseLayerStateTokenReservations([
+ ...reservationRows.filter(([id]) => id !== 'transit'),
+ ['future', 'j'],
+ ]),
+ /Legacy layer-state token is immutable/,
+ );
+ assert.throws(
+ () => parseLayerStateTokenReservations([...reservationRows, ['future']]),
+ /Invalid layer-state token ledger row/,
+ );
+});
+
+test('published retired digits and competing PRs advance the merge-time allocation', () => {
+ withPublishedBase(
+ { rows: [...reservationRows, ['retired-layer', '0']] },
+ (cwd) => {
+ const published = readPublishedLayerStateReservations('HEAD', cwd);
+ assert.equal(nextLayerStateToken(published), '3');
+ assert.equal(
+ validateLayerStateAllocations(published, {
+ ...published,
+ newcomer: '3',
+ }),
+ true,
+ );
+ assert.throws(
+ () =>
+ validateLayerStateAllocations(published, {
+ ...published,
+ competing: '0',
+ }),
+ /next free token 3/,
+ );
+ assert.throws(
+ () =>
+ validateLayerStateAllocations(published, {
+ ...LAYER_STATE_TOKEN_RESERVATIONS,
+ newcomer: '0',
+ }),
+ /changed or removed: retired-layer/,
+ );
+ },
+ );
+});
+
++test('PR B manually replaces provisional 0 with 3 after PR A publishes 0', () => {
++ withPublishedBase({ rows: [...reservationRows, ['pr-a', '0']] }, (cwd) => {
++ mkdirSync(path.join(cwd, 'scripts'));
++ const fixtureChecker = path.join(
++ cwd,
++ 'scripts/check-layer-state-tokens.mjs',
++ );
++ writeFileSync(fixtureChecker, readFileSync(CHECKER_PATH, 'utf8'));
++ const fixtureNext = path.join(cwd, 'scripts/next-layer-state-token.mjs');
++ writeFileSync(fixtureNext, readFileSync(NEXT_PATH, 'utf8'));
++ const runCheck = () =>
++ spawnSync(
++ process.execPath,
++ [realpathSync(fixtureChecker), '--base-ref', 'HEAD'],
++ {
++ cwd,
++ encoding: 'utf8',
++ },
++ );
++
++ writeCodecFixture(
++ cwd,
++ [...reservationRows, ['pr-b', '0']],
++ [{ id: 'pr-b', token: '0' }],
++ );
++ const beforeRebase = runCheck();
++ assert.equal(beforeRebase.status, 1);
++ assert.match(beforeRebase.stderr, /changed or removed: pr-a/);
++
++ writeCodecFixture(
++ cwd,
++ [...reservationRows, ['pr-a', '0'], ['pr-b', '0']],
++ [
++ { id: 'pr-a', token: '0' },
++ { id: 'pr-b', token: '0' },
++ ],
++ );
++ const staleRebase = runCheck();
++ assert.equal(staleRebase.status, 1);
++ assert.match(staleRebase.stderr, /Duplicate layer-state token reservation/);
++
++ const published = readPublishedLayerStateReservations('HEAD', cwd);
++ assert.equal(nextLayerStateToken(published), '3');
++ const validBaselineRows = [...reservationRows, ['pr-a', '0']];
++ writeCodecFixture(cwd, validBaselineRows, [{ id: 'pr-a', token: '0' }]);
++ const helper = spawnSync(
++ process.execPath,
++ [realpathSync(fixtureNext), 'pr-b'],
++ { cwd, encoding: 'utf8' },
++ );
++ assert.equal(helper.status, 0, helper.stderr);
++ assert.match(helper.stdout, /pr-b: 3/);
++ assert.deepEqual(
++ JSON.parse(readFileSync(path.join(cwd, LEDGER_PATH), 'utf8')),
++ validBaselineRows,
++ 'the helper reports a token without rewriting the ledger',
++ );
++ writeCodecFixture(
++ cwd,
++ [...reservationRows, ['pr-a', '0'], ['pr-b', '3']],
++ [
++ { id: 'pr-a', token: '0' },
++ { id: 'pr-b', token: '3' },
++ ],
++ );
++ const corrected = runCheck();
++ assert.equal(corrected.status, 0, corrected.stderr);
++ assert.match(corrected.stdout, /29 published, 1 new/);
++ });
++});
++
+test('allocation batches cross the last digit and base-36 pair boundaries in order', () => {
+ const digitRows = [...'03456789'].map((digit) => [`retired-${digit}`, digit]);
+ const allDigits = parseLayerStateTokenReservations([
+ ...reservationRows,
+ ...digitRows,
+ ]);
+ const beforeNine = { ...allDigits };
+ delete beforeNine['retired-9'];
+ assert.equal(
+ validateLayerStateAllocations(beforeNine, {
+ ...beforeNine,
+ pair: '00',
+ lastDigit: '9',
+ }),
+ true,
+ );
+ const baseBefore0a = {
+ ...allDigits,
+ ...Object.fromEntries(
+ [...'012345678'].map((second) => [`retired-0${second}`, `0${second}`]),
+ ),
+ };
+ assert.equal(nextLayerStateToken(baseBefore0a), '09');
+ assert.equal(
+ validateLayerStateAllocations(baseBefore0a, {
+ ...baseBefore0a,
+ after: '0a',
+ before: '09',
+ }),
+ true,
+ );
+ const baseBefore10 = {
+ ...allDigits,
+ ...Object.fromEntries(
+ [...LAYER_STATE_TOKEN_ALPHABET]
+ .slice(0, -1)
+ .map((second) => [`retired-0${second}`, `0${second}`]),
+ ),
+ };
+ assert.equal(nextLayerStateToken(baseBefore10), '0z');
+ assert.equal(
+ validateLayerStateAllocations(baseBefore10, {
+ ...baseBefore10,
+ after: '10',
+ before: '0z',
+ }),
+ true,
+ );
+});
+
++test('an isolated valid two-character fixture round-trips an l field beyond the old 64-character cap', async () => {
++ const cwd = mkdtempSync(path.join(tmpdir(), 'gev-layer-token-width-'));
++ try {
++ const priorDigits = [...'03456789'].map((digit) => [
++ `qa-prior-digit-${digit}`,
++ digit,
++ ]);
++ const fixtureLayers = ['00', '01', '02', '03'].map((token) => ({
++ id: `qa-layer-${token}`,
++ token,
++ }));
++ const fixtureRows = [
++ ...reservationRows,
++ ...priorDigits,
++ ...fixtureLayers.map(({ id, token }) => [id, token]),
++ ];
++ const fixtureModule = writeCodecFixture(cwd, fixtureRows, fixtureLayers);
++ const codec = await import(pathToFileURL(fixtureModule));
++ assert.equal(codec.validateLayerStateRegistry(), true);
++ assert.equal(
++ nextLayerStateToken(
++ parseLayerStateTokenReservations([...reservationRows, ...priorDigits]),
++ ),
++ '00',
++ );
++ assert.equal(
++ validateLayerStateAllocations(
++ LAYER_STATE_TOKEN_RESERVATIONS,
++ codec.LAYER_STATE_TOKEN_RESERVATIONS,
++ ),
++ true,
++ );
++
++ const expectedLayerIds = codec.REGISTERED_LAYER_IDS;
++ const state = codec.normalizeLayerState({
++ enabledLayerIds: expectedLayerIds,
++ });
++ const params = new URLSearchParams([['v', '2']]);
++ codec.encodeLayerStateParams(params, state);
++ assert.ok(params.get('l').length > 64, 'fixture must cross the old cap');
++ assert.equal(params.get('l').length, 67);
++ const restored = codec.decodeLayerStateParams(params);
++ assert.deepEqual(restored?.enabledLayerIds, expectedLayerIds);
++ assert.deepEqual(restored?.options, state.options);
++ } finally {
++ rmSync(cwd, { recursive: true, force: true });
++ }
++});
++
+test('checker reads a complete future base ledger and rejects retired-token reuse', () => {
+ withPublishedBase(
+ {
+ rows: [...reservationRows, ['retired-layer', '00']],
+ source:
+ 'export const LAYER_STATE_TOKEN_RESERVATIONS = Object.freeze({ ["retired-layer"]: "00" });\n',
+ },
+ (cwd) => {
+ const published = readPublishedLayerStateReservations('HEAD', cwd);
+ assert.equal(Object.keys(published).length, 29);
+ assert.equal(published['retired-layer'], '00');
+ assert.throws(
+ () =>
+ validateLayerStateAllocations(published, {
+ ...LAYER_STATE_TOKEN_RESERVATIONS,
+ newcomer: '00',
+ }),
+ /changed or removed/,
+ );
+ assert.throws(
+ () => checkLayerStateTokens('HEAD', cwd),
+ /changed or removed/,
+ );
+ const cli = spawnSync(
+ process.execPath,
+ [CHECKER_PATH, '--base-ref', 'HEAD'],
+ {
+ cwd,
+ encoding: 'utf8',
+ },
+ );
+ assert.equal(cli.status, 1);
+ assert.match(cli.stderr, /changed or removed/);
+ },
+ );
+});
+
+test('checker fails closed on unknown or malformed published ledgers', () => {
+ withPublishedBase({}, (cwd) => {
+ assert.throws(
+ () => readPublishedLayerStateReservations('HEAD', cwd),
+ /no recognizable layer-state token ledger/,
+ );
+ });
+ withPublishedBase({ rows: [...reservationRows, ['future', 'a']] }, (cwd) => {
+ assert.throws(
+ () => readPublishedLayerStateReservations('HEAD', cwd),
+ /Duplicate layer-state token reservation/,
+ );
+ });
+});