mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 00:01:24 +00:00
test: consolidate redundant suites and speed up timers
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isModernModelRef } from "./live-model-filter.js";
|
||||
|
||||
describe("isModernModelRef", () => {
|
||||
it("excludes opencode minimax variants from modern selection", () => {
|
||||
expect(isModernModelRef({ provider: "opencode", id: "minimax-m2.1" })).toBe(false);
|
||||
expect(isModernModelRef({ provider: "opencode", id: "minimax-m2.5" })).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps non-minimax opencode modern models", () => {
|
||||
expect(isModernModelRef({ provider: "opencode", id: "claude-opus-4-6" })).toBe(true);
|
||||
expect(isModernModelRef({ provider: "opencode", id: "gemini-3-pro" })).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,21 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { loadModelCatalog } from "./model-catalog.js";
|
||||
import {
|
||||
installModelCatalogTestHooks,
|
||||
mockCatalogImportFailThenRecover,
|
||||
} from "./model-catalog.test-harness.js";
|
||||
|
||||
describe("loadModelCatalog e2e smoke", () => {
|
||||
installModelCatalogTestHooks();
|
||||
|
||||
it("recovers after an import failure on the next load", async () => {
|
||||
mockCatalogImportFailThenRecover();
|
||||
|
||||
const cfg = {} as OpenClawConfig;
|
||||
expect(await loadModelCatalog({ config: cfg })).toEqual([]);
|
||||
expect(await loadModelCatalog({ config: cfg })).toEqual([
|
||||
{ id: "gpt-4.1", name: "GPT-4.1", provider: "openai" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Api, Model } from "@mariozechner/pi-ai";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isModernModelRef } from "./live-model-filter.js";
|
||||
import { normalizeModelCompat } from "./model-compat.js";
|
||||
|
||||
const baseModel = (): Model<Api> =>
|
||||
@@ -46,3 +47,15 @@ describe("normalizeModelCompat", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isModernModelRef", () => {
|
||||
it("excludes opencode minimax variants from modern selection", () => {
|
||||
expect(isModernModelRef({ provider: "opencode", id: "minimax-m2.1" })).toBe(false);
|
||||
expect(isModernModelRef({ provider: "opencode", id: "minimax-m2.5" })).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps non-minimax opencode modern models", () => {
|
||||
expect(isModernModelRef({ provider: "opencode", id: "claude-opus-4-6" })).toBe(true);
|
||||
expect(isModernModelRef({ provider: "opencode", id: "gemini-3-pro" })).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -616,7 +616,6 @@ describe("Agent-specific tool filtering", () => {
|
||||
|
||||
const result = await execTool!.execute("call-implicit-sandbox-default", {
|
||||
command: "echo done",
|
||||
yieldMs: 10,
|
||||
});
|
||||
const details = result?.details as { status?: string } | undefined;
|
||||
expect(details?.status).toBe("completed");
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { withFetchPreconnect } from "../../test-utils/fetch-mock.js";
|
||||
|
||||
vi.mock("../../infra/net/fetch-guard.js", () => {
|
||||
return {
|
||||
fetchWithSsrFGuard: vi.fn(async () => {
|
||||
throw new Error("network down");
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe("web_fetch firecrawl apiKey normalization", () => {
|
||||
const priorFetch = global.fetch;
|
||||
|
||||
afterEach(() => {
|
||||
global.fetch = priorFetch;
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("strips embedded CR/LF before sending Authorization header", async () => {
|
||||
const fetchSpy = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : "";
|
||||
expect(url).toContain("/v2/scrape");
|
||||
|
||||
const auth = (init?.headers as Record<string, string> | undefined)?.Authorization;
|
||||
expect(auth).toBe("Bearer firecrawl-test-key");
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: true,
|
||||
data: { markdown: "ok", metadata: { title: "t" } },
|
||||
}),
|
||||
{ status: 200, headers: { "Content-Type": "application/json" } },
|
||||
);
|
||||
});
|
||||
|
||||
global.fetch = withFetchPreconnect(fetchSpy);
|
||||
|
||||
const { createWebFetchTool } = await import("./web-tools.js");
|
||||
const tool = createWebFetchTool({
|
||||
config: {
|
||||
tools: {
|
||||
web: {
|
||||
fetch: {
|
||||
cacheTtlMinutes: 0,
|
||||
firecrawl: { apiKey: "firecrawl-test-\r\nkey" },
|
||||
readability: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = await tool?.execute?.("call", {
|
||||
url: "https://example.com",
|
||||
extractMode: "text",
|
||||
});
|
||||
expect(result?.details).toMatchObject({ extractor: "firecrawl" });
|
||||
expect(fetchSpy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -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) =>
|
||||
|
||||
Reference in New Issue
Block a user