feat: add agent API and operational analytics

This commit is contained in:
jjbrunton committed 2026-08-08 22:08:14 +01:00
1 parent 720ea0652a
commit e8b730b592
65 files changed
+2650 -1214

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
import { describe, expect, it, vi } from 'vitest';
import { RedditBotApiClient, RedditBotApiError } from '../src/mcp/api-client.js';
describe('RedditBotApiClient', () => {
it('uses a bearer token and parses JSON responses', async () => {
const fetchImplementation = vi.fn(async () => new Response(JSON.stringify({ running: true }), { status: 200 }));
const client = new RedditBotApiClient({
baseUrl: 'http://redditbot.test/',
token: 'read-token',
fetchImplementation: fetchImplementation as typeof fetch,
});
await expect(client.get('/api/v1/control')).resolves.toEqual({ running: true });
expect(fetchImplementation).toHaveBeenCalledWith('http://redditbot.test/api/v1/control', expect.objectContaining({
headers: expect.objectContaining({ Authorization: 'Bearer read-token' }),
}));
});
it('returns structured API errors to MCP tools', async () => {
const client = new RedditBotApiClient({
token: 'read-token',
fetchImplementation: vi.fn(async () => new Response(JSON.stringify({ error: 'Agent credential lacks the required access' }), { status: 403 })) as typeof fetch,
});
await expect(client.post('/api/v1/control/start')).rejects.toEqual(
new RedditBotApiError('Agent credential lacks the required access', 403),
);
});
});