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,7 +1,7 @@
import { describe, it, expect, vi } from 'vitest';
import { ConnectorRegistry } from '@waggle/agent';
import { BaseConnector, type ConnectorAction, type ConnectorResult } from '@waggle/agent';
import type { VaultStore } from '@waggle/core';
import type { SecretStore } from '@waggle/core';
import type { ConnectorHealth } from '@waggle/shared';
import { needsConfirmation, getApprovalClass } from '@waggle/agent';
@@ -38,21 +38,30 @@ class TestConnector extends BaseConnector {
}
}
function createMockVault(credentials: Record<string, { value: string; isExpired: boolean }> = {}): VaultStore {
/** Serves `connector:<id>` entries in the layout setConnectorCredential writes. */
function createMockVault(credentials: Record<string, { value: string; isExpired: boolean }> = {}): SecretStore {
return {
getConnectorCredential: vi.fn((id: string) => {
const cred = credentials[id];
get: vi.fn((name: string) => {
const cred = credentials[name.replace(/^connector:/, '')];
if (!cred) return null;
return { value: cred.value, type: 'bearer', isExpired: cred.isExpired };
return {
name,
value: cred.value,
metadata: {
credentialType: 'bearer',
expiresAt: cred.isExpired ? '2020-01-01T00:00:00.000Z' : undefined,
},
updatedAt: new Date().toISOString(),
};
}),
setConnectorCredential: vi.fn(),
set: vi.fn(),
get: vi.fn(),
setAsync: vi.fn(),
writeBatch: vi.fn(),
delete: vi.fn(),
deleteAsync: vi.fn(),
list: vi.fn(() => []),
has: vi.fn(() => false),
migrateFromConfig: vi.fn(() => 0),
} as unknown as VaultStore;
};
}
// ─── Integration Tests ───────────────────────────────────────────────