godcrm/backend/services/__tests__/agent-job-auth-diagnostic.test.js
2026-10-29 07:39:04 +03:00

29 lines
1.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, it, expect } from 'vitest';
import { isAuthError, isAuthErrorBlock } from '../agent-job/auth-error.js';
describe('CLI auth error versus diagnostic response', () => {
it.each([
'Подтвердил обе причины на staging:\n\n- WebM отклоняется: работает старый backend.\n- Текст не распознаётся: Whisper возвращает `401 invalid_api_key`.\nНужно исправить ключ оператора.',
'Нашёл причину: фильтр скрывает ответы, содержащие authentication_error.',
'The log says "Failed to authenticate. API Error: 401 Invalid authentication credentials". Update the staging credential.',
'Whisper reports OAuth token expired; this is not the running agent.',
'Провайдер вернул {"error":{"type":"authentication_error"}}; проверьте настройки.',
])('preserves diagnostic text: %s', (text) => {
expect(isAuthError(text)).toBe(false);
expect(isAuthErrorBlock({ type: 'text', text })).toBe(false);
expect(isAuthErrorBlock({ type: 'thinking', thinking: text })).toBe(false);
});
it.each([
'Failed to authenticate. API Error: 401 Invalid authentication credentials',
'Invalid authentication credentials',
'authentication_error: OAuth token expired',
'invalid_api_key',
'OAuth token expired',
'API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"Invalid authentication credentials"}}',
'{"type":"error","error":{"type":"authentication_error","message":"Invalid authentication credentials"}}',
])('still recognizes raw CLI failure: %s', (text) => {
expect(isAuthError(` ${text}\n`)).toBe(true);
expect(isAuthErrorBlock({ type: 'text', text })).toBe(true);
});
});