Pax Historia-style sim where the LLM is the world engine.
- React 19 + Vite 6 + Tailwind v4 + shadcn/ui frontend
- Express single-port backend (/api + /sse + built client + SPA fallback)
- SQLite (better-sqlite3) persistence, one row per game
- MapLibre choropleth map (OpenFreeMap dark + ISO_A3 regions)
- Defensive turn loop: strip fences, balanced-{} extract, parse, clamp 0-100,
retry-once nudge, generic 'unclear' fallback; never crashes on bad output
- 5 seed presets (wwii-1939, coldwar-1955, modern-2025, no-wwii-1940, aegis-2400)
- LLM client over native fetch w/ injectable transport (mesh-bot pattern);
LLM_STUB=1 deterministic transport for tests/e2e
- Unit (vitest, 19) + deterministic Playwright e2e
- Multi-stage node:22-slim Docker + Traefik (history.dev.kkhost.pl:4321)
Co-Authored-By: OpenCode <opencode@users.noreply.github.com>
61 lines
3.0 KiB
TypeScript
61 lines
3.0 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
/**
|
|
* Fully deterministic end-to-end test. The Playwright webServer boots the real
|
|
* stack (Vite :5173 → Express :4321) with LLM_STUB=1, so the backend uses the
|
|
* deterministic turn simulator in server/stub.ts: the player nation's `military`
|
|
* stat is set to (current + 5, clamped) each turn and exactly one event is
|
|
* emitted (action → military, chat → diplomatic, jump → political). There is no
|
|
* live LLM and no flakiness — every assertion below is an exact, predicted value.
|
|
*/
|
|
test.describe('History — deterministic simulation (LLM_STUB=1)', () => {
|
|
test('scenario → nation → action → jump, with predicted stat changes', async ({ page }) => {
|
|
await page.goto('/');
|
|
|
|
// Home: the scenario grid loads with all 5 presets.
|
|
const presetCards = page.getByTestId('preset-card');
|
|
await expect(presetCards.first()).toBeVisible();
|
|
await expect(presetCards).toHaveCount(5);
|
|
|
|
// Start the first scenario (World War II, 1939).
|
|
await presetCards.first().getByRole('button', { name: 'Play' }).click();
|
|
|
|
// Nation select: the world brief is shown, then we lead the United Kingdom.
|
|
await expect(page.getByTestId('world-background')).toBeVisible();
|
|
await page
|
|
.getByTestId('nation-card-uk')
|
|
.getByRole('button', { name: 'Play as United Kingdom' })
|
|
.click();
|
|
|
|
// Game screen mounts: map, command deck, and event feed all present; turn 1.
|
|
await expect(page.getByTestId('world-map')).toBeVisible();
|
|
await expect(page.getByTestId('action-panel')).toBeVisible();
|
|
await expect(page.getByTestId('event-feed-panel')).toBeVisible();
|
|
await expect(page.getByTestId('turn-count')).toHaveText('1');
|
|
|
|
// The player (UK) starts at military 80, with no events yet.
|
|
const military = page.getByTestId('stat-military');
|
|
await expect(military).toHaveText('80');
|
|
await expect(page.getByTestId('event-item')).toHaveCount(0);
|
|
|
|
// Take an action: the stub bumps UK military to 85 and emits a military event.
|
|
await page.getByTestId('action-textarea').fill('Mobilize the home guard and fortify Dover');
|
|
await page.getByTestId('action-submit').click();
|
|
|
|
await expect(page.getByTestId('turn-count')).toHaveText('2', { timeout: 20000 });
|
|
await expect(military).toHaveText('85', { timeout: 20000 });
|
|
await expect(page.getByTestId('event-item')).toHaveCount(1);
|
|
await expect(
|
|
page.getByTestId('event-feed').getByText('Mobilize the home guard and fortify Dover').first(),
|
|
).toBeVisible();
|
|
|
|
// Jump forward (no action): a "world moves on" political event, military → 90.
|
|
await page.getByTestId('jump-forward').click();
|
|
|
|
await expect(page.getByTestId('turn-count')).toHaveText('3', { timeout: 20000 });
|
|
await expect(military).toHaveText('90', { timeout: 20000 });
|
|
await expect(page.getByTestId('event-item')).toHaveCount(2);
|
|
await expect(page.getByTestId('event-feed').getByText('The world moves on').first()).toBeVisible();
|
|
});
|
|
});
|