runtime: canonicalize Claude token env names
This commit is contained in:
@@ -125,21 +125,28 @@ describe('credentials detection', () => {
|
||||
const content =
|
||||
'SOME_KEY=value\nANTHROPIC_API_KEY=sk-ant-test123\nOTHER=foo';
|
||||
const hasCredentials =
|
||||
/^(CLAUDE_CODE_OAUTH_TOKEN|ANTHROPIC_API_KEY)=/m.test(content);
|
||||
/^(CLAUDE_CODE_OAUTH_TOKENS?|ANTHROPIC_API_KEY)=/m.test(content);
|
||||
expect(hasCredentials).toBe(true);
|
||||
});
|
||||
|
||||
it('detects CLAUDE_CODE_OAUTH_TOKEN in env content', () => {
|
||||
const content = 'CLAUDE_CODE_OAUTH_TOKEN=token123';
|
||||
const hasCredentials =
|
||||
/^(CLAUDE_CODE_OAUTH_TOKEN|ANTHROPIC_API_KEY)=/m.test(content);
|
||||
/^(CLAUDE_CODE_OAUTH_TOKENS?|ANTHROPIC_API_KEY)=/m.test(content);
|
||||
expect(hasCredentials).toBe(true);
|
||||
});
|
||||
|
||||
it('detects CLAUDE_CODE_OAUTH_TOKENS in env content', () => {
|
||||
const content = 'CLAUDE_CODE_OAUTH_TOKENS=token123,token456';
|
||||
const hasCredentials =
|
||||
/^(CLAUDE_CODE_OAUTH_TOKENS?|ANTHROPIC_API_KEY)=/m.test(content);
|
||||
expect(hasCredentials).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false when no credentials', () => {
|
||||
const content = 'ASSISTANT_NAME="Andy"\nOTHER=foo';
|
||||
const hasCredentials =
|
||||
/^(CLAUDE_CODE_OAUTH_TOKEN|ANTHROPIC_API_KEY)=/m.test(content);
|
||||
/^(CLAUDE_CODE_OAUTH_TOKENS?|ANTHROPIC_API_KEY)=/m.test(content);
|
||||
expect(hasCredentials).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,6 +34,17 @@ describe('verify state helpers', () => {
|
||||
expect(detectCredentials(tempRoot)).toBe('configured');
|
||||
});
|
||||
|
||||
it('detects configured multi-account credentials from .env', () => {
|
||||
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'ejclaw-verify-'));
|
||||
tempRoots.push(tempRoot);
|
||||
fs.writeFileSync(
|
||||
path.join(tempRoot, '.env'),
|
||||
'CLAUDE_CODE_OAUTH_TOKENS=test-token-1,test-token-2\n',
|
||||
);
|
||||
|
||||
expect(detectCredentials(tempRoot)).toBe('configured');
|
||||
});
|
||||
|
||||
it('detects canonical role-based channel auth names from process env', () => {
|
||||
expect(
|
||||
detectChannelAuth(
|
||||
|
||||
@@ -38,7 +38,7 @@ export function detectCredentials(projectRoot: string): CredentialsStatus {
|
||||
}
|
||||
|
||||
const envContent = fs.readFileSync(envFile, 'utf-8');
|
||||
return /^(CLAUDE_CODE_OAUTH_TOKEN|ANTHROPIC_API_KEY)=/m.test(envContent)
|
||||
return /^(CLAUDE_CODE_OAUTH_TOKENS?|ANTHROPIC_API_KEY)=/m.test(envContent)
|
||||
? 'configured'
|
||||
: 'missing';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user