Files
ai-job-search/.agents/skills/jobnet-search/cli/tests/request-timeout.test.ts
T
Thejesh Reddy 9cad956cc9 fix(portals): add a 15s request timeout to every board fetch (#197)
None of the board CLIs set a fetch timeout, and the retry loops react only to HTTP status codes, not to a connection that is accepted then never responds (black-holed TCP, hung TLS, stalled proxy) - so await fetch(...) never settles and the command hangs with no output and no exit. freehire's helper even documented a fast-degrade contract its try/catch didn't deliver on a mid-flight stall. Adds signal: AbortSignal.timeout(15000) to every fetch across all six CLIs, with network-free tests asserting the signal is present on each request wrapper.

By @thejesh23. Verified: 8 timeout tests pass locally with fetch stubbed (no network), and would fail on the pre-fix code.

Closes #196
2026-07-20 20:19:27 +02:00

24 lines
868 B
TypeScript

import { afterEach, describe, expect, test } from "bun:test";
import { apiFetch } from "../src/helpers";
// A stalled upstream connection (accepted socket, no response) would otherwise
// hang the CLI forever - fetch has no default timeout. Assert every request
// carries an AbortSignal timeout. This fails on the pre-fix code (no signal).
const originalFetch = globalThis.fetch;
afterEach(() => {
globalThis.fetch = originalFetch;
});
describe("apiFetch request timeout", () => {
test("passes an AbortSignal timeout to fetch", async () => {
let init: RequestInit | undefined;
globalThis.fetch = (async (_url: string | URL | Request, i?: RequestInit) => {
init = i;
return new Response("{}", { status: 200 });
}) as unknown as typeof fetch;
await apiFetch("/search");
expect(init?.signal).toBeInstanceOf(AbortSignal);
});
});