Files
Dune/tests/sapho-battle-order-bots.test.ts
Quintine cb691e1b14 Connect Sapho first and last battle-choice order
Juice of Sapho can change the remaining Battle-phase chooser order at clean boundaries. A chooser may occupy the physical defender slot and select the actual other combatant. Physical storm order, attackers, defenders and tie advantage remain intact. Full-roster phase priority survives aftermath, newly eligible Face Dancers and saved continuation. Controls and all four AI profiles consume the same projected choices.

Independent review verified private options, public geometry, exact physical disposal, rejected-action immutability, phase expiry and boundary-bound saved chooser integrity. Actual Basic/Advanced Face Dance regressions verify later replacement priority. Authenticated SQLite tests cover duplicate concurrent card requests, private restore and battle completion. Chooser/aggressor separation and phase duration remain explicit implementation interpretations; the separate aggressor mode and unresolved timing stay gated. Reinforcements remains disabled pending the documented reserve-cost question.

Types, lint, 4792 offline tests, build and 43 HTTP tests pass with unchanged source. Six fixed genuine Basic/Advanced faction samples finish in 3672 accepted actions and 97 periodic private JSON restores. They retain 82 rejected candidates at existing guarded arrival combinations; subsequent legal candidates finish. This is bounded playability evidence, not complete compliance or AI calibration.

The browser used Sapho first from a later physical circle, chose Emperor, sealed and resolved a battle, then refreshed into its next choice. Emperor retained the tie win. All 9 accepted actions replay exactly using the recorded random battle event; physical custody, all private JSON views and the original seat row pass. A private harness initially needed random-event replay binding and SQLite-row prototype normalization; no production fix or game reset was required.

After the reported outage, the server responded and the staged QA game restored exactly. All 970 opening games and their original seat/recovery records remain preserved (1004 after checks), including all 971 rooms present immediately before checks. SQLite integrity and foreign keys pass. No restart, database reset or recurring automation was needed.

Verified source tree: b699f80600f8e297595a8e756edf367a607ddd99707474c03231e6479bd2f389
2026-09-14 05:14:57 +10:00

69 lines
3.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from 'node:test';
import assert from 'node:assert/strict';
import { applyAction, viewGame, type Game } from '../game/engine';
import { botActions } from '../game/bots';
import { botBattleChoices } from '../game/bot-battle-choices';
import { DIFFICULTIES, type Difficulty } from '../game/bot-profiles';
import { saphoBattleOrderGame } from './fixture-sapho-battle-order';
function choices(game: Game, owner: string, level: Difficulty) {
const view = viewGame(game, owner);
view.players.find(player => player.id === owner)!.bot = level;
const before = JSON.stringify(view);
const actions = botActions(view);
assert.equal(JSON.stringify(view), before, 'policy leaves its private projection unchanged');
return actions;
}
void test('all four profiles use battle first and choose the actual opponent from either stable slot', () => {
for (const advanced of [false, true]) for (const level of DIFFICULTIES) {
const game = saphoBattleOrderGame({ advanced, holder: 'c', geometry: 'shared' });
const actions = choices(game, 'c', level);
const card = actions.find(action => action.card === 'richese-juice-of-sapho');
assert.ok(card, `${level}: offered card action`);
assert.equal(card.scope, 'battleOrder');
assert.equal(card.mode, 'first');
const ordered = applyAction(game, 'c', card);
assert.equal(ordered.active, 'c');
const plans = botBattleChoices(viewGame(ordered, 'c'));
assert.ok(plans.some(action => action.target === 'a'));
assert.ok(plans.every(action => action.target !== 'c'));
for (const action of plans) {
const next = applyAction(ordered, 'c', action);
assert.equal(next.battle?.territory, action.territory);
assert.equal(next.battle?.defender, 'c');
assert.equal(next.battle?.attacker, action.target);
}
const botPlans = choices(ordered, 'c', level).filter(action => action.type === 'chooseBattle');
assert.deepEqual(botPlans, plans);
}
});
void test('all profiles can move the first chooser last without changing physical storm order', () => {
for (const advanced of [false, true]) for (const level of DIFFICULTIES) {
const game = saphoBattleOrderGame({ advanced, holder: 'a', geometry: 'shared' });
const action = choices(game, 'a', level).find(action => action.card === 'richese-juice-of-sapho');
assert.ok(action);
assert.equal(action.scope, 'battleOrder');
assert.equal(action.mode, 'last');
const next = applyAction(game, 'a', action);
assert.deepEqual(next.order, game.order);
assert.notEqual(next.active, 'a');
assert.deepEqual(botBattleChoices(viewGame(next, 'a')), []);
assert.equal(next.discard.filter(card => card.id === 'richese-juice-of-sapho').length, 1);
}
});
void test('Sapho scheduling policy cannot inspect another seat’s concealed cards or resources', () => {
const game = saphoBattleOrderGame({ advanced: true, holder: 'c', geometry: 'shared' });
for (const level of DIFFICULTIES) {
const view = viewGame(game, 'c');
view.players.find(player => player.id === 'c')!.bot = level;
const expected = botActions(view);
for (const other of view.players.filter(player => player.id !== 'c'))
for (const field of ['hand', 'spice', 'traitors', 'faceDancers'])
Object.defineProperty(other, field, { get() { throw new Error(`Unauthorized ${field}`); } });
assert.deepEqual(botActions(view), expected);
}
});