diff --git a/server/src/engine/challenges.test.ts b/server/src/engine/challenges.test.ts index 915a388..adcfd80 100644 --- a/server/src/engine/challenges.test.ts +++ b/server/src/engine/challenges.test.ts @@ -1,5 +1,7 @@ import { describe, it, expect } from 'vitest' import { pickChallenge, pickRankedChallenge, getAllChallengeTypes, getAnswerPool, roundToDifficulty } from './challenges.js' +import { TEMPLATES } from './challenge-data.js' +import { EXTRA_PROMPTS } from './challenges-extra.js' describe('pickChallenge', () => { it('returns a valid challenge', () => { @@ -211,6 +213,38 @@ describe('pickChallenge with roundNumber', () => { }) }) +describe('theme selection', () => { + it('theme bias parameter increases themed prompt selection', () => { + let bitcoinWithBias = 0 + let bitcoinWithout = 0 + const runs = 500 + for (let i = 0; i < runs; i++) { + const biased = pickChallenge(new Set(), null, 'bitcoin') + const unbiased = pickChallenge(new Set(), null) + // Check if prompt text contains bitcoin-related content + // Theme-biased should prefer bitcoin prompts when available + if (biased.prompt.toLowerCase().includes('bitcoin') || biased.prompt.toLowerCase().includes('blockchain')) bitcoinWithBias++ + if (unbiased.prompt.toLowerCase().includes('bitcoin') || unbiased.prompt.toLowerCase().includes('blockchain')) bitcoinWithout++ + } + // With bias, should get more bitcoin prompts + expect(bitcoinWithBias).toBeGreaterThanOrEqual(bitcoinWithout) + }) + + it('all prompts have theme tags after tagging', () => { + let tagged = 0 + let total = 0 + for (const t of TEMPLATES) { + const extras = EXTRA_PROMPTS[t.type] || [] + for (const p of [...t.prompts, ...extras]) { + total++ + if (p.theme) tagged++ + } + } + // All prompts should have themes + expect(tagged).toBe(total) + }) +}) + describe('prompt data integrity', () => { it('all 800 prompts are accessible via pickChallenge', () => { // Run enough picks to verify the system works