forked from WikiDeck/wikideck
Night 2 (2026-11-17), from the `claude/wikideck` fork's `night/2026-11-17` branch. It follows Night 1 (#22).
## What's in it
- **Duel engine** (fork #72, #80): 40-card decks of cards you own, Notability/Citations, keywords, effects T1–T12, Connected, a hidden-information-safe `viewFor`/`logFor`, and replay. Balance v1 tuning (#84) gives the first player about 51%.
- **Card profiles** (#70, #82): Figure, Location, Event, Institution or Doctrine, plus stats, keywords and rules text, all derived from real article data. Templates only.
- **Design and story** (#66, #69, #83): DUEL_DESIGN.md, plus the match log and the encyclopedic "Battle of X (2026)" recap.
- **PvP** (#74, #77, #81, #76, #85):
- The server checks ownership, and 40-card eligibility is enforced.
- Modes: Classic (ranked), Draft and Trending.
- Invites, quick match, Elo, a ladder and recap pages. Online matches render on the duel board.
- **Duel board UI** (#79): MTG-style card faces and combat declaration, built for 360 px first.
- **Polite Wikimedia client** (#73, #75): throttled, cached and identified requests, the mint-path fix, and a prefetch pool.
- **Android mining** (#78): native RandomX, as a sideload build. The emulator mined a testnet block.
- **Testnet ops** (#67, #68).
PR numbers refer to `claude/wikideck`.
## Status
- **Tests:** 423, of which 422 pass, 0 fail and 1 is skipped. The build is OK (`node:24-alpine`, `--network none`).
- **Testnet:** running this commit (036489c) on r350.
- **Untouched:** no changes to `server/testnet/consensus.ts`, `randomx.ts`, `native/` or the mainnet compose.
- **Review:** night-review reviewed fork #66–#79. #80–#85 came from the agents' unfinished branches and were not reviewed.
- **Known gaps:**
- The PvP end-to-end test hasn't been run (it needs two eom.dev accounts).
- Bot matches aren't reachable from Play.
- Card identity pre-bake hasn't been done.
- The RandomX verifier latch (`server/testnet/randomx.ts:140`) is still open.
This PR is for Eric to merge.
🤖 Generated with [Claude Code](https://claude.com/claude-code)Reviewed-on: WikiDeck/wikideck#23
Co-authored-by: Claude <claude@eom.dev>
121 lines
6.9 KiB
TypeScript
121 lines
6.9 KiB
TypeScript
import test from 'node:test';
|
||
import assert from 'node:assert/strict';
|
||
import {
|
||
EMPTY_DECL, NO_LEGAL, blockList, cardSummary, eligibility, firstSentence, previewCombat, tapAttacker, tapBlocker, toggleAttacker, typeLine,
|
||
type BoardCard, type Legal,
|
||
} from '../src/game/duel/model.ts';
|
||
import { PREVIEW_POOL, previewView } from '../src/game/duel/mock.ts';
|
||
|
||
const fig = (id: string, power: number, toughness: number, extra: Partial<BoardCard> = {}): BoardCard =>
|
||
({ id, title: id, type: 'Figure', portal: 'Society', cost: 2, power, toughness, keywords: [], rulesText: '', ...extra });
|
||
|
||
test('attack declaration: one tap toggles a legal attacker, illegal ones are ignored', () => {
|
||
const legal: Legal = { ...NO_LEGAL, attackers: ['a', 'b'] };
|
||
let d = toggleAttacker(EMPTY_DECL, 'a', legal);
|
||
assert.deepEqual(d.attackers, ['a']);
|
||
d = toggleAttacker(d, 'z', legal);
|
||
assert.deepEqual(d.attackers, ['a']);
|
||
d = toggleAttacker(d, 'b', legal);
|
||
d = toggleAttacker(d, 'a', legal);
|
||
assert.deepEqual(d.attackers, ['b']);
|
||
});
|
||
|
||
test('block declaration: two taps per blocker, single blocks, re-tap clears', () => {
|
||
const legal: Legal = { ...NO_LEGAL, blockers: { x: ['A', 'B'], y: ['A'], z: [] } };
|
||
let d = tapBlocker(EMPTY_DECL, 'x', legal);
|
||
assert.equal(d.picked, 'x');
|
||
d = tapAttacker(d, 'A', legal);
|
||
assert.deepEqual(blockList(d), [{ blockerId: 'x', attackerId: 'A' }]);
|
||
assert.equal(d.picked, undefined);
|
||
// y takes over A; x is freed (at most one blocker per attacker).
|
||
d = tapAttacker(tapBlocker(d, 'y', legal), 'A', legal);
|
||
assert.deepEqual(blockList(d), [{ blockerId: 'y', attackerId: 'A' }]);
|
||
// y can't block B: the tap is ignored and y stays picked.
|
||
d = tapAttacker(tapBlocker(EMPTY_DECL, 'y', legal), 'B', legal);
|
||
assert.deepEqual(blockList(d), []);
|
||
// A blocker with no legal attacker can't be picked.
|
||
assert.equal(tapBlocker(EMPTY_DECL, 'z', legal).picked, undefined);
|
||
// Re-tapping an assigned blocker removes the block; so does tapping its attacker with nothing picked.
|
||
d = tapAttacker(tapBlocker(EMPTY_DECL, 'x', legal), 'B', legal);
|
||
assert.deepEqual(blockList(tapBlocker(d, 'x', legal)), []);
|
||
assert.deepEqual(blockList(tapAttacker(d, 'B', legal)), []);
|
||
// One blocker per attacker, and one attacker per blocker.
|
||
d = tapAttacker(tapBlocker(d, 'x', legal), 'A', legal);
|
||
assert.equal(blockList(d).length <= 1, true);
|
||
});
|
||
|
||
test('combat preview: simultaneous damage, single blocks, Well-sourced, marked damage', () => {
|
||
const cards = new Map([fig('a', 3, 3), fig('b', 2, 2), fig('c', 4, 1), fig('w', 1, 3, { keywords: ['Well-sourced'] }), fig('d', 2, 3, { damage: 1 })].map(c => [c.id, c]));
|
||
const out = previewCombat([{ attackerId: 'a', blockerId: 'b' }, { attackerId: 'c' }], cards);
|
||
assert.equal(out.toPlayer, 4);
|
||
assert.deepEqual(out.destroyed.sort(), ['b']);
|
||
// Well-sourced prevents the first 1: a 3-power attacker deals 2 to a 1/3, which survives.
|
||
assert.deepEqual(previewCombat([{ attackerId: 'a', blockerId: 'w' }], cards).destroyed, []);
|
||
// Damage already marked counts: 2 more kills a 2/3 with 1 damage.
|
||
assert.deepEqual(previewCombat([{ attackerId: 'b', blockerId: 'd' }], cards).destroyed.sort(), ['b', 'd']);
|
||
});
|
||
|
||
test('eligibility: exactly the deck size, no borrowed cards, progress label', () => {
|
||
assert.deepEqual(eligibility(23), { eligible: false, owned: 23, needed: 17, label: '23 / 40 cards' });
|
||
assert.equal(eligibility(40).eligible, true);
|
||
assert.equal(eligibility(57).label, '40 / 40 cards');
|
||
assert.equal(eligibility(12, 12).eligible, true); // testnet mode file may lower deckSize
|
||
});
|
||
|
||
test('flavour: first sentence of the extract, not split on initials or abbreviations', () => {
|
||
assert.equal(firstSentence('J. R. R. Tolkien was an English writer. He wrote books.'), 'J. R. R. Tolkien was an English writer.');
|
||
assert.equal(firstSentence('St. Georgen am Längsee is a town. It is in Austria.'), 'St. Georgen am Längsee is a town.');
|
||
assert.equal(firstSentence('Pi is about 3.14 in value. More.'), 'Pi is about 3.14 in value.');
|
||
assert.equal(firstSentence('No full stop here'), 'No full stop here');
|
||
assert.equal(firstSentence(''), undefined);
|
||
assert.ok((firstSentence('word '.repeat(100)) ?? '').length <= 220);
|
||
});
|
||
|
||
test('type line and accessible summary', () => {
|
||
const c = fig('Barack Obama', 3, 4, { subtype: 'People · 1961–', keywords: ['Protected'], tapped: true });
|
||
assert.equal(typeLine(c), 'Figure — People · 1961–');
|
||
assert.equal(cardSummary(c), 'Barack Obama, Figure — People · 1961–, cost 2, 3/4, Protected, tapped');
|
||
});
|
||
|
||
test('preview scenes: a full 5 + 5 board with every card from the real sample', () => {
|
||
assert.equal(PREVIEW_POOL.length, 236);
|
||
for (const scene of ['main', 'attack', 'block', 'over'] as const) {
|
||
const { view } = previewView(scene);
|
||
assert.equal(view.me.battlefield.length, 5);
|
||
assert.equal(view.opponent.battlefield.length, 5);
|
||
}
|
||
for (const c of PREVIEW_POOL) {
|
||
assert.ok(c.keywords.length <= 2, c.title);
|
||
assert.ok(c.cost >= 1 && c.cost <= 6, c.title);
|
||
}
|
||
});
|
||
|
||
test('DuelCard → board card: type line from real data only, flavour is one sentence', async () => {
|
||
const { boardCard, lifespan } = await import('../src/game/duel/cards.ts');
|
||
assert.equal(lifespan('Sultan of Aceh (1530–1537/9)'), '1530–1537');
|
||
assert.equal(lifespan('American voice actor and singer (born 1963)'), '1963–');
|
||
assert.equal(lifespan('American botanist (c.1872–1919)'), '1872–1919');
|
||
assert.equal(lifespan('Species of grasshopper'), undefined);
|
||
const c = boardCard({ cardId: 't', pageId: 1, revisionId: 9, title: 'Salahuddin of Aceh', type: 'Figure', subtype: null, portal: 'History',
|
||
cost: 4, power: 4, toughness: 3, keywords: ['Legacy'], rulesText: 'Legacy.', flavor: 'Sultan of Aceh (1530–1537/9). Second sentence.' });
|
||
assert.equal(typeLine(c), 'Figure — History · 1530–1537');
|
||
assert.equal(c.flavour, 'Sultan of Aceh (1530–1537/9).');
|
||
assert.equal(c.url, 'https://en.wikipedia.org/wiki/Salahuddin_of_Aceh');
|
||
const e = boardCard({ cardId: 'e', pageId: 2, revisionId: 9, title: '1954 Gold Coast general election', type: 'Event', subtype: 'election', portal: 'Society',
|
||
cost: 4, power: null, toughness: null, keywords: [], rulesText: 'x', flavor: '' });
|
||
assert.equal(typeLine(e), 'Event — Society · Election');
|
||
assert.equal(e.power, undefined);
|
||
});
|
||
|
||
test('targeting: multi-step sequences (own Figure, then theirs), players as targets', async () => {
|
||
const { nextTargets, targetsComplete, playerTarget } = await import('../src/game/duel/model.ts');
|
||
const seqs = [['a', 'x'], ['a', 'y'], ['b', 'x']];
|
||
assert.deepEqual([...nextTargets(seqs, [])].sort(), ['a', 'b']);
|
||
assert.deepEqual([...nextTargets(seqs, ['a'])].sort(), ['x', 'y']);
|
||
assert.deepEqual([...nextTargets(seqs, ['b'])], ['x']);
|
||
assert.equal(targetsComplete(seqs, ['a']), false);
|
||
assert.equal(targetsComplete(seqs, ['a', 'y']), true);
|
||
assert.equal(targetsComplete([[]], []), true);
|
||
assert.equal(nextTargets([[playerTarget(1)], ['c']], []).has('player:1'), true);
|
||
});
|