import assert from 'node:assert/strict'; import test from 'node:test'; import { createElement } from 'react'; import { renderToStaticMarkup } from 'react-dom/server'; import { applyAction, viewGame, type Game } from '../game/engine'; import { CaladanReinforcement } from '../components/caladan-reinforcement'; import { caladanReinforcementCanAct, caladanReinforcementChoice } from '../game/caladan-reinforcement-options'; import { caladanVictoryFixture, prepareVictoryBattle, commitVictoryPlans, finishVictoryCalls, victoryPlayer, } from './fixture-caladan-victory'; // Existing controlled victory source: genuine Homeworld setup/deal, staged // later phase/armies/wallets and storm position, then real battle packets yield // the choice. This is not original-game progression or an HMS entry programme. // SSR and shared-adapter checks do not operate the stateful React chooser. const sources = new Map(); function choiceGame(advanced = true): Game { let source = sources.get(advanced); if (!source) { const initial = caladanVictoryFixture({ advanced }); initial.storm = 13; source = finishVictoryCalls(commitVictoryPlans(prepareVictoryBattle(initial))); assert.equal(source.decision?.kind, 'caladanReinforcement'); assert.equal(source.lastBattleContext?.winner, 'a'); sources.set(advanced, source); } return structuredClone(source); } function html(game: Game, owner = 'a', busy = false) { return renderToStaticMarkup(createElement(CaladanReinforcement, { game: viewGame(game, owner), busy, act() { assert.fail('Rendering the chooser must not submit a decision.'); } })); } void test('the engine-owned Caladan choice keeps its default target and original exact one-force adapter packet', () => { const game = choiceGame(), view = viewGame(game, 'a'), offer = view.caladanReinforcement; assert.ok(offer); const target = offer.destinations.find(destination => !destination.blocked); assert.ok(target); assert.ok(target.id.startsWith('hagga_basin:')); const markup = html(game); assert.ok(markup.includes(`