Offer Semuta after clean private Distrans transfer

This commit is contained in:
Quintine committed 2026-09-30 07:53:59 +10:00
1 parent 2ec0422b79
commit 162f01c160
9 files changed
+243 -40

No files matched your search

+57
View File
@@ -263,3 +263,60 @@ void test('a retired Ornithopter can be claimed after one flight group without r
assert.deepEqual(normalizeAutomaticGame(reload(claimed)), reload(claimed));
assert.throws(() => applyAction(claimed, 'r', { type: 'semutaCommit', event }));
});
void test('a completed private Distrans transfer offers only its public used card', () => {
const { g, semuta, hajr } = fixture();
const distrans = take(g, 'richese-distrans');
player(g, 'a').hand.push(distrans);
const original = inventory(g);
const without = reload(g);
player(without, 'r').hand = [];
without.richeseCache!.push(semuta);
player(without, 'r').hand.push(take(without, 'richese-nullentropy-box'));
const pending = applyAction(g, 'a', {
type: 'card', card: distrans.id, target: 'e', give: hajr.id,
});
const absent = applyAction(without, 'a', {
type: 'card', card: distrans.id, target: 'e', give: hajr.id,
});
assert.equal(absent.pendingTreacheryDiscard?.reaction?.stage, 'offer');
for (const id of ['a', 'e'])
assert.deepEqual(viewGame(pending, id), viewGame(absent, id));
assert.equal(pending.pendingTreacheryDiscard?.reaction?.stage, 'offer');
assert.deepEqual(pending.pendingTreacheryDiscard?.batch.entries.map(entry => entry.card.id), [distrans.id]);
assert.equal(player(pending, 'e').hand.filter(card => card.id === hajr.id).length, 1);
assert.equal(player(pending, 'a').hand.some(card => card.id === hajr.id), false);
const event = pending.pendingTreacheryDiscard!.batch.event;
const stranger = JSON.stringify(viewGame(pending, 'r'));
assert.equal(stranger.includes(hajr.id), false);
assert.equal(viewGame(pending, 'r').semutaReaction?.canCommit, true);
assert.equal(viewGame(pending, 'e').semutaReaction?.canCommit, false);
assert.deepEqual(normalizeAutomaticGame(reload(pending)), reload(pending));
const corrupt = reload(pending);
if (corrupt.pendingTreacheryDiscard?.continuation.kind !== 'distransDiscard')
throw Error('Missing saved private transfer');
corrupt.pendingTreacheryDiscard.continuation.transferred = semuta.id;
const before = JSON.stringify(corrupt);
assert.throws(() => viewGame(corrupt, 'r'));
assert.throws(() => applyAction(corrupt, 'r', { type: 'semutaCommit', event }));
assert.equal(JSON.stringify(corrupt), before);
const duplicate = reload(pending);
duplicate.richeseRemoved = [...(duplicate.richeseRemoved ?? []), structuredClone(hajr)];
assert.throws(() => viewGame(duplicate, 'r'));
let declined = reload(pending);
for (const id of ['a', 'e', 'r'])
declined = applyAction(declined, id, { type: 'semutaPass', event });
assert.equal(declined.pendingTreacheryDiscard, null);
assert.equal(declined.discard.filter(card => card.id === distrans.id).length, 1);
assert.deepEqual(inventory(declined), original);
const claimed = applyAction(reload(pending), 'r', botActions(viewGame(pending, 'r'))[0]!);
assert.equal(claimed.pendingTreacheryDiscard, null);
assert.equal(player(claimed, 'e').hand.filter(card => card.id === hajr.id).length, 1);
assert.equal(player(claimed, 'r').hand.filter(card => card.id === distrans.id).length, 1);
assert.equal(claimed.discard.filter(card => card.id === semuta.id).length, 1);
assert.equal(claimed.discard.some(card => card.id === distrans.id), false);
assert.deepEqual(inventory(claimed), original);
for (const p of claimed.players)
assert.deepEqual(viewGame(reload(claimed), p.id), viewGame(claimed, p.id));
assert.throws(() => applyAction(claimed, 'r', { type: 'semutaCommit', event }));
});
+35 -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 ordinary and paid-Box discards preserve one Semuta claim through restart and room CAS', async () => {
void test('authenticated ordinary, paid Box, retired flight and private Distrans claims survive restart and room CAS', async () => {
const f = unitStore();
try {
const created = await f.rooms.createRoom('Semuta QA', 'richese', false, ['choam']);
@@ -174,5 +174,39 @@ void test('authenticated ordinary and paid-Box discards preserve one Semuta clai
assert.deepEqual(f.sqlite.prepare('SELECT * FROM seats').all(), originalSeats);
for (const auth of auths)
assert.deepEqual(await f.restart().readSeatView(code, auth), viewGame(flown, auth.playerId));
const transfer = structuredClone(flown);
const finalSemuta = take(transfer, SEMUTA_DRUG_ID);
const distrans = take(transfer, 'richese-distrans');
transfer.richeseCache!.push(take(transfer, 'richese-nullentropy-box'));
seat(transfer, ids[0]).hand.push(finalSemuta);
seat(transfer, ids[1]).hand.push(distrans);
const given = seat(transfer, ids[1]).hand.find(card => card.id === selected)!;
assert.ok(given);
Object.assign(transfer, { turn: 5, phase: 5, active: ids[1], ready: [],
decision: null, response: null, phaseOpening: null, stormPending: null,
movementRemaining: [ids[1], ids[0], ids[2]], hajr: [] });
transfer.version = flown.version + 1;
assert.equal(f.sqlite.prepare('UPDATE rooms SET state=?,version=? WHERE code=? AND version=?')
.run(JSON.stringify(transfer), transfer.version, code, flown.version).changes, 1);
const handed = await act(1, { type: 'card', card: distrans.id,
target: ids[2], give: given.id });
assert.equal(handed.pendingTreacheryDiscard?.reaction?.stage, 'offer');
assert.equal(seat(handed, ids[2]).hand.filter(card => card.id === given.id).length, 1);
await f.restart().continueRoomAutomatic(code, clock);
assert.equal((await f.restart().readRoom(code)).version, handed.version);
const observer = await f.restart().readSeatView(code, auths[0]);
assert.equal(observer.semutaReaction?.canCommit, true);
assert.equal(JSON.stringify(observer).includes(given.id), false);
const final = await act(0, { type: 'semutaCommit',
event: handed.pendingTreacheryDiscard!.batch.event });
assert.equal(final.pendingTreacheryDiscard, null);
assert.equal(seat(final, ids[2]).hand.filter(card => card.id === given.id).length, 1);
assert.equal(seat(final, ids[0]).hand.filter(card => card.id === distrans.id).length, 1);
assert.equal(final.discard.filter(card => card.id === SEMUTA_DRUG_ID).length, 1);
assert.equal(final.discard.some(card => card.id === distrans.id), false);
assert.deepEqual(f.sqlite.prepare('SELECT * FROM seats').all(), originalSeats);
for (const auth of auths)
assert.deepEqual(await f.restart().readSeatView(code, auth), viewGame(final, auth.playerId));
} finally { f.sqlite.close(); }
});