idle fleet slows world clock to real time instead of freezing (ISS-128)
CI / build + unit + e2e (pull_request) Successful in 10m32s
CI / build + unit + e2e (pull_request) Successful in 10m32s
This commit is contained in:
+17
-6
@@ -8,6 +8,9 @@ import { test, expect } from '@playwright/test';
|
||||
const repoRoot = path.join(__dirname, '..');
|
||||
const composeArgs = process.env.E2E_COMPOSE_ARGS ?? '';
|
||||
|
||||
// Must match lib/sim/engine.ts — kept in sync manually (same pattern as e2e/sim.spec.ts).
|
||||
const MAX_TICK_ELAPSED_MS = 2_000;
|
||||
|
||||
interface StateBody {
|
||||
account: { cash: number; reputation: number };
|
||||
simState: { clockMs: number }; // ISS-117: the snapshot carries only the game clock
|
||||
@@ -42,8 +45,9 @@ test('GET /api/state returns a seeded snapshot', async ({ page }) => {
|
||||
test('state survives a container restart (sim clock + account persisted)', async ({ page }) => {
|
||||
test.setTimeout(180_000);
|
||||
|
||||
// Self-heal to a fully grounded fleet first — idle-pause (ISS-117) then freezes the clock, so the
|
||||
// post-restart snapshot must match byte-for-byte instead of within one tick bound.
|
||||
// Self-heal to a fully grounded fleet first — while idle the clock advances at real time
|
||||
// (ISS-128), so the post-restart snapshot is bounded by one clamped tick of downtime plus live
|
||||
// ticks, not byte-for-byte identical.
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const res = await page.request.get('/api/state');
|
||||
@@ -56,6 +60,7 @@ test('state survives a container restart (sim clock + account persisted)', async
|
||||
const resBefore = await page.request.get('/api/state');
|
||||
expect(resBefore.status()).toBe(200);
|
||||
const before = (await resBefore.json()) as StateBody;
|
||||
const tBefore = Date.now();
|
||||
|
||||
execSync(`docker compose ${composeArgs} restart flight`, { cwd: repoRoot, stdio: 'pipe' });
|
||||
|
||||
@@ -75,11 +80,17 @@ test('state survives a container restart (sim clock + account persisted)', async
|
||||
|
||||
expect(after).toBeDefined();
|
||||
const a = after!;
|
||||
const tAfter = Date.now();
|
||||
|
||||
// The DB file on the volume must be loaded, not re-seeded (PLAN.md: "sim clock
|
||||
// persisted across sessions"): account and entity ids are byte-identical. With the fleet
|
||||
// grounded above, idle-pause keeps the clock frozen across the restart — exact equality.
|
||||
expect(a.simState.clockMs).toBe(before.simState.clockMs);
|
||||
// The DB file on the volume must be loaded, not re-seeded (PLAN.md: "sim clock persisted across
|
||||
// sessions"): account and entity ids are byte-identical. With the fleet grounded above, ISS-128
|
||||
// advances the clock at real time while idle — bounded tolerance instead of exact equality: no
|
||||
// ticks run while the container is down, so the first post-restart tick counts the downtime
|
||||
// clamped to MAX_TICK_ELAPSED_MS × IDLE rate (= 1), and every other counted gap lies inside the
|
||||
// live wall span [tBefore, tAfter] at that same rate. A re-seed would reset clockMs backwards.
|
||||
const delta = a.simState.clockMs - before.simState.clockMs;
|
||||
expect(delta).toBeGreaterThanOrEqual(0); // never goes backwards — not re-seeded
|
||||
expect(delta).toBeLessThanOrEqual(MAX_TICK_ELAPSED_MS + (tAfter - tBefore));
|
||||
expect(a.account.cash).toBe(before.account.cash);
|
||||
expect(a.account.reputation).toBe(before.account.reputation);
|
||||
expect(a.planes.map((p) => p.id).sort()).toEqual(before.planes.map((p) => p.id).sort());
|
||||
|
||||
Reference in New Issue
Block a user