fix: harden agent shutdown and auth rotation

This commit is contained in:
Eyejoker
2026-03-24 17:08:48 +09:00
parent 77b4ab1c83
commit 8b2c46b89e
11 changed files with 969 additions and 80 deletions

View File

@@ -27,6 +27,7 @@ vi.mock('./logger.js', () => ({
import { fetchClaudeUsage } from './claude-usage.js';
import {
clearPrimaryCooldown,
detectFallbackTrigger,
getActiveProvider,
getCooldownInfo,
markPrimaryCooldown,
@@ -100,4 +101,24 @@ describe('provider fallback usage recovery', () => {
await expect(getActiveProvider()).resolves.toBe('claude');
expect(getCooldownInfo()).toEqual({ active: false });
});
it('treats terminated 401 auth failures as an auth-expired fallback trigger', () => {
expect(
detectFallbackTrigger('Failed to authenticate. API Error: 401 terminated'),
).toEqual({
shouldFallback: true,
reason: 'auth-expired',
});
});
it('treats invalid authentication credentials as an auth-expired fallback trigger', () => {
expect(
detectFallbackTrigger(
'Failed to authenticate. API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"Invalid authentication credentials"}}',
),
).toEqual({
shouldFallback: true,
reason: 'auth-expired',
});
});
});