mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-28 08:49:38 +02:00
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { runKtxLlmHealthCheck } from './model-health.js';
|
|
|
|
const anthropicModel = { modelId: 'claude-sonnet-4-6' } as never;
|
|
|
|
describe('KTX LLM health check', () => {
|
|
it('runs a minimal non-streaming model call through the configured provider', async () => {
|
|
const generateText = vi.fn(async () => ({ text: 'ok' }));
|
|
const createAnthropic = vi.fn(() => vi.fn(() => anthropicModel));
|
|
|
|
await expect(
|
|
runKtxLlmHealthCheck(
|
|
{
|
|
backend: 'anthropic',
|
|
anthropic: { apiKey: 'sk-ant-test' },
|
|
modelSlots: { default: 'claude-sonnet-4-6' },
|
|
},
|
|
{ deps: { createAnthropic, generateText } },
|
|
),
|
|
).resolves.toEqual({ ok: true });
|
|
|
|
expect(createAnthropic).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
apiKey: 'sk-ant-test',
|
|
}),
|
|
);
|
|
expect(generateText).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
model: anthropicModel,
|
|
prompt: 'Reply with exactly: ok',
|
|
temperature: 0,
|
|
maxOutputTokens: 8,
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('returns a failed result without exposing secret values', async () => {
|
|
const generateText = vi.fn(async () => {
|
|
throw new Error('401 invalid x-api-key sk-ant-secret');
|
|
});
|
|
|
|
await expect(
|
|
runKtxLlmHealthCheck(
|
|
{
|
|
backend: 'anthropic',
|
|
anthropic: { apiKey: 'sk-ant-secret' },
|
|
modelSlots: { default: 'claude-sonnet-4-6' },
|
|
},
|
|
{
|
|
deps: {
|
|
createAnthropic: vi.fn(() => vi.fn(() => anthropicModel)),
|
|
generateText,
|
|
},
|
|
},
|
|
),
|
|
).resolves.toEqual({
|
|
ok: false,
|
|
message: '401 invalid x-api-key [redacted]',
|
|
});
|
|
});
|
|
});
|