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

+18
View File
@@ -3,6 +3,7 @@ import axios from 'axios';
import type { AxiosInstance } from 'axios';
import type { BrowserContext } from 'playwright';
import { RedditApiClient, RedditRateLimitError } from '../src/reddit/api.js';
import type { RedditRequestScheduler } from '../src/reddit/request-coordinator.js';
import type { RedditPost } from '../src/reddit/api.js';
import { createMockLogger } from '../tests/mockLogger.js';
import { getTestConfig } from '../tests/testUtils.js';
@@ -517,6 +518,23 @@ describe('RedditApiClient', () => {
)).toBe(true);
});
it('extends the shared request cooldown when Reddit returns 429', async () => {
const error = {
isAxiosError: true,
response: { status: 429, headers: { 'retry-after': '12' } },
};
const mockAxios = { get: vi.fn().mockRejectedValue(error) };
vi.mocked(axios.create).mockReturnValue(mockAxios as unknown as AxiosInstance);
const scheduler: RedditRequestScheduler = {
schedule: async (request) => await request(),
extendCooldown: vi.fn(),
};
const client2 = new RedditApiClient(getTestConfig(), logger, scheduler);
await expect(client2.getNewPosts('test')).rejects.toMatchObject({ retryAfterMs: 12_000 });
expect(scheduler.extendCooldown).toHaveBeenCalledWith(12_000);
});
it('parses valid image posts from response', async () => {
const mockResponse = {
data: { data: { children: [