forked from github/copilot-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-ai-service-provider-registry.js
More file actions
41 lines (34 loc) · 1.29 KB
/
test-ai-service-provider-registry.js
File metadata and controls
41 lines (34 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env node
const assert = require('assert');
const path = require('path');
const { createProviderRegistry } = require(path.join(__dirname, '..', 'src', 'main', 'ai-service', 'providers', 'registry.js'));
function test(name, fn) {
try {
fn();
console.log(`PASS ${name}`);
} catch (error) {
console.error(`FAIL ${name}`);
console.error(error.stack || error.message);
process.exitCode = 1;
}
}
const registry = createProviderRegistry({
GH_TOKEN: 'gh-token',
OPENAI_API_KEY: 'openai-key',
ANTHROPIC_API_KEY: 'anthropic-key'
});
test('provider registry exposes default provider', () => {
assert.strictEqual(registry.getCurrentProvider(), 'copilot');
});
test('setProvider accepts known providers only', () => {
assert.strictEqual(registry.setProvider('openai'), true);
assert.strictEqual(registry.getCurrentProvider(), 'openai');
assert.strictEqual(registry.setProvider('unknown'), false);
assert.strictEqual(registry.getCurrentProvider(), 'openai');
});
test('setApiKey mutates shared api key store', () => {
assert.strictEqual(registry.apiKeys.openai, 'openai-key');
assert.strictEqual(registry.setApiKey('openai', 'new-key'), true);
assert.strictEqual(registry.apiKeys.openai, 'new-key');
assert.strictEqual(registry.setApiKey('missing', 'x'), false);
});