mirror of
https://github.com/qwibitai/nanoclaw.git
synced 2026-06-12 18:11:51 +08:00
31 lines
915 B
TypeScript
31 lines
915 B
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { classifyPingResult } from './agent-ping.js';
|
|
|
|
describe('classifyPingResult', () => {
|
|
it('treats a normal text reply as ok', () => {
|
|
expect(classifyPingResult(0, 'pong\n')).toBe('ok');
|
|
});
|
|
|
|
it('detects Anthropic auth errors printed as a chat reply', () => {
|
|
expect(
|
|
classifyPingResult(
|
|
0,
|
|
'Failed to authenticate. API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"Invalid bearer token"}}',
|
|
),
|
|
).toBe('auth_error');
|
|
});
|
|
|
|
it('detects auth errors on stderr too', () => {
|
|
expect(classifyPingResult(1, '', 'Authentication error')).toBe('auth_error');
|
|
});
|
|
|
|
it('preserves socket errors', () => {
|
|
expect(classifyPingResult(2, '')).toBe('socket_error');
|
|
});
|
|
|
|
it('treats empty output as no reply', () => {
|
|
expect(classifyPingResult(0, '')).toBe('no_reply');
|
|
});
|
|
});
|