mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 11:42:21 +00:00
fix(recent-imagery): keep a half confirmed empty when the other half's request fails
When one half of a dateline box rejects or hits its deadline and the other half answered Data-Present: false, the thrown error now carries the per-half answers, and the loader merges them as it does for a 503 or a missing header. The empty side stays undraped and DETAILS shows partial coverage.
This commit is contained in:
1 parent
8604968746
commit
3973772b83
3 files changed
+60
-34
No files matched your search
@@ -1891,35 +1891,45 @@ test('a shown HLS day on a plain box stays draped after a probe without Data-Pre
|
||||
layer.destroy();
|
||||
});
|
||||
|
||||
test('an HLS dateline day leaves out a half confirmed empty when the other half fails', async () => {
|
||||
const day = candidate('S30', '2026-11-10');
|
||||
const { layer, loader, globe } = realLayer({
|
||||
candidates: [day],
|
||||
halfDeadlineMs: 5000,
|
||||
fetchImpl: async (url) =>
|
||||
sideOf(url) === 'west'
|
||||
? snapshotAnswer(false)
|
||||
: snapshotAnswer(null, 503),
|
||||
});
|
||||
layer.enable();
|
||||
layer.setBox(FIJI_BOX);
|
||||
assert.equal(
|
||||
await until(() => loader.get(day.key)?.status === 'error', { ticks: 2000 }),
|
||||
true,
|
||||
);
|
||||
layer.setAssignment('a', day.key);
|
||||
await until(() => false, { ticks: 50 });
|
||||
const entry = loader.get(day.key);
|
||||
const [west] = nonCrossingBoxes(FIJI_BOX);
|
||||
assert.deepEqual(
|
||||
{
|
||||
empty: (entry.emptyBoxes ?? []).map(boxKey),
|
||||
layers: globe.layers.length,
|
||||
for (const [label, failEast] of [
|
||||
['answers 503', async () => snapshotAnswer(null, 503)],
|
||||
[
|
||||
'rejects',
|
||||
async () => {
|
||||
throw new TypeError('Failed to fetch');
|
||||
},
|
||||
{ empty: [boxKey(west)], layers: 1 },
|
||||
);
|
||||
layer.destroy();
|
||||
});
|
||||
],
|
||||
['never answers', () => new Promise(() => {})],
|
||||
]) {
|
||||
test(`an HLS dateline day leaves out a half confirmed empty when the other half ${label}`, async () => {
|
||||
const day = candidate('S30', '2026-11-10');
|
||||
const { layer, loader, globe } = realLayer({
|
||||
candidates: [day],
|
||||
fetchImpl: async (url) =>
|
||||
sideOf(url) === 'west' ? snapshotAnswer(false) : failEast(),
|
||||
});
|
||||
layer.enable();
|
||||
layer.setBox(FIJI_BOX);
|
||||
assert.equal(
|
||||
await until(() => loader.get(day.key)?.status === 'error', {
|
||||
ticks: 2000,
|
||||
}),
|
||||
true,
|
||||
);
|
||||
layer.setAssignment('a', day.key);
|
||||
await until(() => false, { ticks: 50 });
|
||||
const entry = loader.get(day.key);
|
||||
const [west] = nonCrossingBoxes(FIJI_BOX);
|
||||
assert.deepEqual(
|
||||
{
|
||||
empty: (entry.emptyBoxes ?? []).map(boxKey),
|
||||
layers: globe.layers.length,
|
||||
},
|
||||
{ empty: [boxKey(west)], layers: 1 },
|
||||
);
|
||||
layer.destroy();
|
||||
});
|
||||
}
|
||||
|
||||
test('a re-probe of a present HLS dateline day takes a fresh empty half when the shown half has no Data-Present', async () => {
|
||||
const day1 = candidate('S30', '2026-11-10');
|
||||
|
||||
@@ -98,7 +98,8 @@ function withHalves(response, { presentBoxes, emptyBoxes }) {
|
||||
* NASA-compatible imagery acquisition; transport and URL builders are replaceable.
|
||||
* Thumbnail responses must expose Data-Present: true for image admission, or
|
||||
* false for confirmed empty coverage, including injected getThumbnail sources.
|
||||
* getThumbnail also sets presentBoxes and emptyBoxes (see withHalves).
|
||||
* getThumbnail also sets presentBoxes and emptyBoxes (see withHalves),
|
||||
* also on the error it throws when another half was confirmed empty.
|
||||
* Without per-half evidence the renderer drapes every side of an HLS
|
||||
* dateline box and no side of a VIIRS one.
|
||||
*/
|
||||
@@ -144,17 +145,28 @@ export function createRecentImagerySource({
|
||||
const answers = results.map((result) =>
|
||||
result.status === 'fulfilled' ? dataPresent(result.value) : null,
|
||||
);
|
||||
// A missing answer is an error unless another half proved data.
|
||||
const halvesWhere = (value) =>
|
||||
halves.filter((_, i) => answers[i] === value);
|
||||
// A missing answer is an error unless another half proved data. The
|
||||
// error keeps a half confirmed empty (see withHalves).
|
||||
const failure = results.find((result) => result.status === 'rejected');
|
||||
if (failure && !answers.includes('true')) throw failure.reason;
|
||||
if (failure && !answers.includes('true')) {
|
||||
const emptyBoxes = halvesWhere('false');
|
||||
if (Object.isExtensible(failure.reason))
|
||||
withHalves(
|
||||
failure.reason,
|
||||
emptyBoxes.length
|
||||
? { presentBoxes: [], emptyBoxes }
|
||||
: { presentBoxes: null, emptyBoxes: null },
|
||||
);
|
||||
throw failure.reason;
|
||||
}
|
||||
// Show the first half with data (the wider wins a tie), else the first
|
||||
// not confirmed empty, so an unreadable answer is never called empty.
|
||||
// Every half answered here unless one proved data.
|
||||
let shown = answers.indexOf('true');
|
||||
if (shown < 0) shown = answers.findIndex((answer) => answer !== 'false');
|
||||
if (shown < 0) shown = 0;
|
||||
const halvesWhere = (value) =>
|
||||
halves.filter((_, i) => answers[i] === value);
|
||||
return withHalves(results[shown].value, {
|
||||
presentBoxes: halvesWhere('true'),
|
||||
emptyBoxes: halvesWhere('false'),
|
||||
|
||||
@@ -133,7 +133,11 @@ export function createThumbnailLoader({
|
||||
} catch (error) {
|
||||
if (controller.signal.aborted || error?.name === 'AbortError')
|
||||
cancelled = true;
|
||||
else status = 'error';
|
||||
else {
|
||||
status = 'error';
|
||||
availableBoxes = error?.presentBoxes ?? availableBoxes;
|
||||
emptyBoxes = error?.emptyBoxes ?? emptyBoxes;
|
||||
}
|
||||
} finally {
|
||||
inFlight -= 1;
|
||||
entry.loading = false;
|
||||
|
||||
Reference in new issue
Block a user