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:
@@ -2,8 +2,10 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { BaseConnector, type ConnectorAction, type ConnectorResult, type WaggleConnector } from '../src/connector-sdk.js';
|
||||
import { ConnectorRegistry, type AuditLogger } from '../src/connector-registry.js';
|
||||
import { needsConfirmationWithAutonomy } from '../src/confirmation.js';
|
||||
import type { VaultStore } from '@waggle/core';
|
||||
import { getConnectorCredential } from '../src/connectors/connector-credentials.js';
|
||||
import type { SecretStore } from '@waggle/core';
|
||||
import type { ConnectorHealth, ConnectorStatus } from '@waggle/shared';
|
||||
import { createMemorySecretStore, seedCredential } from './helpers/memory-secret-store.js';
|
||||
|
||||
// ─── Mock Connector ──────────────────────────────────────────────────────
|
||||
|
||||
@@ -40,9 +42,9 @@ class MockConnector extends BaseConnector {
|
||||
healthCheckCalled = false;
|
||||
executeCalls: Array<{ action: string; params: Record<string, unknown> }> = [];
|
||||
|
||||
async connect(vault: VaultStore): Promise<void> {
|
||||
async connect(vault: SecretStore): Promise<void> {
|
||||
this.connectCalled = true;
|
||||
const cred = vault.getConnectorCredential(this.id);
|
||||
const cred = getConnectorCredential(vault, this.id);
|
||||
this.token = cred?.value ?? null;
|
||||
}
|
||||
|
||||
@@ -66,21 +68,12 @@ class MockConnector extends BaseConnector {
|
||||
|
||||
// ─── Mock Vault ──────────────────────────────────────────────────────────
|
||||
|
||||
function createMockVault(credentials: Record<string, { value: string; isExpired: boolean }> = {}): VaultStore {
|
||||
return {
|
||||
getConnectorCredential: vi.fn((id: string) => {
|
||||
const cred = credentials[id];
|
||||
if (!cred) return null;
|
||||
return { value: cred.value, type: 'bearer', isExpired: cred.isExpired };
|
||||
}),
|
||||
setConnectorCredential: vi.fn(),
|
||||
set: vi.fn(),
|
||||
get: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
list: vi.fn(() => []),
|
||||
has: vi.fn(() => false),
|
||||
migrateFromConfig: vi.fn(() => 0),
|
||||
} as unknown as VaultStore;
|
||||
function createMockVault(credentials: Record<string, { value: string; isExpired: boolean }> = {}): SecretStore {
|
||||
return createMemorySecretStore({
|
||||
connectors: Object.fromEntries(
|
||||
Object.entries(credentials).map(([id, cred]) => [id, seedCredential(cred)]),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
async function registerAndHydrate(
|
||||
@@ -140,7 +133,7 @@ describe('WaggleConnector interface', () => {
|
||||
// ─── ConnectorRegistry ───────────────────────────────────────────────────
|
||||
|
||||
describe('ConnectorRegistry', () => {
|
||||
let vault: VaultStore;
|
||||
let vault: SecretStore;
|
||||
let registry: ConnectorRegistry;
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user