mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 02:44:02 +00:00
Merge branch 'main' into feat/voice-geometry
Picks up the terrain partial-heights work (#1456). No conflicts; it changes no voice prompt or tool description.
This commit is contained in:
commit
0b6cdc8e1f
8 files changed
+152
-14
No files matched your search
@@ -19,6 +19,7 @@ import assert from 'node:assert/strict';
|
||||
import {
|
||||
resolveEllipsoidalGround,
|
||||
cachedEllipsoidalGround,
|
||||
cachedRealEllipsoidalGround,
|
||||
} from './terrainHeights.js';
|
||||
|
||||
const AUSTIN = { lat: 30.2672, lon: -97.7431 };
|
||||
@@ -362,3 +363,47 @@ test('resolveEllipsoidalGround: null and string heights cannot become real zeroe
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('resolveEllipsoidalGround: a 502 keeps the real heights it carries and falls back only for the rest', async () => {
|
||||
const coords = [
|
||||
{ lat: 62.001, lon: -150.001, sourceOrthometricM: 10 },
|
||||
{ lat: 62.002, lon: -150.002, sourceOrthometricM: 10 },
|
||||
{ lat: 62.003, lon: -150.003, sourceOrthometricM: 10 },
|
||||
];
|
||||
await withFakeFetch(
|
||||
async () => ({
|
||||
ok: false,
|
||||
status: 502,
|
||||
json: async () => ({
|
||||
error: 'terrain heights fetch failed and no cache available for every point',
|
||||
partial: [{ ellipsoid: 412.5 }, null, { ellipsoid: 'x' }],
|
||||
}),
|
||||
}),
|
||||
async () => {
|
||||
const out = await resolveEllipsoidalGround(coords);
|
||||
assert.deepEqual(out[0], { ellipsoid: 412.5, source: 'reearth' });
|
||||
assert.equal(out[1].source, 'geoid-fallback');
|
||||
assert.equal(out[2].source, 'geoid-fallback', 'a non-numeric height is not real');
|
||||
}
|
||||
);
|
||||
assert.equal(cachedRealEllipsoidalGround(62.001, -150.001), 412.5);
|
||||
assert.equal(cachedRealEllipsoidalGround(62.002, -150.002), null);
|
||||
});
|
||||
|
||||
test('resolveEllipsoidalGround: a partial list of the wrong length is ignored', async () => {
|
||||
const coords = [
|
||||
{ lat: 63.001, lon: -151.001 },
|
||||
{ lat: 63.002, lon: -151.002 },
|
||||
];
|
||||
await withFakeFetch(
|
||||
async () => ({
|
||||
ok: false,
|
||||
status: 502,
|
||||
json: async () => ({ error: 'x', partial: [{ ellipsoid: 7 }] }),
|
||||
}),
|
||||
async () => {
|
||||
const out = await resolveEllipsoidalGround(coords);
|
||||
assert.deepEqual(out.map((r) => r.source), ['geoid-fallback', 'geoid-fallback']);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -190,7 +190,8 @@ export async function fetchTerrainChunkWithRetry(
|
||||
* Resolve a requested point batch against a per-point cache and a missing-only
|
||||
* fetcher. Results are reconstructed by canonical key in exact request order,
|
||||
* including duplicates. Stale values remain eligible only when refresh fails.
|
||||
* If any position has no real height, return 502 with no fabricated result.
|
||||
* If any position has no real height, return 502 with no fabricated result;
|
||||
* the body's `partial` lists the real heights it has, null for the rest.
|
||||
*
|
||||
* @param {object} options
|
||||
* @param {Array<[number, number]>} options.points
|
||||
@@ -269,11 +270,19 @@ export async function resolveTerrainHeightRequest({
|
||||
return entry && validTerrainResult(entry.result) ? entry.result : null;
|
||||
});
|
||||
if (results.some((result) => result == null)) {
|
||||
// The real heights this request does have, null elsewhere, so the page
|
||||
// keeps them and uses its geoid only for the rest. Named `partial`, not
|
||||
// `results`, so no reader mistakes it for a complete answer; left out when
|
||||
// no point has a height.
|
||||
const partial = results.some((result) => result != null)
|
||||
? { partial: results }
|
||||
: {};
|
||||
return {
|
||||
status: 502,
|
||||
body: {
|
||||
error:
|
||||
'terrain heights fetch failed and no cache available for every point',
|
||||
...partial,
|
||||
},
|
||||
cacheChanged,
|
||||
upstreamError,
|
||||
|
||||
@@ -268,3 +268,31 @@ test('terrain parser rejects out-of-range WGS84 points and accepts inclusive bou
|
||||
[0, 0],
|
||||
]);
|
||||
});
|
||||
|
||||
test('a 502 lists the real heights it has, null for the rest', async () => {
|
||||
const cache = new Map([
|
||||
[terrainPointKey([1, 1]), { at: 0, result: result('stale-a', 11) }],
|
||||
]);
|
||||
const response = await resolveTerrainHeightRequest({
|
||||
points: [
|
||||
[1, 1],
|
||||
[2, 2],
|
||||
[1, 1],
|
||||
],
|
||||
cache,
|
||||
ttlMs: 100,
|
||||
now: () => 1000,
|
||||
fetchMissing: async () => {
|
||||
const error = new Error('HTTP 429');
|
||||
error.status = 429;
|
||||
error.coolingDown = true;
|
||||
throw error;
|
||||
},
|
||||
});
|
||||
assert.equal(response.status, 502);
|
||||
assert.equal('results' in response.body, false);
|
||||
assert.deepEqual(
|
||||
response.body.partial.map((item) => item?.id ?? null),
|
||||
['stale-a', null, 'stale-a'],
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user