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,25 +1,15 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { JiraConnector } from '../../src/connectors/jira-connector.js';
import type { VaultStore } from '@waggle/core';
import { createMemorySecretStore, type MockSecretStore } from '../helpers/memory-secret-store.js';
function createMockVault(opts?: { token?: string; email?: string; baseUrl?: string }): VaultStore {
return {
getConnectorCredential: vi.fn((id: string) => {
if (id === 'jira' && opts?.token) return { value: opts.token, type: 'bearer', isExpired: false };
return null;
}),
get: vi.fn((name: string) => {
if (name === 'connector:jira:email' && opts?.email) return { value: opts.email };
if (name === 'connector:jira:base_url' && opts?.baseUrl) return { value: opts.baseUrl };
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(opts?: { token?: string; email?: string; baseUrl?: string }): MockSecretStore {
const secrets: Record<string, string> = {};
if (opts?.email) secrets['connector:jira:email'] = opts.email;
if (opts?.baseUrl) secrets['connector:jira:base_url'] = opts.baseUrl;
return createMemorySecretStore({
connectors: opts?.token ? { jira: { type: 'bearer', value: opts.token } } : {},
secrets,
});
}
describe('JiraConnector', () => {
@@ -48,7 +38,7 @@ describe('JiraConnector', () => {
baseUrl: 'https://mycompany.atlassian.net',
});
await connector.connect(vault);
expect(vault.getConnectorCredential).toHaveBeenCalledWith('jira');
expect(vault.get).toHaveBeenCalledWith('connector:jira');
expect(vault.get).toHaveBeenCalledWith('connector:jira:email');
});