Files
wikideck/shared/duel/sample.ts
T
claudeandClaude Opus 5.5 5076299e7c [duel-cards] classify: on-chain fallback (extract definition, title, mint category) before Doctrine
An empty profile typed every card as Doctrine (night-review on #61). derive() now passes
chain.article to classify/subtypeFor; full-profile results are unchanged (fixture identical).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 00:50:13 -05:00

42 lines
1.9 KiB
TypeScript

/**
* Fixture: docs/game/card-sample.json (236 real random cards) → DuelCard[], for sim-balance, the UI
* and tests. The sample has no on-chain extract, so flavour falls back to the description, and its
* tokenIds are synthetic (the pageId as 64 hex digits). Owner: duel-cards.
*/
import type { CardProfile } from './classify.ts';
import { derive, DERIVE_RULES, type CardOnChain, type DeriveRules, type DuelCard } from './derive.ts';
/** The fields of a card-sample.json card that derivation reads. */
export interface SampleCard {
pageId: number; title: string; description: string | null; wikidataId: string | null; revisionId: number;
pageBytes: number; languageCount: number; categories: string[];
stats: { attention: number | null; depth: number; reach: number };
instanceOf: { id: string; label: string }[];
extract?: string;
/** The on-chain mint-time category (server/wiki.ts bucket). */
legacyCategory?: string;
}
export function sampleTokenId(pageId: number): string {
return pageId.toString(16).padStart(64, '0');
}
export function sampleInputs(card: SampleCard): { chain: CardOnChain; profile: CardProfile } {
return {
chain: {
tokenId: sampleTokenId(card.pageId),
article: { pageId: card.pageId, title: card.title, extract: card.extract ?? '', revisionId: card.revisionId,
...(card.legacyCategory ? { category: card.legacyCategory } : {}) },
statsSnapshot: { pageBytes: card.pageBytes, languageCount: card.languageCount, stats: card.stats },
},
profile: {
wikidataId: card.wikidataId, description: card.description, categories: card.categories,
instanceOf: card.instanceOf, fetchedRevisionId: card.revisionId,
},
};
}
export function deriveSample(cards: readonly SampleCard[], rules: DeriveRules = DERIVE_RULES): DuelCard[] {
return cards.map(card => { const { chain, profile } = sampleInputs(card); return derive(chain, profile, rules); });
}