refactor(server): move the config.json provider-key copy out of VaultStore (P1.2)

VaultStore.migrateFromConfig had two callers, both in the server. It is now
copyProviderKeysToVault in provider-env.ts, next to
migrateLegacyProviderKeysToVault, with the same rules: copy keys that have a
value, keep keys the vault already holds, store models and baseUrl as metadata.
Its tests moved from core to provider-env.test.ts.
This commit is contained in:
shumeiko.it
2026-10-24 16:40:39 +02:00
parent 3528a242f6
commit 2226ec1bd7
5 changed files with 65 additions and 61 deletions

View File

@@ -171,47 +171,6 @@ describe('VaultStore', () => {
expect(entry!.value).toBe('sk-ant-shared-secret');
});
it('migration from config — providers migrated to vault', () => {
const dir = makeTempDir();
const vault = new VaultStore(dir);
const config = {
providers: {
anthropic: { apiKey: 'sk-ant-key-1', models: ['claude-sonnet-4-6'], baseUrl: undefined },
openai: { apiKey: 'sk-openai-key-1', models: ['gpt-4o'] },
},
};
const migrated = vault.migrateFromConfig(config);
expect(migrated).toBe(2);
const anthropic = vault.get('anthropic');
expect(anthropic).not.toBeNull();
expect(anthropic!.value).toBe('sk-ant-key-1');
expect(anthropic!.metadata?.models).toEqual(['claude-sonnet-4-6']);
const openai = vault.get('openai');
expect(openai).not.toBeNull();
expect(openai!.value).toBe('sk-openai-key-1');
});
it('migration skips existing — migrate twice, count stays same', () => {
const dir = makeTempDir();
const vault = new VaultStore(dir);
const config = {
providers: {
anthropic: { apiKey: 'sk-ant-key-1', models: ['claude-sonnet-4-6'] },
},
};
const first = vault.migrateFromConfig(config);
expect(first).toBe(1);
const second = vault.migrateFromConfig(config);
expect(second).toBe(0);
});
it('key file is generated on first use and reused', () => {
const dir = makeTempDir();
new VaultStore(dir);