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 GameView } from '../game/engine'; import { act, finishRevival, inventory, player } from './fixture-kull-revival-semuta'; import { createSemutaRevivalBenefitsForcesFixture } from './fixture-semuta-revival-benefits-forces'; 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 {RevivalPromiseGuideButton} = await import('../components/revival-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 source actually buys Semuta, ships four CHOAM forces and * loses them to Storm. Only an original physical Truthtrance is reassigned to * the asker; no phase, force, purse, pending decision or promise is installed. */ void test('the Kull and Richese table renders a real Revival question, answer and owned return guide',()=>{ const source = createSemutaRevivalBenefitsForcesFixture({kind:'choamRevival',advanced:false}); let game = structuredClone(source.beforeRevival); assert.ok(game.kullPreview && game.semutaPreview); assert.equal(player(game,'choam').tanks,4); const originalCards = inventory(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,'atreides'); assert.ok(asker.hand.length < handLimit(asker)); asker.hand.push(card); assert.deepEqual(inventory(game),originalCards); game = act(game,'atreides',{type:'card',card:card.id}); while (game.truthtrance?.stage === 'priority') { const next = game.players.find(seat=>!game.truthtrance!.passed.includes(seat.id)); assert.ok(next); game = act(game,next.id,{type:'truthPass'}); } const asking = viewGame(game,'atreides'); assert.ok(asking.truthRevivalTargets.includes('choam')); assert.match(truth(asking), /