@@ -500,6 +500,22 @@ describe("createPdfTool", () => {
500500 } ) ;
501501 } ) ;
502502
503+ 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+
503519 it ( "uses extraction fallback for non-native models" , async ( ) => {
504520 await withTempPdfAgentDir ( async ( agentDir ) => {
505521 await stubPdfToolInfra ( agentDir , { provider : "openai" , input : [ "text" ] } ) ;
@@ -531,6 +547,58 @@ describe("createPdfTool", () => {
531547 } ) ;
532548 } ) ;
533549
550+ 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+
534602 it ( "adds Codex instructions for PDF extraction fallback requests" , async ( ) => {
535603 await withTempPdfAgentDir ( async ( agentDir ) => {
536604 await stubPdfToolInfra ( agentDir , {
@@ -615,6 +683,7 @@ describe("createPdfTool", () => {
615683 expect ( props ) . toHaveProperty ( "pdf" ) ;
616684 expect ( props ) . toHaveProperty ( "pdfs" ) ;
617685 expect ( props ) . toHaveProperty ( "pages" ) ;
686+ expect ( props ) . toHaveProperty ( "password" ) ;
618687 expect ( props ) . toHaveProperty ( "model" ) ;
619688 expect ( props ) . toHaveProperty ( "maxBytesMb" ) ;
620689 } ) ;
0 commit comments