import { describe, expect, it } from 'vitest'; import { BIOMARKER_KINDS, BIOMARKER_KIND_LABEL, BIOMARKER_SEED, BIOMARKER_SOURCES, NCIT_VERIFICATION, buildMeasurement, seedGeneSymbols } from '../src/seed-data/biomarkers.js'; /** * Pure integrity checks on the curated biomarker catalogue (no database). The NCIt codes themselves * were verified live against the EVS REST API (see the file header); these tests guard the shape * and the editorial rules (CLAUDE.md §8: curated metadata only, verified codes, no advice). */ describe('BIOMARKER_SEED', () => { it('covers the canonical catalogue (≥ 45 entries) with unique slugs and NCIt codes', () => { expect(BIOMARKER_SEED.length).toBeGreaterThanOrEqual(45); const slugs = BIOMARKER_SEED.map((b) => b.slug); expect(new Set(slugs).size).toBe(slugs.length); const codes = BIOMARKER_SEED.map((b) => b.ncitCode); expect(new Set(codes).size).toBe(codes.length); }); it('uses only the frozen kind vocabulary and every kind has a label', () => { for (const b of BIOMARKER_SEED) expect(BIOMARKER_KINDS, b.slug).toContain(b.kind); for (const k of BIOMARKER_KINDS) expect(BIOMARKER_KIND_LABEL[k]).toBeTruthy(); }); it('carries a well-formed, biomarker-level NCIt concept on every row', () => { for (const b of BIOMARKER_SEED) { expect(b.ncitCode, b.slug).toMatch(/^C\d{3,7}$/); expect(b.ncitName.length, b.slug).toBeGreaterThan(3); expect(b.ncitConceptKind).toBe('biomarker'); // Never the bare gene concept ("EGFR Gene") — a biomarker/alteration concept is required // ("BCR/ABL1 Fusion Gene" is a fusion concept and passes). expect(b.ncitName, b.slug).not.toMatch(/^[A-Z0-9]+ Gene$/); } expect(NCIT_VERIFICATION.ncitVersion).toMatch(/^\d{2}\.\d{2}[a-z]$/); expect(NCIT_VERIFICATION.verifiedAt).toMatch(/^\d{4}-\d{2}-\d{2}$/); }); it('is slug-safe and names anchor genes or an explicit gene list (or documents why not)', () => { for (const b of BIOMARKER_SEED) { expect(b.slug, b.slug).toMatch(/^[a-z0-9]+(-[a-z0-9]+)*$/); if (b.geneSymbol) expect(b.geneSymbol).toMatch(/^[A-Z0-9-]+$/); for (const g of b.genes ?? []) expect(g, b.slug).toMatch(/^[A-Z0-9-]+$/); if (!b.geneSymbol && !(b.genes?.length)) { // Non-gene markers must say so in their notes (rendered as the empty-state reason). expect(b.notes, `${b.slug} has no gene and no note`).toBeTruthy(); expect(['tmb', 'hrd', 'ctdna', 'msi', 'signature', 'other', 'methylation', 'gene_mutation']).toContain(b.kind); } } }); it('describes neutrally: one sentence, no dosing, no individual advice', () => { for (const b of BIOMARKER_SEED) { expect(b.description.trim().endsWith('.'), b.slug).toBe(true); expect(b.description, b.slug).not.toMatch(/\b\d+\s?mg\b|\bdose\b|\bdosing\b|\byou should\b|\bpatients should\b|\brecommended\b/i); expect(b.description, b.slug).toMatch(/diagnostic|predictive|prognostic|target|eligibility|screening|subtyping|specimen|marker/i); } }); it('cites only verified authority pages and keeps aliases unique', () => { for (const b of BIOMARKER_SEED) { expect(b.sources.length, b.slug).toBeGreaterThan(0); for (const k of b.sources) expect(BIOMARKER_SOURCES[k].url).toMatch(/^https:\/\/(www\.)?(fda\.gov|cancer\.gov)\//); expect(new Set(b.aliases).size, b.slug).toBe(b.aliases.length); expect(b.assays.length, b.slug).toBeGreaterThan(0); } }); it('flags tumor-agnostic only for the markers with FDA tissue-agnostic indications', () => { const flagged = BIOMARKER_SEED.filter((b) => b.tumorAgnostic).map((b) => b.slug).sort(); expect(flagged).toEqual(['braf-v600e', 'dmmr', 'her2', 'msi-h', 'ntrk-fusion', 'ret-fusion', 'tmb-h']); // Each flagged marker needs indication terms so the UI can show the actual approval rows. for (const b of BIOMARKER_SEED.filter((x) => x.tumorAgnostic)) expect(b.indicationTerms?.length, b.slug).toBeGreaterThan(0); }); it('states the MSI-H / dMMR relationship on both entries', () => { const msi = BIOMARKER_SEED.find((b) => b.slug === 'msi-h')!; const dmmr = BIOMARKER_SEED.find((b) => b.slug === 'dmmr')!; expect(msi.notes).toMatch(/dMMR/); expect(dmmr.notes).toMatch(/MSI-H/); expect(msi.genes).toEqual(['MLH1', 'MSH2', 'MSH6', 'PMS2']); expect(dmmr.genes).toEqual(msi.genes); }); }); describe('buildMeasurement', () => { it('produces the jsonb shape the queries read (aliases, genes, variantSlugs, terms, verification)', () => { const her2 = BIOMARKER_SEED.find((b) => b.slug === 'her2')!; const m = buildMeasurement(her2); expect(m.aliases).toContain('ERBB2'); expect(m.tumorAgnostic).toBe(true); expect(m.ncit).toEqual({ code: 'C68748', name: 'HER2/Neu Positive', conceptKind: 'biomarker' }); expect(m.verification).toBe(NCIT_VERIFICATION); expect(m.sources[0]).toHaveProperty('url'); expect(m.genes).toEqual([]); expect(m.variantSlugs).toContain('erbb2-amplification'); expect(m.scoring).toMatch(/3\+/); }); it('omits absent optional fields instead of writing null', () => { const cd19 = BIOMARKER_SEED.find((b) => b.slug === 'cd19')!; const m = buildMeasurement(cd19); expect('scoring' in m).toBe(false); expect(m.tumorAgnostic).toBe(false); }); }); describe('seedGeneSymbols', () => { it('returns every anchor and multi-gene symbol once, sorted', () => { const s = seedGeneSymbols(); expect(s).toEqual([...new Set(s)].sort()); for (const g of ['ERBB2', 'EGFR', 'MLH1', 'PMS2', 'NTRK3', 'BCR', 'ABL1', 'TP53']) expect(s).toContain(g); }); });