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>
57 lines
3.4 KiB
TypeScript
57 lines
3.4 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { WikipediaArticleSource } from '../server/wiki.ts';
|
|
import { WikipediaEnrichment } from '../server/enrichment.ts';
|
|
import { PROJECT_URL, defaultUserAgent, wikimediaUserAgent } from '../server/wikimedia-user-agent.ts';
|
|
|
|
function capture() {
|
|
const agents: string[] = [];
|
|
const fetcher: typeof fetch = async (_input, init) => {
|
|
agents.push(new Headers(init?.headers).get('User-Agent') ?? '');
|
|
return new Response('rate limited', { status: 429, headers: { 'Content-Type': 'text/plain' } });
|
|
};
|
|
return { agents, fetcher };
|
|
}
|
|
async function agentsFor(env: string | undefined, contact?: string) {
|
|
const previous = process.env.WIKIDECK_USER_AGENT, previousContact = process.env.WIKIDECK_OPERATOR_CONTACT;
|
|
if (env === undefined) delete process.env.WIKIDECK_USER_AGENT; else process.env.WIKIDECK_USER_AGENT = env;
|
|
if (contact === undefined) delete process.env.WIKIDECK_OPERATOR_CONTACT; else process.env.WIKIDECK_OPERATOR_CONTACT = contact;
|
|
try {
|
|
const article = capture(), enrichment = capture();
|
|
await assert.rejects(new WikipediaArticleSource(article.fetcher).random());
|
|
await new WikipediaEnrichment({ fetch: enrichment.fetcher }).getFresh(12345).catch(() => {});
|
|
return { article: article.agents, enrichment: enrichment.agents };
|
|
} finally {
|
|
if (previous === undefined) delete process.env.WIKIDECK_USER_AGENT; else process.env.WIKIDECK_USER_AGENT = previous;
|
|
if (previousContact === undefined) delete process.env.WIKIDECK_OPERATOR_CONTACT;
|
|
else process.env.WIKIDECK_OPERATOR_CONTACT = previousContact;
|
|
}
|
|
}
|
|
|
|
test('default Wikimedia user agent names the project, the operator contact and node', async () => {
|
|
const { article, enrichment } = await agentsFor(undefined, 'ops@example.org');
|
|
const expected = `WikiDeck/0.1.0 (+${PROJECT_URL}; ops@example.org) node/${process.versions.node}`;
|
|
assert.equal(defaultUserAgent({ WIKIDECK_OPERATOR_CONTACT: 'ops@example.org' }), expected);
|
|
assert.ok(article.length > 0 && article.every(a => a === expected));
|
|
assert.ok(enrichment.length > 0 && enrichment.every(a => a === expected));
|
|
assert.equal(defaultUserAgent({ PUBLIC_ORIGIN: 'https://node.example' }),
|
|
`WikiDeck/0.1.0 (+${PROJECT_URL}; https://node.example) node/${process.versions.node}`);
|
|
assert.equal(defaultUserAgent({}), `WikiDeck/0.1.0 (+${PROJECT_URL}) node/${process.versions.node}`);
|
|
// Unsafe contacts are dropped rather than breaking the header's comment syntax.
|
|
assert.equal(defaultUserAgent({ WIKIDECK_OPERATOR_CONTACT: 'a); evil(' }), defaultUserAgent({}));
|
|
});
|
|
|
|
test('WIKIDECK_USER_AGENT overrides both Wikimedia clients', async () => {
|
|
const ua = 'WikiDeck-testnet/0.1 (https://gitea.eom.dev/claude/wikideck; private testnet)';
|
|
const { article, enrichment } = await agentsFor(ua);
|
|
assert.ok(article.length > 0 && article.every(a => a === ua));
|
|
assert.ok(enrichment.length > 0 && enrichment.every(a => a === ua));
|
|
});
|
|
|
|
test('blank, oversized or control-character overrides fall back to the default', () => {
|
|
for (const bad of ['', ' ', 'x'.repeat(257), 'bad\r\nX-Injected: 1', 'tab\there'])
|
|
assert.equal(wikimediaUserAgent('fallback', { WIKIDECK_USER_AGENT: bad }), 'fallback');
|
|
assert.equal(wikimediaUserAgent('fallback', {}), 'fallback');
|
|
assert.equal(wikimediaUserAgent('fallback', { WIKIDECK_USER_AGENT: ' Custom/1.0 (x) ' }), 'Custom/1.0 (x)');
|
|
});
|