Files
Dune/tests/nexus-harkonnen-occupy-quote.test.ts
T
Quintine a2e7029a72
Verify and publish checkpoint container / container (push) Successful in 11m17s
Connect Harkonnen Nexus to Ecaz Occupy
2026-11-16 21:11:16 +11:00

115 lines
6.3 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { leaders, treacheryDeck } from '../game/cards';
import { quoteEcazOccupyBattle } from '../game/ecaz-occupy-battle';
import { NEXUS_FACTIONS, type NexusPlayer } from '../game/nexus-cards';
import {
closeHarkonnenBetrayalSource,
createHarkonnenBetrayalSource,
initialHarkonnenBetrayalCursor,
validateHarkonnenBetrayalHistory,
validateHarkonnenBetrayalSource,
type HarkonnenBetrayalAuthority,
type HarkonnenBetrayalContext,
} from '../game/nexus-harkonnen-betrayal';
import { createTraitorDeclaration } from '../game/traitor-declarations';
import { traitorDeck } from '../game/traitors';
/** The original public alliance, actual traitor custody and complete Occupy
* quote are retained in each source; no runtime battle is claimed here. */
function fixture(side: 'ecaz-leads' | 'harkonnen-leads' | 'opposing' | 'external-ally') {
const together = side === 'ecaz-leads' || side === 'harkonnen-leads';
const external = side === 'external-ally';
const players: NexusPlayer[] = [
{ id: 'e', faction: 'ecaz', ally: together ? 'h' : 'g' },
{ id: 'h', faction: 'harkonnen', ally: together ? 'e' : external ? 'a' : null },
{ id: 'g', faction: 'guild', ally: together ? null : 'e' },
{ id: 'a', faction: 'atreides', ally: external ? 'h' : null },
...(external ? [{ id: 'f', faction: 'fremen' as const, ally: null }] : []),
];
const ally = together ? players[1] : players[2];
const lead = side === 'harkonnen-leads' ? 'h' : 'e';
const opposing = together ? 'g' : external ? 'a' : 'h';
const identity = together ? 'guild-0' : 'ecaz-1';
const holder = external ? 'f' : 'a';
const ecazLoyalty = { player: 'e', card: 'ecaz-0' };
const universe = traitorDeck(players.map(player => ({ leaders: leaders(player.faction) })))
.filter(card => card !== ecazLoyalty.card);
const forces = { normal: 4, elite: 0, eliteStrength: 2 as const, freeSupport: false };
const occupy = quoteEcazOccupyBattle({ advanced: true, battleOrderActor: opposing,
ecaz: { id: 'e', faction: 'ecaz', ally: ally.id, forces },
ally: { id: ally.id, faction: ally.faction, ally: 'e', forces },
lead, canceled: false });
const ctx: HarkonnenBetrayalContext = {
status: 'playing', phase: 6, turn: 2, advanced: true, sequence: 0,
expansions: ['ecaz'], players, ecazLoyalty, universe,
physicalCards: treacheryDeck(['ecaz']),
cards: { version: 1, deck: NEXUS_FACTIONS.filter(card => card !== 'harkonnen'),
discard: [], hands: Object.fromEntries(players.map(player => [player.id,
player.id === holder ? 'harkonnen' : null])) },
traitors: { reserve: universe.filter(card => card !== identity),
players: players.map(player => ({ id: player.id, faction: player.faction,
traitors: player.id === 'h' ? [identity] : [] })) },
battle: { event: 'occupy-battle', attacker: lead, defender: opposing,
plans: { [lead]: { leader: lead === 'h' ? 'harkonnen-0' : 'ecaz-1' },
[opposing]: { leader: opposing === 'g' ? 'guild-0' : opposing === 'a' ? 'atreides-0' : 'harkonnen-0' } },
heroLeaderIds: [], ecazOccupy: occupy },
};
const declaration = createTraitorDeclaration({ ...ctx.battle, players: players.map(player => ({ ...player,
traitors: ctx.traitors.players.find(seat => seat.id === player.id)!.traitors })) }, 'h');
const native: HarkonnenBetrayalAuthority = { provider: 'h', declaration,
nativeWindow: external ? 'harkonnenTraitor' : 'direct', nativeContext: 'original-native-source',
nativeRequired: external ? ['e'] : [], nativePassed: external ? ['e'] : [] };
return { ctx, native, holder, identity };
}
for (const side of ['ecaz-leads', 'harkonnen-leads', 'opposing', 'external-ally'] as const)
void test(`Occupy ${side} preserves the canonical Harkonnen declaration and physical source`, () => {
const { ctx, native, holder, identity } = fixture(side);
const before = structuredClone(ctx);
const source = createHarkonnenBetrayalSource(ctx, native, 'battle-parent');
assert.equal(source.declaration.identity, identity);
assert.equal(source.battle.ecazOccupy?.lead, ctx.battle.ecazOccupy?.lead);
assert.equal(source.eligible, holder);
validateHarkonnenBetrayalSource(ctx, source, native, 'battle-parent');
const { receipt, cursor } = closeHarkonnenBetrayalSource(source, 'use', holder,
initialHarkonnenBetrayalCursor());
validateHarkonnenBetrayalHistory([receipt], cursor, ctx.universe);
assert.deepEqual(ctx, before);
});
void test('Occupy co-side calls never invent an allied Karama counter', () => {
const { ctx, native } = fixture('ecaz-leads');
assert.equal(native.declaration.beneficiary, 'e');
assert.equal(native.declaration.voter, 'h');
assert.throws(() => createHarkonnenBetrayalSource(ctx,
{ ...native, nativeWindow: 'harkonnenTraitor' }, 'battle-parent'));
assert.throws(() => createHarkonnenBetrayalSource(ctx,
{ ...native, nativeRequired: ['a'], nativePassed: ['a'] }, 'battle-parent'));
});
void test('Occupy external Harkonnen ally retains the completed native counter', () => {
const { ctx, native } = fixture('external-ally');
assert.throws(() => createHarkonnenBetrayalSource(ctx,
{ ...native, nativeWindow: 'direct', nativeRequired: [], nativePassed: [] }, 'battle-parent'));
assert.throws(() => createHarkonnenBetrayalSource(ctx,
{ ...native, nativePassed: [] }, 'battle-parent'));
});
void test('Occupy source rejects changed derived profile, rules band or original alliance', () => {
const { ctx, native } = fixture('ecaz-leads');
const source = createHarkonnenBetrayalSource(ctx, native, 'battle-parent');
for (const altered of [
{ ...ctx.battle.ecazOccupy!, fixedEcazDial: ctx.battle.ecazOccupy!.fixedEcazDial + 1 },
{ ...ctx.battle.ecazOccupy!, forceOwner: 'e' },
{ ...ctx.battle.ecazOccupy!, advanced: false },
]) {
const changed = { ...ctx, battle: { ...ctx.battle, ecazOccupy: altered } };
assert.throws(() => createHarkonnenBetrayalSource(changed, native, 'battle-parent'));
assert.throws(() => validateHarkonnenBetrayalSource(changed, source, native, 'battle-parent'));
}
const changedAlliance = { ...ctx, players: ctx.players.map(player => player.id === 'h'
? { ...player, ally: null } : player) };
assert.throws(() => createHarkonnenBetrayalSource(changedAlliance, native, 'battle-parent'));
});