chore: Fix types in tests 7/N.

This commit is contained in:
cpojer
2026-02-17 11:16:24 +09:00
parent 0aa28c71ca
commit ac38d51290
9 changed files with 36 additions and 34 deletions

View File

@@ -1,9 +1,8 @@
import { Type } from "@sinclair/typebox";
import type { OpenClawConfig } from "../../config/config.js";
import type { AnyAgentTool } from "./common.js";
import { normalizeGroupActivation } from "../../auto-reply/group-activation.js";
import { getFollowupQueueDepth, resolveQueueSettings } from "../../auto-reply/reply/queue.js";
import { buildStatusMessage } from "../../auto-reply/status.js";
import type { OpenClawConfig } from "../../config/config.js";
import { loadConfig } from "../../config/config.js";
import {
loadSessionStore,
@@ -34,6 +33,7 @@ import {
resolveDefaultModelForAgent,
resolveModelRefFromString,
} from "../model-selection.js";
import type { AnyAgentTool } from "./common.js";
import { readStringParam } from "./common.js";
import {
shouldResolveSessionIdInput,

View File

@@ -1,7 +1,7 @@
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
import type { OpenClawConfig } from "../../config/config.js";
import type { TelegramButtonStyle, TelegramInlineButtons } from "../../telegram/button-types.js";
import { createTelegramActionGate } from "../../telegram/accounts.js";
import type { TelegramButtonStyle, TelegramInlineButtons } from "../../telegram/button-types.js";
import {
resolveTelegramInlineButtonsScope,
resolveTelegramTargetChatType,

View File

@@ -37,7 +37,6 @@ function htmlResponse(body: string): Response {
describe("web_fetch Cloudflare Markdown for Agents", () => {
it("sends Accept header preferring text/markdown", async () => {
const fetchSpy = vi.fn().mockResolvedValue(markdownResponse("# Test Page\n\nHello world."));
// @ts-expect-error mock fetch
global.fetch = fetchSpy;
const tool = createWebFetchTool(baseToolConfig);
@@ -52,34 +51,36 @@ describe("web_fetch Cloudflare Markdown for Agents", () => {
it("uses cf-markdown extractor for text/markdown responses", async () => {
const md = "# CF Markdown\n\nThis is server-rendered markdown.";
const fetchSpy = vi.fn().mockResolvedValue(markdownResponse(md));
// @ts-expect-error mock fetch
global.fetch = fetchSpy;
const tool = createWebFetchTool(baseToolConfig);
const result = await tool?.execute?.("call", { url: "https://example.com/cf" });
expect(result?.details).toMatchObject({
const details = result?.details as
| { status?: number; extractor?: string; contentType?: string; text?: string }
| undefined;
expect(details).toMatchObject({
status: 200,
extractor: "cf-markdown",
contentType: "text/markdown",
});
// The body should contain the original markdown (wrapped with security markers)
expect(result?.details?.text).toContain("CF Markdown");
expect(result?.details?.text).toContain("server-rendered markdown");
expect(details?.text).toContain("CF Markdown");
expect(details?.text).toContain("server-rendered markdown");
});
it("falls back to readability for text/html responses", async () => {
const html =
"<html><body><article><h1>HTML Page</h1><p>Content here.</p></article></body></html>";
const fetchSpy = vi.fn().mockResolvedValue(htmlResponse(html));
// @ts-expect-error mock fetch
global.fetch = fetchSpy;
const tool = createWebFetchTool(baseToolConfig);
const result = await tool?.execute?.("call", { url: "https://example.com/html" });
expect(result?.details?.extractor).toBe("readability");
expect(result?.details?.contentType).toBe("text/html");
const details = result?.details as { extractor?: string; contentType?: string } | undefined;
expect(details?.extractor).toBe("readability");
expect(details?.contentType).toBe("text/html");
});
it("logs x-markdown-tokens when header is present", async () => {
@@ -87,7 +88,6 @@ describe("web_fetch Cloudflare Markdown for Agents", () => {
const fetchSpy = vi
.fn()
.mockResolvedValue(markdownResponse("# Tokens Test", { "x-markdown-tokens": "1500" }));
// @ts-expect-error mock fetch
global.fetch = fetchSpy;
const tool = createWebFetchTool(baseToolConfig);
@@ -108,7 +108,6 @@ describe("web_fetch Cloudflare Markdown for Agents", () => {
it("converts markdown to text when extractMode is text", async () => {
const md = "# Heading\n\n**Bold text** and [a link](https://example.com).";
const fetchSpy = vi.fn().mockResolvedValue(markdownResponse(md));
// @ts-expect-error mock fetch
global.fetch = fetchSpy;
const tool = createWebFetchTool(baseToolConfig);
@@ -117,20 +116,22 @@ describe("web_fetch Cloudflare Markdown for Agents", () => {
url: "https://example.com/text-mode",
extractMode: "text",
});
expect(result?.details).toMatchObject({
const details = result?.details as
| { extractor?: string; extractMode?: string; text?: string }
| undefined;
expect(details).toMatchObject({
extractor: "cf-markdown",
extractMode: "text",
});
// Text mode strips header markers (#) and link syntax
expect(result?.details?.text).not.toContain("# Heading");
expect(result?.details?.text).toContain("Heading");
expect(result?.details?.text).not.toContain("[a link](https://example.com)");
expect(details?.text).not.toContain("# Heading");
expect(details?.text).toContain("Heading");
expect(details?.text).not.toContain("[a link](https://example.com)");
});
it("does not log x-markdown-tokens when header is absent", async () => {
const logSpy = vi.spyOn(logger, "logDebug").mockImplementation(() => {});
const fetchSpy = vi.fn().mockResolvedValue(markdownResponse("# No tokens"));
// @ts-expect-error mock fetch
global.fetch = fetchSpy;
const tool = createWebFetchTool(baseToolConfig);

View File

@@ -1,12 +1,12 @@
import { Type } from "@sinclair/typebox";
import type { OpenClawConfig } from "../../config/config.js";
import type { AnyAgentTool } from "./common.js";
import { fetchWithSsrFGuard } from "../../infra/net/fetch-guard.js";
import { SsrFBlockedError } from "../../infra/net/ssrf.js";
import { logDebug } from "../../logger.js";
import { wrapExternalContent, wrapWebContent } from "../../security/external-content.js";
import { normalizeSecretInput } from "../../utils/normalize-secret-input.js";
import { stringEnum } from "../schema/typebox.js";
import type { AnyAgentTool } from "./common.js";
import { jsonResult, readNumberParam, readStringParam } from "./common.js";
import {
extractReadableContent,

View File

@@ -1,9 +1,9 @@
import { Type } from "@sinclair/typebox";
import type { OpenClawConfig } from "../../config/config.js";
import type { AnyAgentTool } from "./common.js";
import { formatCliCommand } from "../../cli/command-format.js";
import type { OpenClawConfig } from "../../config/config.js";
import { wrapWebContent } from "../../security/external-content.js";
import { normalizeSecretInput } from "../../utils/normalize-secret-input.js";
import type { AnyAgentTool } from "./common.js";
import { jsonResult, readNumberParam, readStringParam } from "./common.js";
import {
CacheEntry,