Allow bounded Kull cancellation continuations
Verify and publish checkpoint container / container (push) Successful in 10m22s

This commit is contained in:
Quintine committed 2026-10-29 01:46:28 +11:00
1 parent 07f1f1f2ae
commit 6e1b95d2fc
9 files changed
+569 -7

No files matched your search

+163
View File
@@ -0,0 +1,163 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createGame, joinGame, newPlayer, viewGame, type Game } from '../game/engine';
import { TERRITORIES } from '../game/board';
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
import { windowCardOpportunity } from '../game/window-card-play';
import { act, advance, clean, inventory, player } from './fixture-kull-richese-semuta';
import { nextSemutaRicheseCacheKarama } from './fixture-semuta-richese-cache-karama';
/** A genuine five-seat Basic game. Select only physical unopened starting
* cards and a safe unopened Spice card; the Truth answer, cache purchase,
* shipment, battle, parent power, and Kull actions are all native actions. */
function source(power:'voice'|'prescience', answer:'yes'|'no') {
const owner=power==='voice'?'beneGesserit':'atreides';
let game=createGame('KULLWHOLECANCEL',newPlayer('choam','CHOAM','choam'),false,['choam','ix']);
for (const id of ['richese','emperor',owner,'harkonnen'] as const) joinGame(game,newPlayer(id,id,id));
game=act(game,'choam',{type:'moduleOption',module:'kullPreview',enabled:true});
for (const seat of game.players) game=act(game,seat.id,{type:'ready'});
game=act(game,'choam',{type:'start'});
assert.equal(game.status,'setup'); assert.ok(game.kullPreview && game.semutaPreview);
const originalCards=inventory(game), selected:Game['deck']=[];
for (const kind of ['kull','filler','karama','filler','karama','truth'] as const) {
const index=game.deck.findIndex(card=>kind==='kull'?card.id==='ix-kull-wahad':
kind==='truth'?card.effect==='truthtrance':kind==='karama'?card.effect==='karama':
card.kind==='worthless' && card.id!=='ix-kull-wahad');
assert.ok(index>=0); selected.push(game.deck.splice(index,1)[0]);
}
game.deck.unshift(...selected);
game=advance(game,state=>state.status==='playing');
const [kull,,karama,,counter,truth]=selected.map(card=>card.id);
for (const [id,card] of [['choam',kull],['emperor',karama],['harkonnen',counter],['harkonnen',truth]] as const)
assert.ok(player(game,id).hand.some(row=>row.id===card));
const safe=game.spiceDeck.findIndex(card=>'territory' in card && !card.discovery); assert.ok(safe>=0);
game.spiceDeck.unshift(game.spiceDeck.splice(safe,1)[0]);
game=advance(game,state=>state.phase===2 && clean(state) && state.choamCharity?.turn===state.turn);
game=act(game,'harkonnen',{type:'card',card:truth});
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'});
}
game=act(game,'harkonnen',{type:'truthAsk',question:{kind:'turnActions',target:'emperor',turn:game.turn,
mixed:{kind:'action',action:{kind:'payment',recipient:'richese',minimum:1}}}});
assert.ok(viewGame(game,'emperor').truthTurnActionAnswers?.includes(answer));
game=act(game,'emperor',{type:'truthAnswer',answer});
const commitment=game.turnActionPromises?.at(-1); assert.ok(commitment);
game=advance(game,state=>player(state,'richese').hand.some(card=>card.id===SEMUTA_DRUG_ID) && clean(state));
let target:{territory:string;sector:number}|null=null;
for (let count=0;count<1000 && game.phase!==6;count++) {
if (game.phase===5 && clean(game) && game.active) {
const actor=game.active, seat=player(game,actor);
if ((actor==='emperor'||actor===owner) && !seat.shipped) {
if (!target) {
const territory=TERRITORIES.find(row=>row.type==='stronghold' && row.sectors.some(s=>s!==game.storm) &&
game.players.every(p=>!Object.keys(p.forces).some(key=>key.startsWith(`${row.id}:`))));
assert.ok(territory);
target={territory:territory.id,sector:territory.sectors.find(s=>s!==game.storm)!};
}
game=act(game,actor,{type:'ship',territory:target.territory,sector:target.sector,amount:1,elite:0,allyPayment:0});
} else game=act(game,actor,{type:'endMovement'});
continue;
}
const next=nextSemutaRicheseCacheKarama(game); assert.ok(next);
game=act(game,next.actor,next.action);
}
assert.equal(game.phase,6); assert.ok(target);
assert.equal(player(game,'emperor').forces[`${target.territory}:${target.sector}`],1);
assert.equal(player(game,owner).forces[`${target.territory}:${target.sector}`],1);
for (let count=0;count<30 && !game.battle;count++) {
const view=game.active?viewGame(game,game.active):null;
const choice=view?.battleChoices?.find(row=>row.territory===target!.territory &&
(row.chooser??row.attacker)===game.active && [row.attacker,row.defender].includes(game.active!));
if (choice) {
game=act(game,game.active!,{type:'chooseBattle',territory:target.territory,
target:game.active==='emperor'?owner:'emperor'});
break;
}
const next=nextSemutaRicheseCacheKarama(game); assert.ok(next);
game=act(game,next.actor,next.action);
}
assert.ok(game.battle);
for (let count=0;count<30 && game.battle?.preparation?.kind!==power;count++) {
const next=nextSemutaRicheseCacheKarama(game); assert.ok(next);
game=act(game,next.actor,next.action);
}
assert.equal(game.battle?.preparation?.kind,power);
game=act(game,owner,power==='voice'?{type:'voice',kind:'shield',must:false}:{type:'prescience',field:'dial'});
assert.equal(game.response?.kind,power);
assert.ok(game.turnActionPromises?.some(row=>row.event===commitment.event && !row.released));
assert.deepEqual(inventory(game),originalCards);
return {game,kull,karama,counter,truth,event:commitment.event,owner,originalCards};
}
function passDiscard(game:Game):Game {
const pending=game.pendingTreacheryDiscard; assert.ok(pending?.reaction?.stage==='offer');
const event=pending.batch.event;
for (let count=0;game.pendingTreacheryDiscard?.batch.event===event && count<game.players.length;count++) {
const reaction=game.pendingTreacheryDiscard!.reaction; assert.ok(reaction?.stage==='offer');
const seat=game.players.find(row=>!reaction.passed.includes(row.id)); assert.ok(seat);
game=act(game,seat.id,{type:'semutaPass',event});
}
assert.notEqual(game.pendingTreacheryDiscard?.batch.event,event);
return game;
}
for (const power of ['voice','prescience'] as const) for (const outcome of ['decline','success','counter'] as const)
void test(`Basic whole payment Yes survives ${power} cancellation and Kull ${outcome}`,()=>{
const f=source(power,'yes'); let game=f.game;
assert.ok(viewGame(game,'emperor').responseControls?.cancelCards.includes(f.karama));
game=act(game,'emperor',{type:'card',mode:'cancel',card:f.karama});
const reaction=viewGame(game,'choam').kullReaction; assert.ok(reaction);
game=outcome==='decline'?act(game,'choam',{type:'kullDecision',event:reaction.event,decline:true}):
act(game,'choam',{type:'kullDecision',event:reaction.event,source:'printed',card:f.kull});
if (outcome==='counter') game=act(game,'harkonnen',{type:'card',mode:'cancel',card:f.counter});
if (outcome==='success') game=advance(game,state=>!!state.pendingTreacheryDiscard);
while (game.pendingTreacheryDiscard) game=passDiscard(game);
assert.ok(game.turnActionPromises?.some(row=>row.event===f.event && !row.released));
if (outcome==='success') assert.ok(player(game,'emperor').hand.some(card=>card.id===f.karama));
else assert.ok(!player(game,'emperor').hand.some(card=>card.id===f.karama));
assert.deepEqual(inventory(game),f.originalCards);
});
void test('Basic whole payment No remains binding when a Voice cancellation resolves',()=>{
const f=source('voice','no'); let game=f.game;
assert.ok(viewGame(game,'emperor').responseControls?.cancelCards.includes(f.karama));
game=act(game,'emperor',{type:'card',mode:'cancel',card:f.karama});
const reaction=viewGame(game,'choam').kullReaction; assert.ok(reaction);
game=act(game,'choam',{type:'kullDecision',event:reaction.event,decline:true});
while (game.pendingTreacheryDiscard) game=passDiscard(game);
assert.ok(game.turnActionPromises?.some(row=>row.event===f.event && !row.released));
assert.deepEqual(inventory(game),f.originalCards);
});
for (const answer of ['yes','no'] as const)
void test(`the exact Voice cancellation whole-answer ${answer} governs the printed Karama through Kull`,()=>{
const f=source('voice','no'); let game=structuredClone(f.game);
// Recycle the fixture's original physical Truthtrance to ask at the actual
// response; the preceding payment commitment and native battle stay real.
const index=game.discard.findIndex(card=>card.id===f.truth); assert.ok(index>=0);
player(game,'harkonnen').hand.push(game.discard.splice(index,1)[0]);
const window=windowCardOpportunity(game,'karamaBattleCancel'); assert.ok(window);
game=act(game,'harkonnen',{type:'card',card:f.truth});
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'});
}
game=act(game,'harkonnen',{type:'truthAsk',question:{kind:'turnActions',target:'emperor',turn:game.turn,
mixed:{kind:'action',action:{kind:'windowCardPlay',effect:'karamaBattleCancel',source:window.source}}}});
assert.ok(viewGame(game,'emperor').truthTurnActionAnswers?.includes(answer));
game=act(game,'emperor',{type:'truthAnswer',answer});
const promise=game.turnActionPromises?.at(-1); assert.ok(promise);
while (game.pendingTreacheryDiscard) game=passDiscard(game);
if (answer==='no') {
assert.ok(!viewGame(game,'emperor').responseControls?.cancelCards.includes(f.karama));
assert.throws(()=>act(game,'emperor',{type:'card',mode:'cancel',card:f.karama}));
} else {
assert.ok(viewGame(game,'emperor').responseControls?.cancelCards.includes(f.karama));
game=act(game,'emperor',{type:'card',mode:'cancel',card:f.karama});
const reaction=viewGame(game,'choam').kullReaction; assert.ok(reaction);
game=act(game,'choam',{type:'kullDecision',event:reaction.event,decline:true});
while (game.pendingTreacheryDiscard) game=passDiscard(game);
assert.equal(game.turnActionPromises?.find(row=>row.event===promise.event)?.fulfilled,true);
}
assert.deepEqual(inventory(game),f.originalCards);
});
+118
View File
@@ -0,0 +1,118 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createGame, joinGame, newPlayer, viewGame, type Game } from '../game/engine';
import { TERRITORIES } from '../game/board';
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
import { act, advance, clean, inventory, player } from './fixture-kull-richese-semuta';
import { nextSemutaRicheseCacheKarama } from './fixture-semuta-richese-cache-karama';
/** Native five-seat Basic setup, actual Truthtrance answer, cache purchase,
* shipments and battle. Only unopened starting cards and one safe Spice
* position are selected; no wallet, force, response or promise is staged. */
function source(power:'voice'|'prescience') {
const owner=power==='voice'?'beneGesserit':'atreides';
let game=createGame('KULLWHOLECHOAM',newPlayer('choam','CHOAM','choam'),false,['choam','ix']);
for (const id of ['richese','emperor',owner,'harkonnen'] as const) joinGame(game,newPlayer(id,id,id));
game=act(game,'choam',{type:'moduleOption',module:'kullPreview',enabled:true});
for (const seat of game.players) game=act(game,seat.id,{type:'ready'});
game=act(game,'choam',{type:'start'});
assert.equal(game.status,'setup'); assert.ok(game.kullPreview && game.semutaPreview);
const originalCards=inventory(game), selected:Game['deck']=[];
for (const kind of ['kull','filler','karama','filler','karama','truth'] as const) {
const index=game.deck.findIndex(card=>kind==='kull'?card.id==='ix-kull-wahad':
kind==='truth'?card.effect==='truthtrance':kind==='karama'?card.effect==='karama':
card.kind==='worthless' && card.id!=='ix-kull-wahad');
assert.ok(index>=0); selected.push(game.deck.splice(index,1)[0]);
}
game.deck.unshift(...selected);
game=advance(game,state=>state.status==='playing');
const [kull,,karama,,counter,truth]=selected.map(card=>card.id);
for (const [id,card] of [['choam',kull],['emperor',karama],['harkonnen',counter],['harkonnen',truth]] as const)
assert.ok(player(game,id).hand.some(row=>row.id===card));
const safe=game.spiceDeck.findIndex(card=>'territory' in card && !card.discovery); assert.ok(safe>=0);
game.spiceDeck.unshift(game.spiceDeck.splice(safe,1)[0]);
game=advance(game,state=>state.phase===2 && clean(state) && state.choamCharity?.turn===state.turn);
game=act(game,'harkonnen',{type:'card',card:truth});
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'});
}
game=act(game,'harkonnen',{type:'truthAsk',question:{kind:'turnActions',target:'choam',turn:game.turn,
mixed:{kind:'action',action:{kind:'payment',recipient:'richese',minimum:1}}}});
assert.ok(viewGame(game,'choam').truthTurnActionAnswers?.includes('yes'));
game=act(game,'choam',{type:'truthAnswer',answer:'yes'});
const commitment=game.turnActionPromises?.at(-1); assert.ok(commitment);
game=advance(game,state=>player(state,'richese').hand.some(card=>card.id===SEMUTA_DRUG_ID) && clean(state));
let target:{territory:string;sector:number}|null=null;
for (let count=0;count<1000 && game.phase!==6;count++) {
if (game.phase===5 && clean(game) && game.active) {
const actor=game.active, seat=player(game,actor);
if ((actor==='emperor'||actor===owner) && !seat.shipped) {
if (!target) {
const territory=TERRITORIES.find(row=>row.type==='stronghold' && row.sectors.some(s=>s!==game.storm) &&
game.players.every(p=>!Object.keys(p.forces).some(key=>key.startsWith(`${row.id}:`))));
assert.ok(territory);
target={territory:territory.id,sector:territory.sectors.find(s=>s!==game.storm)!};
}
game=act(game,actor,{type:'ship',territory:target.territory,sector:target.sector,amount:1,elite:0,allyPayment:0});
} else game=act(game,actor,{type:'endMovement'});
continue;
}
const next=nextSemutaRicheseCacheKarama(game); assert.ok(next);
game=act(game,next.actor,next.action);
}
assert.equal(game.phase,6); assert.ok(target);
for (let count=0;count<30 && !game.battle;count++) {
const view=game.active?viewGame(game,game.active):null;
const choice=view?.battleChoices?.find(row=>row.territory===target!.territory &&
(row.chooser??row.attacker)===game.active && [row.attacker,row.defender].includes(game.active!));
if (choice) {
game=act(game,game.active!,{type:'chooseBattle',territory:target.territory,
target:game.active==='emperor'?owner:'emperor'});
break;
}
const next=nextSemutaRicheseCacheKarama(game); assert.ok(next);
game=act(game,next.actor,next.action);
}
assert.ok(game.battle);
for (let count=0;count<30 && game.battle?.preparation?.kind!==power;count++) {
const next=nextSemutaRicheseCacheKarama(game); assert.ok(next);
game=act(game,next.actor,next.action);
}
assert.equal(game.battle?.preparation?.kind,power);
game=act(game,owner,power==='voice'?{type:'voice',kind:'shield',must:false}:{type:'prescience',field:'dial'});
assert.equal(game.response?.kind,power);
const row=game.turnActionPromises?.find(promise=>promise.event===commitment.event); assert.ok(row);
assert.ok(!row.fulfilled && !row.released);
assert.deepEqual(inventory(game),originalCards);
return {game,kull,karama,counter,event:commitment.event,originalCards};
}
function passDiscard(game:Game):Game {
const pending=game.pendingTreacheryDiscard; assert.ok(pending?.reaction?.stage==='offer');
const event=pending.batch.event;
for (let count=0;game.pendingTreacheryDiscard?.batch.event===event && count<game.players.length;count++) {
const reaction=game.pendingTreacheryDiscard!.reaction; assert.ok(reaction?.stage==='offer');
const seat=game.players.find(row=>!reaction.passed.includes(row.id)); assert.ok(seat);
game=act(game,seat.id,{type:'semutaPass',event});
}
assert.notEqual(game.pendingTreacheryDiscard?.batch.event,event);
return game;
}
for (const power of ['voice','prescience'] as const) for (const countered of [false,true])
void test(`CHOAM's live whole answer survives Kull ${countered?'counter':'success'} against ${power} cancellation`,()=>{
const f=source(power); let game=f.game;
assert.ok(viewGame(game,'emperor').responseControls?.cancelCards.includes(f.karama));
game=act(game,'emperor',{type:'card',mode:'cancel',card:f.karama});
const reaction=viewGame(game,'choam').kullReaction; assert.ok(reaction);
assert.ok(reaction.plays.some(play=>play.source==='printed' && play.card.id===f.kull));
game=act(game,'choam',{type:'kullDecision',event:reaction.event,source:'printed',card:f.kull});
if (countered) game=act(game,'harkonnen',{type:'card',mode:'cancel',card:f.counter});
else game=advance(game,state=>!!state.pendingTreacheryDiscard);
while (game.pendingTreacheryDiscard) game=passDiscard(game);
const promise=game.turnActionPromises?.find(row=>row.event===f.event); assert.ok(promise);
assert.ok(!promise.released && !promise.fulfilled);
assert.equal(player(game,'emperor').hand.some(card=>card.id===f.karama),!countered);
if (!countered) assert.equal(game.response?.kind,power);
assert.deepEqual(inventory(game),f.originalCards);
});
+92
View File
@@ -0,0 +1,92 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame, type Game } from '../game/engine';
import { TERRITORIES } from '../game/board';
import { act, advance, clean, createKullNativeIxFixture, inventory, player } from './fixture-kull-native-ix';
import { nextKullPurposeStep } from './fixture-kull-purpose';
/** Start from the native public five-seat setup before Spice Blow. The fixture
* selects original unopened cards but all questions, auctions, shipments and
* battle responses below are real actions. */
function answered(target:'ixians'|'emperor') {
const f=createKullNativeIxFixture('ixians');
let game=f.early;
game=act(game,'guild',{type:'card',card:f.truth});
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'});
}
const recipient=target==='ixians'?'emperor':'ixians';
game=act(game,'guild',{type:'truthAsk',question:{kind:'turnActions',target,turn:game.turn,
mixed:{kind:'action',action:{kind:'payment',recipient,minimum:1}}}});
assert.ok(viewGame(game,target).truthTurnActionAnswers?.includes('yes'));
game=act(game,target,{type:'truthAnswer',answer:'yes'});
const row=game.turnActionPromises?.at(-1); assert.ok(row);
return {...f,game,event:row.event};
}
function offer(game:Game,actor:string,card:string) {
assert.ok(viewGame(game,actor).responseControls?.cancelCards.includes(card));
game=act(game,actor,{type:'card',mode:'cancel',card});
const reaction=viewGame(game,'choam').kullReaction; assert.ok(reaction);
return {game,event:reaction.event};
}
for (const outcome of ['decline','success','counter'] as const)
void test(`whole payment answer survives real Guild income cancellation and Kull ${outcome}`,()=>{
const f=answered('ixians');
let game=advance(f.game,state=>state.phase===5 && state.active==='ixians' && clean(state));
game=act(game,'ixians',{type:'ship',territory:'polar_sink',sector:0,amount:1,elite:0,allyPayment:0});
assert.equal(game.response?.kind,'guildIncome');
const choice=offer(game,'ixians',f.karama); game=choice.game;
game=outcome==='decline'?act(game,'choam',{type:'kullDecision',event:choice.event,decline:true}):
act(game,'choam',{type:'kullDecision',event:choice.event,source:'printed',card:f.kull});
if (outcome==='counter') game=act(game,'emperor',{type:'card',mode:'cancel',card:f.counter});
if (outcome==='success') game=advance(game,state=>!state.pendingKull && state.response?.kind!=='choamWorthless');
assert.ok(game.turnActionPromises?.some(row=>row.event===f.event && !row.released));
assert.equal(player(game,'ixians').hand.some(card=>card.id===f.karama),outcome==='success');
assert.deepEqual(inventory(game),f.originalCards);
});
void test('whole payment answer survives real Basic Ixian cyborg-strength cancellation and Kull decline',()=>{
const f=answered('emperor'); let game=f.game;
let target:{territory:string;sector:number}|null=null;
for (let count=0;count<1200 && game.phase!==6;count++) {
if (game.phase===5 && clean(game) && game.active) {
const actor=game.active, seat=player(game,actor);
if ((actor==='emperor'||actor==='ixians') && !seat.shipped) {
if (!target) {
const territory=TERRITORIES.find(row=>row.type==='stronghold' && row.sectors.some(s=>s!==game.storm) &&
game.players.every(p=>!Object.keys(p.forces).some(key=>key.startsWith(`${row.id}:`))));
assert.ok(territory);
target={territory:territory.id,sector:territory.sectors.find(s=>s!==game.storm)!};
}
game=act(game,actor,{type:'ship',territory:target.territory,sector:target.sector,amount:1,
elite:actor==='ixians'?1:0,allyPayment:0});
} else game=act(game,actor,{type:'endMovement'});
continue;
}
const next=nextKullPurposeStep(game); assert.ok(next);
game=act(game,next.actor,next.action);
}
assert.equal(game.phase,6); assert.ok(target);
assert.equal(player(game,'emperor').forces[`${target.territory}:${target.sector}`],1);
assert.equal(player(game,'ixians').elites?.forces[`${target.territory}:${target.sector}`],1);
for (let count=0;count<30 && !game.battle;count++) {
const view=game.active?viewGame(game,game.active):null;
const choice=view?.battleChoices?.find(row=>row.territory===target!.territory &&
(row.chooser??row.attacker)===game.active && [row.attacker,row.defender].includes(game.active!));
if (choice) {
game=act(game,game.active!,{type:'chooseBattle',territory:target.territory,
target:game.active==='emperor'?'ixians':'emperor'});
break;
}
const next=nextKullPurposeStep(game); assert.ok(next);
game=act(game,next.actor,next.action);
}
assert.equal(game.response?.kind,'eliteStrength');
const choice=offer(game,'emperor',f.counter); game=choice.game;
game=act(game,'choam',{type:'kullDecision',event:choice.event,decline:true});
assert.ok(game.turnActionPromises?.some(row=>row.event===f.event && !row.released));
assert.ok(!player(game,'emperor').hand.some(card=>card.id===f.counter));
assert.deepEqual(inventory(game),f.originalCards);
});
@@ -0,0 +1,68 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createGame, joinGame, newPlayer, viewGame, type Game } from '../game/engine';
import { act, advance, clean, inventory, player } from './fixture-kull-native-ix';
/** Genuine public Basic setup and movement; only unopened card and Spice
* order is selected. The live whole answer and both overlapping response
* windows arise through original actions, not installed pending state. */
function source() {
let game=createGame('KULLBGGUILD',newPlayer('choam','CHOAM','choam'),false,['choam','ix']);
for (const id of ['emperor','beneGesserit','guild','harkonnen'] as const)
joinGame(game,newPlayer(id,id,id));
game=act(game,'choam',{type:'moduleOption',module:'kullPreview',enabled:true});
for (const seat of game.players) game=act(game,seat.id,{type:'ready'});
game=act(game,'choam',{type:'start'});
assert.equal(game.status,'setup'); assert.ok(game.kullPreview);
const originalCards=inventory(game), selected:Game['deck']=[];
for (const kind of ['kull','karama','filler','truth','karama','filler'] as const) {
const index=game.deck.findIndex(card=>kind==='kull'?card.id==='ix-kull-wahad':
kind==='truth'?card.effect==='truthtrance':kind==='karama'?card.effect==='karama':
card.kind==='worthless' && card.id!=='ix-kull-wahad');
assert.ok(index>=0); selected.push(game.deck.splice(index,1)[0]);
}
game.deck.unshift(...selected);
game=advance(game,state=>state.status==='playing');
const [,karama,,truth]=selected.map(card=>card.id);
assert.ok(player(game,'emperor').hand.some(card=>card.id===karama));
assert.ok(player(game,'guild').hand.some(card=>card.id===truth));
const safe=game.spiceDeck.findIndex(card=>'territory' in card && !card.discovery); assert.ok(safe>=0);
game.spiceDeck.unshift(game.spiceDeck.splice(safe,1)[0]);
game=advance(game,state=>state.phase===2 && clean(state) && state.choamCharity?.turn===state.turn);
game=act(game,'guild',{type:'card',card:truth});
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'});
}
game=act(game,'guild',{type:'truthAsk',question:{kind:'turnActions',target:'emperor',turn:game.turn,
mixed:{kind:'action',action:{kind:'payment',recipient:'harkonnen',minimum:1}}}});
assert.ok(viewGame(game,'emperor').truthTurnActionAnswers?.includes('yes'));
game=act(game,'emperor',{type:'truthAnswer',answer:'yes'});
const promise=game.turnActionPromises?.at(-1); assert.ok(promise);
game=advance(game,state=>state.phase===5 && state.active==='emperor' && clean(state));
game=act(game,'emperor',{type:'ship',territory:'polar_sink',sector:0,amount:1,elite:0,allyPayment:0});
assert.equal(game.response?.kind,'guildIncome');
assert.equal(game.decision?.kind,'advisor');
assert.ok(!promise.released);
return {game,karama,event:promise.event,originalCards};
}
void test('live whole-answer preflight fences Guild income cancellation without consuming a simultaneous BG arrival decision',()=>{
const f=source(); let game=f.game;
const before=structuredClone(game);
assert.ok(!viewGame(game,'emperor').responseControls?.cancelCards.includes(f.karama));
assert.throws(()=>act(game,'emperor',{type:'card',mode:'cancel',card:f.karama}));
assert.deepEqual(game,before);
assert.equal(game.pendingKull ?? null,null);
assert.deepEqual(game.decision,before.decision);
assert.ok(game.turnActionPromises?.some(row=>row.event===f.event && !row.released));
for (let count=0;game.response?.kind==='guildIncome' && count<game.players.length;count++) {
const seat=game.players.find(row=>!game.response!.passed.includes(row.id)); assert.ok(seat);
game=act(game,seat.id,{type:'passResponse'});
}
assert.equal(game.response,null);
assert.deepEqual(game.decision,before.decision);
game=act(game,'beneGesserit',{type:'decision',accept:false});
assert.equal(game.decision,null);
assert.deepEqual(inventory(game),f.originalCards);
});