fix: stabilize Claude usage cache across token refreshes

This commit is contained in:
Eyejoker
2026-03-26 16:37:00 +09:00
parent 34c9ecd10b
commit d865a6b07f
4 changed files with 190 additions and 33 deletions

View File

@@ -1,6 +1,9 @@
import { describe, expect, it } from 'vitest';
import { shouldStartTokenRefreshLoop } from './token-refresh.js';
import {
applyUpdatedTokensToEnvContent,
shouldStartTokenRefreshLoop,
} from './token-refresh.js';
describe('shouldStartTokenRefreshLoop', () => {
it('starts refresh for the Claude service', () => {
@@ -10,4 +13,32 @@ describe('shouldStartTokenRefreshLoop', () => {
it('skips refresh for the Codex service', () => {
expect(shouldStartTokenRefreshLoop('codex')).toBe(false);
});
it('updates both multi-token and single-token env vars when present', () => {
const next = applyUpdatedTokensToEnvContent(
[
'CLAUDE_CODE_OAUTH_TOKEN=old-primary',
'CLAUDE_CODE_OAUTH_TOKENS=old-primary,old-secondary',
'OTHER=value',
].join('\n'),
['new-primary', 'new-secondary'],
);
expect(next).toContain('CLAUDE_CODE_OAUTH_TOKEN=new-primary');
expect(next).toContain(
'CLAUDE_CODE_OAUTH_TOKENS=new-primary,new-secondary',
);
});
it('adds the multi-token env var when it is missing', () => {
const next = applyUpdatedTokensToEnvContent(
['CLAUDE_CODE_OAUTH_TOKEN=old-primary', 'OTHER=value'].join('\n'),
['new-primary', 'new-secondary'],
);
expect(next).toContain('CLAUDE_CODE_OAUTH_TOKEN=new-primary');
expect(next).toContain(
'CLAUDE_CODE_OAUTH_TOKENS=new-primary,new-secondary',
);
});
});