From a49cc124fed9855d5a2a4cd38ee42ec3a60de900 Mon Sep 17 00:00:00 2001 From: Dorian Date: Thu, 12 Mar 2026 23:37:21 +0000 Subject: [PATCH] test: expand human-responses tests to 11 cases (isHumanPlayer, getPendingAnswers, numericDistractors) Co-Authored-By: Claude Opus 4.6 --- server/src/engine/human-responses.test.ts | 49 ++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/server/src/engine/human-responses.test.ts b/server/src/engine/human-responses.test.ts index ac464a6..f1eac6a 100644 --- a/server/src/engine/human-responses.test.ts +++ b/server/src/engine/human-responses.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, afterEach } from 'vitest' -import { waitForHumanResponse, submitHumanResponse, getPendingChallenge, clearAllPending } from './human-responses.js' +import { waitForHumanResponse, submitHumanResponse, getPendingChallenge, getPendingAnswers, clearAllPending, isHumanPlayer } from './human-responses.js' import type { Challenge } from './challenges.js' const mockChallenge: Challenge = { @@ -86,3 +86,50 @@ describe('submitHumanResponse', () => { expect(result.answer!.length).toBe(2000) }) }) + +describe('isHumanPlayer', () => { + it('returns true for human webhook URL', () => { + expect(isHumanPlayer('http://human.local/')).toBe(true) + }) + + it('returns false for non-human webhook URL', () => { + expect(isHumanPlayer('https://example.com/webhook')).toBe(false) + expect(isHumanPlayer('')).toBe(false) + }) +}) + +describe('getPendingAnswers', () => { + it('returns answers for a pending challenge', () => { + waitForHumanResponse('fight-6', 'bot-6', mockChallenge, 1) + const answers = getPendingAnswers('fight-6', 'bot-6') + expect(answers).toEqual(['2009']) + }) + + it('returns undefined for non-pending challenge', () => { + const answers = getPendingAnswers('nonexistent', 'nobody') + expect(answers).toBeUndefined() + }) +}) + +describe('generateChoices (via waitForHumanResponse)', () => { + it('generates numeric distractors for numeric answers', () => { + const numericChallenge: Challenge = { + type: 'math_blitz', + label: 'Math', + prompt: 'What is 7 * 8?', + answers: ['56'], + scoring: 'factual', + timeout_ms: 5000, + baseDamage: 18, + } + const { choices } = waitForHumanResponse('fight-7', 'bot-7', numericChallenge, 1) + expect(choices).toContain('56') + expect(choices.length).toBe(3) + // Distractors should be different from correct answer + const distractors = choices.filter(c => c !== '56') + expect(distractors.length).toBe(2) + for (const d of distractors) { + expect(Number(d)).not.toBeNaN() + } + }) +})