Ratchet Cesium-shaped viewer access in files off the Cesium list

A second ratchet beside the Cesium allow-list: files off that list (and
outside the Cesium adapter) may no longer reach Cesium through the viewer
either. src/render/viewerAccessAllowList.json records, per file, how many
such accesses it still makes (the viewer's entities, dataSources, scene,
camera, clock, imageryLayers, terrainProvider, trackedEntity and canvas;
the scene's primitives, pick, drillPick, pickPosition, globe, frame
events, canvas, requestRender and camera), read from the parsed source in
their plain, optional, bracketed, call-result and destructured forms.
viewer.container, comments and tests do not count.

The test fails when a file makes more accesses than recorded, when a
recorded count is higher than the file now needs or names a file gone or
back on the Cesium list, and when the record grows against origin/main.
scripts/viewer-access-baseline.mjs lowers the record to what the files
hold; it never adds or raises an entry. The record starts with 25 files
and 50 accesses.
This commit is contained in:
Sameh Khamis committed 2026-11-07 19:44:15 -08:00
1 parent 0f9bd23829
commit 396e7f0deb
7 files changed
+557

No files matched your search

+63
View File
@@ -0,0 +1,63 @@
/**
* Lower `src/render/viewerAccessAllowList.json` to the Cesium-shaped viewer
* accesses the files off the Cesium list still hold
* (`src/render/viewerAccess.test.mjs`). It only lowers counts and drops
* entries (files with none left, gone, or back on the Cesium list); it never
* adds a file or raises a count. A file over its count is reported and the
* script exits 1: port that access instead.
*
* `--check` reports what it would change without writing, and exits 1 when
* there is anything to lower.
*/
import { writeFileSync } from 'node:fs';
import path from 'node:path';
import {
BASELINE,
countedFiles,
currentHits,
readBaseline,
ROOT,
} from '../src/testSupport/viewerAccess.mjs';
const check = process.argv.includes('--check');
const baseline = readBaseline();
const hits = currentHits();
const counted = new Set(countedFiles());
const next = {};
const changes = [];
for (const [file, allowed] of Object.entries(baseline)) {
const found = counted.has(file) ? (hits.get(file)?.length ?? 0) : 0;
const count = Math.min(allowed, found);
if (count > 0) next[file] = count;
if (count !== allowed) changes.push(`${file}: ${allowed} → ${count}`);
}
const over = [...hits]
.filter(([file, found]) => found.length > (baseline[file] ?? 0))
.map(
([file, found]) =>
`${file}: ${found.length} found, ${baseline[file] ?? 0} recorded`,
);
if (changes.length) {
console.log(
`${check ? 'Would lower' : 'Lowered'}:\n ${changes.join('\n ')}`,
);
if (!check) {
const sorted = Object.fromEntries(
Object.keys(next)
.sort()
.map((file) => [file, next[file]]),
);
writeFileSync(
path.join(ROOT, BASELINE),
`${JSON.stringify(sorted, null, 2)}\n`,
);
} else process.exitCode = 1;
} else console.log(`${BASELINE} is as low as it goes.`);
if (over.length) {
console.error(
`Over their counts (never raised; port these):\n ${over.join('\n ')}`,
);
process.exitCode = 1;
}