























@@ -500,6 +500,22 @@ describe("createPdfTool", () => {
500500});
501501});
502502503+it("rejects password parameter for native PDF providers", async () => {
504+await withTempPdfAgentDir(async (agentDir) => {
505+await stubPdfToolInfra(agentDir, { provider: "anthropic", input: ["text", "document"] });
506+const cfg = withPdfModel(ANTHROPIC_PDF_MODEL);
507+const tool = requirePdfTool((await loadCreatePdfTool())({ config: cfg, agentDir }));
508+509+await expect(
510+tool.execute("t1", {
511+prompt: "summarize",
512+pdf: "/tmp/doc.pdf",
513+password: "secret",
514+}),
515+).rejects.toThrow("password is not supported with native PDF providers");
516+});
517+});
518+503519it("uses extraction fallback for non-native models", async () => {
504520await withTempPdfAgentDir(async (agentDir) => {
505521await stubPdfToolInfra(agentDir, { provider: "openai", input: ["text"] });
@@ -531,6 +547,58 @@ describe("createPdfTool", () => {
531547});
532548});
533549550+it("passes password to PDF extraction fallback", async () => {
551+await withTempPdfAgentDir(async (agentDir) => {
552+await stubPdfToolInfra(agentDir, { provider: "openai", input: ["text"] });
553+const extractSpy = vi.spyOn(pdfExtractModule, "extractPdfContent").mockResolvedValue({
554+text: "Encrypted content",
555+images: [],
556+});
557+completeMock.mockResolvedValue({
558+role: "assistant",
559+stopReason: "stop",
560+content: [{ type: "text", text: "fallback summary" }],
561+} as never);
562+563+const cfg = withPdfModel(OPENAI_PDF_MODEL);
564+const tool = requirePdfTool((await loadCreatePdfTool())({ config: cfg, agentDir }));
565+566+await tool.execute("t1", {
567+prompt: "summarize",
568+pdf: "/tmp/doc.pdf",
569+password: "secret",
570+});
571+572+expect(extractSpy).toHaveBeenCalledWith(expect.objectContaining({ password: "secret" }));
573+});
574+});
575+576+it("preserves PDF password whitespace before extraction fallback", async () => {
577+await withTempPdfAgentDir(async (agentDir) => {
578+await stubPdfToolInfra(agentDir, { provider: "openai", input: ["text"] });
579+const extractSpy = vi.spyOn(pdfExtractModule, "extractPdfContent").mockResolvedValue({
580+text: "Plain content",
581+images: [],
582+});
583+completeMock.mockResolvedValue({
584+role: "assistant",
585+stopReason: "stop",
586+content: [{ type: "text", text: "fallback summary" }],
587+} as never);
588+589+const cfg = withPdfModel(OPENAI_PDF_MODEL);
590+const tool = requirePdfTool((await loadCreatePdfTool())({ config: cfg, agentDir }));
591+592+await tool.execute("t1", {
593+prompt: "summarize",
594+pdf: "/tmp/doc.pdf",
595+password: " secret ",
596+});
597+598+expect(extractSpy).toHaveBeenCalledWith(expect.objectContaining({ password: " secret " }));
599+});
600+});
601+534602it("adds Codex instructions for PDF extraction fallback requests", async () => {
535603await withTempPdfAgentDir(async (agentDir) => {
536604await stubPdfToolInfra(agentDir, {
@@ -615,6 +683,7 @@ describe("createPdfTool", () => {
615683expect(props).toHaveProperty("pdf");
616684expect(props).toHaveProperty("pdfs");
617685expect(props).toHaveProperty("pages");
686+expect(props).toHaveProperty("password");
618687expect(props).toHaveProperty("model");
619688expect(props).toHaveProperty("maxBytesMb");
620689});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。