Compose phase-wide and Richese bid commitments
Verify and publish checkpoint container / container (push) Successful in 11m13s

This commit is contained in:
Quintine committed 2026-11-16 19:31:35 +11:00
1 parent 38f1684e03
commit 9e020ccd64
12 files changed
+664 -13

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {jointRicheseBidCompletionRange,richeseBidsWithPhaseBounds} from '../game/joint-richese-bids';
import type {RicheseBidOpportunity,RicheseBidPromise} from '../game/richese-bid-promises';
import type {PhaseBidPromise} from '../game/turn-bid-promises';
const opportunity: RicheseBidOpportunity = {turn:2,event:'lot',player:'p',minimum:2,maximum:10};
const richese = (id:string,minimum:number,answer:boolean): RicheseBidPromise =>
({id,turn:2,event:'lot',player:'p',asker:'a',minimum,answer});
const phase = (event:string,minimum:number,answer:boolean): PhaseBidPromise =>
({event,turn:2,player:'p',asker:'a',minimum,answer});
void test('native and phase-wide answers share one funded Richese declaration', () => {
const native = [richese('r-yes',4,true),richese('r-no',9,false)];
const all = [phase('p-yes',7,true),phase('p-no',8,false)];
const before = structuredClone({native,all});
assert.deepEqual(jointRicheseBidCompletionRange(native,all,opportunity),{minimum:7,maximum:7});
assert.deepEqual({native,all},before,'A quote cannot mutate either actual ledger');
assert.equal(jointRicheseBidCompletionRange(native,[...all,phase('contradiction',7,false)],opportunity),null);
});
void test('a separately witnessed future phase Yes does not relax current No caps', () => {
const native = [richese('current-yes',3,true)];
const all = [phase('later-yes',7,true),phase('all-no',6,false)];
assert.equal(jointRicheseBidCompletionRange(native,all,opportunity),null);
assert.deepEqual(jointRicheseBidCompletionRange(native,all,opportunity,{includePhaseYes:false}),
{minimum:3,maximum:5});
});
void test('only this bidder’s live phase bounds enter the original event without ID collisions', () => {
const native = [richese('phase-any:live',2,false)];
const all = [phase('live',5,false),{...phase('other',1,true),player:'q'},
{...phase('earlier',1,true),turn:1},{...phase('fulfilled',1,true),fulfilled:true},
{...phase('released',1,true),released:true}];
const rows = richeseBidsWithPhaseBounds(native,all,opportunity);
assert.equal(rows.length,2);
assert.equal(rows[0],native[0]);
assert.notEqual(rows[1].id,native[0].id);
assert.deepEqual({...rows[1],id:'synthetic'},
{id:'synthetic',turn:2,event:'lot',player:'p',asker:'a',minimum:5,answer:false});
assert.deepEqual(jointRicheseBidCompletionRange([],all,opportunity),{minimum:2,maximum:4});
});
void test('a synthetic bound requires the actual bidder, turn and lot event', () => {
assert.throws(() => richeseBidsWithPhaseBounds([],[],{...opportunity,event:''}));
assert.throws(() => richeseBidsWithPhaseBounds([],[],{...opportunity,player:' p'}));
assert.throws(() => richeseBidsWithPhaseBounds([],[],{...opportunity,turn:0}));
});
@@ -0,0 +1,93 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createElement, isValidElement, type ReactElement, type ReactNode } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { PhaseAnyBidGuideButton, PhaseAnyBidPromises } from '../components/phase-any-bid-promises';
import { RicheseBidPromiseGuide, RicheseBidPromisePanel } from '../components/richese-bid-promise-panel';
import { MixedRicheseBidPromises } from '../components/mixed-richese-bid-promises';
import { viewGame, type Action, type Game } from '../game/engine';
import { createTruthRicheseBidFixture } from './fixture-truth-richese-bid';
import { createTruthRicheseSilentFixture } from './fixture-truth-richese-silent';
import { actTruthtranceRichesePromises as act, passTruthRicheseFreshDiscard,
truthtranceRichesePromisesInventory as inventory, truthtranceRichesePromisesPlayer as player } from './fixture-truthtrance-richese-promises';
type Props = { children?: ReactNode; [key:string]:unknown };
type Fixture = ReturnType<typeof createTruthRicheseBidFixture> | ReturnType<typeof createTruthRicheseSilentFixture>;
type Kind = 'richeseBid' | 'mixedRicheseBid';
const elements = (node:ReactNode):ReactElement<Props>[] => Array.isArray(node) ? node.flatMap(elements) :
!isValidElement<Props>(node) ? [] : [node,...elements(node.props.children)];
function answer(game:Game,f:Fixture,card:string,question:Record<string,unknown>) {
let state = act(game,f.asker,{type:'card',card});
for (let n=0;state.truthtrance?.stage === 'priority' && n<state.players.length;n++) {
const actor=state.players.find(row => !state.truthtrance!.passed.includes(row.id)); assert.ok(actor);
state=act(state,actor.id,{type:'truthPass'});
}
assert.equal(state.truthtrance?.stage,'ask');
state=act(state,f.asker,{type:'truthAsk',question});
return passTruthRicheseFreshDiscard(act(state,f.target,{type:'truthAnswer',answer:'yes'}));
}
/** Real Advanced public start and original cache auction; stage only a second
* original unopened Truth into the asker's hand. The source fixture documents
* its selected unopened deal and Spice order and native scalar rolls. */
function joint(method:'onceAround'|'silent',kind:Kind) {
const f:Fixture=method === 'onceAround' ? createTruthRicheseBidFixture(true) : createTruthRicheseSilentFixture(true);
let game=structuredClone(f.game);
const at=game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth); assert.ok(at >= 0);
const [second]=game.deck.splice(at,1); player(game,f.asker).hand.push(second);
assert.deepEqual(inventory(game),f.originalCards);
if(method === 'onceAround') game=act(game,f.asker,{type:'richeseBid',event:f.lot,amount:null});
game=answer(game,f,f.truth,{kind:'phaseAnyBid',target:f.target,turn:game.turn,minimum:4});
const question=kind === 'richeseBid' ? {kind,target:f.target,turn:game.turn,event:f.lot,minimum:6} :
{kind,target:f.target,turn:game.turn,event:f.lot,mixed:{kind:'and',terms:[
{kind:'fact',fact:{kind:'spice',compare:'gte',value:10}},{kind:'action',action:{minimum:6}},
]}};
game=answer(game,f,second.id,question);
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.target && row.answer));
assert.ok(game.richeseBidPromises?.some(row => row.player === f.target && row.answer));
return {game,f};
}
for (const method of ['onceAround','silent'] as const) for (const kind of ['richeseBid','mixedRicheseBid'] as const) void test(
`real Advanced ${method} ${kind} joint controls render and submit one shared native guide`,() => {
const {game,f}=joint(method,kind), view=viewGame(game,f.target), sent:Action[]=[];
assert.ok(view.phaseAnyBidGuide && view.richeseBidPromiseGuide);
assert.deepEqual(view.phaseAnyBidGuide.action,view.richeseBidPromiseGuide.action);
assert.equal(view.phaseAnyBidGuide.action.amount,6);
const phaseHtml=renderToStaticMarkup(createElement(PhaseAnyBidPromises,{game:view,busy:false,send() {}}));
assert.match(phaseHtml,/Your any-auction bid promises/);
assert.match(phaseHtml,/data-testid="phase-any-bid-guide"/);
const phaseProps={game:view,busy:false,send(action:Action){sent.push(action);}};
const phaseButton=PhaseAnyBidGuideButton(phaseProps); assert.ok(phaseButton);
const localProps={promises:view.richeseBidPromises,guide:view.richeseBidPromiseGuide,game:view,busy:false,
act(action:Action){sent.push(action);}};
const mixedProps={game:view,busy:false,send(action:Action){sent.push(action);}};
const localHtml=kind === 'richeseBid'
? renderToStaticMarkup(createElement(RicheseBidPromisePanel,localProps))
: renderToStaticMarkup(createElement(MixedRicheseBidPromises,mixedProps));
assert.match(localHtml,kind === 'richeseBid' ? /Your (?:Once Around|Silent) bid promises/ : /Your mixed Richese bid promises/);
const localButton=kind === 'richeseBid' ? RicheseBidPromiseGuide(localProps) :
elements(MixedRicheseBidPromises(mixedProps)).find(node => node.props['data-testid'] === 'mixed-richese-bid-promise-guide');
assert.ok(localButton);
const clickPhase=() => phaseButton.props.onClick();
const clickLocal=() => (localButton.props.onClick as () => void)();
clickPhase(); clickLocal();
assert.deepEqual(sent,[view.phaseAnyBidGuide.action,view.phaseAnyBidGuide.action]);
phaseProps.busy=true; localProps.busy=true; mixedProps.busy=true;
clickPhase(); clickLocal(); assert.equal(sent.length,2);
phaseProps.busy=false; localProps.busy=false; mixedProps.busy=false;
const originalEvent=view.richeseAuction!.event;
view.richeseAuction!.event='stale-lot';
clickPhase(); clickLocal(); assert.equal(sent.length,2);
view.richeseAuction!.event=originalEvent;
view.phaseAnyBidPromises[0].fulfilled=true;
clickPhase(); clickLocal(); assert.equal(sent.length,2,'A closed phase answer invalidates either shared callback');
view.phaseAnyBidPromises[0].fulfilled=false;
const localReceipt=kind === 'richeseBid' ? view.richeseBidPromises[0] : view.mixedRicheseBidPromises[0];
assert.ok(localReceipt); localReceipt.fulfilled=true;
clickPhase(); clickLocal(); assert.equal(sent.length,2,'A closed local answer invalidates either shared callback');
localReceipt.fulfilled=false;
const applied=act(game,f.target,sent[0]);
assert.ok(applied.phaseAnyBidPromises?.some(row => row.player === f.target && row.fulfilled));
assert.ok(applied.richeseBidPromises?.some(row => row.player === f.target && row.fulfilled));
assert.deepEqual(inventory(applied),f.originalCards);
});
+288
View File
@@ -0,0 +1,288 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { advanceAuctionClock, synchronizeAuctionClock, viewGame, type Action, type Game } from '../game/engine';
import { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import { createTruthRicheseBidFixture } from './fixture-truth-richese-bid';
import { createTruthRicheseSilentFixture } from './fixture-truth-richese-silent';
import { actTruthtranceRichesePromises as act, advanceTruthtranceRichesePromises as advance,
createTruthtranceRichesePromisesFixture as baseFixture, passTruthRicheseFreshDiscard,
truthtranceRichesePromisesClean as clean, truthtranceRichesePromisesInventory as inventory,
truthtranceRichesePromisesPlayer as player } from './fixture-truthtrance-richese-promises';
type Method = 'onceAround' | 'silent';
type Kind = 'richeseBid' | 'mixedRicheseBid';
type Answer = 'yes' | 'no';
type Fixture = ReturnType<typeof createTruthRicheseBidFixture> | ReturnType<typeof createTruthRicheseSilentFixture>;
function reject(game:Game, actor:string, action:Action) {
const before = structuredClone(game);
assert.throws(() => act(game,actor,action));
assert.deepEqual(game,before,'A rejected native action keeps its input unchanged');
}
/** The starting games, sale and native funds are real. To obtain two questions
* in one turn, move the second original Truthtrance from the unopened deck to
* the same asker's hand; the underlying fixture stages its original deal,
* unopened Spice order and native scalar rolls. */
function source(method:Method, advanced = false) {
const f:Fixture = method === 'silent' ? createTruthRicheseSilentFixture(advanced) : createTruthRicheseBidFixture(advanced);
let game = structuredClone(f.game);
const index = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
assert.ok(index >= 0);
const [second] = game.deck.splice(index,1); player(game,f.asker).hand.push(second);
assert.deepEqual(inventory(game),f.originalCards);
if (method === 'onceAround') game = act(game,f.asker,{type:'richeseBid',event:f.lot,amount:null});
assert.ok(method === 'silent' || game.richeseAuction?.active === f.target);
return {f,game,second:second.id};
}
function ask(game:Game, f:Fixture, card:string, question:Record<string,unknown>, answer:Answer) {
let current = act(game,f.asker,{type:'card',card});
for (let n = 0; current.truthtrance?.stage === 'priority' && n < current.players.length; n++) {
const actor = current.players.find(row => !current.truthtrance!.passed.includes(row.id)); assert.ok(actor);
current = act(current,actor.id,{type:'truthPass'});
}
assert.equal(current.truthtrance?.stage,'ask');
current = act(current,f.asker,{type:'truthAsk',question});
const view = viewGame(current,f.target);
const options = question.kind === 'phaseAnyBid' ? view.truthPhaseAnyBidAnswers :
question.kind === 'richeseBid' ? view.truthRicheseBidAnswers : view.truthMixedRicheseBidAnswers;
assert.ok(options?.includes(answer),`The compatible ${String(question.kind)} ${answer} must be offered`);
return passTruthRicheseFreshDiscard(act(current,f.target,{type:'truthAnswer',answer}));
}
function questions(f:Fixture, game:Game, kind:Kind, phaseAnswer:Answer, _lotAnswer:Answer) {
// Every pair has a joint funded witness: Yes/Yes requires six; Yes/No and
// No/Yes each permit four; No/No permits a two-spice bid or a pass.
const phaseMinimum = phaseAnswer === 'yes' ? 4 : 6;
const lotMinimum = phaseAnswer === 'yes' ? 6 : 4;
const phase = {kind:'phaseAnyBid',target:f.target,turn:game.turn,minimum:phaseMinimum};
const lot = kind === 'richeseBid'
? {kind,target:f.target,turn:game.turn,event:f.lot,minimum:lotMinimum}
: {kind,target:f.target,turn:game.turn,event:f.lot,mixed:{kind:'and',terms:[
{kind:'fact',fact:{kind:'spice',compare:'gte',value:10}},
{kind:'action',action:{minimum:lotMinimum}},
]}};
return {phase,lot,phaseMinimum,lotMinimum};
}
for (const method of ['onceAround','silent'] as const)
for (const kind of ['richeseBid','mixedRicheseBid'] as const)
for (const first of ['phase','lot'] as const)
for (const phaseAnswer of ['yes','no'] as const)
for (const lotAnswer of ['yes','no'] as const) void test(
`Basic ${method} ${kind} ${first} first: phase ${phaseAnswer} and lot ${lotAnswer} share native bid`, () => {
const f = source(method), q = questions(f.f,f.game,kind,phaseAnswer,lotAnswer);
const firstQuestion = first === 'phase' ? q.phase : q.lot;
const secondQuestion = first === 'phase' ? q.lot : q.phase;
let game = ask(f.game,f.f,f.f.truth,firstQuestion,first === 'phase' ? phaseAnswer : lotAnswer);
game = ask(game,f.f,f.second,secondQuestion,first === 'phase' ? lotAnswer : phaseAnswer);
const phase = game.phaseAnyBidPromises?.find(row => row.player === f.f.target); assert.ok(phase);
const native = game.richeseBidPromises?.find(row => row.player === f.f.target); assert.ok(native);
assert.equal(phase.answer,phaseAnswer === 'yes'); assert.equal(native.answer,lotAnswer === 'yes');
const view = viewGame(game,f.f.target), phaseGuide = view.phaseAnyBidGuide?.action;
const lotGuide = view.richeseBidPromiseGuide?.action;
assert.ok(phaseGuide || lotGuide,'The combined answer has a native guide');
for (const guide of [phaseGuide,lotGuide]) if (guide) {
assert.equal(guide.type,'richeseBid');
assert.doesNotThrow(() => act(game,f.f.target,guide),'Each offered guide must honor both answers');
}
for (const difficulty of DIFFICULTIES) {
const bot = viewGame(game,f.f.target); bot.players.find(row => row.id === f.f.target)!.bot = difficulty;
const chosen = botActions(bot)[0]; assert.ok(chosen,difficulty);
assert.equal(chosen.type,'richeseBid');
assert.doesNotThrow(() => act(game,f.f.target,chosen),difficulty);
}
const packet = phaseGuide ?? lotGuide!;
if (packet.phaseAnyBidPromiseEvent !== undefined)
reject(game,f.f.target,{...packet,phaseAnyBidPromiseEvent:'stale-phase-event'});
if (packet.richeseBidPromiseId !== undefined)
reject(game,f.f.target,{...packet,richeseBidPromiseId:'stale-lot-promise'});
if (lotAnswer === 'yes')
reject(game,f.f.target,{type:'richeseBid',event:f.f.lot,amount:method === 'silent' ? 0 : null});
if (phaseAnswer === 'no')
reject(game,f.f.target,{type:'richeseBid',event:f.f.lot,amount:q.phaseMinimum,allyPayment:0});
if (lotAnswer === 'no')
reject(game,f.f.target,{type:'richeseBid',event:f.f.lot,amount:q.lotMinimum,allyPayment:0});
const amount = lotAnswer === 'yes' ? q.lotMinimum : phaseAnswer === 'yes' ? q.phaseMinimum : 2;
const before = player(game,f.f.target).spice;
game = act(game,f.f.target,{type:'richeseBid',event:f.f.lot,amount,allyPayment:0});
assert.equal(player(game,f.f.target).spice,before,'A bid is not its eventual invoice');
assert.equal(!!game.phaseAnyBidPromises?.find(row => row.event === phase.event)?.fulfilled,phaseAnswer === 'yes');
const accepted = game.richeseBidPromises?.find(row => row.id === native.id); assert.ok(accepted?.fulfilled);
if (method === 'silent') {
assert.equal(viewGame(game,f.f.target).richeseAuction?.ownBid,amount);
assert.equal(viewGame(game,f.f.owner).richeseAuction?.revealedBids,null);
assert.equal(viewGame(game,f.f.owner).richeseAuction?.ownBid,null);
game = act(game,f.f.asker,{type:'richeseBid',event:f.f.lot,amount:0,allyPayment:0});
game = act(game,f.f.owner,{type:'richeseBid',event:f.f.lot,amount:0,allyPayment:0});
} else if (game.richeseAuction?.event === f.f.lot && game.richeseAuction.active === f.f.owner) {
game = act(game,f.f.owner,{type:'richeseBid',event:f.f.lot,amount:null});
}
assert.ok(player(game,f.f.target).hand.some(card => card.id === f.f.card));
assert.equal(player(game,f.f.target).spice,before-amount);
assert.deepEqual(inventory(game),f.f.originalCards);
});
for (const method of ['onceAround','silent'] as const) for (const first of ['phase','lot'] as const) void test(
`Advanced ${method} ${first} first preserves two independently answered Yes requirements`, () => {
const f = source(method,true), q = questions(f.f,f.game,'richeseBid','yes','yes');
let game = ask(f.game,f.f,f.f.truth,first === 'phase' ? q.phase : q.lot,'yes');
game = ask(game,f.f,f.second,first === 'phase' ? q.lot : q.phase,'yes');
const before = player(game,f.f.target).spice;
const guide = viewGame(game,f.f.target).phaseAnyBidGuide?.action ?? viewGame(game,f.f.target).richeseBidPromiseGuide?.action;
assert.ok(guide); assert.equal(guide.type,'richeseBid'); assert.equal(guide.amount,6);
game = act(game,f.f.target,guide);
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.f.target && row.fulfilled));
assert.ok(game.richeseBidPromises?.some(row => row.player === f.f.target && row.fulfilled));
assert.equal(player(game,f.f.target).spice,before);
if (method === 'silent') {
assert.equal(viewGame(game,f.f.owner).richeseAuction?.revealedBids,null);
game = act(game,f.f.asker,{type:'richeseBid',event:f.f.lot,amount:0,allyPayment:0});
game = act(game,f.f.owner,{type:'richeseBid',event:f.f.lot,amount:0,allyPayment:0});
} else if (game.richeseAuction?.event === f.f.lot && game.richeseAuction.active === f.f.owner)
game = act(game,f.f.owner,{type:'richeseBid',event:f.f.lot,amount:null});
assert.ok(player(game,f.f.target).hand.some(card => card.id === f.f.card));
assert.equal(player(game,f.f.target).spice,before-6);
assert.deepEqual(inventory(game),f.f.originalCards);
});
for (const method of ['onceAround','silent'] as const) for (const first of ['phase','lot'] as const) void test(
`${method} live lot No permits an all-auction Yes in the actual later ordinary auction, ${first} first`, () => {
const f = source(method), phase = {kind:'phaseAnyBid',target:f.f.target,turn:f.game.turn,minimum:6};
const lot = {kind:'richeseBid',target:f.f.target,turn:f.game.turn,event:f.f.lot,minimum:4};
let game = ask(f.game,f.f,f.f.truth,first === 'phase' ? phase : lot,first === 'phase' ? 'yes' : 'no');
game = ask(game,f.f,f.second,first === 'phase' ? lot : phase,first === 'phase' ? 'no' : 'yes');
const guide = viewGame(game,f.f.target).phaseAnyBidGuide?.action ?? viewGame(game,f.f.target).richeseBidPromiseGuide?.action;
assert.ok(guide);
assert.doesNotThrow(() => act(game,f.f.target,guide));
if (typeof guide.amount === 'number') assert.ok(guide.amount < 4,'The current-lot No is never bypassed');
game = act(game,f.f.target,guide);
const promise = game.phaseAnyBidPromises?.find(row => row.player === f.f.target); assert.ok(promise);
assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false);
game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.f.target,
[], {position:'first',method});
const later = viewGame(game,f.f.target).phaseAnyBidGuide; assert.ok(later);
assert.equal(later.action.type,'bid'); assert.ok(Number(later.action.amount) >= 6);
game = act(game,f.f.target,later.action);
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === promise.event && row.fulfilled));
assert.deepEqual(inventory(game),f.f.originalCards);
});
void test('legacy ordinary-only No does not restrict the physical Richese cache bid', () => {
const f = baseFixture({advanced:false});
let game = act(structuredClone(f.earlySource),f.asker,f.declarationStep.action);
game = advance(game,state => state.truthtrance?.stage === 'ask');
game = act(game,f.asker,{type:'truthAsk',question:{kind:'phaseBid',target:f.emperor,turn:game.turn,minimum:4}});
game = passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer:'no'}));
game = advance(game,state => clean(state) && !!state.richeseAuction && !state.richeseAuction.outcome,
[], {position:'first',method:'silent'});
const lot = game.richeseAuction!;
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0});
const legacy = game.phaseBidPromises?.find(row => row.player === f.emperor); assert.ok(legacy);
assert.equal(legacy.answer,false); assert.equal(!!legacy.fulfilled,false); assert.equal(!!legacy.released,false);
assert.deepEqual(inventory(game),f.originalCards);
});
for (const advanced of [false,true]) for (const method of ['onceAround','silent'] as const)
for (const first of ['phase','lot'] as const) for (const claim of [false,true]) void test(
`${advanced ? 'Advanced' : 'Basic'} ${method} ${first} first: second queued Truth offers Semuta ${claim ? 'claim' : 'pass'}`, () => {
const f = source(method,advanced), cache = f.game.richeseCache!;
const at = cache.findIndex(card => card.effect === 'semutaDrug'); assert.ok(at >= 0);
// Additional conserved supplement: move the original Semuta from the
// cache to Richese's hand; the native offered cache card is untouched.
const [semuta] = cache.splice(at,1); player(f.game,f.f.owner).hand.push(semuta);
assert.deepEqual(inventory(f.game),f.f.originalCards);
const lot = structuredClone(f.game.richeseAuction), funding = structuredClone(f.game.richeseFunding);
const q = questions(f.f,f.game,'richeseBid','yes','yes');
let game = act(f.game,f.f.asker,{type:'card',card:f.f.truth,cards:[f.second]});
for (let n = 0; game.truthtrance?.stage === 'priority' && n < game.players.length; n++) {
const actor = game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(actor);
game = act(game,actor.id,{type:'truthPass'});
}
assert.equal(game.truthtrance?.stage,'ask');
assert.deepEqual(game.truthtrance?.queue.map(row => row.card),[f.f.truth,f.second]);
game = act(game,f.f.asker,{type:'truthAsk',question:first === 'phase' ? q.phase : q.lot});
game = act(game,f.f.target,{type:'truthAnswer',answer:'yes'});
assert.equal(game.pendingTreacheryDiscard?.continuation.kind,'truthtranceDiscard');
game = passTruthRicheseFreshDiscard(game);
assert.equal(game.truthtrance?.stage,'ask');
assert.deepEqual(game.truthtrance?.queue.map(row => row.card),[f.second]);
game = act(game,f.f.asker,{type:'truthAsk',question:first === 'phase' ? q.lot : q.phase});
game = act(game,f.f.target,{type:'truthAnswer',answer:'yes'});
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.equal(pending.continuation.kind,'truthtranceDiscard');
assert.equal(pending.batch.entries[0].card.id,f.second);
assert.equal(viewGame(game,f.f.owner).semutaReaction?.canCommit,true);
const phase = structuredClone(game.phaseAnyBidPromises), native = structuredClone(game.richeseBidPromises);
assert.deepEqual(game.richeseAuction,lot); assert.deepEqual(game.richeseFunding,funding);
game = claim ? act(game,f.f.owner,{type:'semutaCommit',event:pending.batch.event}) : passTruthRicheseFreshDiscard(game);
assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance,null);
assert.deepEqual(game.phaseAnyBidPromises,phase); assert.deepEqual(game.richeseBidPromises,native);
assert.deepEqual(game.richeseAuction,lot); assert.deepEqual(game.richeseFunding,funding);
assert.equal(player(game,f.f.owner).hand.some(card => card.id === f.second),claim);
assert.equal(game.discard.some(card => card.id === semuta.id),claim);
const guide = viewGame(game,f.f.target).phaseAnyBidGuide?.action ?? viewGame(game,f.f.target).richeseBidPromiseGuide?.action;
assert.ok(guide); assert.equal(guide.amount,6);
game = act(game,f.f.target,guide);
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.f.target && row.fulfilled));
assert.ok(game.richeseBidPromises?.some(row => row.player === f.f.target && row.fulfilled));
assert.deepEqual(inventory(game),f.f.originalCards);
});
void test('an opposing raise releases the impossible local Yes but preserves and later fulfills phase-wide Yes', () => {
const f = createTruthRicheseBidFixture(false);
let game = structuredClone(f.game);
// The original second Truth is moved from the unopened deck, without
// injecting a bid, wallet, promise or later auction state.
const index = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth); assert.ok(index >= 0);
const [second] = game.deck.splice(index,1); player(game,f.asker).hand.push(second);
assert.deepEqual(inventory(game),f.originalCards);
assert.equal(game.richeseAuction?.active,f.asker);
game = ask(game,f,f.truth,{kind:'phaseAnyBid',target:f.target,turn:game.turn,minimum:4},'yes');
game = ask(game,f,second.id,{kind:'richeseBid',target:f.target,turn:game.turn,event:f.lot,minimum:4},'yes');
const lot = game.richeseBidPromises?.find(row => row.player === f.target); assert.ok(lot);
const phase = game.phaseAnyBidPromises?.find(row => row.player === f.target); assert.ok(phase);
game = act(game,f.asker,{type:'richeseBid',event:f.lot,amount:10,allyPayment:0});
assert.equal(game.richeseAuction?.active,f.target);
const released = game.richeseBidPromises?.find(row => row.id === lot.id); assert.ok(released);
assert.equal(!!released.released,true); assert.equal(!!released.fulfilled,false);
const retained = game.phaseAnyBidPromises?.find(row => row.event === phase.event); assert.ok(retained);
assert.equal(!!retained.released,false); assert.equal(!!retained.fulfilled,false);
game = act(game,f.target,{type:'richeseBid',event:f.lot,amount:null});
game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.target,
[], {position:'first',method:'onceAround'});
const guide = viewGame(game,f.target).phaseAnyBidGuide; assert.ok(guide);
assert.equal(guide.action.type,'bid'); assert.ok(Number(guide.action.amount) >= 4);
game = act(game,f.target,guide.action);
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === phase.event && row.fulfilled));
assert.ok(game.richeseBidPromises?.some(row => row.id === lot.id && row.released));
assert.deepEqual(inventory(game),f.originalCards);
});
/** Genuine last-position cache, preceded by a real ordinary purchase. The
* undealt second Truth is the only physical custody supplement. */
void test('final Once Around cache clock executes one bid satisfying both live Yes answers', () => {
const f = baseFixture({advanced:false}), options = {position:'last' as const,method:'onceAround' as const};
let game = advance(structuredClone(f.earlySource),state => clean(state) && !!state.auction,[],options);
const secondIndex = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth); assert.ok(secondIndex >= 0);
const [second] = game.deck.splice(secondIndex,1); player(game,f.asker).hand.push(second);
assert.deepEqual(inventory(game),f.originalCards);
game = act(game,f.richese,{type:'bid',amount:1,allyPayment:0});
game = advance(game,state => clean(state) && !!state.richeseAuction && !state.richeseAuction.outcome,[],options);
const lot = game.richeseAuction!;
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:1,allyPayment:0});
assert.equal(game.richeseAuction?.active,f.asker);
const sf = {game,asker:f.asker,target:f.richese,owner:f.richese,lot:lot.event,card:lot.cardId,truth:f.truth,
original:f,originalCards:f.originalCards,staging:f.staging};
game = ask(game,sf,f.truth,{kind:'phaseAnyBid',target:f.richese,turn:game.turn,minimum:3},'yes');
game = ask(game,sf,second.id,{kind:'richeseBid',target:f.richese,turn:game.turn,event:lot.event,minimum:4},'yes');
game = act(game,f.asker,{type:'richeseBid',event:lot.event,amount:null});
assert.equal(game.richeseAuction?.active,f.richese);
reject(game,f.richese,{type:'richeseBid',event:lot.event,amount:null});
const guide = viewGame(game,f.richese).phaseAnyBidGuide?.action ?? viewGame(game,f.richese).richeseBidPromiseGuide?.action;
assert.ok(guide); assert.equal(guide.amount,4);
const armed = synchronizeAuctionClock(game,1_000,'joint-richese:0');
const expired = advanceAuctionClock(armed,11_000,'joint-richese:0');
assert.ok(expired.phaseAnyBidPromises?.some(row => row.player === f.richese && row.fulfilled));
assert.ok(expired.richeseBidPromises?.some(row => row.player === f.richese && row.fulfilled));
assert.deepEqual(inventory(expired),f.originalCards);
});