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>
86 lines
5.1 KiB
TypeScript
86 lines
5.1 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import { parseMode, parseModeJson, parseModeList, resolveRuleset, trendBonus, mappedPower,
|
|
MAX_MODE_BYTES, MODE_SCHEMA_VERSION } from '../shared/game/modes.ts';
|
|
import { BUILTIN_MODES_DIR, BUILTIN_MODE_IDS, loadModes } from '../server/game/config.ts';
|
|
import { parsePeerOrigins } from '../server/game/discovery.ts';
|
|
import { stubEngine } from './modes-stub-engine.ts';
|
|
import { engineBinding } from '../server/game/engine-binding.ts';
|
|
|
|
const base = { schema: MODE_SCHEMA_VERSION, engine: 'editwar', id: 'my-mode', version: 1, name: 'My mode', description: 'A test mode.' };
|
|
|
|
test('modes: minimal document gets safe defaults', () => {
|
|
const m = parseMode(base);
|
|
assert.deepEqual(m.cards, { preset: 'standard' });
|
|
assert.equal(m.decks.kind, 'constructed');
|
|
assert.equal(m.limits.maxConcurrentMatches, 32);
|
|
assert.deepEqual(m.rules, {});
|
|
});
|
|
|
|
test('modes: built-in example modes parse and resolve against the engine ruleset', () => {
|
|
for (const id of BUILTIN_MODE_IDS) {
|
|
const m = parseModeJson(readFileSync(`${BUILTIN_MODES_DIR}${id}.json`, 'utf8'));
|
|
assert.equal(m.id, id);
|
|
assert.doesNotThrow(() => resolveRuleset(engineBinding.defaultRuleset, m.rules, engineBinding.parseRuleset));
|
|
}
|
|
assert.deepEqual(loadModes({ WIKIDECK_MODES: 'classic,draft' }).map(m => m.id), ['classic', 'draft']);
|
|
assert.deepEqual(loadModes({ WIKIDECK_MODES: 'none' }), []);
|
|
assert.throws(() => loadModes({ WIKIDECK_MODES: 'classic,classic' }), /Duplicate/);
|
|
assert.throws(() => loadModes({ WIKIDECK_MODES: '../../etc/passwd' }), /unknown built-in/);
|
|
});
|
|
|
|
test('modes: schema rejects code, markup, unknown fields and oversize documents', () => {
|
|
assert.throws(() => parseMode({ ...base, script: 'alert(1)' }));
|
|
assert.throws(() => parseMode({ ...base, name: '<img src=x onerror=alert(1)>' }));
|
|
assert.throws(() => parseMode({ ...base, id: 'Bad Id' }));
|
|
assert.throws(() => parseMode({ ...base, cards: { preset: 'eval', code: 'x' } }));
|
|
assert.throws(() => parseMode({ ...base, cards: { preset: 'trending', maxBonus: 99 } }));
|
|
assert.throws(() => parseMode({ ...base, limits: { maxConcurrentMatches: 100000 } }));
|
|
assert.throws(() => parseMode({ ...base, rules: { deep: { deeper: { deepest: 1 } } } }));
|
|
assert.throws(() => parseModeJson(JSON.stringify(base).replace('}', ',"rules":{"__proto__":{"turns":1}}}')));
|
|
assert.throws(() => resolveRuleset(stubEngine.defaultRuleset, JSON.parse('{"__proto__":{"turns":1}}'), stubEngine.parseRuleset));
|
|
assert.throws(() => parseModeJson(JSON.stringify({ ...base, description: 'x'.repeat(MAX_MODE_BYTES) })), /exceeds|too_big|400/);
|
|
const many = Object.fromEntries(Array.from({ length: 60 }, (_, i) => [`k${i}`, i]));
|
|
assert.throws(() => parseMode({ ...base, rules: many }));
|
|
});
|
|
|
|
test('modes: rule overrides merge one level deep and the engine parser has the final say', () => {
|
|
const r = resolveRuleset(stubEngine.defaultRuleset, { turns: 5, scoring: { tieBreak: 'first' } }, stubEngine.parseRuleset);
|
|
assert.deepEqual(r, { deckSize: 4, turns: 5, scoring: { tieBreak: 'first' } });
|
|
assert.throws(() => resolveRuleset(stubEngine.defaultRuleset, { turns: 500 }, stubEngine.parseRuleset));
|
|
assert.throws(() => resolveRuleset(stubEngine.defaultRuleset, { unknownRule: 1 }, stubEngine.parseRuleset));
|
|
assert.deepEqual(stubEngine.defaultRuleset.scoring, { tieBreak: 'draw' }, 'base ruleset is not mutated');
|
|
});
|
|
|
|
test('modes: trending bonus is bounded, optional and symmetric', () => {
|
|
const t = parseMode({ ...base, cards: { preset: 'trending' } }).cards;
|
|
assert.equal(t.preset, 'trending');
|
|
if (t.preset !== 'trending') return;
|
|
assert.equal(trendBonus(t, 60), 2);
|
|
assert.equal(trendBonus(t, 1000), 3);
|
|
assert.equal(trendBonus(t, -1000), -3);
|
|
assert.equal(trendBonus(t, null), 0);
|
|
assert.equal(trendBonus(t, Number.NaN), 0);
|
|
assert.equal(trendBonus({ ...t, penalise: false }, -80), 0);
|
|
assert.equal(mappedPower(4, { preset: 'standard' }, { trendPercent: 500 }), 4);
|
|
});
|
|
|
|
test('modes: peer lists drop invalid modes instead of failing, and are size capped', () => {
|
|
const good = { mode: parseMode(base), stats: { playersOnline: 0, openLobbies: 0, liveMatches: 0, matchesPlayed: 3, distinctPlayers: 2 } };
|
|
const body = { schema: MODE_SCHEMA_VERSION, host: { origin: 'http://a.example', operator: 'A' }, matchesHosted: 3,
|
|
modes: [good, { mode: { ...base, id: 'X' }, stats: good.stats }] };
|
|
const { list, rejected } = parseModeList(JSON.stringify(body));
|
|
assert.equal(list.modes.length, 1);
|
|
assert.equal(rejected, 1);
|
|
assert.throws(() => parseModeList(' '.repeat(300 * 1024)), /too large/);
|
|
});
|
|
|
|
test('modes: game peers are operator-configured origins only', () => {
|
|
assert.deepEqual(parsePeerOrigins('https://a.example, https://a.example/,https://b.example', false), ['https://a.example', 'https://b.example']);
|
|
assert.throws(() => parsePeerOrigins('http://a.example', false));
|
|
assert.deepEqual(parsePeerOrigins('http://node-b:3001', true), ['http://node-b:3001']);
|
|
assert.throws(() => parsePeerOrigins('https://a.example/api', false));
|
|
assert.throws(() => parsePeerOrigins('https://user@a.example', false));
|
|
});
|