Files
Dune/tests/leader-skill-battle-fixture.ts
Quintine 9f1f783be4 Prototype private Mentat questions behind explicit preview opt-in
Connect the optional named-weapon question before skill posture and faction powers. Every accepted question waits for the same target-owned private card-show action, preserving held/absent privacy; matching cards are compulsory, otherwise the owner selects a fallback. Keep cards in hand and retain historical observations only for the questioner and target, without binding later plans. Support actual controls, inspectors, all four AI profiles and saved JSON/SQLite continuation.

Normal activation remains disabled pending the user's uniform-response UX exception. The private flag is neither projected nor writable through actions. Legacy battles remain unchanged. Empty hands skip with an explicit unavailable receipt and no invented answer. Source and unresolved boundaries are documented, with a compact current-status dashboard preserving all goal, Git, subagent, usage and saved-game requirements.

Independent review passed privacy, custody, sequencing and preview gating. Twenty-two focused tests cover canonical card roles, exact-match/fallback symmetry, target-only controls, captured lower-only behavior, stale/duplicate requests and concurrent SQLite writes. Typecheck, lint, 4605 offline tests, production build and 43 HTTP tests passed with stable source. The first broad run retained one outdated Mentat card-copy assertion; update it to verify private disclosure, custody, optional question and subsequent concealment. Gameplay source was unchanged by that test-only correction.

Two genuine-setup sample games deliberately deal Mentat via a controlled initial skill shuffle. Basic: 100 actions, 3 JSON restores, turn-one Harkonnen win. Advanced: 507 actions, 14 restores, turn-five Harkonnen win. Each has one private observation, subsequent Atreides Prescience and no rejected candidate. These bounded force/skill custody samples do not establish general card-custody coverage, calibration or full module acceptance.

After the reported outage all 665 opening rooms and original seat/recovery/receipt records were preserved (699 after integration). A fresh 666-room backup preceded checks; database integrity and foreign keys pass. The existing localhost server was reused; its live lock prevented a duplicate start. Existing Ecaz and Ixian browser seats restored their same hands and pending choices. A separate conserved staged Mentat preview restored its private history and posture, then legally concealed its leader before subsequent faction powers. Human/browser paths are distinguished from genuine-setup simulations. No database reset, recurring automation, public activation or publication.

Verified source tree: 297ae06e0764d7cad525a802fe383a84971c3e9c5d6362c8cd0b79c5c3977caf
Final source tree: 177c98415098ea42174a860d8b1fac4f7c7dd6c3e67c93b18330d1d0fc4edf0e
The only post-verification edit removed one surplus newline at the end of the new developer document; its exact before/after content and fingerprints are retained privately. Staged diff checking caught this whitespace issue before commit. No application or test code changed.
2026-09-13 23:55:45 +10:00

107 lines
5.7 KiB
TypeScript

import assert from 'node:assert/strict';
import { mock } from 'node:test';
import { applyAction, createGame, initializeLeaderSkillsGameForAudit, joinGame, newPlayer, type Game } from '../game/engine';
import { LEADER_SKILL_CARDS, type LeaderSkillId } from '../game/leader-skill-cards';
import { validateLeaderSkills } from '../game/leader-skills';
function dealtSkillGame(native: 'emperor' | 'atreides' | 'harkonnen', advanced: boolean, skill: LeaderSkillId = 'suk-graduate'): Game {
let game = createGame('SUKTEST', newPlayer('a', 'Rescuer', native), advanced);
joinGame(game, newPlayer('d', 'Opponent', 'guild'));
for (const player of game.players) game = applyAction(game, player.id, { type: 'ready' });
const index = LEADER_SKILL_CARDS.findIndex((card) => card.id === skill);
let shuffleIndex = LEADER_SKILL_CARDS.length - 1;
mock.method(globalThis.crypto, 'getRandomValues', (array: Uint32Array) => {
array[0] = shuffleIndex-- === index ? 0 : 0xffffffff;
return array;
});
try { game = initializeLeaderSkillsGameForAudit(game); }
finally { mock.restoreAll(); }
assert.equal(game.leaderSkills!.offers.a.cards[0], skill);
return game;
}
export function advancedAtreidesSukOffer(): Game {
return dealtSkillGame('atreides', true);
}
/** Genuine module setup, then a conserved, explicitly staged battle position. */
export function leaderSkillBattle({ skill = 'suk-graduate' as LeaderSkillId, unsealed = false, hide = true, advanced = false, elite = false, bluff = false, captured = false, capturedNativeSkill = undefined as LeaderSkillId | undefined, weaponKills = false, dial = 4, atreides = false, territory = 'arrakeen', sector = 10 } = {}): Game {
const native = captured ? 'harkonnen' : atreides ? 'atreides' : 'emperor';
let game = dealtSkillGame(native, advanced, skill);
for (const id of ['a', 'd']) {
const offer = game.leaderSkills!.offers[id];
const selected = id === 'a' && advanced && atreides && skill === 'suk-graduate' ? offer.cards[1] : offer.cards[0];
game = applyAction(game, id, { type: 'leaderSkill', event: offer.event,
skill: selected, leader: id === 'a' ? `${native}-0` : 'guild-0' });
}
if (advanced && atreides && skill === 'suk-graduate') {
// Stage an old saved assignment only after setup legally returned Suk to the deck.
const assignment = game.leaderSkills!.assignments.find((a) => a.owner === 'a')!;
const sukIndex = game.leaderSkills!.deck.indexOf('suk-graduate');
assert.ok(sukIndex >= 0);
game.leaderSkills!.deck[sukIndex] = assignment.skill;
assignment.skill = 'suk-graduate';
validateLeaderSkills(game.leaderSkills!, game.players);
}
for (let i = 0; game.status === 'setup' && i < 10; i++) {
const owner = game.players.find((p) => p.traitorChoices.length);
assert.ok(owner);
game = applyAction(game, owner.id, { type: 'traitor', leader: owner.traitorChoices[0] });
}
assert.equal(game.status, 'playing');
if (captured) {
const [own, other] = game.leaderSkills!.assignments;
[own.skill, other.skill] = [other.skill, own.skill];
game.players[1].leaders[0].capturedBy = 'a';
if (capturedNativeSkill && own.skill !== capturedNativeSkill) {
const index = game.leaderSkills!.deck.indexOf(capturedNativeSkill);
assert.ok(index >= 0);
[own.skill, game.leaderSkills!.deck[index]] = [game.leaderSkills!.deck[index], own.skill];
}
}
const battleKey = `${territory}:${sector}`;
for (const player of game.players) {
game.deck.push(...player.hand); player.hand = [];
player.forces = { [battleKey]: 5 }; player.reserves = 15; player.tanks = 0;
player.spice = 20; player.battleLosses = 0;
if (player.elites) player.elites = { forces: {}, reserves: 5, tanks: 0, revived: 0 };
}
if (elite) game.players[0].elites = { forces: { [battleKey]: 2 }, reserves: 3, tanks: 0, revived: 0 };
const cardIndex = game.deck.findIndex((card) => card.kind === 'worthless');
assert.ok(cardIndex >= 0);
const [played] = game.deck.splice(cardIndex, 1);
game.players[0].hand.push(played);
let enemyWeapon: string | undefined;
if (weaponKills) {
const index = game.deck.findIndex((card) => card.kind === 'projectile');
assert.ok(index >= 0);
const [weapon] = game.deck.splice(index, 1);
game.players[1].hand.push(weapon); enemyWeapon = weapon.id;
}
Object.assign(game, { phase: 6, storm: 18, order: ['a', 'd'], active: 'a', ready: [], decision: null, response: null, phaseOpening: null });
game = applyAction(game, 'a', { type: 'chooseBattle', territory, target: 'd' });
while (game.decision?.kind === 'leaderSkillVisibility' || game.decision?.kind === 'mentatQuestion') {
const decision = game.decision;
if (decision.kind === 'mentatQuestion') {
game = applyAction(game, decision.player, { type: 'decision', event: decision.event, decline: true });
continue;
}
game = applyAction(game, decision.player, { type: 'leaderSkillVisibility', event: decision.event,
hide: decision.player === 'a' ? hide : false });
}
while (game.battle?.preparation)
game = applyAction(game, game.battle.preparation.owner, { type: 'declineBattlePower' });
if (game.decision?.kind === 'fullPlanOffer')
game = applyAction(game, game.decision.player, { type: 'decision', decline: true });
if (unsealed) return game;
game = applyAction(game, 'a', { type: 'battlePlan', dial, support: advanced ? 3 : 0,
leader: captured ? 'guild-0' : hide && !bluff ? `${native}-0` : `${native}-1`, weapon: played.id });
game = applyAction(game, 'd', { type: 'battlePlan', dial: 0, leader: 'guild-1', weapon: enemyWeapon });
game = applyAction(game, 'a', { type: 'traitorCall', call: false });
return game;
}
export function resolveLeaderSkillBattle(game: Game): Game {
return applyAction(game, 'd', { type: 'traitorCall', call: false });
}