fix: forFlight refuel leaves an exactly-feasible tank (round up) — e2e 409
CI / build + unit + e2e (pull_request) Failing after 5m26s

This commit is contained in:
2026-09-19 13:00:06 +00:00
parent a801311fc5
commit 687e4f2169
4 changed files with 52 additions and 14 deletions
+18 -8
View File
@@ -115,20 +115,29 @@ async function nearestToHub(page: Page): Promise<{ icao: string; lat: number; lo
return nearest;
}
// Farthest airport from EDDF — the longest possible leg (v0.16.0 refuel-for-flight test).
async function farthestToHub(page: Page): Promise<{ icao: string; lat: number; lon: number; hubLat: number; hubLon: number }> {
// Farthest airport from EDDF whose leg still FITS A FULL TANK — the longest flyable leg (v0.16.0
// refuel-for-flight test). The dataset's absolute farthest can exceed the aircraft's range (UNNT is
// ~4803 km out and needs ~6955 L > the 6300 L tank), so a full-tank fly there would rightly 409;
// this test wants a long-but-flyable leg instead.
async function farthestFlyableToHub(
page: Page,
entry: CatalogEntry,
): Promise<{ icao: string; lat: number; lon: number; hubLat: number; hubLon: number }> {
const fc = (await (await page.request.get('/api/airports')).json()) as {
features: Array<{ properties: { icao: string; lat: number; lon: number } }>;
};
const hub = fc.features.find((f) => f.properties.icao === HUB)!.properties;
let farthest = fc.features.filter((f) => f.properties.icao !== HUB)[0].properties;
let farthest: { icao: string; lat: number; lon: number; d: number } | null = null;
for (const f of fc.features) {
if (f.properties.icao === HUB) continue;
if (haversineKm(hub.lat, hub.lon, f.properties.lat, f.properties.lon) > haversineKm(hub.lat, hub.lon, farthest.lat, farthest.lon)) {
farthest = f.properties;
const d = haversineKm(hub.lat, hub.lon, f.properties.lat, f.properties.lon);
if (requiredFuelFor(entry.burnPerKm, entry.emptyWeightKg, entry.maxFuel, d) > entry.maxFuel) continue; // beyond range
if (!farthest || d > farthest.d) {
farthest = { icao: f.properties.icao, lat: f.properties.lat, lon: f.properties.lon, d };
}
}
return { icao: farthest.icao, lat: farthest.lat, lon: farthest.lon, hubLat: hub.lat, hubLon: hub.lon };
if (!farthest) throw new Error('no full-tank-flyable airport found in the dataset');
return { ...farthest, hubLat: hub.lat, hubLon: hub.lon };
}
// Mirrors lib/sim/movement.ts (v0.16.0): fuel required to cover distanceKm arriving empty —
@@ -343,8 +352,9 @@ test('on-board row Refuel tops up just enough for the package leg; market button
// Deterministic baseline: a full tank.
expect((await page.request.post('/api/planes/plane-starter/refuel')).status()).toBe(200);
// Longest leg from the hub — long enough that "just enough" for it exceeds what's left on arrival.
const farthest = await farthestToHub(page);
// Longest FLYABLE leg from the hub (fits a full tank) — long enough that "just enough" for it
// exceeds what's left on arrival.
const farthest = await farthestFlyableToHub(page, entry);
const pkg1 = await createPackage(page, HUB, farthest.icao, 24 * 3_600_000);
expect((await page.request.post(`/api/packages/${pkg1.id}/load`, { data: { planeId: 'plane-starter' } })).status()).toBe(200);