diff --git a/scripts/deadcode-exports.baseline.mjs b/scripts/deadcode-exports.baseline.mjs index d159d8bd9038..aaf4c71d0eb6 100644 --- a/scripts/deadcode-exports.baseline.mjs +++ b/scripts/deadcode-exports.baseline.mjs @@ -380,8 +380,6 @@ export const KNIP_UNUSED_EXPORT_BASELINE = [ "src/mcp/openclaw-tools-serve-config.ts: resolveOpenClawToolsMcpSystemAgentApproval", "src/mcp/openclaw-tools-serve-config.ts: resolveOpenClawToolsMcpSystemAgentSurface", "src/mcp/openclaw-tools-serve-config.ts: resolveOpenClawToolsMcpToolSelection", - "src/media/input-files.ts: fetchWithGuard", - "src/media/parse.ts: SplitMediaFromOutputOptions", "src/music-generation/capabilities.ts: resolveMusicGenerationMode", "src/music-generation/runtime.ts: MusicGenerationRuntimeDeps", "src/node-host/invoke.ts: testing", diff --git a/src/media/input-files.fetch-guard.test.ts b/src/media/input-files.fetch-guard.test.ts index 0460856ff70f..5398df171931 100644 --- a/src/media/input-files.fetch-guard.test.ts +++ b/src/media/input-files.fetch-guard.test.ts @@ -28,12 +28,11 @@ async function waitForMicrotaskTurn(): Promise { }); } -let fetchWithGuard: typeof import("./input-files.js").fetchWithGuard; let extractImageContentFromSource: typeof import("./input-files.js").extractImageContentFromSource; let extractFileContentFromSource: typeof import("./input-files.js").extractFileContentFromSource; beforeAll(async () => { - ({ fetchWithGuard, extractImageContentFromSource, extractFileContentFromSource } = + ({ extractImageContentFromSource, extractFileContentFromSource } = await import("./input-files.js")); }); @@ -241,7 +240,7 @@ describe("HEIC input image normalization", () => { }); }); -describe("fetchWithGuard", () => { +describe("guarded input file URL fetches", () => { it("cancels ignored HTTP error bodies", async () => { let canceled = false; const stream = new ReadableStream({ @@ -263,11 +262,12 @@ describe("fetchWithGuard", () => { }); await expect( - fetchWithGuard({ - url: "https://example.com/file.bin", - maxBytes: 1024, - timeoutMs: 1000, - maxRedirects: 0, + extractFileContentFromSource({ + source: { type: "url", url: "https://example.com/file.bin" }, + limits: { + ...createFileSourceLimits(["application/octet-stream"], true), + maxBytes: 1024, + }, }), ).rejects.toThrow("Failed to fetch: 503 Service Unavailable"); @@ -296,11 +296,12 @@ describe("fetchWithGuard", () => { }); await expect( - fetchWithGuard({ - url: "https://example.com/file.bin", - maxBytes: 1024, - timeoutMs: 1000, - maxRedirects: 0, + extractFileContentFromSource({ + source: { type: "url", url: "https://example.com/file.bin" }, + limits: { + ...createFileSourceLimits(["application/octet-stream"], true), + maxBytes: 1024, + }, }), ).rejects.toThrow("Content too large: 2048 bytes"); @@ -329,11 +330,12 @@ describe("fetchWithGuard", () => { }); await expect( - fetchWithGuard({ - url: "https://example.com/file.bin", - maxBytes: 1024, - timeoutMs: 1000, - maxRedirects: 0, + extractFileContentFromSource({ + source: { type: "url", url: "https://example.com/file.bin" }, + limits: { + ...createFileSourceLimits(["application/octet-stream"], true), + maxBytes: 1024, + }, }), ).rejects.toThrow("invalid content-length header: 1e9"); @@ -371,11 +373,12 @@ describe("fetchWithGuard", () => { }); await expect( - fetchWithGuard({ - url: "https://example.com/file.bin", - maxBytes: 6, - timeoutMs: 1000, - maxRedirects: 0, + extractFileContentFromSource({ + source: { type: "url", url: "https://example.com/file.bin" }, + limits: { + ...createFileSourceLimits(["application/octet-stream"], true), + maxBytes: 6, + }, }), ).rejects.toThrow("Content too large"); diff --git a/src/media/input-files.ts b/src/media/input-files.ts index 56c3d02bf3ab..abd3b15fe8b5 100644 --- a/src/media/input-files.ts +++ b/src/media/input-files.ts @@ -201,7 +201,7 @@ export function resolveInputFileLimits(config?: InputFileLimitsConfig): InputFil } /** Fetches an input source URL through SSRF, redirect, timeout, and byte-limit guards. */ -export async function fetchWithGuard(params: { +async function fetchWithGuard(params: { url: string; maxBytes: number; timeoutMs: number; diff --git a/src/media/parse.test.ts b/src/media/parse.test.ts index 9340f93958cf..b39a509d5d56 100644 --- a/src/media/parse.test.ts +++ b/src/media/parse.test.ts @@ -1,6 +1,8 @@ // Media parse tests cover media reference parsing from text and payloads. import { describe, expect, it } from "vitest"; -import { splitMediaFromOutput, type SplitMediaFromOutputOptions } from "./parse.js"; +import { splitMediaFromOutput } from "./parse.js"; + +type SplitMediaFromOutputOptions = NonNullable[1]>; describe("splitMediaFromOutput", () => { function expectParsedMediaOutputCase( diff --git a/src/media/parse.ts b/src/media/parse.ts index aa9bc39a7004..5b002ffadf50 100644 --- a/src/media/parse.ts +++ b/src/media/parse.ts @@ -29,7 +29,7 @@ type ParsedMediaOutputSegment = }; /** Controls which non-MEDIA syntaxes may be lifted into media attachments. */ -export type SplitMediaFromOutputOptions = { +type SplitMediaFromOutputOptions = { extractMarkdownImages?: boolean; extractMediaDirectives?: boolean; };