fix(live): cache the oversized-track 502 like other upstream errors (#722)

Keep the new 502, but store it in the 60 s cache as the proxy already does
for 404/429: /tracks/all costs OpenSky credits, so an oversized track must
not be re-downloaded on every reselect. Update the regression test and
credit the fix in CHANGELOG.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Sameh KhamisandClaude Opus 5.5 committed 2026-09-24 22:09:17 -07:00
1 parent 0d58d6e1c4
commit 3a23dc393d
3 files changed
+15 -19

No files matched your search

+6 -16
View File
@@ -354,27 +354,17 @@ test('military cooldown bounds untrusted Retry-After and defaults server errors'
}
});
test('track backfill proxy returns 502 and skips cache when upstream response exceeds body cap', async (t) => {
test('track backfill proxy returns 502 on an oversized upstream body and caches it as an error', async (t) => {
const tracks = install(providers.trackBackfillProxies(), true);
let callCount = 0;
t.mock.method(globalThis, 'fetch', async () => {
callCount++;
if (callCount === 1) {
return {
ok: true,
status: 200,
headers: new Map(),
body: (async function* () {
yield Buffer.alloc(6 * 1024 * 1024, 'x');
})(),
};
}
return {
ok: true,
status: 200,
headers: new Map(),
body: (async function* () {
yield Buffer.from(JSON.stringify({ path: [] }));
yield Buffer.alloc(6 * 1024 * 1024, 'x');
})(),
};
});
@@ -385,9 +375,9 @@ test('track backfill proxy returns 502 and skips cache when upstream response ex
error: 'Upstream track response too large',
});
// Verify failure was NOT cached: second request invokes upstream again and succeeds
// Cached as a 502 (never a 200): a retry inside the window neither
// reads as an empty track nor spends OpenSky credits on another download.
const res2 = await tracks('/api/opensky-track', '?icao24=def456');
assert.equal(res2.statusCode, 200);
assert.deepEqual(JSON.parse(res2.body), { path: [] });
assert.equal(callCount, 2);
assert.equal(res2.statusCode, 502);
assert.equal(callCount, 1);
});