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>
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { buildRegionMap } from './map';
|
|
import { nationColor } from '../shared/protocol';
|
|
import type { GameState } from '../shared/types';
|
|
|
|
const state: GameState = {
|
|
id: 'g',
|
|
presetId: 'p',
|
|
presetTitle: 'P',
|
|
playerNationId: 'uk',
|
|
turn: 1,
|
|
date: '1939-09-01',
|
|
nations: {
|
|
uk: {
|
|
id: 'uk',
|
|
name: 'UK',
|
|
type: 'major',
|
|
stats: { military: 80, economy: 70, stability: 60, population: 50 },
|
|
territory: ['GBR', 'IRL'],
|
|
relations: {},
|
|
},
|
|
de: {
|
|
id: 'de',
|
|
name: 'DE',
|
|
type: 'major',
|
|
stats: { military: 90, economy: 70, stability: 70, population: 90 },
|
|
territory: ['DEU'],
|
|
relations: {},
|
|
},
|
|
},
|
|
events: [],
|
|
};
|
|
|
|
describe('buildRegionMap', () => {
|
|
it('maps each ISO_A3 region to its owner + that nation\'s stable color', () => {
|
|
const m = buildRegionMap(state);
|
|
expect(m.GBR).toEqual({ color: nationColor('uk'), owner: 'UK', ownerId: 'uk' });
|
|
expect(m.IRL).toEqual({ color: nationColor('uk'), owner: 'UK', ownerId: 'uk' });
|
|
expect(m.DEU).toEqual({ color: nationColor('de'), owner: 'DE', ownerId: 'de' });
|
|
// a region nobody owns is simply absent
|
|
expect(m.FRA).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe('nationColor', () => {
|
|
it('is deterministic per id and distinct across different ids', () => {
|
|
expect(nationColor('uk')).toBe(nationColor('uk'));
|
|
expect(nationColor('uk')).not.toBe(nationColor('de'));
|
|
// always a valid HSL string
|
|
expect(nationColor('uk')).toMatch(/^hsl\(\d+ 58% 46%\)$/);
|
|
});
|
|
});
|