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>
83 lines
5.8 KiB
TypeScript
83 lines
5.8 KiB
TypeScript
// testnet-ops: live identity source over a FAKE Wikimedia client. Zero network calls.
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { mkdtempSync, rmSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { wikimediaIdentitySource } from '../server/game/identity-source.ts';
|
|
import { IdentityStore, prebake, toProfile } from '../server/game/identity.ts';
|
|
import type { BackgroundRequest, ProfileBuilder } from '../server/game/identity-source.ts';
|
|
|
|
// A minimal stand-in for shared/duel/profile.ts (#70), so this test needs no unmerged module.
|
|
const ids = (e: any, p: string): string[] => (e?.claims?.[p] ?? []).map((s: any) => s.mainsnak?.datavalue?.value?.id).filter(Boolean);
|
|
const yrs = (e: any, p: string): number[] => (e?.claims?.[p] ?? []).map((s: any) => Number(/^[+-]0*(\d+)-/.exec(s.mainsnak?.datavalue?.value?.time ?? '')?.[1])).filter(Boolean);
|
|
const profile: ProfileBuilder = {
|
|
wikidataEntityParams: q => ({ action: 'wbgetentities', ids: [...q].sort().join('|'), props: 'claims', format: 'json', formatversion: '2' }),
|
|
wikidataLabelParams: q => ({ action: 'wbgetentities', ids: [...q].sort().join('|'), props: 'labels', languages: 'en', format: 'json', formatversion: '2' }),
|
|
classIdsOf: e => [...new Set([...ids(e, 'P31'), ...ids(e, 'P279')])].sort(),
|
|
profileFromSources: ({ enrichment, entity, labels = {} }) => ({
|
|
wikidataId: enrichment.wikidataId, description: enrichment.description, categories: enrichment.categories,
|
|
instanceOf: ids(entity, 'P31').map(id => ({ id, label: labels[id] ?? id })), countries: ids(entity, 'P27'),
|
|
years: [...yrs(entity, 'P569'), ...yrs(entity, 'P570')], died: ids(entity, 'P570').length > 0 || yrs(entity, 'P570').length > 0,
|
|
fetchedRevisionId: enrichment.revisionId }),
|
|
};
|
|
|
|
const enrichmentFor = (pageId: number, wikidataId: string | null) => ({
|
|
pageId, title: `Page ${pageId}`, description: `desc ${pageId}`, wikidataId, revisionId: 1000 + pageId, pageBytes: 1,
|
|
languageCount: 1, languagesTruncated: false, categories: ['Living people', '1948 births'], categoriesTruncated: false,
|
|
fetchedAt: '2026-11-17T00:00:00Z',
|
|
pageviews: { status: 'unavailable', months: [], latestMonth: '2026-10', total: null, dailyAverage: null, trendPercent: null },
|
|
}) as any;
|
|
const claim = (id: string) => ({ rank: 'normal', mainsnak: { snaktype: 'value', datavalue: { type: 'wikibase-entityid', value: { id } } } });
|
|
const time = (t: string) => ({ rank: 'normal', mainsnak: { snaktype: 'value', datavalue: { type: 'time', value: { time: t } } } });
|
|
|
|
function fakeClient(opts: { failClaims?: boolean } = {}) {
|
|
const calls: { url: URL; options: BackgroundRequest }[] = [];
|
|
return { calls, async request(url: URL, options: BackgroundRequest) {
|
|
calls.push({ url, options });
|
|
const props = url.searchParams.get('props'), ids = url.searchParams.get('ids')!.split('|');
|
|
if (props === 'claims' && opts.failClaims) return { response: new Response('busy', { status: 503 }), signal: new AbortController().signal, fromCache: false };
|
|
const entities = Object.fromEntries(ids.map(id => [id, props === 'claims'
|
|
? { id, claims: { P31: [claim('Q5')], P27: [claim('Q30')], P569: [time('+1948-01-02T00:00:00Z')], P570: [time('+2001-01-01T00:00:00Z')] } }
|
|
: { id, labels: { en: { value: id === 'Q5' ? 'human' : `label ${id}` } } }]));
|
|
return { response: Response.json({ entities }), signal: new AbortController().signal, fromCache: false };
|
|
} };
|
|
}
|
|
|
|
test('every request is on the background lane, batched, and the frozen identity is derive-ready', async () => {
|
|
const realFetch = globalThis.fetch;
|
|
globalThis.fetch = (() => { throw new Error('network call in test'); }) as typeof fetch;
|
|
const dir = mkdtempSync(join(tmpdir(), 'identity-src-'));
|
|
try {
|
|
const client = fakeClient();
|
|
const source = wikimediaIdentitySource({ client, profile, enrichment: { async getBackground(id) { return enrichmentFor(id, `Q${id}`); } } });
|
|
const store = new IdentityStore(join(dir, 'id.sqlite'));
|
|
const articles = [1, 2, 3].map(i => ({ tokenId: String(i).repeat(64), pageId: i, title: `Page ${i}`, revisionId: i }));
|
|
const r = await prebake(store, source, articles);
|
|
assert.deepEqual(r, { seen: 3, alreadyFrozen: 0, frozen: 3, unknown: 0 });
|
|
assert.ok(client.calls.every(c => c.options.lane === 'background'));
|
|
assert.ok(client.calls.every(c => c.url.hostname === 'www.wikidata.org'));
|
|
assert.deepEqual(client.calls.map(c => c.url.searchParams.get('props')), ['claims', 'labels']);
|
|
assert.equal(client.calls[0].url.searchParams.get('ids'), 'Q1|Q2|Q3');
|
|
const one = store.get('1'.repeat(64))!;
|
|
assert.equal(one.source, 'wikimedia');
|
|
assert.deepEqual(one.instanceOf, [{ id: 'Q5', label: 'human' }]);
|
|
assert.deepEqual(one.countries, ['Q30']);
|
|
assert.deepEqual(one.years, [1948, 2001]);
|
|
assert.equal(one.died, true);
|
|
assert.equal(one.fetchedRevisionId, 1001);
|
|
assert.equal(toProfile(one).description, 'desc 1');
|
|
store.close();
|
|
} finally { globalThis.fetch = realFetch; rmSync(dir, { recursive: true, force: true }); }
|
|
});
|
|
|
|
test('a failed claims request leaves cards unknown so they are retried, never frozen half-empty', async () => {
|
|
const source = wikimediaIdentitySource({ client: fakeClient({ failClaims: true }), profile,
|
|
enrichment: { async getBackground(id) { if (id === 9) throw new Error('throttled'); return enrichmentFor(id, id === 8 ? null : `Q${id}`); } } });
|
|
const got = await source.lookup([7, 8, 9].map(i => ({ tokenId: String(i).repeat(64), pageId: i, title: `P${i}` })));
|
|
assert.equal(got.get(7), undefined); // has an item, claims failed → retry
|
|
assert.equal(got.get(9), undefined); // enrichment failed → retry
|
|
assert.equal(got.get(8)?.wikidataId, null); // no Wikidata item at all → enrichment-only profile is final
|
|
assert.deepEqual(got.get(8)?.instanceOf, []);
|
|
});
|