Files
homeclaw/tests/anthropic-outage.test.ts

17 lines
1.3 KiB
TypeScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { classifyAnthropicOutage, isAnthropicOutageError, recordAnthropicFailure, isAnthropicBlocked, resetAnthropicBlock } from '../src/providers/anthropic-usage';
test('크레딧 부족 400 → credit', () => assert.equal(classifyAnthropicOutage(400, '{"error":{"message":"Your credit balance is too low to access the Anthropic API"}}'), 'credit'));
test('일반 잘못된 요청 400은 대상 아님', () => assert.equal(classifyAnthropicOutage(400, 'max_tokens: must be > 0'), null));
test('429·529 → busy', () => { assert.equal(classifyAnthropicOutage(429, ''), 'busy'); assert.equal(classifyAnthropicOutage(529, 'overloaded'), 'busy'); });
test('오류 메시지 판별', () => {
assert.equal(isAnthropicOutageError(new Error('Anthropic API error 400: credit balance is too low')), true);
assert.equal(isAnthropicOutageError(new Error('Anthropic API error 400: invalid tool schema')), false);
});
test('기록 후 막힘, 초기화하면 풀림', () => {
resetAnthropicBlock(); assert.equal(isAnthropicBlocked(), false);
recordAnthropicFailure(400, 'credit balance is too low'); assert.equal(isAnthropicBlocked(), true);
resetAnthropicBlock(); assert.equal(isAnthropicBlocked(), false);
});