Compose Semuta with completed paid Box discard

This commit is contained in:
Quintine committed 2026-09-30 01:25:22 +10:00
1 parent 9ea50a792e
commit 0e9945e333
9 files changed
+146 -28

No files matched your search

+46
View File
@@ -166,3 +166,49 @@ void test('an impossible saved all-passed offer rejects instead of waiting forev
assert.throws(() => normalizeAutomaticGame(corrupt));
assert.equal(JSON.stringify(corrupt), before);
});
void test('a completed paid Box discard can be claimed before resumption without repeating its search', () => {
const { g, semuta, hajr } = fixture();
player(g, 'a').hand = [];
g.deck.push(hajr);
const box = take(g, 'richese-nullentropy-box');
player(g, 'a').hand.push(box);
g.discard.push(g.deck.shift()!, g.deck.shift()!);
g.phase = 4;
g.active = null;
const original = inventory(g);
const spice = player(g, 'a').spice;
const paid = applyAction(g, 'a', { type: 'card', card: box.id });
assert.ok(paid.pendingNullentropy);
assert.equal(player(paid, 'a').spice, spice - 2);
const target = paid.discard[0].id;
const pending = applyAction(paid, 'a', {
type: 'decision', event: paid.pendingNullentropy.event, card: target,
});
assert.equal(pending.pendingTreacheryDiscard?.continuation.kind, 'nullentropyDiscard');
assert.equal(pending.pendingTreacheryDiscard?.reaction?.stage, 'offer');
const event = pending.pendingTreacheryDiscard!.batch.event;
const shuffled = pending.discard.filter(card => card.id !== box.id).map(card => card.id);
assert.equal(viewGame(pending, 'r').semutaReaction?.canCommit, true);
assert.equal(viewGame(pending, 'a').semutaReaction?.canCommit, false);
assert.deepEqual(viewGame(pending, 'r').semutaReaction?.candidates, []);
assert.deepEqual(normalizeAutomaticGame(reload(pending)), reload(pending));
let declined = reload(pending);
for (const id of ['r', 'e', 'a']) declined = applyAction(declined, id, { type: 'semutaPass', event });
assert.equal(declined.pendingTreacheryDiscard, null);
assert.deepEqual(declined.discard, pending.discard);
assert.equal(player(declined, 'a').spice, spice - 2);
assert.equal(player(declined, 'a').hand.filter(card => card.id === target).length, 1);
assert.deepEqual(inventory(declined), original);
const claimed = applyAction(reload(pending), 'r', { type: 'semutaCommit', event });
assert.equal(claimed.pendingTreacheryDiscard, null);
assert.equal(player(claimed, 'a').spice, spice - 2);
assert.equal(player(claimed, 'a').hand.filter(card => card.id === target).length, 1);
assert.equal(player(claimed, 'r').hand.filter(card => card.id === box.id).length, 1);
assert.equal(claimed.discard.filter(card => card.id === semuta.id).length, 1);
assert.deepEqual(claimed.discard.filter(card => card.id !== semuta.id).map(card => card.id), shuffled);
assert.deepEqual(inventory(claimed), original);
for (const p of claimed.players)
assert.deepEqual(viewGame(reload(claimed), p.id), viewGame(claimed, p.id));
assert.deepEqual(normalizeAutomaticGame(reload(claimed)), reload(claimed));
});
+37 -1
View File
@@ -16,7 +16,7 @@ function take(g: Game, identity: string) {
throw new Error('The genuine setup lost a physical card.');
}
void test('authenticated fresh discard survives restart and duplicate Semuta commits transfer one physical card', async () => {
void test('authenticated ordinary and paid-Box discards preserve one Semuta claim through restart and room CAS', async () => {
const f = unitStore();
try {
const created = await f.rooms.createRoom('Semuta QA', 'richese', false, ['choam']);
@@ -93,5 +93,41 @@ void test('authenticated fresh discard survives restart and duplicate Semuta com
assert.equal(new Set(cards.map(card => card.id)).size, cards.length);
assert.deepEqual(f.sqlite.prepare('SELECT * FROM seats').all(), originalSeats);
for (const auth of auths) assert.deepEqual(await f.restart().readSeatView(code, auth), viewGame(done, auth.playerId));
const next = structuredClone(done);
const usedSemuta = take(next, SEMUTA_DRUG_ID);
const box = take(next, 'richese-nullentropy-box');
seat(next, ids[0]).hand.push(usedSemuta);
seat(next, ids[1]).hand.push(box);
const older = [next.deck.shift(), next.deck.shift()];
assert.ok(older[0] && older[1]);
next.discard.push(older[0], older[1]);
Object.assign(next, { turn: 3, phase: 4, active: null, ready: [], decision: null,
response: null, phaseOpening: null, stormPending: null });
next.version = done.version + 1;
assert.equal(f.sqlite.prepare('UPDATE rooms SET state=?,version=? WHERE code=? AND version=?')
.run(JSON.stringify(next), next.version, code, done.version).changes, 1);
const beforeSpice = seat(next, ids[1]).spice;
const paid = await act(1, { type: 'card', card: box.id });
assert.ok(paid.pendingNullentropy);
const selected = paid.discard[0].id;
const offered = await act(1, { type: 'decision', event: paid.pendingNullentropy.event, card: selected });
assert.equal(offered.pendingTreacheryDiscard?.reaction?.stage, 'offer');
assert.equal((await f.restart().readSeatView(code, auths[0])).semutaReaction?.canCommit, true);
await f.restart().continueRoomAutomatic(code, clock);
assert.equal((await f.restart().readRoom(code)).version, offered.version);
const claimedBox = await act(0, { type: 'semutaCommit', event: offered.pendingTreacheryDiscard!.batch.event });
assert.equal(claimedBox.pendingTreacheryDiscard, null);
assert.equal(seat(claimedBox, ids[1]).spice, beforeSpice - 2);
assert.equal(seat(claimedBox, ids[1]).hand.filter(card => card.id === selected).length, 1);
assert.equal(seat(claimedBox, ids[0]).hand.filter(card => card.id === box.id).length, 1);
assert.equal(claimedBox.discard.filter(card => card.id === SEMUTA_DRUG_ID).length, 1);
assert.equal(claimedBox.discard.some(card => card.id === box.id), false);
const finalCards = [...claimedBox.deck, ...claimedBox.discard, ...claimedBox.richeseCache!,
...claimedBox.players.flatMap(p => p.hand)];
assert.equal(new Set(finalCards.map(card => card.id)).size, finalCards.length);
assert.deepEqual(f.sqlite.prepare('SELECT * FROM seats').all(), originalSeats);
for (const auth of auths)
assert.deepEqual(await f.restart().readSeatView(code, auth), viewGame(claimedBox, auth.playerId));
} finally { f.sqlite.close(); }
});