Files
Dune/tests/harass-withdraw-choice-controls.test.tsx
Quintine 62e87d2b96 Connect revealed Harass force allocation and exact casualties
Harass & Withdraw now admits legal Basic/Advanced mixed ordinary/elite commitments and multi-sector returns. A shared physical quote validates every returned counter against one exact legal dial/support complement. After both plans are revealed, the owner selects an ambiguous allocation; unique returns remain automatic. Selected counters become public before Traitor declarations, while physical transfer waits for atomic settlement and opposing-Traitor cancellation. This information is never added to a sealed Battle Plan or complete-plan inspection. Existing optional-module and Richese/Ecaz-allied gates remain.

The player panel, four AI profiles and saved event use the same quote. A versioned receipt binds the revealed plans, current typed location pools, battle and owner. Missing or altered receipts fail before reads, normalization and writes; concurrent choices select once. Previously valid legacy unique plans continue without reopening. Winner casualties now equal the selected dialed group, preventing a second smaller physical commitment after its undialed complement has returned.

Independent source and implementation review passed. Pure, engine, control and SQLite regressions cover typed/sector legality, exact complement, private pre-reveal views, public selected views, stale/malformed state, cross-owner actions, raced allocations, selected restoration, automatic exact casualties, opposing-Traitor cancellation and mandatory disposal. Types, lint and 4850 offline tests, production build and 43 HTTP/session tests pass. The first broad check caught the exhaustive decision registry and test union-narrowing omissions; those were fixed before the final stable checks. Browser testing corrected the incomplete-allocation selector label before verification.

Eight genuine card-variant Basic/Advanced games across all four homogeneous AI profiles completed with 9956 accepted actions, 266 periodic JSON restores and zero rejected candidates. Three Harass plans/returns and two Recruits plays occurred; no ambiguous allocation arose in these seeds. The new choice is exercised by targeted engine, authenticated recovery and browser cases, not inferred from those full-game samples. Full variant and combined-expansion acceptance remains incomplete.

A fresh isolated browser room used genuine Advanced card-variant setup followed by a conserved two-sector battle fixture. Actual controls rejected a partial return, selected two ordinary counters from sector nine, and preserved the selected state after refresh. Following actual owner and engine-driven opponent Traitor declines, two counters returned, the exact remaining ordinary/elite pair went to the Tanks, support cost one, and Harass discarded once. Final refresh restored 18 reserves, two Tanks, 29 spice and the same private Traitor. This is targeted browser evidence, not a complete human game.

All 1038 opening games and original seat/recovery/entry/handover records are unchanged; 1072 rooms remain including new QA. SQLite integrity and foreign keys pass. The healthy development server was reused without restart or reset. No mode/publication gate was opened.

Verified source tree: 61ee78f6e2bce47cb322b04f896db27fef28c56ba2097571a1d85bad5c121156
2026-09-14 06:37:23 +10:00

183 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 {
HarassWithdrawChoice,
harassWithdrawChoiceState,
} from '../components/harass-withdraw-choice';
import {
HarassWithdrawGuide,
harassWithdrawControlState,
} from '../components/harass-withdraw';
import { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import { applyAction, viewGame, type Game } from '../game/engine';
import {
defaultHarassWithdrawAllocation,
harassWithdrawCommitments,
} from '../game/harass-withdraw';
import { harassWithdrawGame } from './fixture-harass-withdraw';
function submitPlans(game: Game) {
const owner = game.players[0];
const opponent = game.players[1];
let next = applyAction(game, owner.id, {
type: 'battlePlan',
dial: game.advanced ? 2 : 2,
support: game.advanced ? 1 : 0,
leader: owner.leaders.find((leader) => !leader.dead)!.id,
weapon: 'ecaz-harass-withdraw',
});
next = applyAction(next, opponent.id, {
type: 'battlePlan',
dial: 0,
support: 0,
leader: opponent.leaders.find((leader) => !leader.dead)!.id,
});
assert.equal(next.decision?.kind, 'harassWithdraw');
return next;
}
function multiSectorGame() {
const game = harassWithdrawGame({
territory: 'imperial_basin',
sector: 9,
});
game.players[0].forces = {
'imperial_basin:9': 2,
'imperial_basin:10': 3,
};
return game;
}
void test('pre-seal guidance permits a supported ambiguous plan and defers its private allocation', () => {
const game = harassWithdrawGame({ advanced: true, normal: 3, elite: 1 });
const preview = viewGame(game, 'a').battle!.harassWithdraw!;
const state = harassWithdrawControlState(preview, true, 2, 1);
assert.deepEqual(state, { blocked: null, returned: null });
const html = renderToStaticMarkup(
createElement(HarassWithdrawGuide, { preview, state }),
);
assert.match(html, /After plans are revealed/);
assert.match(html, /choose exactly which undialed ordinary and elite forces/);
assert.doesNotMatch(html, /ambiguous regular\/elite/);
for (const difficulty of DIFFICULTIES) {
const botView = viewGame(game, 'a');
botView.players.find((player) => player.id === 'a')!.bot = difficulty;
const candidates = botActions(botView).filter(
(action) =>
action.type === 'battlePlan' &&
(action.weapon === 'ecaz-harass-withdraw' ||
action.defense === 'ecaz-harass-withdraw'),
);
assert.ok(candidates.length, `${difficulty} omitted legal Harass plans`);
assert.ok(
candidates.every((action) => !Object.hasOwn(action, 'returns')),
`${difficulty} exposed an early return selection`,
);
}
});
void test('the revealed owner gets exact commitment and per-sector controls while rivals get no allocation', () => {
const revealed = submitPlans(multiSectorGame());
const ownerView = viewGame(revealed, 'a');
const observerView = viewGame(revealed, 't');
assert.equal(observerView.battle!.harassAllocation, null);
const offer = ownerView.battle!.harassAllocation!;
assert.equal(offer.selection, null);
const commitments = harassWithdrawCommitments(
offer.context,
offer.dial,
offer.support,
);
assert.deepEqual(commitments, [{ normal: 2, elite: 0 }]);
const first = defaultHarassWithdrawAllocation(
offer.context,
offer.dial,
offer.support,
commitments[0],
);
assert.deepEqual(first, {
'imperial_basin:10': { normal: 3, elite: 0 },
});
assert.equal(
harassWithdrawChoiceState(offer.context, offer.dial, offer.support, first)
.blocked,
null,
);
assert.match(
harassWithdrawChoiceState(offer.context, offer.dial, offer.support, {
'imperial_basin:9': { normal: 2, elite: 0 },
}).blocked!,
/exact undialed complement/,
);
const html = renderToStaticMarkup(
createElement(HarassWithdrawChoice, {
game: ownerView,
act() {},
busy: false,
}),
);
assert.match(html, /aria-label="Harass and Withdraw force allocation"/);
assert.match(html, /Dialed physical commitment/);
assert.match(html, /2 ordinary · 0 elite/);
assert.match(html, /Imperial Basin · sector 9/);
assert.match(html, /Imperial Basin · sector 10/);
assert.match(html, /Confirm returned forces/);
assert.equal(
renderToStaticMarkup(
createElement(HarassWithdrawChoice, {
game: observerView,
act() {},
busy: false,
}),
),
'',
);
assert.match(
renderToStaticMarkup(
createElement(HarassWithdrawChoice, {
game: ownerView,
act() {},
busy: true,
}),
),
/disabled=""/,
);
});
void test('every bot profile submits the shared deterministic allocation only at its revealed decision', () => {
for (const difficulty of DIFFICULTIES) {
const revealed = submitPlans(
harassWithdrawGame({ advanced: true, normal: 3, elite: 1 }),
);
const view = viewGame(revealed, 'a');
view.players.find((player) => player.id === 'a')!.bot = difficulty;
const offer = view.battle!.harassAllocation!;
const expected = defaultHarassWithdrawAllocation(
offer.context,
offer.dial,
offer.support,
);
const action = botActions(view)[0];
assert.deepEqual(action, {
type: 'decision',
event:
revealed.decision?.kind === 'harassWithdraw'
? revealed.decision.event
: '',
returns: expected,
});
const selected = applyAction(revealed, 'a', action);
assert.deepEqual(selected.battle!.harassAllocation!.selection, expected);
assert.notEqual(selected.decision?.kind, 'harassWithdraw');
assert.deepEqual(
viewGame(selected, 't').battle!.harassAllocation!.selection,
expected,
);
}
});