forked from WikiDeck/wikideck
Overnight build by 17 Claude agents (2026-11-16 22:45 → 01:30 EST), coordinated in [claude/wikideck milestone 63](https://gitea.eom.dev/claude/wikideck/milestone/63). **For Eric's review. Do not merge without it.** The full write-up is in `docs/night/REPORT.md`. **What's in it** (38 reviewed PRs, squash-merged into `night/2026-11-16`): - **Edit War:** - a 3-lane, 6-turn card game built on what WikiDeck cards actually hold - a pure, deterministic, off-chain rules engine (`shared/game/`, with the API in `docs/game/ENGINE_API.md`); rules are data and v1.1 is the default - a mobile-first Play UI with a lobby, deck builder, four loaner starter decks, a match against the AI, results and a tutorial - a landing page (fixes #3) - **Design and balance:** `docs/game/DESIGN.md`, `CARD_DATA.md` (236 sampled articles) and `BALANCE.md` (bot simulations). Starter pairings went from 23–77% on v1 to roughly even on v1.1. - **eom.dev accounts:** Dex OIDC with PKCE, plus off-chain wallet linking, where the client builds the message it signs (`server/account/`, `src/auth/`). - **Peer-hosted game modes:** modes are JSON data, never code. Node API at `/api/game/*`, with host credit and leaderboards. Three example modes (`shared/game/modes.ts`, `server/game/`, `docs/game/HOSTING.md`). - **Mobile:** Capacitor 7 Android app (a debug APK played a full match against the AI in the emulator), and an iOS project waiting on Xcode (`docs/night/ANDROID.md`, `docs/night/IOS.md`). - **Testnet tooling:** `deploy/night/` (LAN-only, 3 nodes) and an optional `WIKIDECK_USER_AGENT` (the default is unchanged). **Not touched:** consensus and protocol (`server/chain.ts`, `shared/protocol.ts`, `server/testnet/{consensus,ledger,…}.ts`, `native/`), the live deployment and mainnet. Matches run off-chain and never move or burn NFTs. **Checks:** the final integration gate passed in `node:24-alpine`: `npm test` 241/242 with 0 fail (1 skipped), and `npm run build` passes. The repo needs Node 24, because Node 20 fails 12 tests falsely. **Decisions for Eric** (see REPORT.md, Known issues and Next steps): 1. whether the live node should set `WIKIDECK_USER_AGENT` 2. the Xcode licence, which you should accept yourself 3. #49 in the fork, a bot change held after the freeze 4. on-chain host rewards (proposal only, in HOSTING.md) 🤖 Generated with [Claude Code](https://claude.com/claude-code)Reviewed-on: WikiDeck/wikideck#22 Co-authored-by: Claude <claude@eom.dev>
124 lines
5.4 KiB
TypeScript
124 lines
5.4 KiB
TypeScript
// Property tests over random legal play (engine-b). Failures print a seed: rerun with PROP_SEED=<seed>.
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
DEFAULT_RULESET, FACTION_KEYWORD, PLAYERS, applyAction, createMatch, deserialize, isOver, legalActions, replay, result,
|
|
serialize, starterDeck, viewFor, type Action, type Faction, type GameCard, type MatchState,
|
|
} from '../shared/game/index.ts';
|
|
import { forAll, type Gen } from './game/property.ts';
|
|
|
|
const MAX_ACTIONS = 2000;
|
|
const FACTIONS = Object.keys(FACTION_KEYWORD) as Faction[];
|
|
const STATS = ['attention', 'depth', 'reach'] as const;
|
|
|
|
/** A starter deck with random factions, homes and trend, keywords per §10.1, so every keyword and Portal gets exercised. */
|
|
function randomDeck(g: Gen, tag: string): GameCard[] {
|
|
return starterDeck(tag).map(card => {
|
|
const faction = g.pick(FACTIONS);
|
|
return { ...card, cardId: `${tag}:${card.cardId}`, faction, home: g.pick(STATS), trend: g.pick([-1, 0, 0, 1] as const),
|
|
keyword: card.cost === 1 ? null : FACTION_KEYWORD[faction] };
|
|
});
|
|
}
|
|
|
|
function decksFor(g: Gen, seed: number): [GameCard[], GameCard[]] {
|
|
return [randomDeck(g, `a-${seed}`), randomDeck(g, `b-${seed}`)];
|
|
}
|
|
|
|
/** Random legal play; commits come out at random so queues of every length happen. Concede is rare. */
|
|
function playOut(g: Gen, state: MatchState, check?: (s: MatchState) => void) {
|
|
const log: Action[] = [];
|
|
for (let steps = 0; !isOver(state); steps++) {
|
|
assert.ok(steps <= MAX_ACTIONS, `match did not terminate within ${MAX_ACTIONS} actions`);
|
|
const options = PLAYERS.flatMap(player => legalActions(state, player));
|
|
assert.ok(options.length > 0, `no legal actions in a live match (turn ${state.turn})`);
|
|
const action: Action = g.bool(0.002) ? { type: 'concede', player: g.pick(PLAYERS) } : g.pick(options);
|
|
log.push(action);
|
|
state = applyAction(state, action);
|
|
check?.(state);
|
|
}
|
|
return { state, log };
|
|
}
|
|
|
|
test('random legal play never crashes, always terminates within the turn cap, and has a result', () => {
|
|
forAll(200, (g, seed) => {
|
|
const { state } = playOut(g, createMatch(DEFAULT_RULESET, decksFor(g, seed), seed));
|
|
const r = result(state);
|
|
assert.ok(r, 'finished match has a result');
|
|
assert.ok(r.turns <= DEFAULT_RULESET.turns);
|
|
if (r.reason !== 'concede' && r.reason !== 'afk') {
|
|
const led = r.topicsLed;
|
|
if (r.winner === null) assert.equal(led[0], led[1]);
|
|
else assert.ok(led[r.winner] > led[1 - r.winner] || r.reason === 'totalPower');
|
|
}
|
|
});
|
|
});
|
|
|
|
test('same seed, decks and actions give the same match (replay)', () => {
|
|
forAll(50, (g, seed) => {
|
|
const decks = decksFor(g, seed);
|
|
const first = playOut(g, createMatch(DEFAULT_RULESET, decks, seed));
|
|
const again = replay(DEFAULT_RULESET, decks, seed, first.log);
|
|
assert.deepEqual(again, first.state);
|
|
});
|
|
});
|
|
|
|
test('createMatch is deterministic per seed and varies across seeds', () => {
|
|
const decks = (): [GameCard[], GameCard[]] => [starterDeck('x'), starterDeck('y')];
|
|
assert.deepEqual(createMatch(DEFAULT_RULESET, decks(), 7), createMatch(DEFAULT_RULESET, decks(), 7));
|
|
const distinct = new Set(Array.from({ length: 20 }, (_, i) => JSON.stringify(createMatch(DEFAULT_RULESET, decks(), i))));
|
|
assert.ok(distinct.size > 1);
|
|
});
|
|
|
|
test('serialize/deserialize round-trips after every action', () => {
|
|
forAll(30, (g, seed) => {
|
|
playOut(g, createMatch(DEFAULT_RULESET, decksFor(g, seed), seed), s => assert.deepEqual(deserialize(serialize(s)), s));
|
|
});
|
|
});
|
|
|
|
test('applyAction never mutates its input', () => {
|
|
forAll(30, (g, seed) => {
|
|
let state = createMatch(DEFAULT_RULESET, decksFor(g, seed), seed);
|
|
for (let steps = 0; !isOver(state) && steps < MAX_ACTIONS; steps++) {
|
|
const before = serialize(state);
|
|
const next = applyAction(state, g.pick(PLAYERS.flatMap(player => legalActions(state, player))));
|
|
assert.equal(serialize(state), before);
|
|
state = next;
|
|
}
|
|
});
|
|
});
|
|
|
|
test('every listed legal action is accepted; a finished match lists none', () => {
|
|
forAll(30, (g, seed) => {
|
|
const { state } = playOut(g, createMatch(DEFAULT_RULESET, decksFor(g, seed), seed), s => {
|
|
for (const player of PLAYERS) for (const action of legalActions(s, player)) assert.doesNotThrow(() => applyAction(s, action));
|
|
});
|
|
for (const player of PLAYERS) assert.deepEqual(legalActions(state, player), []);
|
|
});
|
|
});
|
|
|
|
test('lane power is never negative and lanes never exceed capacity', () => {
|
|
forAll(50, (g, seed) => {
|
|
playOut(g, createMatch(DEFAULT_RULESET, decksFor(g, seed), seed), s => {
|
|
for (const player of PLAYERS) {
|
|
const view = viewFor(s, player);
|
|
for (const lane of view.lanes) {
|
|
assert.ok(lane.power[0] >= 0 && lane.power[1] >= 0);
|
|
for (const side of lane.cardPower) for (const p of side) assert.ok(p >= 0);
|
|
}
|
|
}
|
|
for (const lane of s.lanes) for (const side of lane.cards) assert.ok(side.length <= s.ruleset.laneCapacity);
|
|
});
|
|
});
|
|
});
|
|
|
|
test('a view never shows the opponent hand or queue', () => {
|
|
forAll(30, (g, seed) => {
|
|
playOut(g, createMatch(DEFAULT_RULESET, decksFor(g, seed), seed), s => {
|
|
for (const player of PLAYERS) {
|
|
const text = JSON.stringify(viewFor(s, player));
|
|
for (const card of s.players[1 - player].hand) assert.ok(!text.includes(`"${card.cardId}"`), `p${player} sees ${card.cardId}`);
|
|
}
|
|
});
|
|
});
|
|
});
|