test: expand human-responses tests to 11 cases (isHumanPlayer, getPendingAnswers, numericDistractors)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-12 23:37:21 +00:00
co-authored by Claude Opus 4.6
parent 5f732d139c
commit a49cc124fe
+48 -1
View File
@@ -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()
}
})
})