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>
72 lines
4.1 KiB
TypeScript
72 lines
4.1 KiB
TypeScript
import test from 'node:test';
|
||
import assert from 'node:assert/strict';
|
||
import {
|
||
canonicalProfile, classIdsOf, profileFromSources, wikidataEntityParams, wikidataLabelParams, type WikidataEntity,
|
||
} from '../shared/duel/profile.ts';
|
||
import { classify } from '../shared/duel/classify.ts';
|
||
import { derive } from '../shared/duel/derive.ts';
|
||
|
||
const item = (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 } } } });
|
||
|
||
const EWELL: WikidataEntity = {
|
||
id: 'Q1351340',
|
||
claims: {
|
||
P31: [item('Q5')],
|
||
P27: [item('Q30')],
|
||
P569: [time('+1909-04-29T00:00:00Z')],
|
||
P570: [time('+1994-09-12T00:00:00Z')],
|
||
P19: [item('Q1018580')],
|
||
P106: [item('Q33999')],
|
||
P17: [{ rank: 'deprecated', mainsnak: { snaktype: 'value', datavalue: { value: { id: 'Q999' } } } }],
|
||
},
|
||
};
|
||
const ENRICH = { description: 'American actor (1909–1994)', wikidataId: 'Q1351340', categories: ['1994 deaths', 'American male actors'], revisionId: 42 };
|
||
|
||
test('profileFromSources reads P31, countries, years, death and cited items; ignores deprecated claims', () => {
|
||
const p = profileFromSources({ enrichment: ENRICH, entity: EWELL, labels: { Q5: 'human' }, links: [9, 3, 9] });
|
||
assert.deepEqual(p, {
|
||
wikidataId: 'Q1351340', description: 'American actor (1909–1994)', categories: ['1994 deaths', 'American male actors'],
|
||
instanceOf: [{ id: 'Q5', label: 'human' }], fetchedRevisionId: 42,
|
||
countries: ['Q30'], years: [1909, 1994], died: true, cites: ['Q1018580', 'Q30'], links: [3, 9],
|
||
});
|
||
assert.equal(classify(p).type, 'Figure');
|
||
});
|
||
|
||
test('BCE years are negative; malformed and novalue claims are skipped without throwing', () => {
|
||
const entity: WikidataEntity = { claims: {
|
||
P571: [time('-0753-04-21T00:00:00Z'), { mainsnak: { snaktype: 'novalue' } }, { mainsnak: { snaktype: 'value', datavalue: { value: 'junk' } } }],
|
||
P31: [item('not-a-qid'), item('Q515')],
|
||
} };
|
||
const p = profileFromSources({ enrichment: { ...ENRICH, categories: [] }, entity });
|
||
assert.deepEqual(p.years, [-753]);
|
||
assert.deepEqual(p.instanceOf, [{ id: 'Q515', label: 'Q515' }]);
|
||
assert.equal(classify(p).type, 'Location', 'Q-id anchors classify even without labels');
|
||
assert.equal(profileFromSources({ enrichment: ENRICH, entity: null }).instanceOf.length, 0);
|
||
});
|
||
|
||
test('without a Wikidata item the profile still classifies from categories and description', () => {
|
||
const p = profileFromSources({ enrichment: { description: 'Village in Poland', wikidataId: null, categories: ['Villages in Gmina X'], revisionId: 1 } });
|
||
assert.equal(classify(p).type, 'Location');
|
||
});
|
||
|
||
test('request parameters: claims-only entities, English labels, ≤ 50 sorted ids', () => {
|
||
assert.deepEqual(wikidataEntityParams(['Q5', 'Q1']), { action: 'wbgetentities', ids: 'Q1|Q5', props: 'claims', format: 'json', formatversion: '2' });
|
||
assert.equal(wikidataLabelParams(['Q5']).props, 'labels');
|
||
assert.throws(() => wikidataEntityParams([]), RangeError);
|
||
assert.throws(() => wikidataLabelParams(Array.from({ length: 51 }, (_, i) => `Q${i + 1}`)), RangeError);
|
||
assert.deepEqual(classIdsOf({ claims: { P31: [item('Q5')], P279: [item('Q2'), item('Q5')] } }), ['Q2', 'Q5']);
|
||
});
|
||
|
||
test('canonicalProfile is key-order independent, and the frozen profile derives the same card twice', () => {
|
||
const p = profileFromSources({ enrichment: ENRICH, entity: EWELL, labels: { Q5: 'human' } });
|
||
const shuffled = Object.fromEntries(Object.entries(p).reverse()) as typeof p;
|
||
assert.equal(canonicalProfile(shuffled), canonicalProfile(p));
|
||
const chain = { tokenId: 'ab'.repeat(32), article: { pageId: 1, title: 'Tom Ewell', extract: 'Tom Ewell was an American actor. More.', revisionId: 42 },
|
||
statsSnapshot: { pageBytes: 9000, languageCount: 30, stats: { attention: 60, depth: 70, reach: 50 } } };
|
||
const thawed = JSON.parse(canonicalProfile(p));
|
||
assert.deepEqual(derive(chain, thawed), derive(chain, p));
|
||
assert.equal(derive(chain, p).flavor, 'Tom Ewell was an American actor.');
|
||
assert.ok(derive(chain, p).keywords.includes('Legacy'));
|
||
});
|