fix(terrain): keep cold height requests within the browser deadline (#348)

Use 64-point browser and upstream terrain batches to reduce cold-cache timeouts. Preserve successful chunk results, distinguish absent readings from malformed responses, and reject fabricated zero heights.

Original terrain resilience contribution by ItzDESTAQ, with browser batching, validation and regression follow-up by Sameh Khamis.

Validated with unit/build/format/boundary checks, 108 tracking checks, 5 terrain-outage checks, controlled slow-upstream comparison and live browser checks.

Co-authored-by: ItzDESTAQ <[email protected]>
Co-authored-by: Sameh Khamis <[email protected]>
This commit is contained in:
DESTAQandSameh Khamis authored and GitHub committed 2026-09-12 14:04:08 -07:00
1 parent 4e99f40488
commit db49edf363
8 files changed
+254 -32

No files matched your search

+82
View File
@@ -145,3 +145,85 @@ test('stale per-point entries serve through a failed refresh only when every poi
['stale-b', 'stale-a'],
);
});
test('a null-height row counts as absent, not a refresh failure, and is re-asked next poll', async () => {
const cache = new Map();
let calls = 0;
const options = {
points: [
[-97.428, 40.194],
[139.729, 35.693],
],
cache,
ttlMs: 30 * 24 * 3600_000,
now: () => 1_000_000,
// Re:Earth's observed transient shape: real elevation, null geoid/ellipsoid.
fetchMissing: async (missing) => {
calls += 1;
return missing.map(([lon, lat]) =>
lon === -97.428
? { lon, lat, elevation: 443.855, geoid: null, ellipsoid: null }
: result('real', 69.93),
);
},
};
const first = await resolveTerrainHeightRequest(options);
assert.equal(
first.upstreamError,
null,
'upstream answered every position; absence is not its fault',
);
assert.equal(first.absentPoints, 1);
assert.equal(first.requestedPoints, 2);
assert.equal(
first.status,
502,
'still no usable height, and none may be fabricated',
);
assert.equal(
cache.has(terrainPointKey([-97.428, 40.194])),
false,
'absent points stay uncached',
);
assert.equal(
cache.get(terrainPointKey([139.729, 35.693])).result.id,
'real',
'a batch-mate with a real height still caches',
);
await resolveTerrainHeightRequest(options);
assert.equal(calls, 2, 'a transient null must be re-asked, never suppressed');
});
test('a dropped position remains a genuine upstream fault', async () => {
const response = await resolveTerrainHeightRequest({
points: [
[1, 1],
[2, 2],
],
cache: new Map(),
ttlMs: 10_000,
now: () => 5_000,
fetchMissing: async () => [result('ok-a', 11)],
});
assert.notEqual(response.upstreamError, null);
assert.match(response.upstreamError.message, /omitted/);
assert.equal(response.absentPoints, 0, 'an omission is not an absence');
});
test('malformed height objects remain refresh failures, not absent readings', async () => {
for (const row of [{}, [], { ellipsoid: '0' }, { ellipsoid: null }]) {
const response = await resolveTerrainHeightRequest({
points: [[1, 2]],
cache: new Map(),
ttlMs: 10_000,
fetchMissing: async () => [row],
});
assert.equal(response.status, 502);
assert.ok(response.upstreamError);
assert.equal(response.absentPoints, 0);
assert.equal(response.cacheChanged, false);
}
});