An unallied player holding CHOAM Nexus while CHOAM is absent can now discard one Worthless card during Spice Collection for two bank spice. The server spends both physical cards once, exposes only private legal card choices, and persists an already-paid discard receipt. Human controls and all four AI profiles share the action. The after-victory inspection alternative remains missing; normal unfinished modes and publication stay gated. Independent review caught and fixed a queued Grumman Collection lock mismatch. Focused tests cover Basic/Advanced, actual card custody, private controls, all AI profiles, stale and wrong-mode rejection, Truthtrance and Grumman locks, JSON corruption/replay, competing production SQLite writes and private seat restoration. A separate bounded acquisition helper recorded all seven Discovery Spice Cards, eight tokens and exact physical card placements from publisher-authored sources. Discovery runtime remains missing. Validation: types, lint, 4,217 offline tests, production build and 40 HTTP tests passed. Durations: check 139298 ms; build 6617 ms; HTTP 24329 ms. Source fingerprint dfdaaf8bafe69acd31c9d0afc13f7a0d070da43deb544f091e95fe840b399493; private report under ~/.local/share/dune/checkpoints/20260913-choam-nexus-trade/verification/report.json. Browser reference search, Prototyped label and related Collection link checked. All 95 opening saved rooms unchanged; 30 HTTP test rooms added, 125 total. No server restart or database reset. Efficiency counter: 59,982,405 at batch start; 60,581,959 after broad verification, delta 599,554 aggregate tokens before final preservation/Git/usage checks. One newly playable function plus the acquired Discovery inventory; this is not full CHOAM or Nexus compliance.
102 lines
5.8 KiB
TypeScript
102 lines
5.8 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createElement } from 'react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { applyAction, normalizeAutomaticGame, viewGame } from '../game/engine';
|
|
import { botActions } from '../game/bots';
|
|
import { quoteNexusChoamTrade } from '../game/nexus-choam-trade';
|
|
import { NexusChoamTrade } from '../components/nexus-choam-trade';
|
|
import { nexusChoamTradeAction } from '../game/nexus-choam-trade-options';
|
|
import { holdNexusChoamCard } from './fixture-nexus-choam';
|
|
import { nexusChoamTradeFixture, pausedNexusChoamTrade } from './fixture-nexus-choam-trade';
|
|
import { nexusTraitorFixture, nexusTraitorInventory } from './fixture-nexus-traitors';
|
|
import { nexusReject, nexusReload, nexusReady } from './fixture-nexus-cards';
|
|
|
|
void test('Basic and Advanced Collection trade spends both physical cards and pays exactly two bank spice once', () => {
|
|
for (const advanced of [false, true]) {
|
|
const f = nexusChoamTradeFixture(advanced), before = nexusReload(f.g);
|
|
const g = applyAction(f.g, f.owner, f.action);
|
|
assert.deepEqual(f.g, before);
|
|
assert.equal(g.players[0].spice, before.players[0].spice + 2);
|
|
assert.deepEqual(g.players.slice(1), before.players.slice(1));
|
|
assert.deepEqual(g.players[0].hand, before.players[0].hand.filter(card => card.id !== f.cost.id));
|
|
assert.equal(g.discard.filter(card => card.id === f.cost.id).length, 1);
|
|
assert.equal(g.nexusCards!.cards!.hands[f.owner], null);
|
|
assert.ok(g.nexusCards!.cards!.discard.includes('choam'));
|
|
assert.equal(g.nexusChoamTrades!.length, 1);
|
|
assert.equal(g.nexusChoamTrades![0].stage, 'complete');
|
|
assert.equal(g.response, null);
|
|
assert.equal(g.pendingTreacheryDiscard, null);
|
|
nexusReject(g, f.owner, f.action);
|
|
assert.deepEqual(normalizeAutomaticGame(nexusReload(g)), g);
|
|
assert.equal(nexusReady(g).phase, 8);
|
|
nexusTraitorInventory(g);
|
|
}
|
|
});
|
|
|
|
void test('private trade choices stay hidden and all four AI profiles use the same legal physical-card action', () => {
|
|
for (const difficulty of ['Easy', 'Medium', 'Hard', 'Brutal'] as const) {
|
|
const f = nexusChoamTradeFixture(true);
|
|
const v = viewGame(f.g, f.owner);
|
|
v.players.find(p => p.id === f.owner)!.bot = difficulty;
|
|
assert.deepEqual(botActions(v)[0], f.action);
|
|
assert.equal(nexusChoamTradeAction(v, f.other.id), null);
|
|
const opponent = viewGame(f.g, f.target);
|
|
assert.equal(opponent.nexusChoamTrade, null);
|
|
assert.equal(opponent.nexusCards?.card, null);
|
|
const ownHtml = renderToStaticMarkup(createElement(NexusChoamTrade, {game: v, busy: false, act() {}}));
|
|
assert.match(ownHtml, /Worthless card to trade/);
|
|
assert.ok(ownHtml.includes(f.cost.name) && ownHtml.includes(f.spare.name));
|
|
assert.match(ownHtml, /Inspect card/);
|
|
assert.match(ownHtml, /for 2 spice/);
|
|
assert.equal(renderToStaticMarkup(createElement(NexusChoamTrade, {game: opponent, busy: false, act() {}})), '');
|
|
assert.match(renderToStaticMarkup(createElement(NexusChoamTrade, {game: v, busy: true, act() {}})), /disabled=""/);
|
|
const done = applyAction(f.g, f.owner, botActions(v)[0]);
|
|
assert.equal(viewGame(done, f.target).nexusChoamTrade, null);
|
|
assert.equal(Object.hasOwn(viewGame(done, f.target), 'nexusChoamTrades'), false);
|
|
nexusTraitorInventory(done);
|
|
}
|
|
});
|
|
|
|
void test('trade rejects stale/forged/foreign/wrong-role requests and does not interrupt Truthtrance', () => {
|
|
const f = nexusChoamTradeFixture();
|
|
for (const action of [{...f.action, event: 'stale'}, {...f.action, card: f.other.id},
|
|
{...f.action, amount: 99}, {...f.action, card: 'missing'}]) nexusReject(f.g, f.owner, action);
|
|
nexusReject(f.g, f.target, f.action);
|
|
const phase = nexusReload(f.g); phase.phase = 8;
|
|
nexusReject(phase, f.owner, f.action, /Collection/);
|
|
const truth = holdNexusChoamCard(f.g, f.target, 'truthtrance');
|
|
const pending = applyAction(f.g, f.target, {type: 'card', card: truth.id});
|
|
assert.ok(pending.truthtrance);
|
|
assert.match(viewGame(pending, f.owner).nexusChoamTrade!.blocked!, /current interaction/);
|
|
nexusReject(pending, f.owner, f.action, /current interaction/);
|
|
const native = nexusTraitorFixture({ownerFaction: 'choam', phase: 7});
|
|
const deck = native.nexusCards!.cards!;
|
|
deck.deck[deck.deck.indexOf('choam')] = deck.hands.p!; deck.hands.p = 'choam';
|
|
assert.equal(quoteNexusChoamTrade(native, 'p', false), null);
|
|
const betrayal = nexusTraitorFixture({ownerFaction: 'atreides', opponentFaction: 'choam', phase: 7});
|
|
const second = betrayal.nexusCards!.cards!;
|
|
second.deck[second.deck.indexOf('choam')] = second.hands.p!; second.hands.p = 'choam';
|
|
assert.equal(quoteNexusChoamTrade(betrayal, 'p', false), null);
|
|
});
|
|
|
|
void test('paid discard resumes after JSON reload without replay and rejects damaged custody/payment/history', () => {
|
|
const f = nexusChoamTradeFixture(), done = applyAction(f.g, f.owner, f.action);
|
|
const paused = pausedNexusChoamTrade(done);
|
|
assert.ok(viewGame(paused, f.owner).automaticContinuationPending);
|
|
assert.deepEqual(normalizeAutomaticGame(nexusReload(paused)), done);
|
|
nexusReject(paused, f.owner, f.action, /committed discard/);
|
|
for (const damage of [
|
|
(g: typeof done) => { g.players[0].spice++; },
|
|
(g: typeof done) => { g.players[0].hand.push(f.cost); },
|
|
(g: typeof done) => { g.nexusChoamTrades![0].card = f.spare.id; },
|
|
(g: typeof done) => { delete g.nexusChoamTrades; },
|
|
(g: typeof done) => { g.pendingTreacheryDiscard = null; g.resolvedTreacheryDiscardSequence = g.treacheryDiscardSequence; },
|
|
]) {
|
|
const bad = nexusReload(paused); damage(bad); const before = nexusReload(bad);
|
|
for (const work of [() => viewGame(bad, f.owner), () => normalizeAutomaticGame(bad), () => applyAction(bad, f.owner, {type: 'advanceBots'})])
|
|
assert.throws(work, /trade|custody|history|discard/i);
|
|
assert.deepEqual(bad, before);
|
|
}
|
|
});
|