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,8 +1,4 @@
import { describe, it, expect } from 'vitest';
import path from 'node:path';
import { VaultStore } from '@waggle/core';
import fs from 'node:fs';
import os from 'node:os';
describe('Connector Foundation', () => {
it('exports connectorRoutes function', async () => {
@@ -12,74 +8,6 @@ describe('Connector Foundation', () => {
});
});
describe('Vault Connector Credential Methods', () => {
const tmpDir = path.join(os.tmpdir(), `waggle-vault-test-${Date.now()}`);
it('setConnectorCredential stores and getConnectorCredential retrieves', () => {
fs.mkdirSync(tmpDir, { recursive: true });
const vault = new VaultStore(tmpDir);
vault.setConnectorCredential('github', {
type: 'bearer',
value: 'ghp_test_token_12345',
scopes: ['repo', 'user'],
});
const cred = vault.getConnectorCredential('github');
expect(cred).not.toBeNull();
expect(cred!.value).toBe('ghp_test_token_12345');
expect(cred!.type).toBe('bearer');
expect(cred!.scopes).toEqual(['repo', 'user']);
expect(cred!.isExpired).toBe(false);
// Cleanup
fs.rmSync(tmpDir, { recursive: true, force: true });
});
it('detects expired tokens', () => {
fs.mkdirSync(tmpDir, { recursive: true });
const vault = new VaultStore(tmpDir);
vault.setConnectorCredential('slack', {
type: 'oauth2',
value: 'xoxb-expired-token',
expiresAt: '2020-01-01T00:00:00.000Z', // Way in the past
});
const cred = vault.getConnectorCredential('slack');
expect(cred).not.toBeNull();
expect(cred!.isExpired).toBe(true);
fs.rmSync(tmpDir, { recursive: true, force: true });
});
it('returns null for non-existent connector', () => {
fs.mkdirSync(tmpDir, { recursive: true });
const vault = new VaultStore(tmpDir);
const cred = vault.getConnectorCredential('nonexistent');
expect(cred).toBeNull();
fs.rmSync(tmpDir, { recursive: true, force: true });
});
it('disconnect removes credential from vault', () => {
fs.mkdirSync(tmpDir, { recursive: true });
const vault = new VaultStore(tmpDir);
vault.setConnectorCredential('github', {
type: 'bearer',
value: 'ghp_test_token',
});
expect(vault.getConnectorCredential('github')).not.toBeNull();
vault.delete('connector:github');
expect(vault.getConnectorCredential('github')).toBeNull();
fs.rmSync(tmpDir, { recursive: true, force: true });
});
});
describe('ConnectorDefinition Types', () => {
it('shared types include connector types', async () => {
// Verify the types compile correctly by importing them