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

@@ -3,25 +3,13 @@ import { LinearConnector } from '../../src/connectors/linear-connector.js';
import { AsanaConnector } from '../../src/connectors/asana-connector.js';
import { TrelloConnector } from '../../src/connectors/trello-connector.js';
import { MondayConnector } from '../../src/connectors/monday-connector.js';
import type { VaultStore } from '@waggle/core';
import { createMemorySecretStore, seedCredential, type MockSecretStore } from '../helpers/memory-secret-store.js';
function createMockVault(connectorId: string, cred?: { value: string; isExpired: boolean }, extras?: Record<string, string>): VaultStore {
return {
getConnectorCredential: vi.fn((id: string) => {
if (id === connectorId && cred) return { ...cred, type: 'bearer' };
return null;
}),
get: vi.fn((key: string) => {
if (extras && extras[key]) return { value: extras[key] };
return 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(connectorId: string, cred?: { value: string; isExpired: boolean }, extras?: Record<string, string>): MockSecretStore {
return createMemorySecretStore({
connectors: cred ? { [connectorId]: seedCredential(cred) } : {},
secrets: extras,
});
}
// ─── Linear Connector ───
@@ -81,7 +69,7 @@ describe('LinearConnector', () => {
it('connect retrieves token from vault', async () => {
const vault = createMockVault('linear', { value: 'lin_api_test123', isExpired: false });
await connector.connect(vault);
expect(vault.getConnectorCredential).toHaveBeenCalledWith('linear');
expect(vault.get).toHaveBeenCalledWith('connector:linear');
});
it('healthCheck returns connected when API responds OK', async () => {
@@ -239,7 +227,7 @@ describe('AsanaConnector', () => {
it('connect retrieves token from vault', async () => {
const vault = createMockVault('asana', { value: 'asana_pat_test123', isExpired: false });
await connector.connect(vault);
expect(vault.getConnectorCredential).toHaveBeenCalledWith('asana');
expect(vault.get).toHaveBeenCalledWith('connector:asana');
});
it('healthCheck returns connected when API responds OK', async () => {
@@ -341,7 +329,7 @@ describe('TrelloConnector', () => {
'connector:trello:api_key': 'trello_key_test',
});
await connector.connect(vault);
expect(vault.getConnectorCredential).toHaveBeenCalledWith('trello');
expect(vault.get).toHaveBeenCalledWith('connector:trello');
expect(vault.get).toHaveBeenCalledWith('connector:trello:api_key');
});
@@ -453,7 +441,7 @@ describe('MondayConnector', () => {
it('connect retrieves token from vault', async () => {
const vault = createMockVault('monday', { value: 'monday_api_test123', isExpired: false });
await connector.connect(vault);
expect(vault.getConnectorCredential).toHaveBeenCalledWith('monday');
expect(vault.get).toHaveBeenCalledWith('connector:monday');
});
it('healthCheck returns connected when API responds OK', async () => {