Files
oh-my-pi/packages/coding-agent/test/helpers/fetch-mock.ts
T
can1357 eb1a46baf5 feat: added injectable fetch transport across AI and coding network flows
- Added optional FetchImpl fields to compaction, proxy, AI, coding-agent, and mnemopi options.
- Threaded injected fetch implementations through OAuth, discovery, and search/LLM request flows.
- Removed exported hookFetch utility and its package entrypoint from utils.
- Replaced global-fetch test monkeypatching with per-test FetchImpl mocks across test suites.
2026-06-09 04:51:17 +02:00

19 lines
745 B
TypeScript

import type { FetchImpl } from "@oh-my-pi/pi-ai/types";
type FetchHandler = (input: string | URL | Request, init?: RequestInit) => Response | Promise<Response>;
/** Wrap a fetch handler as a {@link FetchImpl}, normalizing sync `Response` returns. */
export function mockFetch(fn: FetchHandler): FetchImpl {
return async (input, init) => fn(input, init);
}
/** Satisfies Bun's `typeof fetch` (includes `preconnect`). */
export function asGlobalFetch(fn: FetchHandler): typeof fetch {
return Object.assign(async (input: string | URL | Request, init?: RequestInit) => fn(input, init), {
preconnect: fetch.preconnect,
});
}
/** `RequestInfo` alias for test fetch handlers (DOM lib name). */
export type FetchInput = string | URL | Request;