import assert from 'node:assert/strict'; import test from 'node:test'; import { registerHooks } from 'node:module'; import { readFileSync } from 'node:fs'; import { createElement } from 'react'; import { renderToStaticMarkup } from 'react-dom/server'; import { handLimit, viewGame, type Action, type Game, type GameView } from '../game/engine'; import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards'; import { act, advance, clean, createKullRicheseSemutaFixture, inventory, player } from './fixture-kull-richese-semuta'; const aliases = registerHooks({ resolve(specifier, context, next) { return next(specifier === 'next/image' ? 'vinext/shims/image' : specifier === 'next/link' ? 'vinext/shims/link' : specifier, context); }, load(url, context, next) { if (!url.endsWith('.module.css')) return next(url, context); const css = readFileSync(new URL(url), 'utf8'); const classes = Object.fromEntries([...css.matchAll(/\.([a-zA-Z_][\w-]*)/g)].map(match => [match[1], match[1]])); return {format:'module', source:`export default ${JSON.stringify(classes)}`, shortCircuit:true}; }, }); const { GameTable } = await import('../components/game-table'); const { Truthtrance } = await import('../components/truthtrance'); const { AlliancePromiseGuideButton } = await import('../components/alliance-promises'); aliases.deregister(); const table = (game:GameView) => renderToStaticMarkup(createElement(GameTable, {game,busy:false,send:async () => {},onExit() {}})); const truth = (game:GameView) => renderToStaticMarkup(createElement(Truthtrance, {game,busy:false,act() {}})); /** The native Basic game purchases Semuta through Richese's real cache auction. * Only a physical Truthtrance is reassigned and an unopened Worm and replacement * are selected; the offer, question, Semuta pass and acceptance are real actions. */ function source() { const f = createKullRicheseSemutaFixture(); let game = structuredClone(f.game); const zones = [game.deck, game.discard, ...(game.richeseCache ? [game.richeseCache] : []), ...(game.richeseRemoved ? [game.richeseRemoved] : []), ...game.players.map(seat => seat.hand)]; const zone = zones.find(cards => cards.some(card => card.effect === 'truthtrance')); assert.ok(zone); const [card] = zone.splice(zone.findIndex(row => row.effect === 'truthtrance'), 1); const asker = player(game,'harkonnen'); assert.ok(asker.hand.length < handLimit(asker)); asker.hand.push(card); assert.deepEqual(inventory(game),f.originalCards); game = advance(game,state => state.turn === 2 && beforeIxSpiceDraw(state)); orderIxSpiceCards(game,['worm','land']); game = advance(game,state => state.phase === 1 && state.nexus && clean(state) && !state.spiceWindow && !state.spiceResolution); game = act(game,'richese',{type:'alliance',target:'emperor'}); game = act(game,'harkonnen',{type:'card',card:card.id}); while (game.truthtrance?.stage === 'priority') { const seat = game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(seat); game = act(game,seat.id,{type:'truthPass'}); } return {game,originalCards:f.originalCards}; } void test('Basic Kull and Richese render a genuine alliance question and owned acceptance guide',()=>{ const f = source(); let game:Game = f.game; const asker = viewGame(game,'harkonnen'); assert.ok(asker.truthAllianceTargets.includes('emperor')); assert.match(truth(asker), /