@@ -179,6 +179,22 @@ describe("readFileBounded", () => {
179179 expect ( content ) . not . toContain ( "brew install" ) ;
180180 } ) ;
181181
182+ test ( "UTF-8 .pdf without magic still reads as text" , async ( ) => {
183+ const p = await fixture ( "utf8.pdf" , "plain utf-8 notes\nsecond line" ) ;
184+ const { content, isError } = await readFileBounded (
185+ p ,
186+ 0 ,
187+ 2000 ,
188+ neverAbort ( ) ,
189+ { whichExtractor : ( ) => null , canExecuteHostCommands : ( ) => false } ,
190+ ) ;
191+ expect ( isError ) . toBeUndefined ( ) ;
192+ expect ( content ) . toContain ( "plain utf-8 notes" ) ;
193+ expect ( content ) . toContain ( "second line" ) ;
194+ expect ( content ) . not . toContain ( "not a valid PDF" ) ;
195+ expect ( content ) . not . toContain ( "malformed" ) ;
196+ } ) ;
197+
182198 test ( "a NUL deep in an otherwise-valid file does not discard streamed content" , async ( ) => {
183199 // Enough valid text (>64KB) to guarantee the NUL lands in a later chunk.
184200 const head = Array . from (
@@ -825,6 +841,38 @@ describe("readFileGuardPlugin", () => {
825841 expect ( String ( blockedResult . content ) ) . toContain ( "run_shell" ) ;
826842 expect ( String ( blockedResult . content ) ) . not . toContain ( "brew install" ) ;
827843 } ) ;
844+
845+ test ( "UTF-8 .pdf without magic still reads as text through the plugin" , async ( ) => {
846+ await fixture ( "notes.pdf" , "hello from a misnamed text file" ) ;
847+ const result = await run ( {
848+ id : "utf8-pdf" ,
849+ name : "read_file" ,
850+ arguments : { path : "notes.pdf" } ,
851+ } ) ;
852+ expect ( result . isError ) . toBeFalsy ( ) ;
853+ expect ( result . content ) . toContain ( "hello from a misnamed text file" ) ;
854+ expect ( String ( result . content ) ) . not . toContain ( "not a valid PDF" ) ;
855+ expect ( String ( result . content ) ) . not . toContain ( "malformed" ) ;
856+ } ) ;
857+
858+ test ( "extractor_ready quotes a PDF path that contains spaces" , async ( ) => {
859+ await fixture ( "my report.pdf" , Buffer . from ( "%PDF-1.4\n" ) ) ;
860+ const plugin = readFileGuardPlugin ( dir , {
861+ whichExtractor : ( ) => "/usr/bin/pdftotext" ,
862+ canExecuteHostCommands : ( ) => true ,
863+ } ) ;
864+ const result = await defined ( plugin . middleware ) ( fallback ) (
865+ {
866+ id : "quoted-pdf" ,
867+ name : "read_file" ,
868+ arguments : { path : "my report.pdf" } ,
869+ } ,
870+ neverAbort ( ) ,
871+ ) ;
872+ expect ( result . isError ) . toBe ( true ) ;
873+ const abs = join ( dir , "my report.pdf" ) ;
874+ expect ( String ( result . content ) ) . toContain ( `pdftotext '${ abs } ' -` ) ;
875+ } ) ;
828876} ) ;
829877
830878describe ( "CL-8980 single-way path+offset resume" , ( ) => {
0 commit comments