Files
Dune/tests/sapho-battle-order-controls.test.tsx
T
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

68 lines
3.6 KiB
TypeScript
Raw 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 { registerHooks } from 'node:module';
import { readFileSync } from 'node:fs';
import { createElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { applyAction, viewGame, type GameView } from '../game/engine';
import { JuiceOfSapho } from '../components/juice-of-sapho';
import { botBattleChoices } from '../game/bot-battle-choices';
import { saphoBattleOrderGame, saphoBattleOrderAction } from './fixture-sapho-battle-order';
const aliases = registerHooks({
resolve(specifier, context, next) {
return next(specifier === 'next/image' ? 'vinext/shims/image' : specifier === 'next/link' ? 'vinext/shims/link' : specifier, context);
},
load(url, context, next) {
if (!url.endsWith('.module.css')) return next(url, context);
const css = readFileSync(new URL(url), 'utf8');
const classes = Object.fromEntries([...css.matchAll(/\.([a-zA-Z_][\w-]*)/g)].map(match => [match[1], match[1]]));
return { format: 'module', source: `export default ${JSON.stringify(classes)}`, shortCircuit: true };
},
});
const { GameTable } = await import('../components/game-table');
aliases.deregister();
const panel = (game: GameView, busy = false) => renderToStaticMarkup(createElement(JuiceOfSapho, { game, act() {}, busy }));
const table = (game: GameView) => renderToStaticMarkup(createElement(GameTable, { game, send: async () => {}, onExit() {}, busy: false }));
void test('held Sapho exposes the legal battle-order action with its actual timing and limits', () => {
for (const [holder, mode] of [['c', 'first'], ['a', 'last']] as const) {
const game = saphoBattleOrderGame({ holder, geometry: 'shared' });
const view = viewGame(game, holder);
const html = panel(view);
assert.match(html, new RegExp(`Choose battles ${mode} and`));
assert.match(html, /Other players may still choose battles against you/);
assert.match(html, /not the aggressor or tie advantage/);
assert.match(html, /Battle aggressor[\s\S]*unfinished/);
assert.match(panel(view, true), /<button[^>]*disabled=""[^>]*>Choose battles/);
const observer = game.players.find(player => player.id !== holder)!;
assert.equal(panel(viewGame(game, observer.id)), '');
}
});
void test('the actual table offers an earlier physical attacker as the reordered chooser’s opponent', () => {
const original = saphoBattleOrderGame({ holder: 'c', geometry: 'shared' });
const game = applyAction(original, 'c', saphoBattleOrderAction(original, 'c', 'first'));
const view = viewGame(game, 'c');
const html = table(view);
const opponent = game.players.find(player => player.id === 'a')!;
assert.match(html, new RegExp(`Fight ${opponent.name} · Arrakeen`));
assert.match(html, /Remaining battle-choice order/);
assert.doesNotMatch(html, /Choose battles first and/);
const action = botBattleChoices(view).find(candidate => candidate.target === 'a' && candidate.territory === 'arrakeen');
assert.ok(action);
const opened = applyAction(game, 'c', action);
assert.equal(opened.battle?.attacker, 'a');
assert.equal(opened.battle?.defender, 'c');
});
void test('a held Sapho explains why ordering must wait through the current battle', () => {
const game = saphoBattleOrderGame({ holder: 'c', geometry: 'shared' });
const action = botBattleChoices(viewGame(game, game.active!))[0];
assert.ok(action);
const opened = applyAction(game, game.active!, action);
const html = panel(viewGame(opened, 'c'));
assert.doesNotMatch(html, /Choose battles (first|last) and/);
assert.match(html, /Finish the current (battle|interaction)/);
});