mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-12 06:12:18 +00:00
Cut duplicated and dead code across the engines, the layers and the QA scripts
- src/geo drops the ported debug argument checks and the tests that bitExact already covers; package boundaries accept a directory entry, so src/geo/ is listed once per group. - Cesium no longer carries movers and lines nobody draws with: they are optional engine capabilities. The fake engine and the Cesium camera use the shared cameraMath; unused contract tables, clock.ticked, the 'finest' surface detail and Navara click statistics are gone. - ALPR keeps one overlay core and one presentation model for both engines, bikeshare one station bookkeeping, the Navara ground effects one definition helper; image atlases, view centres, mover banks and colours are shared. - The legacy switch route, the clock offset and rate controls and other unused exports are removed. - The acceptance runs the Navara draw, geo import and scope checks; scenarios use the harness switch and page helpers; the main chunk check keeps the size budget only and runs once in CI.
This commit is contained in:
1 parent
c502404e1d
commit
7abf74518f
272 files changed
+4828
-10213
No files matched your search
@@ -1,14 +1,12 @@
|
||||
// Map tiles for headless QA: a disk cache shared by every run (in the system
|
||||
// temp directory) and one fetch per missing tile, with backoff on HTTP 429,
|
||||
// for the free tile hosts the QA pages load (OpenStreetMap imagery, the
|
||||
// keyless re:earth terrain). Back-to-back QA runs otherwise reload the same
|
||||
// tiles until those hosts rate-limit them. Only requests to these hosts are
|
||||
// paused (CDP Fetch with URL patterns); page-wide request interception also
|
||||
// held the Navara workers' requests and kept workers alive past their globe.
|
||||
// Map tiles for headless QA: the disk cache entry of a tile request and one
|
||||
// fetch per missing tile, with backoff on HTTP 429, for the free tile hosts
|
||||
// the QA pages load (OpenStreetMap imagery, the keyless re:earth terrain).
|
||||
// Back-to-back QA runs otherwise reload the same tiles until those hosts
|
||||
// rate-limit them. The strict harness (scripts/qa-strict-harness.mjs) pauses
|
||||
// only the requests to these hosts (CDP Fetch with URL patterns) and answers
|
||||
// them from the cache in the system temp directory.
|
||||
|
||||
import { createHash } from 'node:crypto';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
|
||||
export const CACHED_TILE_HOSTS = Object.freeze([
|
||||
@@ -119,82 +117,3 @@ export function createMissLoader({
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves the page's requests to CACHED_TILE_HOSTS (or `hosts`) from the
|
||||
* cache (filling it on a miss). Returns the counts.
|
||||
*/
|
||||
export async function installTileCache(
|
||||
page,
|
||||
{
|
||||
dir = path.join(os.tmpdir(), 'gev-qa-tiles'),
|
||||
hosts = CACHED_TILE_HOSTS,
|
||||
} = {},
|
||||
) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
const stats = { hits: 0, fetched: 0, cancelled: 0, failed: 0, errors: {} };
|
||||
const client = await page.createCDPSession();
|
||||
const misses = createMissLoader();
|
||||
client.on('Fetch.requestPaused', async ({ requestId, request }) => {
|
||||
const accept = Object.entries(request.headers ?? {}).find(
|
||||
([name]) => name.toLowerCase() === 'accept',
|
||||
)?.[1];
|
||||
const file =
|
||||
request.method === 'GET'
|
||||
? tileCacheFile(request.url, accept, dir, hosts)
|
||||
: null;
|
||||
try {
|
||||
if (!file)
|
||||
return await client.send('Fetch.continueRequest', { requestId });
|
||||
let entry = null;
|
||||
if (fs.existsSync(`${file}.json`)) {
|
||||
entry = {
|
||||
...JSON.parse(fs.readFileSync(`${file}.json`, 'utf8')),
|
||||
body: fs.readFileSync(file),
|
||||
};
|
||||
stats.hits++;
|
||||
} else {
|
||||
const tile = await misses.load(request.url, accept);
|
||||
// Only successes are cached; a 404 (no tile there) is passed on.
|
||||
if (tile.status === 200) {
|
||||
fs.writeFileSync(file, tile.body);
|
||||
fs.writeFileSync(
|
||||
`${file}.json`,
|
||||
JSON.stringify({ status: 200, contentType: tile.contentType }),
|
||||
);
|
||||
stats.fetched++;
|
||||
} else if (tile.status === 429) stats.failed++;
|
||||
entry = tile;
|
||||
}
|
||||
await client.send('Fetch.fulfillRequest', {
|
||||
requestId,
|
||||
responseCode: entry.status,
|
||||
responseHeaders: [
|
||||
...(entry.contentType
|
||||
? [{ name: 'Content-Type', value: entry.contentType }]
|
||||
: []),
|
||||
{ name: 'Access-Control-Allow-Origin', value: '*' },
|
||||
],
|
||||
body: entry.body.toString('base64'),
|
||||
});
|
||||
} catch (error) {
|
||||
// The page dropped the request meanwhile (a tile no longer in view).
|
||||
if (/Invalid InterceptionId/.test(String(error?.message))) {
|
||||
stats.cancelled++;
|
||||
return;
|
||||
}
|
||||
stats.failed++;
|
||||
const reason = String(error?.message ?? error).slice(0, 80);
|
||||
stats.errors[reason] = (stats.errors[reason] ?? 0) + 1;
|
||||
await client
|
||||
.send('Fetch.failRequest', { requestId, errorReason: 'Failed' })
|
||||
.catch(() => {});
|
||||
}
|
||||
});
|
||||
await client.send('Fetch.enable', {
|
||||
patterns: hosts.map((host) => ({
|
||||
urlPattern: `https://${host}/*`,
|
||||
})),
|
||||
});
|
||||
return stats;
|
||||
}
|
||||
Reference in new issue
Block a user