Files
Dune/tests/moritani-assassinate-controls.test.tsx
T
Quintine 58ae84f8e2 Prototype Moritani Assassinate Leaders with saved Mentat replacement
Connect a qualifying native Advanced Moritani battle loss to private reveal/continue controls, live or already-dead opposing-faction targets, printed-strength bank bounty, and automatic Mentat replacement. Keep the revealed physical card held until Mentat, then set it aside as a public per-faction use marker and draw one private card. All four AI profiles use the owner-only legal quote. New local preview profile supports genuine setup without opening public starts.

Keep unresolved normal traitor-call duration and uniform private no-choice UX explicit. Record normal calls and guard later use without claiming a settled permanent loss. Exclude exceptional captured/foreign leader custody, other expansion factions and combined optional modules from this bounded preview. No mode or publication gate opens.

Independent source/privacy/persistence review and 32 focused cases pass. Battle obligations independently bind cleanup, sealed normal-call logs wait for public revelation, physical replacement custody rejects missing cards and forged same-turn chains, and invalid actions remain immutable. Five authenticated SQLite cases cover pending/resolved restoration, Truthtrance interruption, competing submissions, stale/duplicate actions and corrupt saves. The local writer preserves seats and unrelated rooms.

Validation: types, lint, 4690 offline tests, production build and 43 HTTP tests passed with unchanged source. Two genuine Advanced four-profile games finish in 296 and 101 actions with zero rejected candidates, ten periodic JSON rounds and eight restored final seat views. All physical cards, forces and elites remain conserved. Two observed assassination opportunities are declined; these complete games do not establish natural reveal/replacement use.

The separate browser exercise explicitly stages conserved battle forces and one physical traitor swap after genuine setup. Actual battle actions open the choice. Master Bewt dies once and pays three spice; the card remains held through cleanup and is automatically replaced at Mentat with a public set-aside marker. Pending and resolved refresh, readable context-correct inspectors, physical custody and private projection pass. Guild independently collects two spice from Arrakeen. The saved QA game remains at human Terror placement.

After the reported outage, all 801 opening games and original seat/recovery records are preserved (835 after HTTP checks). All 802 rooms and original records immediately before verification also remain unchanged. Database integrity and foreign keys pass. The healthy server was reused without restart, reset or recurring automation.

Verified source tree: ad64f6775fb4c481002cc5eccf6d31e490085d11e10b7b19fb7df4947bcf0ccd
2026-09-14 02:16:58 +10:00

104 lines
4.3 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { registerHooks } from 'node:module';
import { createElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import type { GameView } from '../game/engine';
const aliases = registerHooks({
resolve(specifier, context, next) {
return next(specifier === 'next/image' ? 'vinext/shims/image' : specifier, context);
},
});
const { MoritaniAssassinate, MoritaniAssassinateHistory } = await import('../components/moritani-assassinate');
function view(overrides: Record<string, unknown> = {}) {
return {
me: 'm',
players: [
{ id: 'm', name: 'Moritani', faction: 'moritani' },
{ id: 'o', name: 'House Opponent', faction: 'atreides' },
],
response: null,
truthtrance: null,
allLeaders: [
{ id: 'atreides-leader-1', name: 'Duke Leto', faction: 'atreides', strength: 5 },
{ id: 'atreides-leader-2', name: 'Thufir Hawat', faction: 'atreides', strength: 3 },
{ id: 'traitor-1', name: 'Duke Leto', faction: 'atreides', strength: 5 },
{ id: 'traitor-2', name: 'Thufir Hawat', faction: 'atreides', strength: 4 },
],
decision: { kind: 'moritaniAssassinate', player: 'm', event: 'assassinate-1' },
moritaniAssassinate: {
owner: 'm',
blocked: null,
pending: {
event: 'assassinate-1', opponent: 'o', territory: 'Arrakeen',
cards: [
{ card: 'traitor-1', name: 'Duke Leto', bounty: 5, dead: false },
{ card: 'traitor-2', name: 'Thufir Hawat', bounty: 0, dead: true },
], blocked: null,
},
history: [],
},
...overrides,
} as unknown as GameView;
}
function markup(game: GameView, busy = false) {
return renderToStaticMarkup(createElement(MoritaniAssassinate, { game, act() {}, busy }));
}
void test('owner sees public traitor choices, bounty, dead-target legality and rules', () => {
const html = markup(view());
assert.match(html, /Traitor Card to reveal/);
assert.match(html, /Duke Leto/);
assert.match(html, /5 spice bounty/);
assert.match(html, /Thufir Hawat · dead target · 0 spice/);
assert.match(html, /replaced automatically during Mentat Pause/);
assert.match(html, /cannot be canceled with Karama/);
const dead = markup(view({ moritaniAssassinate: {
owner: 'm', blocked: null, pending: {
event: 'assassinate-1', opponent: 'o', territory: 'Arrakeen',
cards: [{ card: 'traitor-2', name: 'Thufir Hawat', bounty: 0, dead: true }], blocked: null,
}, history: [],
} }));
assert.match(dead, /0 spice; target already dead/);
assert.match(dead, /Printed leader strength: 4/);
});
void test('nonowner, stale, blocked, response and Truthtrance contexts stay guarded', () => {
assert.equal(markup(view({ me: 'o' })), '');
assert.equal(markup(view({ decision: { kind: 'moritaniAssassinate', player: 'm', event: 'old' } })), '');
const blocked = markup(view({ moritaniAssassinate: {
owner: 'm', blocked: 'No eligible leader remains.', pending: {
event: 'assassinate-1', opponent: 'o', territory: 'Arrakeen', cards: [], blocked: 'No eligible leader remains.',
}, history: [],
} }));
assert.match(blocked, /No eligible leader remains/);
assert.match(blocked, />Continue</);
assert.match(markup(view({ response: { kind: 'test' } })), /disabled=""/);
assert.match(markup(view({ truthtrance: { stage: 'answer' } })), /disabled=""/);
});
void test('public history shows face-up traitor markers and read-only inspection for every seat', () => {
const html = renderToStaticMarkup(createElement(MoritaniAssassinateHistory, {
game: view({
moritaniAssassinate: {
owner: 'm', blocked: null, pending: null,
history: [
{ event: 'old-1', turn: 2, opponent: 'o', faction: 'atreides', territory: 'arrakeen', card: 'atreides-leader-1', bounty: 5, stage: 'revealed' },
{ event: 'old-2', turn: 3, opponent: 'o', faction: 'atreides', territory: 'carthag', card: 'atreides-leader-2', bounty: 3, stage: 'replaced' },
],
},
}),
}));
assert.match(html, /Assassinate Leaders revealed cards/);
assert.match(html, /Revealed · awaiting replacement/);
assert.match(html, /Set aside face up · replaced/);
assert.match(html, /Arrakeen/);
assert.match(html, /Inspect traitor/);
assert.doesNotMatch(html, /Decline Assassinate/);
});
aliases.deregister();