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:
@@ -5,6 +5,7 @@ import { afterEach, describe, expect, it } from 'vitest';
|
||||
import { VaultStore } from '@waggle/core';
|
||||
import {
|
||||
applyProviderKeyToEnv,
|
||||
copyProviderKeysToVault,
|
||||
hydrateProviderEnvFromVault,
|
||||
migrateLegacyProviderKeysToVault,
|
||||
} from '../../src/local/provider-env.js';
|
||||
@@ -50,6 +51,45 @@ describe('provider environment hydration', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('copies config.json provider keys into the vault with their models and base URL', () => {
|
||||
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-provider-copy-'));
|
||||
try {
|
||||
const vault = new VaultStore(dataDir);
|
||||
|
||||
expect(copyProviderKeysToVault(vault, {
|
||||
anthropic: { apiKey: 'sk-ant-key-1', models: ['claude-sonnet-4-6'], baseUrl: undefined },
|
||||
openai: { apiKey: 'sk-openai-key-1', models: ['gpt-4o'], baseUrl: 'https://api.openai.com' },
|
||||
empty: { apiKey: '', models: [] },
|
||||
})).toBe(2);
|
||||
|
||||
expect(vault.get('anthropic')).toMatchObject({
|
||||
value: 'sk-ant-key-1',
|
||||
metadata: { models: ['claude-sonnet-4-6'] },
|
||||
});
|
||||
expect(vault.get('openai')).toMatchObject({
|
||||
value: 'sk-openai-key-1',
|
||||
metadata: { models: ['gpt-4o'], baseUrl: 'https://api.openai.com' },
|
||||
});
|
||||
expect(vault.has('empty')).toBe(false);
|
||||
} finally {
|
||||
fs.rmSync(dataDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('keeps a key the vault already holds', () => {
|
||||
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-provider-copy-'));
|
||||
try {
|
||||
const vault = new VaultStore(dataDir);
|
||||
vault.set('anthropic', 'sk-ant-from-settings');
|
||||
const providers = { anthropic: { apiKey: 'sk-ant-from-config', models: ['claude-sonnet-4-6'] } };
|
||||
|
||||
expect(copyProviderKeysToVault(vault, providers)).toBe(0);
|
||||
expect(vault.get('anthropic')?.value).toBe('sk-ant-from-settings');
|
||||
} finally {
|
||||
fs.rmSync(dataDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('migrates and scrubs legacy keys before startup catalog discovery', () => {
|
||||
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-provider-migrate-'));
|
||||
const configPath = path.join(dataDir, 'config.json');
|
||||
|
||||
Reference in New Issue
Block a user