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:
@@ -3,22 +3,10 @@ import { GmailConnector } from '../../src/connectors/gmail-connector.js';
|
||||
import { GoogleDocsConnector } from '../../src/connectors/gdocs-connector.js';
|
||||
import { GoogleDriveConnector } from '../../src/connectors/gdrive-connector.js';
|
||||
import { GoogleSheetsConnector } from '../../src/connectors/gsheets-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 }): VaultStore {
|
||||
return {
|
||||
getConnectorCredential: vi.fn((id: string) => {
|
||||
if (id === connectorId && cred) return { ...cred, type: 'bearer' };
|
||||
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(connectorId: string, cred?: { value: string; isExpired: boolean }): MockSecretStore {
|
||||
return createMemorySecretStore({ connectors: cred ? { [connectorId]: seedCredential(cred) } : {} });
|
||||
}
|
||||
|
||||
// ─── Gmail Connector ───
|
||||
@@ -91,7 +79,7 @@ describe('GmailConnector', () => {
|
||||
it('connect retrieves token from vault', async () => {
|
||||
const vault = createMockVault('gmail', { value: 'ya29.test_token', isExpired: false });
|
||||
await connector.connect(vault);
|
||||
expect(vault.getConnectorCredential).toHaveBeenCalledWith('gmail');
|
||||
expect(vault.get).toHaveBeenCalledWith('connector:gmail');
|
||||
});
|
||||
|
||||
it('healthCheck returns connected when API responds OK', async () => {
|
||||
@@ -201,7 +189,7 @@ describe('GoogleDocsConnector', () => {
|
||||
it('connect retrieves token from vault', async () => {
|
||||
const vault = createMockVault('gdocs', { value: 'ya29.test_token', isExpired: false });
|
||||
await connector.connect(vault);
|
||||
expect(vault.getConnectorCredential).toHaveBeenCalledWith('gdocs');
|
||||
expect(vault.get).toHaveBeenCalledWith('connector:gdocs');
|
||||
});
|
||||
|
||||
it('healthCheck returns connected when API responds OK', async () => {
|
||||
@@ -317,7 +305,7 @@ describe('GoogleDriveConnector', () => {
|
||||
it('connect retrieves token from vault', async () => {
|
||||
const vault = createMockVault('gdrive', { value: 'ya29.test_token', isExpired: false });
|
||||
await connector.connect(vault);
|
||||
expect(vault.getConnectorCredential).toHaveBeenCalledWith('gdrive');
|
||||
expect(vault.get).toHaveBeenCalledWith('connector:gdrive');
|
||||
});
|
||||
|
||||
it('healthCheck returns connected when API responds OK', async () => {
|
||||
@@ -431,7 +419,7 @@ describe('GoogleSheetsConnector', () => {
|
||||
it('connect retrieves token from vault', async () => {
|
||||
const vault = createMockVault('gsheets', { value: 'ya29.test_token', isExpired: false });
|
||||
await connector.connect(vault);
|
||||
expect(vault.getConnectorCredential).toHaveBeenCalledWith('gsheets');
|
||||
expect(vault.get).toHaveBeenCalledWith('connector:gsheets');
|
||||
});
|
||||
|
||||
it('healthCheck returns connected when API responds OK', async () => {
|
||||
|
||||
Reference in New Issue
Block a user