test: consolidate redundant suites and speed up timers

This commit is contained in:
Peter Steinberger
2026-02-23 04:44:42 +00:00
parent a6a2a9276e
commit 86a8b65e9d
10 changed files with 171 additions and 224 deletions

View File

@@ -91,8 +91,12 @@ function requestUrl(input: RequestInfo | URL): string {
return "";
}
function installMockFetch(impl: (input: RequestInfo | URL) => Promise<Response>) {
const mockFetch = vi.fn(async (input: RequestInfo | URL) => await impl(input));
function installMockFetch(
impl: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>,
) {
const mockFetch = vi.fn(
async (input: RequestInfo | URL, init?: RequestInit) => await impl(input, init),
);
global.fetch = withFetchPreconnect(mockFetch);
return mockFetch;
}
@@ -253,6 +257,36 @@ describe("web_fetch extraction fallbacks", () => {
expect(details.text).toContain("firecrawl content");
});
it("normalizes firecrawl Authorization header values", async () => {
const fetchSpy = installMockFetch((input: RequestInfo | URL) => {
const url = requestUrl(input);
if (url.includes("api.firecrawl.dev/v2/scrape")) {
return Promise.resolve(firecrawlResponse("firecrawl normalized")) as Promise<Response>;
}
return Promise.resolve(
htmlResponse("<!doctype html><html><head></head><body></body></html>", url),
) as Promise<Response>;
});
const tool = createFetchTool({
firecrawl: { apiKey: "firecrawl-test-\r\nkey" },
});
const result = await tool?.execute?.("call", {
url: "https://example.com/firecrawl",
extractMode: "text",
});
expect(result?.details).toMatchObject({ extractor: "firecrawl" });
const firecrawlCall = fetchSpy.mock.calls.find((call) =>
requestUrl(call[0]).includes("/v2/scrape"),
);
expect(firecrawlCall).toBeTruthy();
const init = firecrawlCall?.[1];
const authHeader = new Headers(init?.headers).get("Authorization");
expect(authHeader).toBe("Bearer firecrawl-test-key");
});
it("throws when readability is disabled and firecrawl is unavailable", async () => {
installMockFetch(
(input: RequestInfo | URL) =>