





























@@ -287,6 +287,42 @@ describe("createPdfTool", () => {
287287});
288288});
289289290+it("rejects invalid maxBytesMb before loading PDFs", async () => {
291+await withConfiguredPdfTool(async (tool) => {
292+const loadSpy = vi.spyOn(webMedia, "loadWebMediaRaw");
293+294+await expect(
295+tool.execute("t1", {
296+prompt: "test",
297+pdf: "/tmp/doc.pdf",
298+maxBytesMb: 0,
299+}),
300+).rejects.toThrow("maxBytesMb must be greater than 0");
301+expect(loadSpy).not.toHaveBeenCalled();
302+});
303+});
304+305+it("passes validated maxBytesMb to PDF loading", async () => {
306+await withTempPdfAgentDir(async (agentDir) => {
307+const { loadSpy } = await stubPdfToolInfra(agentDir, {
308+provider: "anthropic",
309+input: ["text", "document"],
310+});
311+vi.spyOn(pdfNativeProviders, "anthropicAnalyzePdf").mockResolvedValue("native summary");
312+const cfg = withPdfModel(ANTHROPIC_PDF_MODEL);
313+const tool = requirePdfTool((await loadCreatePdfTool())({ config: cfg, agentDir }));
314+315+await tool.execute("t1", {
316+prompt: "summarize",
317+pdf: "/tmp/doc.pdf",
318+maxBytesMb: "0.5",
319+});
320+321+const [, loadOptions] = firstMockCall(loadSpy, "loadWebMediaRaw");
322+expectFields(loadOptions, { maxBytes: 524_288 });
323+});
324+});
325+290326it("respects fsPolicy.workspaceOnly for non-sandbox pdf paths", async () => {
291327await withTempPdfAgentDir(async (agentDir) => {
292328const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-pdf-ws-"));
@@ -686,5 +722,9 @@ describe("createPdfTool", () => {
686722expect(props).toHaveProperty("password");
687723expect(props).toHaveProperty("model");
688724expect(props).toHaveProperty("maxBytesMb");
725+expect(PdfToolSchema.properties.maxBytesMb).toMatchObject({
726+type: "number",
727+exclusiveMinimum: 0,
728+});
689729});
690730});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。