cli: improve doctor auth diagnostics
This commit is contained in:
@@ -292,4 +292,80 @@ skills:
|
||||
expect(skillsCheck?.status).toBe('pass');
|
||||
expect(skillsCheck?.detail).toContain('1 skill(s), 1 available, 0 unavailable');
|
||||
});
|
||||
|
||||
it('reports FAIL when OpenAI auth_mode=api_key has no available key sources', async () => {
|
||||
const originalHome = process.env.HOME;
|
||||
const originalKey = process.env.OPENAI_API_KEY;
|
||||
delete process.env.OPENAI_API_KEY;
|
||||
|
||||
const homeDir = join(tmpdir(), `flynn-test-doctor-home-${Date.now()}`);
|
||||
process.env.HOME = homeDir;
|
||||
|
||||
try {
|
||||
mkdirSync(testDir, { recursive: true });
|
||||
const configPath = join(testDir, 'openai-missing.yaml');
|
||||
writeFileSync(configPath, `
|
||||
telegram:
|
||||
bot_token: "test-token"
|
||||
allowed_chat_ids: [123]
|
||||
models:
|
||||
default:
|
||||
provider: openai
|
||||
model: gpt-4o
|
||||
auth_mode: api_key
|
||||
`);
|
||||
|
||||
const ctx: DoctorContext = { configPath, dataDir: testDir };
|
||||
const results = await runChecks(ctx);
|
||||
const modelCheck = results.find(r => r.label.includes('Model connectivity')) as CheckResult | undefined;
|
||||
expect(modelCheck?.status).toBe('fail');
|
||||
expect(modelCheck?.detail).toContain('OPENAI_API_KEY');
|
||||
expect(modelCheck?.detail).toContain('flynn openai-key');
|
||||
} finally {
|
||||
process.env.HOME = originalHome;
|
||||
if (originalKey) {
|
||||
process.env.OPENAI_API_KEY = originalKey;
|
||||
} else {
|
||||
delete process.env.OPENAI_API_KEY;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('reports FAIL when Anthropic auth_mode=oauth has no available auth token sources', async () => {
|
||||
const originalHome = process.env.HOME;
|
||||
const originalToken = process.env.ANTHROPIC_AUTH_TOKEN;
|
||||
delete process.env.ANTHROPIC_AUTH_TOKEN;
|
||||
|
||||
const homeDir = join(tmpdir(), `flynn-test-doctor-home-${Date.now()}-2`);
|
||||
process.env.HOME = homeDir;
|
||||
|
||||
try {
|
||||
mkdirSync(testDir, { recursive: true });
|
||||
const configPath = join(testDir, 'anthropic-missing-token.yaml');
|
||||
writeFileSync(configPath, `
|
||||
telegram:
|
||||
bot_token: "test-token"
|
||||
allowed_chat_ids: [123]
|
||||
models:
|
||||
default:
|
||||
provider: anthropic
|
||||
model: claude-sonnet
|
||||
auth_mode: oauth
|
||||
`);
|
||||
|
||||
const ctx: DoctorContext = { configPath, dataDir: testDir };
|
||||
const results = await runChecks(ctx);
|
||||
const modelCheck = results.find(r => r.label.includes('Model connectivity')) as CheckResult | undefined;
|
||||
expect(modelCheck?.status).toBe('fail');
|
||||
expect(modelCheck?.detail).toContain('ANTHROPIC_AUTH_TOKEN');
|
||||
expect(modelCheck?.detail).toContain('flynn anthropic-auth --token');
|
||||
} finally {
|
||||
process.env.HOME = originalHome;
|
||||
if (originalToken) {
|
||||
process.env.ANTHROPIC_AUTH_TOKEN = originalToken;
|
||||
} else {
|
||||
delete process.env.ANTHROPIC_AUTH_TOKEN;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user