chore(#1): apply Prettier formatting to all source and test files
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 22:48:08 -06:00
parent 9df760cab2
commit 493bc72601
16 changed files with 283 additions and 262 deletions

View File

@@ -1,6 +1,6 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { BatchSubmitter } from '../src/submitter.js';
import { ResolvedConfig } from '../src/config.js';
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { BatchSubmitter } from "../src/submitter.js";
import { ResolvedConfig } from "../src/config.js";
import {
TaskCompletionEvent,
TaskType,
@@ -8,13 +8,13 @@ import {
Harness,
Provider,
Outcome,
} from '../src/types/events.js';
} from "../src/types/events.js";
function makeConfig(overrides: Partial<ResolvedConfig> = {}): ResolvedConfig {
return {
serverUrl: 'https://tel.example.com',
apiKey: 'a'.repeat(64),
instanceId: 'test-instance-id',
serverUrl: "https://tel.example.com",
apiKey: "a".repeat(64),
instanceId: "test-instance-id",
enabled: true,
submitIntervalMs: 300_000,
maxQueueSize: 1000,
@@ -28,17 +28,17 @@ function makeConfig(overrides: Partial<ResolvedConfig> = {}): ResolvedConfig {
};
}
function makeEvent(id = 'evt-1'): TaskCompletionEvent {
function makeEvent(id = "evt-1"): TaskCompletionEvent {
return {
instance_id: 'test-instance-id',
instance_id: "test-instance-id",
event_id: id,
schema_version: '1.0',
schema_version: "1.0",
timestamp: new Date().toISOString(),
task_duration_ms: 5000,
task_type: TaskType.IMPLEMENTATION,
complexity: Complexity.MEDIUM,
harness: Harness.CLAUDE_CODE,
model: 'claude-3-opus',
model: "claude-3-opus",
provider: Provider.ANTHROPIC,
estimated_input_tokens: 1000,
estimated_output_tokens: 500,
@@ -57,13 +57,13 @@ function makeEvent(id = 'evt-1'): TaskCompletionEvent {
};
}
describe('BatchSubmitter', () => {
describe("BatchSubmitter", () => {
let fetchSpy: ReturnType<typeof vi.fn>;
beforeEach(() => {
vi.useFakeTimers();
fetchSpy = vi.fn();
vi.stubGlobal('fetch', fetchSpy);
vi.stubGlobal("fetch", fetchSpy);
});
afterEach(() => {
@@ -71,11 +71,11 @@ describe('BatchSubmitter', () => {
vi.unstubAllGlobals();
});
it('should submit a batch successfully', async () => {
it("should submit a batch successfully", async () => {
const responseBody = {
accepted: 1,
rejected: 0,
results: [{ event_id: 'evt-1', status: 'accepted' }],
results: [{ event_id: "evt-1", status: "accepted" }],
};
fetchSpy.mockResolvedValueOnce({
ok: true,
@@ -91,13 +91,13 @@ describe('BatchSubmitter', () => {
expect(fetchSpy).toHaveBeenCalledTimes(1);
const [url, options] = fetchSpy.mock.calls[0];
expect(url).toBe('https://tel.example.com/v1/events/batch');
expect(options.method).toBe('POST');
expect(options.headers['Authorization']).toBe(`Bearer ${'a'.repeat(64)}`);
expect(url).toBe("https://tel.example.com/v1/events/batch");
expect(options.method).toBe("POST");
expect(options.headers["Authorization"]).toBe(`Bearer ${"a".repeat(64)}`);
});
it('should handle 429 with Retry-After header', async () => {
const headers = new Map([['Retry-After', '1']]);
it("should handle 429 with Retry-After header", async () => {
const headers = new Map([["Retry-After", "1"]]);
fetchSpy.mockResolvedValueOnce({
ok: false,
status: 429,
@@ -108,7 +108,7 @@ describe('BatchSubmitter', () => {
const responseBody = {
accepted: 1,
rejected: 0,
results: [{ event_id: 'evt-1', status: 'accepted' }],
results: [{ event_id: "evt-1", status: "accepted" }],
};
fetchSpy.mockResolvedValueOnce({
ok: true,
@@ -129,23 +129,23 @@ describe('BatchSubmitter', () => {
expect(fetchSpy).toHaveBeenCalledTimes(2);
});
it('should handle 403 error', async () => {
it("should handle 403 error", async () => {
fetchSpy.mockResolvedValueOnce({
ok: false,
status: 403,
statusText: 'Forbidden',
statusText: "Forbidden",
});
const submitter = new BatchSubmitter(makeConfig({ maxRetries: 0 }));
const result = await submitter.submit([makeEvent()]);
expect(result.success).toBe(false);
expect(result.error?.message).toContain('Forbidden');
expect(result.error?.message).toContain('403');
expect(result.error?.message).toContain("Forbidden");
expect(result.error?.message).toContain("403");
});
it('should retry on network error with backoff', async () => {
fetchSpy.mockRejectedValueOnce(new Error('Network error'));
it("should retry on network error with backoff", async () => {
fetchSpy.mockRejectedValueOnce(new Error("Network error"));
fetchSpy.mockResolvedValueOnce({
ok: true,
status: 202,
@@ -153,7 +153,7 @@ describe('BatchSubmitter', () => {
Promise.resolve({
accepted: 1,
rejected: 0,
results: [{ event_id: 'evt-1', status: 'accepted' }],
results: [{ event_id: "evt-1", status: "accepted" }],
}),
});
@@ -168,8 +168,8 @@ describe('BatchSubmitter', () => {
expect(fetchSpy).toHaveBeenCalledTimes(2);
});
it('should fail after max retries exhausted', async () => {
fetchSpy.mockRejectedValue(new Error('Network error'));
it("should fail after max retries exhausted", async () => {
fetchSpy.mockRejectedValue(new Error("Network error"));
const submitter = new BatchSubmitter(makeConfig({ maxRetries: 2 }));
const submitPromise = submitter.submit([makeEvent()]);
@@ -179,12 +179,15 @@ describe('BatchSubmitter', () => {
const result = await submitPromise;
expect(result.success).toBe(false);
expect(result.error?.message).toBe('Network error');
expect(result.error?.message).toBe("Network error");
});
it('should not call fetch in dryRun mode', async () => {
it("should not call fetch in dryRun mode", async () => {
const submitter = new BatchSubmitter(makeConfig({ dryRun: true }));
const result = await submitter.submit([makeEvent('evt-1'), makeEvent('evt-2')]);
const result = await submitter.submit([
makeEvent("evt-1"),
makeEvent("evt-2"),
]);
expect(result.success).toBe(true);
expect(result.response?.accepted).toBe(2);
@@ -192,12 +195,14 @@ describe('BatchSubmitter', () => {
expect(fetchSpy).not.toHaveBeenCalled();
});
it('should handle request timeout via AbortController', async () => {
it("should handle request timeout via AbortController", async () => {
fetchSpy.mockImplementation(
(_url: string, options: { signal: AbortSignal }) =>
new Promise((_resolve, reject) => {
options.signal.addEventListener('abort', () => {
reject(new DOMException('The operation was aborted.', 'AbortError'));
options.signal.addEventListener("abort", () => {
reject(
new DOMException("The operation was aborted.", "AbortError"),
);
});
}),
);
@@ -211,6 +216,6 @@ describe('BatchSubmitter', () => {
const result = await submitPromise;
expect(result.success).toBe(false);
expect(result.error?.message).toContain('aborted');
expect(result.error?.message).toContain("aborted");
});
});