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 { MSTeamsConnector } from '../../src/connectors/ms-teams-connector.js';
import { OutlookConnector } from '../../src/connectors/outlook-connector.js';
import { OneDriveConnector } from '../../src/connectors/onedrive-connector.js';
import { OneNoteConnector } from '../../src/connectors/onenote-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;
): MockSecretStore {
return createMemorySecretStore({ connectors: cred ? { [connectorId]: seedCredential(cred) } : {} });
}
// ── Microsoft Teams Connector ─────────────────────────────────────────
@@ -79,7 +67,7 @@ describe('MSTeamsConnector', () => {
it('connect() retrieves token from vault', async () => {
const vault = createMockVault('ms-teams', { value: 'graph-token-123', isExpired: false });
await connector.connect(vault);
expect(vault.getConnectorCredential).toHaveBeenCalledWith('ms-teams');
expect(vault.get).toHaveBeenCalledWith('connector:ms-teams');
});
it('healthCheck() returns connected when Graph API responds OK', async () => {
@@ -209,7 +197,7 @@ describe('OutlookConnector', () => {
it('connect() retrieves token from vault', async () => {
const vault = createMockVault('outlook', { value: 'graph-token-456', isExpired: false });
await connector.connect(vault);
expect(vault.getConnectorCredential).toHaveBeenCalledWith('outlook');
expect(vault.get).toHaveBeenCalledWith('connector:outlook');
});
it('healthCheck() returns connected when Graph API responds OK', async () => {
@@ -368,7 +356,7 @@ describe('OneDriveConnector', () => {
it('connect() retrieves token from vault', async () => {
const vault = createMockVault('onedrive', { value: 'graph-token-789', isExpired: false });
await connector.connect(vault);
expect(vault.getConnectorCredential).toHaveBeenCalledWith('onedrive');
expect(vault.get).toHaveBeenCalledWith('connector:onedrive');
});
it('healthCheck() returns connected when Graph API responds OK', async () => {
@@ -562,7 +550,7 @@ describe('OneNoteConnector', () => {
it('connect() retrieves token from vault', async () => {
const vault = createMockVault('onenote', { value: 'graph-token-onenote', isExpired: false });
await connector.connect(vault);
expect(vault.getConnectorCredential).toHaveBeenCalledWith('onenote');
expect(vault.get).toHaveBeenCalledWith('connector:onenote');
});
it('healthCheck() probes /me/onenote/notebooks to exercise the Notes.Read scope', async () => {