v0.62.0: fixed 24x world clock — frozen when fully grounded (#135)
CI / build + unit + e2e (pull_request) Successful in 16m31s

This commit is contained in:
2026-09-23 08:02:15 +00:00
parent 1d9e9ade58
commit 71dea3ffb8
14 changed files with 122 additions and 124 deletions
+4 -13
View File
@@ -274,26 +274,17 @@ test('on-board list: fly-to-destination + abandon with penalty preview; flying p
// The abandon button previews the penalty at its snapshot's clock (same formula as the server).
// The fleet is grounded here (the starter just loaded; workers:1 and every spec's cleanup leave no
// other planes), so the world runs at the idle real-time rate (ISS-128) — verify it actually did,
// then bound the UI's staleness instead of racing a frozen clock.
// other planes), so the world clock is FROZEN (#135) — verify it actually is, then the preview must
// match the server exactly: a frozen clock means zero drift between any two snapshots.
const c0 = (await getState(page)).simState.clockMs;
const t0 = Date.now();
await new Promise((r) => setTimeout(r, 1_500)); // > one background-tick interval
const state = await getState(page);
const idleDelta = state.simState.clockMs - c0;
expect(idleDelta, 'world should advance at the idle real-time rate while grounded (ISS-128)').toBeGreaterThan(0);
expect(idleDelta).toBeLessThan((Date.now() - t0) * WORLD); // clearly below the full world rate
expect(state.simState.clockMs - c0, 'the grounded clock must stay frozen (#135)').toBe(0);
// The UI renders the penalty from its last snapshot — up to one poll interval (~1 s, useGameState)
// older than `state`, i.e. ≤ ~2 game-seconds of clock drift at the idle real-time rate (ISS-128).
// Allow the formula's slope over that window instead of an exact string match.
const DRIFT_MS = 3_000; // a couple of poll intervals at the idle rate (= 1), margin for slow CI boxes
const span = pkg.deadlineSimTime - pkg.createdSimTime;
const penaltyText = ((await page.getByTestId(`abandon-penalty-${pkg.id}`).textContent()) ?? '').replace(/[^0-9.]/g, '');
expect(Number.isFinite(Number(penaltyText)), `penalty text: ${penaltyText}`).toBe(true);
const expectedPenalty = penaltyFor(pkg.reward, pkg.createdSimTime, pkg.deadlineSimTime, state.simState.clockMs);
const slopePerGameMs = (pkg.reward * 0.45) / span; // abandonPenaltyPct's SPAN across the package lifetime
expect(Math.abs(Number(penaltyText) - expectedPenalty)).toBeLessThanOrEqual(slopePerGameMs * DRIFT_MS + 0.01);
expect(Number(penaltyText), 'frozen clock → the preview matches the server exactly').toBe(expectedPenalty);
// Fly to the destination through the UI — the button is the destination's name.
const flyBtn = page.getByTestId(`fly-to-${pkg.id}`);