- Point AI client to localhost:11434/v1 (Ollama) - Remove DeepSeek API key dependency - Update model name to qwen3:14b across all routes - Update test mocks to use createLocalLLMClient - Removes need for DEEPSEEK_API_KEY setting Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest'
|
|
|
|
const mockIncident = {
|
|
id: 'inc-1',
|
|
incident_type: 'injury',
|
|
description: 'Worker slipped on wet floor in cold store, fractured wrist.',
|
|
injury_involved: true,
|
|
asset_involved: false,
|
|
medical_status: 'medical_treatment',
|
|
}
|
|
|
|
const triageOutput = {
|
|
severity: 3,
|
|
is_fatality: false,
|
|
is_serious_bodily_injury: true,
|
|
is_dangerous_occurrence: false,
|
|
is_occupational_disease: false,
|
|
rationale: 'Fracture constitutes serious bodily injury under NADOPOD 2004.',
|
|
}
|
|
|
|
vi.mock('@/lib/supabase/server', () => ({
|
|
createClient: vi.fn().mockResolvedValue({
|
|
auth: {
|
|
getUser: vi.fn().mockResolvedValue({ data: { user: { id: 'user-1' } }, error: null }),
|
|
},
|
|
from: vi.fn().mockReturnValue({
|
|
select: vi.fn().mockReturnThis(),
|
|
eq: vi.fn().mockReturnThis(),
|
|
gte: vi.fn().mockResolvedValue({ count: 0 }),
|
|
single: vi.fn()
|
|
.mockResolvedValueOnce({ data: { role: 'hse' } }) // profile
|
|
.mockResolvedValueOnce({ data: mockIncident }), // incident
|
|
}),
|
|
rpc: vi.fn().mockResolvedValue({ error: null }),
|
|
}),
|
|
}))
|
|
|
|
vi.mock('@/lib/claude/client', () => ({
|
|
createLocalLLMClient: vi.fn().mockReturnValue({
|
|
chat: {
|
|
completions: {
|
|
create: vi.fn().mockResolvedValue({
|
|
choices: [{
|
|
message: {
|
|
tool_calls: [{
|
|
type: 'function',
|
|
function: {
|
|
name: 'suggest_triage',
|
|
arguments: JSON.stringify(triageOutput),
|
|
},
|
|
}],
|
|
},
|
|
}],
|
|
}),
|
|
},
|
|
},
|
|
}),
|
|
}))
|
|
|
|
describe('POST /api/incidents/[id]/ai/triage-suggest', () => {
|
|
it('returns triage suggestion with severity and DOSH flags', async () => {
|
|
const { POST } = await import('@/app/api/incidents/[id]/ai/triage-suggest/route')
|
|
const req = new Request('http://localhost/api/incidents/inc-1/ai/triage-suggest', { method: 'POST' })
|
|
const res = await POST(req as never, { params: Promise.resolve({ id: 'inc-1' }) })
|
|
expect(res.status).toBe(200)
|
|
const body = await res.json()
|
|
expect(body.severity).toBe(3)
|
|
expect(body.is_serious_bodily_injury).toBe(true)
|
|
expect(body.rationale).toBeTruthy()
|
|
})
|
|
})
|