mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 22:07:28 +00:00
fix: use logDebug instead of console.log for x-markdown-tokens
Address Greptile review: route x-markdown-tokens logging through the project's logger abstraction (logDebug) instead of unconditional console.log. This respects verbose/debug level filtering and avoids noisy stdout output during normal tool execution. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
Peter Steinberger
parent
29be310c99
commit
bbc9d71428
@@ -1,5 +1,6 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import * as ssrf from "../../infra/net/ssrf.js";
|
||||
import * as logger from "../../logger.js";
|
||||
|
||||
const lookupMock = vi.fn();
|
||||
const resolvePinnedHostname = ssrf.resolvePinnedHostname;
|
||||
@@ -108,7 +109,7 @@ describe("web_fetch Cloudflare Markdown for Agents", () => {
|
||||
});
|
||||
|
||||
it("logs x-markdown-tokens when header is present", async () => {
|
||||
const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
const logSpy = vi.spyOn(logger, "logDebug").mockImplementation(() => {});
|
||||
const fetchSpy = vi
|
||||
.fn()
|
||||
.mockResolvedValue(markdownResponse("# Tokens Test", { "x-markdown-tokens": "1500" }));
|
||||
@@ -124,7 +125,7 @@ describe("web_fetch Cloudflare Markdown for Agents", () => {
|
||||
|
||||
await tool?.execute?.("call", { url: "https://example.com/tokens" });
|
||||
|
||||
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining("x-markdown-tokens: 1500"));
|
||||
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("x-markdown-tokens: 1500"));
|
||||
});
|
||||
|
||||
it("converts markdown to text when extractMode is text", async () => {
|
||||
@@ -155,7 +156,7 @@ describe("web_fetch Cloudflare Markdown for Agents", () => {
|
||||
});
|
||||
|
||||
it("does not log x-markdown-tokens when header is absent", async () => {
|
||||
const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
const logSpy = vi.spyOn(logger, "logDebug").mockImplementation(() => {});
|
||||
const fetchSpy = vi.fn().mockResolvedValue(markdownResponse("# No tokens"));
|
||||
// @ts-expect-error mock fetch
|
||||
global.fetch = fetchSpy;
|
||||
@@ -169,7 +170,7 @@ describe("web_fetch Cloudflare Markdown for Agents", () => {
|
||||
|
||||
await tool?.execute?.("call", { url: "https://example.com/no-tokens" });
|
||||
|
||||
const tokenLogs = consoleSpy.mock.calls.filter(
|
||||
const tokenLogs = logSpy.mock.calls.filter(
|
||||
(args) => typeof args[0] === "string" && args[0].includes("x-markdown-tokens"),
|
||||
);
|
||||
expect(tokenLogs).toHaveLength(0);
|
||||
|
||||
@@ -3,6 +3,7 @@ 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";
|
||||
@@ -422,7 +423,7 @@ async function runWebFetch(params: {
|
||||
// Cloudflare Markdown for Agents — log token budget hint when present
|
||||
const markdownTokens = res.headers.get("x-markdown-tokens");
|
||||
if (markdownTokens) {
|
||||
console.log(`[web-fetch] x-markdown-tokens: ${markdownTokens} (${finalUrl})`);
|
||||
logDebug(`[web-fetch] x-markdown-tokens: ${markdownTokens} (${finalUrl})`);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof SsrFBlockedError) {
|
||||
|
||||
Reference in New Issue
Block a user