feat: v0.14.0 — ISS-006 time-scale slider values up to 1000x; tests use fastest time
CI / build + unit + e2e (pull_request) Failing after 4m52s

This commit is contained in:
2026-09-19 08:49:30 +00:00
parent 0c9279818a
commit bd00b2b4c4
18 changed files with 141 additions and 80 deletions
+7 -7
View File
@@ -3,12 +3,12 @@ import { expect, test } from '@playwright/test';
// v0.12.0 package model against the live origin (https://flight.dev.kkhost.pl):
// the full core loop through the UI — hook creates a short package at EDDF → Load
// via the right pane → click its destination in the on-board list → fly at 60× →
// via the right pane → click its destination in the on-board list → fly at 1000× →
// arrival delivers EXACTLY the reward + rep; abandon deducts exactly the formula
// penalty while grounded; expired packages deliver/abandon with no reward and no
// penalty. Mirrors lib/game/penalty.ts for exact-value assertions.
const SCALE = 60; // fastest sim speed — keeps flights to seconds of real time
const SCALE = 1000; // fastest sim speed (v0.14.0 ladder top) — keeps flights to seconds of real time
const HUB = 'EDDF'; // Frankfurt Main — the seeded starter plane's home base (lib/game/seed.ts)
const FAR = 'LEZL'; // Seville — one-way burn 3174 L > half tank, so the return leg is unfuelable
@@ -93,7 +93,7 @@ async function flyHomeViaApi(page: Page): Promise<void> {
const s0 = await getState(page);
const plane = s0.planes.find((p) => p.id === 'plane-starter')!;
if (plane.status === 'flying' || plane.locationIcao !== HUB) {
// Fast-forward any leftover leg / repositioning flight (~3 min real time worst case at 60×).
// Fast-forward any leftover leg / repositioning flight (~20 s real time worst case at 1000×).
await setScale(page, SCALE);
}
if (plane.status === 'flying') {
@@ -119,7 +119,7 @@ async function flyHomeViaApi(page: Page): Promise<void> {
test('full core loop via UI: load → fly to destination → exact reward + rep on arrival', async ({ page }) => {
test.setTimeout(300_000); // self-heal (worst case ~3 min at 60×) + two short flights + refuel
test.setTimeout(300_000); // self-heal (worst case ~20 s at 1000×) + two short flights + refuel
// Self-heal: the starter plane may be anywhere from a previous run/spec.
await flyHomeViaApi(page);
const before = await getState(page);
@@ -154,7 +154,7 @@ test('full core loop via UI: load → fly to destination → exact reward + rep
expect(s.planes.find((p) => p.id === planeId)!.status).toBe('flying');
expect(s.planes.find((p) => p.id === planeId)!.destIcao).toBe(nearest.icao);
// Fast-forward to arrival (≤ ~10 min game time at 60× → seconds of real time).
// Fast-forward to arrival (a few seconds of real time at 1000×).
await setScale(page, SCALE);
await expect.poll(async () => ((await getState(page)).planes.find((p) => p.id === planeId)!.status), { timeout: 120_000 }).toBe('available');
@@ -230,7 +230,7 @@ test('abandon while grounded deducts exactly the formula penalty', async ({ page
});
test('expired packages deliver and abandon with no reward and no penalty', async ({ page }) => {
test.setTimeout(480_000); // two ~3 min real-time legs at 60× (HUB↔LEMD) plus expiry wait
test.setTimeout(480_000); // two ~10 s real-time legs at 1000× (HUB↔LEMD) plus expiry wait
await flyHomeViaApi(page);
const before = await getState(page);
@@ -281,7 +281,7 @@ test('expired packages deliver and abandon with no reward and no penalty', async
});
test('load and fly validation paths (404 / 409 / 400)', async ({ page }) => {
test.setTimeout(600_000); // the FAR round trip alone is ~7.5 min real time at 60×
test.setTimeout(600_000); // the FAR round trip alone is ~30 s real time at 1000×
await flyHomeViaApi(page);
// Load a package whose origin the plane is not at → 409.
+17 -10
View File
@@ -5,14 +5,16 @@ import { test, expect, type Page } from '@playwright/test';
// deterministic generated weather), plane markers whose positions come from the
// /api/state polls, each FLYING plane's current leg as a route line (origin →
// dest_icao; grounded planes draw nothing), and the plane status popup. Packages
// are created on a known EDDF→EDDV route via POST /api/test/create-package
// are created on a known EDDF→LEMD route via POST /api/test/create-package
// (FLIGHT_TEST_HOOKS=1).
const HUB = 'EDDF'; // must match HUB_ICAO in lib/game/seed.ts
// Hannover — ~282 km from EDDF → ~33 min game time ≈ 33 s at scale 60, a comfortable
// window for the click assertions below (the nearest airport would land too fast).
const DEST = 'EDDV';
const SCALE = 60;
// Madrid–Barajas — ~1420 km from EDDF → ~2.8 h game time ≈ 10 s at scale 1000, a comfortable
// window for the mid-flight click assertions below (at 1000× even Hannover's 33-min leg would
// land in ~2 s — shorter than the map poll + click pipeline). Round-trip burn (~4970 L) fits
// the 6300 L tank, so a full-tank departure always makes it home.
const DEST = 'LEMD';
const SCALE = 1000; // fastest sim speed (v0.14.0 ladder top)
interface PlaneState {
id: string;
@@ -91,7 +93,7 @@ async function createPackage(page: Page, fromIcao: string, toIcao: string): Prom
}
// Load a package onto plane-starter and fly it from → to via the API, then poll at
// scale 60 until the plane lands at `to`. Same pattern as e2e/actions.spec.ts.
// scale 1000 until the plane lands at `to`. Same pattern as e2e/actions.spec.ts.
async function loadAndFly(page: Page, fromIcao: string, toIcao: string): Promise<PackageState> {
const pkg = await createPackage(page, fromIcao, toIcao);
const load = await page.request.post(`/api/packages/${pkg.id}/load`, { data: { planeId: 'plane-starter' } });
@@ -171,7 +173,7 @@ test('airport popup shows name, ICAO, local time and generated weather', async (
});
test('plane markers move while flying and the plane popup shows status + route', async ({ page }) => {
test.setTimeout(600_000); // self-heal from a far airport (~4 min worst case at 60×) + main flight + cleanup
test.setTimeout(600_000); // self-heal from a far airport (~20 s worst case at 1000×) + main flight + cleanup
await page.goto('/');
await waitForAirportCount(page);
@@ -195,6 +197,11 @@ test('plane markers move while flying and the plane popup shows status + route',
await loadAndFly(page, starterLoc, HUB);
}
// Full tank before departure — the EDDF↔LEMD round trip burns ~4970 L of the 6300 L tank,
// so a partially drained plane left by an earlier spec could not make it home.
const refuel = await page.request.post('/api/planes/plane-starter/refuel');
expect(refuel.status()).toBe(200);
// 1) Load the hook-created package — a GROUNDED plane draws no route line yet.
const pkg = await createPackage(page, HUB, DEST);
const load = await page.request.post(`/api/packages/${pkg.id}/load`, { data: { planeId: 'plane-starter' } });
@@ -244,8 +251,8 @@ test('plane markers move while flying and the plane popup shows status + route',
// The arc itself stays covered by unit tests: lib/mapData.test.ts.)
// 4) Click the flying plane → status popup with model, status, fuel and the leg.
// Fetch + project in one evaluate so the click lands on a fresh position (the
// marker drifts only ~1 px/s of screen space at scale 60).
// Fetch + project in one evaluate so the click lands on a fresh position (at scale
// 1000 the marker moves fast — a stale projection would miss it).
const pt = await page.evaluate(async () => {
const m = (window as any).__flightMap;
if (!m) return null;
@@ -257,7 +264,7 @@ test('plane markers move while flying and the plane popup shows status + route',
const rect = m.getContainer().getBoundingClientRect();
return { x: rect.left + projected.x, y: rect.top + projected.y };
});
expect(pt).not.toBeNull(); // the flight (~33 s at scale 60) is still in progress here
expect(pt).not.toBeNull(); // the ~10 s window at scale 1000 is still open this early after departure
await page.mouse.click(pt!.x, pt!.y);
const popup = page.getByTestId('plane-popup');
+8 -8
View File
@@ -69,7 +69,7 @@ test('left pane renders wallet, reputation and the starter fleet at Frankfurt',
await expect(page.getByTestId('sim-clock')).toContainText(/UTC/);
});
test('time controls: pause freezes the sim and the power-of-two slider sets timeScale', async ({ page }) => {
test('time controls: pause freezes the sim and the ladder slider sets timeScale', async ({ page }) => {
await page.goto('/');
const pauseBtn = page.getByTestId('pause-toggle');
await expect(pauseBtn).toBeVisible({ timeout: 15_000 });
@@ -80,13 +80,13 @@ test('time controls: pause freezes the sim and the power-of-two slider sets time
// …and in the pane itself (the refetch after POST flips the button to Resume).
await expect(pauseBtn).toHaveText('Resume');
// Scale via the power-of-two slider. End jumps to max (t=1 → 64×): the label updates
// Scale via the ladder slider. End jumps to max (t=1 → 1000×): the label updates
// optimistically on input, and release flushes the debounced POST immediately.
const slider = page.getByTestId('time-scale-slider');
await slider.focus();
await page.keyboard.press('End');
await expect(page.getByTestId('time-scale-value')).toHaveText('64×', { timeout: 10_000 });
await expect.poll(async () => (await getState(page)).simState.timeScale, { timeout: 10_000 }).toBe(64);
await expect(page.getByTestId('time-scale-value')).toHaveText('1000×', { timeout: 10_000 });
await expect.poll(async () => (await getState(page)).simState.timeScale, { timeout: 10_000 }).toBe(1000);
// Home jumps to min (t=0 → 1×).
await page.keyboard.press('Home');
@@ -116,19 +116,19 @@ test('slider commit keeps the chosen scale on screen until confirmed — no snap
// …and sample the displayed value rapidly across the whole commit→confirm window. With the
// ISS-001 fix the optimistic value stays until a snapshot confirms it, so EVERY sample must
// be '64×' — never snapping back to the previous scale for one poll cycle (the old bug).
// be '1000×' — never snapping back to the previous scale for one poll cycle (the old bug).
const seen: string[] = [];
for (let i = 0; i < 30; i++) {
seen.push(((await page.getByTestId('time-scale-value').textContent()) ?? '').trim());
await new Promise((r) => setTimeout(r, 25));
}
expect(
seen.every((v) => v === '64×'),
`displayed scale must stay 64× during the commit window (saw: ${[...new Set(seen)].join(', ')})`,
seen.every((v) => v === '1000×'),
`displayed scale must stay 1000× during the commit window (saw: ${[...new Set(seen)].join(', ')})`,
).toBe(true);
// …and the server confirms it.
await expect.poll(async () => (await getState(page)).simState.timeScale, { timeout: 10_000 }).toBe(64);
await expect.poll(async () => (await getState(page)).simState.timeScale, { timeout: 10_000 }).toBe(1000);
// Restore to min for later tests (afterEach restores scale anyway).
await page.keyboard.press('Home');
+5 -5
View File
@@ -8,7 +8,7 @@ import { expect, test } from '@playwright/test';
// match the catalog + economy constants exposed in /api/state. Packages are created via
// POST /api/test/create-package (FLIGHT_TEST_HOOKS=1), same pattern as e2e/actions.spec.ts.
const SCALE = 60;
const SCALE = 1000; // fastest sim speed (v0.14.0 ladder top) — keeps flights to seconds of real time
const HUB = 'EDDF'; // must match HUB_ICAO in lib/game/seed.ts
interface PlaneState {
@@ -98,7 +98,7 @@ function penaltyFor(reward: number, createdSimTime: number, deadlineSimTime: num
return Math.round(reward * (0.15 + 0.45 * frac) * 100) / 100;
}
// Closest airport to EDDF from /api/airports → shortest possible arrival time at scale 60.
// Closest airport to EDDF from /api/airports → shortest possible arrival time at scale 1000.
async function nearestToHub(page: Page): Promise<{ icao: string; lat: number; lon: number }> {
const fc = (await (await page.request.get('/api/airports')).json()) as {
features: Array<{ properties: { icao: string; lat: number; lon: number } }>;
@@ -128,7 +128,7 @@ async function flyHomeViaApi(page: Page): Promise<void> {
const s0 = await getState(page);
const starter = s0.planes.find((p) => p.id === 'plane-starter')!;
if (starter.status === 'flying' || starter.locationIcao !== HUB) {
// Fast-forward any leftover leg / repositioning flight (~3 min real time worst case at 60×).
// Fast-forward any leftover leg / repositioning flight (~20 s real time worst case at 1000×).
await setScale(page, SCALE);
}
if (starter.status === 'flying') {
@@ -197,7 +197,7 @@ test('Load is disabled when no plane sits at the package origin', async ({ page
});
test('on-board list: fly-to-destination + abandon with penalty preview; flying planes show their leg', async ({ page }) => {
test.setTimeout(240_000); // one short flight at scale 60 plus UI steps — typical run well under three minutes
test.setTimeout(240_000); // one short flight at scale 1000 (seconds of real time) plus UI steps
await flyHomeViaApi(page);
const nearest = await nearestToHub(page);
@@ -241,7 +241,7 @@ test('on-board list: fly-to-destination + abandon with penalty preview; flying p
const b = await getState(page);
const p = b.planes.find((x) => x.id === 'plane-starter');
return !!p && p.status === 'available' && p.locationIcao === nearest.icao;
}, { timeout: 120_000, message: `waiting for arrival at ${nearest.icao} (scale 60)` })
}, { timeout: 120_000, message: `waiting for arrival at ${nearest.icao} (scale 1000)` })
.toBe(true);
// The in-deadline package was delivered on arrival — it leaves the on-board list…
+12 -8
View File
@@ -6,8 +6,8 @@ import { test, expect, type Page } from '@playwright/test';
// Must match lib/sim/engine.ts — kept in sync manually (same pattern as MIN_ZOOM/MAX_ZOOM in map.spec.ts).
const MAX_TICK_ELAPSED_MS = 2_000;
const SCALE = 60;
const MAX_DELTA_PER_TICK = MAX_TICK_ELAPSED_MS * SCALE; // 120_000 game ms per tick at scale 60
const SCALE = 1000; // fastest sim speed — top of the v0.14.0 ladder
const MAX_DELTA_PER_TICK = MAX_TICK_ELAPSED_MS * SCALE; // 2_000_000 game ms per tick at scale 1000
// Must match MARKET_TARGET_OPEN_PACKAGES in lib/game/seed.ts.
const MARKET_TARGET = 10;
@@ -42,7 +42,7 @@ test.afterEach(async ({ page }) => {
expect(res.status()).toBe(200);
});
test('timeScale 60 advances the clock by roughly real-time × 60 between polls', async ({ page }) => {
test('timeScale 1000 advances the clock by roughly real-time × 1000 between polls', async ({ page }) => {
const post = await postSim(page, { timeScale: SCALE });
expect(post.status()).toBe(200);
const s1 = (await post.json()) as SimState;
@@ -51,11 +51,11 @@ test('timeScale 60 advances the clock by roughly real-time × 60 between polls',
let prev = s1.clockMs;
for (let i = 0; i < 3; i++) {
await sleep(1_000); // one real second ≈ 60 game seconds at scale 60 — well under the clamp
await sleep(1_000); // one real second ≈ 1000 game seconds at scale 1000 — well under the clamp
const body = await getState(page);
const now = body.simState.clockMs;
expect(now).toBeGreaterThan(prev); // strictly advances while actively polled
expect(now - prev).toBeGreaterThanOrEqual(30_000); // ≥ ~500 ms real × 60
expect(now - prev).toBeGreaterThanOrEqual(500_000); // ≥ ~500 ms real × 1000
expect(now - prev).toBeLessThanOrEqual(MAX_DELTA_PER_TICK + 60); // clamp bounds each tick
prev = now;
}
@@ -82,7 +82,7 @@ test('an open package past its short deadline expires and the market stays toppe
expect(victim).toBeDefined(); // steady state always has open packages
// Test-only hook (FLIGHT_TEST_HOOKS=1 in docker-compose): move an existing open
// package's deadline ~10 game-seconds out so expiry is observable at scale 60.
// package's deadline ~10 game-seconds out so expiry is observable at scale 1000.
const hook = await page.request.post('/api/test/expire-package', { data: { packageId: victim!.id } });
expect(hook.status()).toBe(200);
const moved = (await hook.json()) as { id: string; deadlineSimTime: number };
@@ -132,9 +132,13 @@ test('the hook can also create a fresh short-deadline package, which then expire
});
test('POST /api/sim validates and clamps its input', async ({ page }) => {
const clampHigh = await postSim(page, { timeScale: 500 });
const clampHigh = await postSim(page, { timeScale: 2000 });
expect(clampHigh.status()).toBe(200);
expect(((await clampHigh.json()) as SimState).timeScale).toBe(64); // top of the power-of-two ladder (v0.9.2)
expect(((await clampHigh.json()) as SimState).timeScale).toBe(1000); // top of the ladder (v0.14.0)
const inRange = await postSim(page, { timeScale: 500 });
expect(inRange.status()).toBe(200);
expect(((await inRange.json()) as SimState).timeScale).toBe(500); // ladder value passes through unclamped
const clampLow = await postSim(page, { timeScale: 0.1 });
expect(clampLow.status()).toBe(200);