Files
Dune/tests/deferred-shipment-arrival.test.ts
T
Quintine 9ca17a66a0 Honor allied Fremen victory and prevent deferred shipment deadlocks
Reciprocal allied Ecaz and Fremen with fighters in Sietch Tabr now satisfy that part of the Fremen final-turn victory, as explicitly clarified by the GF9 Ecaz/Moritani p15 FAQ. One public board quote drives automatic victory and the table guide; the chronicle explains the result. Other blockers, ordinary stronghold/BG prediction precedence, Guild fallback, advisor posture and concealed marker privacy remain intact. Habbanya symmetry and full mode/publication acceptance remain unfinished.

A genuine Advanced sample also exposed a pre-existing accepted Guild shipment which could never finish: allowance opened BG accompaniment and then hit the Ambassador arrival guard. Prior HEAD replay reproduced the exact 90-action failure. Fresh shipment preflight now rejects unsupported arrival combinations before accepting their pending windows. A valid legacy ordinary Guild allowance can return its unspent declaration to choose another destination; special parent/card receipts retain their separate gates. The change does not invent simultaneous reaction order or refund spent cards.

Independent rules/privacy/persistence review and focused engine/controls tests pass. Seventeen Fremen/Ecaz tests include all four profiles and authenticated final readiness/restart/concurrent writes. Shipment regressions cover pre-declaration immutability, supported arrival, malformed saved declarations and authenticated unspent return/replacement/reconnect/concurrency. All 4716 offline tests, types, lint, production build and 43 HTTP tests passed against unchanged source.

The original fixed seeds were repeated after repair and the exact failed snapshot resumed with documented new continuation seed 202609147: resume-advanced-202609147: 842 accepted, 109 guarded rejections, 22 periodic JSON restores; genuine-basic-202609145: 563 accepted, 14 guarded rejections, 15 periodic JSON restores; genuine-advanced-202609146: 806 accepted, 81 guarded rejections, 21 periodic JSON restores. All three finish and preserve physical custody/private views. These samples do not establish naturally reached allied Fremen special wins; a separate conserved browser final-turn fixture verifies the actual Ready-to-win transition, public guide/log, private hand and pending/finished refresh.

All 835 opening games and original seat/recovery records remain unchanged (902 after checks). All 869 rooms and records present after the reported outage also remain unchanged; database integrity and foreign keys pass. The healthy server and finished browser seat recovered without restart, reset or recurring automation. Full rules coverage and release gates remain open work.

Verified source tree: 1d9fcf30b54132f66be5f994f410dec6ec019683ee66b24fd4efb7a6aa7f7bbd
2026-09-14 02:59:50 +10:00

126 lines
4.5 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { applyAction, type Action, type Game } from '../game/engine';
import {
addShipmentArrivalAmbassador,
legacyGuildArrival,
richeseNoFieldArrivalAction,
shipmentArrivalAction,
shipmentArrivalGame,
shipmentArrivalPlayer,
shipmentArrivalReload,
shipmentArrivalResources,
} from './fixture-deferred-shipment-arrival';
const overlap = /Ambassadors combined with another arrival reaction/;
function reject(g: Game, player: string, action: Action, pattern: RegExp) {
const before = structuredClone(g);
assert.throws(() => applyAction(g, player, action), pattern);
assert.deepEqual(g, before);
}
void test('an ordinary Guild shipment rejects a known Ambassador and advisor overlap before declaration or payment', (t) => {
const g = shipmentArrivalGame();
addShipmentArrivalAmbassador(g);
const resources = structuredClone(shipmentArrivalResources(g));
const uuid = t.mock.method(crypto, 'randomUUID', () => {
throw Error('Unsupported shipment allocated an event');
});
reject(g, 'guild', shipmentArrivalAction, overlap);
assert.deepEqual(shipmentArrivalResources(g), resources);
assert.equal(g.pendingShipment, null);
assert.equal(g.decision, null);
assert.equal(uuid.mock.callCount(), 0);
});
void test('an own Richese No-Field rejects the unsupported arrival before saving its private cancellation response', () => {
const g = shipmentArrivalGame();
g.active = 'richese';
shipmentArrivalPlayer(g, 'richese').shipped = false;
addShipmentArrivalAmbassador(g);
const action = richeseNoFieldArrivalAction(g);
const before = structuredClone(g);
assert.throws(() => applyAction(g, 'richese', action), overlap);
assert.deepEqual(g, before);
assert.equal(g.pendingShipment, null);
assert.equal(g.response, null);
assert.equal(g.decision, null);
assert.equal(shipmentArrivalPlayer(g, 'richese').noField!.deployed, null);
});
void test('a saved Guild allowance returns only the uncommitted ordinary shipment and permits a safe replacement', () => {
const g = legacyGuildArrival();
const before = structuredClone(g);
const resources = structuredClone(shipmentArrivalResources(g));
const returned = applyAction(shipmentArrivalReload(g), 'guild', {
type: 'decision',
allow: true,
});
assert.deepEqual(g, before);
assert.deepEqual(shipmentArrivalResources(returned), resources);
assert.equal(returned.pendingShipment, null);
assert.equal(returned.decision, null);
assert.equal(shipmentArrivalPlayer(returned, 'guild').shipped, false);
assert.deepEqual(shipmentArrivalPlayer(returned, 'guild').forces, {});
assert.match(returned.log.at(-1)!.text, overlap);
assert.match(
returned.log.at(-1)!.text,
/No forces, spice, cards or shipment allowance were spent/,
);
const retried = applyAction(returned, 'guild', {
...shipmentArrivalAction,
territory: 'polar_sink',
sector: 0,
});
assert.equal(retried.decision?.kind, 'guildShipment');
assert.equal(retried.pendingShipment?.territory, 'polar_sink');
});
void test('a supported Guild allowance still commits once and opens the advisor choice', () => {
let g = shipmentArrivalGame();
g = applyAction(g, 'guild', shipmentArrivalAction);
assert.equal(g.decision?.kind, 'guildShipment');
g = applyAction(shipmentArrivalReload(g), 'guild', {
type: 'decision',
allow: true,
});
assert.deepEqual(shipmentArrivalPlayer(g, 'guild').forces, {
'carthag:11': 4,
});
assert.equal(shipmentArrivalPlayer(g, 'guild').reserves, 16);
assert.equal(shipmentArrivalPlayer(g, 'guild').shipped, true);
assert.equal(g.pendingShipment, null);
assert.equal(g.decision?.kind, 'advisor');
assert.equal(g.decision?.player, 'bg');
});
void test('a malformed saved shipment remains rejected and is not treated as a recoverable arrival overlap', () => {
const g = legacyGuildArrival();
g.pendingShipment!.cost++;
reject(
g,
'guild',
{ type: 'decision', allow: true },
/declared shipment price is no longer current/,
);
});
void test('forged or null special receipts cannot enter the ordinary legacy return path', () => {
for (const corrupt of [
(g: Game) => {
g.pendingShipment!.ambassadorEvent = 'forged';
},
(g: Game) => {
g.pendingShipment!.guildSecretEvent = null as unknown as string;
},
]) {
const g = legacyGuildArrival();
corrupt(g);
reject(g, 'guild', { type: 'decision', allow: true }, overlap);
assert.ok(g.pendingShipment);
assert.equal(g.decision?.kind, 'guildShipment');
}
});