The existing offline faction runner now selects genuine Basic and Advanced base games with two through six players. Original six expansion defaults and seed offsets remain stable; player-count filters require the explicit base profile. Saved AI profiles choose every setup and game action. This replaces repeated private harness copies while preserving source-bound private reports, failed traces and explicit snapshot resume. Shared custody checks include every physical Treachery zone, nonnegative integer resources, twenty-force totals, the distinct Emperor/Fremen/Ixian elite totals and subsets, and canonical base Traitor identities after dealing. Rejected actions must leave their input unchanged; periodic JSON restoration compares all private views and excludes rival private hand/spice/Traitor/Face Dancer fields. Optional modules and separate private previews cannot be resumed as ordinary fixed scenarios. Resume still requires checking original setup provenance and intentionally restarts the selected random stream. Independent review caught and corrected seven-cyborg accounting, save-derived Traitor expectations, missing elite records and private-preview classification. Meaningful regressions cover those failures plus strict filters, original names/seeds, failed subprocess reporting, source stability and resume. Types, lint and 4823 offline tests pass. No application, dependency, HTTP or database code changed, so build/HTTP suites were not repeated. All ten base and six existing expansion samples completed on the final unchanged source: 6746 accepted actions, 175 periodic restores, 82 rejected candidates retained in traces. The expansion guarded-arrival fallbacks remain visible; these samples do not certify every faction, optional module, player-count rule or difficulty ordering. Exact expansion Traitor/Face Dancer custody still needs its own adapter. The earlier pilot/source-changed report remains private; the required check was repeated after the late review correction rather than accepting results from changing source. All 1038 opening games and original seat/recovery records are unchanged; 1038 rooms remain. SQLite integrity and foreign keys pass. The existing QA table restored its saved seat and fulfilled shipment after browser refresh. The healthy server was reused without reset or restart. The rules register now explicitly records the Moritani Secret Ally after-loss privacy blocker. A holder-only pause exposes its hidden Nexus; the existing alliance-retention helper does not resolve the shared pending response UX decision. No duplicate user question, new house rule or mode/publication gate change was introduced. Verified source tree: 85d5a53fa72efb9704c1828526aaccba1554670307ce476f729eae9c5c4abff9
135 lines
4.5 KiB
TypeScript
135 lines
4.5 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { botActions } from '../game/bots';
|
|
import {
|
|
applyAction,
|
|
createGame,
|
|
initializeBaseGameForAudit,
|
|
initializeFactionExpansionsGameForAudit,
|
|
joinGame,
|
|
newPlayer,
|
|
viewGame,
|
|
} from '../game/engine';
|
|
import { sampleInventory, verifySampleCustody } from '../tools/sample-custody';
|
|
|
|
function fixture(advanced = false) {
|
|
let game = createGame(
|
|
'SAMPLEQA',
|
|
newPlayer('emperor', 'Emperor', 'emperor'),
|
|
advanced,
|
|
);
|
|
for (const faction of ['fremen', 'atreides', 'harkonnen'] as const)
|
|
joinGame(game, newPlayer(faction, faction, faction));
|
|
for (const player of game.players) {
|
|
player.ready = true;
|
|
player.bot = 'Medium';
|
|
}
|
|
game = initializeBaseGameForAudit(game);
|
|
const inventory = sampleInventory(game);
|
|
verifySampleCustody(game, inventory);
|
|
for (let steps = 0; game.status === 'setup' && steps < 30; steps++) {
|
|
const choice = game.players.flatMap((player) =>
|
|
botActions(viewGame(game, player.id)).map((action) => ({
|
|
player,
|
|
action,
|
|
})),
|
|
)[0];
|
|
assert.ok(choice, 'genuine setup has a legal AI choice');
|
|
game = applyAction(game, choice.player.id, choice.action);
|
|
verifySampleCustody(game, inventory);
|
|
}
|
|
assert.equal(game.status, 'playing');
|
|
return { game, inventory };
|
|
}
|
|
|
|
void test('sample custody follows genuine setup and distinct Advanced elite inventories', () => {
|
|
for (const advanced of [false, true]) {
|
|
const { game, inventory } = fixture(advanced);
|
|
verifySampleCustody(JSON.parse(JSON.stringify(game)), inventory);
|
|
const corrupted = structuredClone(game);
|
|
const card = corrupted.deck.pop();
|
|
assert.ok(card);
|
|
assert.throws(
|
|
() => verifySampleCustody(corrupted, inventory),
|
|
/physical card custody/,
|
|
);
|
|
}
|
|
});
|
|
|
|
void test('sample custody detects balanced negative forces and elite subsets outside their group', () => {
|
|
const { game, inventory } = fixture(true);
|
|
const negative = structuredClone(game);
|
|
negative.players[0].tanks = -1;
|
|
negative.players[0].reserves++;
|
|
assert.throws(
|
|
() => verifySampleCustody(negative, inventory),
|
|
/nonnegative forces/,
|
|
);
|
|
const missing = structuredClone(game);
|
|
delete missing.players.find((seat) => seat.faction === 'fremen')!.elites;
|
|
assert.throws(
|
|
() => verifySampleCustody(missing, inventory),
|
|
/missing elite inventory fremen/,
|
|
);
|
|
const misplaced = structuredClone(game);
|
|
const player = misplaced.players.find((seat) => seat.faction === 'emperor')!;
|
|
assert.ok(player.elites);
|
|
player.elites.reserves--;
|
|
player.elites.forces['arrakeen:10'] = 1;
|
|
assert.throws(
|
|
() => verifySampleCustody(misplaced, inventory),
|
|
/elite board subset/,
|
|
);
|
|
});
|
|
|
|
void test('sample custody catches a duplicated base traitor after setup despite preserved hand size', () => {
|
|
const { game, inventory } = fixture();
|
|
const original = game.players[0].traitors[0];
|
|
assert.ok(original);
|
|
const other = game.players.find((player) => player.id !== game.players[0].id)!
|
|
.traitors[0];
|
|
assert.ok(other && other !== original);
|
|
game.players[0].traitors[0] = other;
|
|
assert.throws(
|
|
() => verifySampleCustody(game, inventory),
|
|
/physical base traitor custody/,
|
|
);
|
|
});
|
|
|
|
void test('sample custody retains all seven Ixian cyborgs in genuine expansion setup', () => {
|
|
const lobby = createGame(
|
|
'SAMPLEIX',
|
|
newPlayer('ixians', 'Ixians', 'ixians'),
|
|
false,
|
|
['ix'],
|
|
);
|
|
for (const faction of ['tleilaxu', 'atreides', 'harkonnen'] as const)
|
|
joinGame(lobby, newPlayer(faction, faction, faction));
|
|
for (const player of lobby.players) player.ready = true;
|
|
const game = initializeFactionExpansionsGameForAudit(lobby);
|
|
const inventory = sampleInventory(game);
|
|
verifySampleCustody(game, inventory);
|
|
const player = game.players.find((seat) => seat.faction === 'ixians')!;
|
|
assert.ok(player.elites);
|
|
player.elites.reserves--;
|
|
assert.throws(
|
|
() => verifySampleCustody(game, inventory),
|
|
/elite custody ixians/,
|
|
);
|
|
});
|
|
|
|
void test('resumed sample inventory cannot shrink with a deleted leader and matching Traitor card', () => {
|
|
const { game } = fixture();
|
|
const leader = game.players[0].leaders.pop();
|
|
assert.ok(leader);
|
|
game.traitorReserve = game.traitorReserve?.filter(
|
|
(card) => card !== leader.id,
|
|
);
|
|
for (const player of game.players)
|
|
player.traitors = player.traitors.filter((card) => card !== leader.id);
|
|
assert.throws(
|
|
() => verifySampleCustody(game, sampleInventory(game)),
|
|
/physical base traitor custody/,
|
|
);
|
|
});
|