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>
100 lines
5.5 KiB
TypeScript
100 lines
5.5 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { collectionFromBlocks, deckProblem, eligibility, fillDeck, parseCollection, playableCount, progressLabel, type Collection } from '../src/game/collection/collection.ts';
|
|
import { CLASSIC, parseDuelModes } from '../src/game/collection/duelModes.ts';
|
|
import { inviteCode, inviteFromPath, parseDuelStatus, parseLadder, parseSeat } from '../src/game/online.ts';
|
|
import type { TestnetBlock } from '../shared/testnet.ts';
|
|
|
|
const card = (i: number, pageId = 1000 + i) => ({ tokenId: `t${i}`, pageId, title: `Article ${pageId}` });
|
|
const coll = (n: number, pages?: (i: number) => number, deckSize = 40): Collection =>
|
|
({ deckSize, copyLimit: 4, source: 'server', cards: Array.from({ length: n }, (_, i) => card(i, pages?.(i))) });
|
|
|
|
test('23 owned cards: not eligible, shows "23 / 40 cards" and needs 17 more', () => {
|
|
const e = eligibility(coll(23));
|
|
assert.equal(e.eligible, false);
|
|
assert.equal(e.needed, 17);
|
|
assert.equal(progressLabel(e), '23 / 40 cards');
|
|
});
|
|
|
|
test('40 owned distinct cards are eligible; the copy limit caps playable cards per article', () => {
|
|
assert.equal(eligibility(coll(40)).eligible, true);
|
|
// 44 cards over 10 articles: at most 4 copies each → 40 playable.
|
|
assert.equal(playableCount(coll(44, i => i % 10)), 40);
|
|
// 50 cards of 5 articles: only 20 playable, so not eligible despite owning 50.
|
|
const e = eligibility(coll(50, i => i % 5));
|
|
assert.equal(e.owned, 50);
|
|
assert.equal(e.playable, 20);
|
|
assert.equal(e.eligible, false);
|
|
});
|
|
|
|
test('deckProblem: exactly deckSize owned cards, no repeats, copy limit enforced', () => {
|
|
const c = coll(60, i => (i < 8 ? 1 : 1000 + i));
|
|
const legal = fillDeck([], c);
|
|
assert.equal(legal.length, 40);
|
|
assert.equal(deckProblem(legal, c), '');
|
|
assert.match(deckProblem(legal.slice(1), c), /exactly 40/);
|
|
assert.match(deckProblem([...legal.slice(1), 'not-mine'], c), /no longer own/);
|
|
assert.match(deckProblem([...legal.slice(1), legal[2]], c), /twice/);
|
|
const fiveCopies = [...c.cards.slice(0, 5).map(x => x.tokenId), ...c.cards.slice(8, 43).map(x => x.tokenId)];
|
|
assert.match(deckProblem(fiveCopies, c), /At most 4 copies/);
|
|
});
|
|
|
|
test('fillDeck keeps still-owned saved cards first and drops sold ones', () => {
|
|
const c = coll(45);
|
|
const deck = fillDeck(['t44', 'gone', 't43'], c);
|
|
assert.deepEqual(deck.slice(0, 2), ['t44', 't43']);
|
|
assert.equal(deck.length, 40);
|
|
assert.ok(!deck.includes('gone'));
|
|
});
|
|
|
|
test('a testnet mode may lower deckSize; production default stays 40', () => {
|
|
assert.equal(parseCollection({}).deckSize, 40);
|
|
assert.equal(eligibility(coll(12, undefined, 10)).eligible, true);
|
|
});
|
|
|
|
test('parseCollection drops malformed cards, duplicate tokenIds and non-https urls', () => {
|
|
const c = parseCollection({ deckSize: 40, copyLimit: 4, cards: [
|
|
{ tokenId: 'a', pageId: 5, title: 'Five', url: 'javascript:alert(1)', imageUrl: 'https://upload.wikimedia.org/x.jpg' },
|
|
{ tokenId: 'a', pageId: 6, title: 'Dup' }, { tokenId: 'b' }, null, 'x', { tokenId: 'c', pageId: -1 },
|
|
] });
|
|
assert.equal(c.cards.length, 1);
|
|
assert.equal(c.cards[0].url, undefined);
|
|
assert.equal(c.cards[0].imageUrl, 'https://upload.wikimedia.org/x.jpg');
|
|
});
|
|
|
|
test('the local fallback reads real owned blocks only', () => {
|
|
const block = { tokenId: 'tok', height: 7, article: { pageId: 9, title: 'Nine', revisionId: 3, url: 'https://en.wikipedia.org/wiki/Nine', extract: 'x', category: 'Places', source: 'live' } } as unknown as TestnetBlock;
|
|
const c = collectionFromBlocks([block]);
|
|
assert.equal(c.source, 'local');
|
|
assert.deepEqual(c.cards.map(x => [x.tokenId, x.pageId, x.height]), [['tok', 9, 7]]);
|
|
});
|
|
|
|
test('invite links: parse a pasted URL, a bare code, and the deep link path', () => {
|
|
assert.equal(inviteCode('https://wikideck.eom.dev/play/invite/AbC_123'), 'AbC_123');
|
|
assert.equal(inviteCode(' AbC_123 '), 'AbC_123');
|
|
assert.equal(inviteCode('https://evil.example/<script>'), '');
|
|
assert.equal(inviteFromPath('/play/invite/xyz9'), 'xyz9');
|
|
assert.equal(inviteFromPath('/play/join/lob_1'), 'lob_1');
|
|
assert.equal(inviteFromPath('/battle/abc'), '');
|
|
});
|
|
|
|
test('host responses are validated: seats, statuses and the ladder', () => {
|
|
assert.deepEqual(parseSeat({ lobbyId: 'L1', seat: 1, token: 'tok', invite: 'inv1' }), { lobbyId: 'L1', seat: 1, token: 'tok', invite: 'inv1' });
|
|
assert.throws(() => parseSeat({ lobbyId: 'L1', seat: 2, token: 'tok' }), /invalid seat/);
|
|
const s = parseDuelStatus({ lobbyId: 'L1', version: 4, phase: 'bogus', players: [{ name: 'x'.repeat(99), rating: 1211.6 }], matchId: '../etc' });
|
|
assert.equal(s.phase, 'waiting');
|
|
assert.equal(s.players[0].name.length, 24);
|
|
assert.equal(s.players[0].rating, 1212);
|
|
assert.equal(s.matchId, undefined);
|
|
const l = parseLadder({ entries: [{ name: 'alice', rating: 1224, wins: 3, losses: 1 }, { name: '', wins: -2 }, 7] });
|
|
assert.deepEqual(l, [{ name: 'alice', rating: 1224, wins: 3, losses: 1, draws: 0 }, { name: 'Anonymous', rating: null, wins: 0, losses: 0, draws: 0 }]);
|
|
});
|
|
|
|
test('only duel-engine modes are offered; Classic is the default', () => {
|
|
assert.equal(CLASSIC.id, 'classic');
|
|
const m = parseDuelModes({ modes: [{ mode: { id: 'standard', name: 'Edit War', engine: 'editwar' } },
|
|
{ mode: { id: 'classic', name: 'Classic', engine: 'duel', limits: { rated: true } } },
|
|
{ mode: { id: 'e2e', name: 'Testnet E2E', engine: 'duel', rules: { deckSize: 20 } } }] });
|
|
assert.deepEqual(m.map(x => [x.id, x.ranked, x.deckSize]), [['classic', true, undefined], ['e2e', false, 20]]);
|
|
});
|