refactor(agent): move the connector credential helpers out of VaultStore (P1.2)

getConnectorCredential, setConnectorCredential and setConnectorCredentialBundle
are now plain functions over a SecretStore in
packages/agent/src/connectors/connector-credentials.ts. The secret names,
metadata layout and the rule that tokens never go into plaintext metadata are
unchanged, so existing vault files keep working.

A bundle still lands as one update: SecretStore gains writeBatch, which
VaultStore applies with a single vault-file replacement.

Connector tests seed a Map-backed SecretStore instead of mocking VaultStore
methods; the helper tests from core and server moved to the agent package.
This commit is contained in:
shumeiko.it
2026-10-24 16:34:20 +02:00
parent 23431550ae
commit 3528a242f6
60 changed files with 602 additions and 606 deletions

View File

@@ -1,21 +1,9 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { EmailConnector } from '../../src/connectors/email-connector.js';
import type { VaultStore } from '@waggle/core';
import { createMemorySecretStore, type MockSecretStore } from '../helpers/memory-secret-store.js';
function createMockVault(cred?: { value: string }): VaultStore {
return {
getConnectorCredential: vi.fn((id: string) => {
if (id === 'email' && cred) return { ...cred, type: 'api_key', isExpired: false };
return null;
}),
get: vi.fn(() => null),
set: vi.fn(),
delete: vi.fn(),
list: vi.fn(() => []),
has: vi.fn(() => false),
setConnectorCredential: vi.fn(),
migrateFromConfig: vi.fn(() => 0),
} as unknown as VaultStore;
function createMockVault(cred?: { value: string }): MockSecretStore {
return createMemorySecretStore({ connectors: cred ? { email: { type: 'api_key', value: cred.value } } : {} });
}
describe('EmailConnector', () => {
@@ -41,7 +29,7 @@ describe('EmailConnector', () => {
it('connect() retrieves API key from vault', async () => {
const vault = createMockVault({ value: 'SG.test_key' });
await connector.connect(vault);
expect(vault.getConnectorCredential).toHaveBeenCalledWith('email');
expect(vault.get).toHaveBeenCalledWith('connector:email');
});
it('healthCheck() validates API key', async () => {