import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import test from 'node:test'; import { runInNewContext } from 'node:vm'; import { createElement, isValidElement, type ReactElement, type ReactNode } from 'react'; import { renderToStaticMarkup } from 'react-dom/server'; import * as jsxRuntime from 'react/jsx-runtime'; import ts from 'typescript'; import type { Action, GameView } from '../game/engine'; import { HomeworldNoFieldShipment } from '../components/homeworld-shipment'; import { createRicheseNoField, deployRicheseNoField } from '../game/richese-no-field'; import { homeworldForceGroups, type HomeworldCustody } from '../game/homeworld-custody'; import { homeworldPopulations } from '../game/homeworld-population'; import * as combat from '../game/combat'; import * as options from '../game/homeworld-shipment-options'; /** Personalized public Homeworld view with one real deployed marker. */ function fixture(advanced: boolean): GameView { const context = { advanced, players: [ { id: 'r', faction: 'richese' as const, reserves: 12, eliteReserves: 0, ally: null as string | null }, { id: 'a', faction: 'atreides' as const, reserves: 15, eliteReserves: 0, ally: null as string | null }, { id: 'g', faction: 'guild' as const, reserves: 20, eliteReserves: 0, ally: null as string | null }, ] }; const custody: HomeworldCustody = { salusa: null, visitors: { 'homeworld:atreides': { r: { normal: 2, elite: 0 } }, } }; const populations = homeworldPopulations(context, custody); const marker = deployRicheseNoField(createRicheseNoField(['zero', 'three', 'five']), { tokenId: 'five', controller: 'r', location: { homeworld: 'homeworld:atreides' } }); return { me: 'r', active: 'r', advanced, status: 'playing', phase: 5, homeworldShipment: { event: 'homeworld-event', blocked: null }, aid: { available: 0, pledged: 0 }, players: context.players.map(p => ({ ...p, name: p.faction, spice: p.id === 'r' ? 4 : undefined, shipped: false, elites: { reserves: 0 } })), homeworlds: { worlds: homeworldForceGroups(context, custody).map(world => ({ ...world, ...populations.find(population => population.location === world.id)! })) }, richeseNoField: { owner: 'r', event: 'marker-event', private: marker, canShip: false, shipBlock: 'Reveal the existing No-Field before shipping another.' }, } as unknown as GameView; } function markup(view: GameView): string { return renderToStaticMarkup(createElement(HomeworldNoFieldShipment, { game: view, act() {}, busy: false })); } function destinations(html: string): string { const match = /