chore: Fix types in tests 31/N.
This commit is contained in:
@@ -77,7 +77,7 @@ function errorHtmlResponse(
|
||||
text: async () => html,
|
||||
};
|
||||
}
|
||||
function requestUrl(input: RequestInfo): string {
|
||||
function requestUrl(input: RequestInfo | URL): string {
|
||||
if (typeof input === "string") {
|
||||
return input;
|
||||
}
|
||||
@@ -90,9 +90,9 @@ function requestUrl(input: RequestInfo): string {
|
||||
return "";
|
||||
}
|
||||
|
||||
function installMockFetch(impl: (input: RequestInfo) => Promise<Response>) {
|
||||
const mockFetch = vi.fn(impl);
|
||||
global.fetch = mockFetch;
|
||||
function installMockFetch(impl: (input: RequestInfo | URL) => Promise<Response>) {
|
||||
const mockFetch = vi.fn(async (input: RequestInfo | URL) => await impl(input));
|
||||
global.fetch = mockFetch as typeof global.fetch;
|
||||
return mockFetch;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ describe("web_fetch extraction fallbacks", () => {
|
||||
});
|
||||
|
||||
it("wraps fetched text with external content markers", async () => {
|
||||
installMockFetch((input: RequestInfo) =>
|
||||
installMockFetch((input: RequestInfo | URL) =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
status: 200,
|
||||
@@ -183,7 +183,7 @@ describe("web_fetch extraction fallbacks", () => {
|
||||
|
||||
it("enforces maxChars after wrapping", async () => {
|
||||
const longText = "x".repeat(5_000);
|
||||
installMockFetch((input: RequestInfo) =>
|
||||
installMockFetch((input: RequestInfo | URL) =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
status: 200,
|
||||
@@ -206,7 +206,7 @@ describe("web_fetch extraction fallbacks", () => {
|
||||
});
|
||||
|
||||
it("honors maxChars even when wrapper overhead exceeds limit", async () => {
|
||||
installMockFetch((input: RequestInfo) =>
|
||||
installMockFetch((input: RequestInfo | URL) =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
status: 200,
|
||||
@@ -232,7 +232,7 @@ describe("web_fetch extraction fallbacks", () => {
|
||||
// The sanitization of these fields is verified by external-content.test.ts tests.
|
||||
|
||||
it("falls back to firecrawl when readability returns no content", async () => {
|
||||
installMockFetch((input: RequestInfo) => {
|
||||
installMockFetch((input: RequestInfo | URL) => {
|
||||
const url = requestUrl(input);
|
||||
if (url.includes("api.firecrawl.dev")) {
|
||||
return Promise.resolve(firecrawlResponse("firecrawl content")) as Promise<Response>;
|
||||
@@ -253,8 +253,11 @@ describe("web_fetch extraction fallbacks", () => {
|
||||
});
|
||||
|
||||
it("throws when readability is disabled and firecrawl is unavailable", async () => {
|
||||
installMockFetch((input: RequestInfo) =>
|
||||
Promise.resolve(htmlResponse("<html><body>hi</body></html>", requestUrl(input))),
|
||||
installMockFetch(
|
||||
(input: RequestInfo | URL) =>
|
||||
Promise.resolve(
|
||||
htmlResponse("<html><body>hi</body></html>", requestUrl(input)),
|
||||
) as Promise<Response>,
|
||||
);
|
||||
|
||||
const tool = createFetchTool({
|
||||
@@ -268,7 +271,7 @@ describe("web_fetch extraction fallbacks", () => {
|
||||
});
|
||||
|
||||
it("throws when readability is empty and firecrawl fails", async () => {
|
||||
installMockFetch((input: RequestInfo) => {
|
||||
installMockFetch((input: RequestInfo | URL) => {
|
||||
const url = requestUrl(input);
|
||||
if (url.includes("api.firecrawl.dev")) {
|
||||
return Promise.resolve(firecrawlError()) as Promise<Response>;
|
||||
@@ -288,7 +291,7 @@ describe("web_fetch extraction fallbacks", () => {
|
||||
});
|
||||
|
||||
it("uses firecrawl when direct fetch fails", async () => {
|
||||
installMockFetch((input: RequestInfo) => {
|
||||
installMockFetch((input: RequestInfo | URL) => {
|
||||
const url = requestUrl(input);
|
||||
if (url.includes("api.firecrawl.dev")) {
|
||||
return Promise.resolve(firecrawlResponse("firecrawl fallback", url)) as Promise<Response>;
|
||||
@@ -314,7 +317,7 @@ describe("web_fetch extraction fallbacks", () => {
|
||||
it("wraps external content and clamps oversized maxChars", async () => {
|
||||
const large = "a".repeat(80_000);
|
||||
installMockFetch(
|
||||
(input: RequestInfo) =>
|
||||
(input: RequestInfo | URL) =>
|
||||
Promise.resolve(textResponse(large, requestUrl(input))) as Promise<Response>,
|
||||
);
|
||||
|
||||
@@ -340,8 +343,11 @@ describe("web_fetch extraction fallbacks", () => {
|
||||
"<!doctype html><html><head><title>Not Found</title></head><body><h1>Not Found</h1><p>" +
|
||||
long +
|
||||
"</p></body></html>";
|
||||
installMockFetch((input: RequestInfo) =>
|
||||
Promise.resolve(errorHtmlResponse(html, 404, requestUrl(input), "Text/HTML; charset=utf-8")),
|
||||
installMockFetch(
|
||||
(input: RequestInfo | URL) =>
|
||||
Promise.resolve(
|
||||
errorHtmlResponse(html, 404, requestUrl(input), "Text/HTML; charset=utf-8"),
|
||||
) as Promise<Response>,
|
||||
);
|
||||
|
||||
const tool = createFetchTool({ firecrawl: { enabled: false } });
|
||||
@@ -361,8 +367,9 @@ describe("web_fetch extraction fallbacks", () => {
|
||||
it("strips HTML errors when content-type is missing", async () => {
|
||||
const html =
|
||||
"<!DOCTYPE HTML><html><head><title>Oops</title></head><body><h1>Oops</h1></body></html>";
|
||||
installMockFetch((input: RequestInfo) =>
|
||||
Promise.resolve(errorHtmlResponse(html, 500, requestUrl(input), null)),
|
||||
installMockFetch(
|
||||
(input: RequestInfo | URL) =>
|
||||
Promise.resolve(errorHtmlResponse(html, 500, requestUrl(input), null)) as Promise<Response>,
|
||||
);
|
||||
|
||||
const tool = createFetchTool({ firecrawl: { enabled: false } });
|
||||
@@ -377,7 +384,7 @@ describe("web_fetch extraction fallbacks", () => {
|
||||
});
|
||||
|
||||
it("wraps firecrawl error details", async () => {
|
||||
installMockFetch((input: RequestInfo) => {
|
||||
installMockFetch((input: RequestInfo | URL) => {
|
||||
const url = requestUrl(input);
|
||||
if (url.includes("api.firecrawl.dev")) {
|
||||
return Promise.resolve({
|
||||
|
||||
Reference in New Issue
Block a user