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.
78 lines
2.8 KiB
TypeScript
78 lines
2.8 KiB
TypeScript
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
import { SlackConnector } from '../../src/connectors/slack-connector.js';
|
|
import { createMemorySecretStore, seedCredential, type MockSecretStore } from '../helpers/memory-secret-store.js';
|
|
|
|
function createMockVault(cred?: { value: string; isExpired: boolean }): MockSecretStore {
|
|
return createMemorySecretStore({ connectors: cred ? { slack: seedCredential(cred) } : {} });
|
|
}
|
|
|
|
describe('SlackConnector', () => {
|
|
let connector: SlackConnector;
|
|
let originalFetch: typeof globalThis.fetch;
|
|
|
|
beforeEach(() => {
|
|
connector = new SlackConnector();
|
|
originalFetch = globalThis.fetch;
|
|
});
|
|
|
|
afterEach(() => {
|
|
globalThis.fetch = originalFetch;
|
|
});
|
|
|
|
it('implements WaggleConnector interface', () => {
|
|
expect(connector.id).toBe('slack');
|
|
expect(connector.name).toBe('Slack');
|
|
expect(connector.authType).toBe('bearer');
|
|
expect(connector.actions).toHaveLength(4);
|
|
});
|
|
|
|
it('connect() retrieves token from vault', async () => {
|
|
const vault = createMockVault({ value: 'xoxb-test-token', isExpired: false });
|
|
await connector.connect(vault);
|
|
expect(vault.get).toHaveBeenCalledWith('connector:slack');
|
|
});
|
|
|
|
it('healthCheck() returns connected when auth.test succeeds', async () => {
|
|
const vault = createMockVault({ value: 'xoxb-test-token', isExpired: false });
|
|
await connector.connect(vault);
|
|
|
|
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
ok: true, json: async () => ({ ok: true, user: 'waggle-bot' }),
|
|
}) as unknown as typeof fetch;
|
|
|
|
const health = await connector.healthCheck();
|
|
expect(health.status).toBe('connected');
|
|
});
|
|
|
|
it('execute(send_message) sends message', async () => {
|
|
const vault = createMockVault({ value: 'xoxb-test-token', isExpired: false });
|
|
await connector.connect(vault);
|
|
|
|
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
ok: true, json: async () => ({ ok: true, ts: '1234567890.123456' }),
|
|
}) as unknown as typeof fetch;
|
|
|
|
const result = await connector.execute('send_message', { channel: '#general', text: 'Hello!' });
|
|
expect(result.success).toBe(true);
|
|
});
|
|
|
|
it('execute() returns error for unknown action', async () => {
|
|
const vault = createMockVault({ value: 'xoxb-test-token', isExpired: false });
|
|
await connector.connect(vault);
|
|
|
|
const result = await connector.execute('unknown', {});
|
|
expect(result.success).toBe(false);
|
|
expect(result.error).toContain('Unknown action');
|
|
});
|
|
|
|
it('toDefinition() maps tools correctly', () => {
|
|
const def = connector.toDefinition('connected');
|
|
expect(def.tools).toEqual([
|
|
'connector_slack_list_channels',
|
|
'connector_slack_read_channel',
|
|
'connector_slack_search_messages',
|
|
'connector_slack_send_message',
|
|
]);
|
|
});
|
|
});
|