@@ -14,8 +14,10 @@ const mockGetMetadata = vi.fn();
1414const mockGetPage = vi . fn ( ) ;
1515const mockGetDocument = vi . fn ( ) ;
1616const mockReadFile = vi . fn ( ) ;
17+ const mockStat = vi . fn ( ) ;
1718const mockExtractPageContent = vi . fn ( ) ;
1819let actualExtractPageContent : typeof import ( '../../src/pdf/extractor.js' ) [ 'extractPageContent' ] ;
20+ let extractorModule : typeof import ( '../../src/pdf/extractor.js' ) ;
1921
2022vi . mock ( 'pdfjs-dist/legacy/build/pdf.mjs' , ( ) => ( {
2123 getDocument : mockGetDocument ,
@@ -28,19 +30,12 @@ vi.mock('pdfjs-dist/legacy/build/pdf.mjs', () => ({
2830vi . mock ( 'node:fs/promises' , ( ) => ( {
2931 default : {
3032 readFile : mockReadFile ,
33+ stat : mockStat ,
3134 } ,
3235 readFile : mockReadFile ,
36+ stat : mockStat ,
3337} ) ) ;
3438
35- vi . mock ( '../../src/pdf/extractor.js' , async ( ) => {
36- const actual = await vi . importActual < typeof import ( '../../src/pdf/extractor.js' ) > ( '../../src/pdf/extractor.js' ) ;
37- actualExtractPageContent = actual . extractPageContent ;
38- return {
39- ...actual ,
40- extractPageContent : mockExtractPageContent ,
41- } ;
42- } ) ;
43-
4439// Dynamically import the handler *once* after mocks are defined
4540// Define a more specific type for the handler's return value content
4641interface HandlerResultContent {
@@ -51,6 +46,10 @@ let handler: (args: unknown) => Promise<{ content: HandlerResultContent[] }>;
5146let readPdfSchema : Schema < unknown > ;
5247
5348beforeAll ( async ( ) => {
49+ extractorModule = await import ( '../../src/pdf/extractor.js' ) ;
50+ actualExtractPageContent = extractorModule . extractPageContent ;
51+ vi . spyOn ( extractorModule , 'extractPageContent' ) . mockImplementation ( mockExtractPageContent ) ;
52+
5453 // Import the readPdf tool - the new SDK uses a builder pattern
5554 const { readPdf } = await import ( '../../src/handlers/readPdf.js' ) ;
5655 const { readPdfArgsSchema } = await import ( '../../src/schemas/readPdf.js' ) ;
@@ -90,6 +89,7 @@ describe('handleReadPdfFunc Integration Tests', () => {
9089 beforeEach ( ( ) => {
9190 vi . resetAllMocks ( ) ;
9291 mockExtractPageContent . mockImplementation ( ( ...args ) => actualExtractPageContent ( ...args ) ) ;
92+ vi . spyOn ( extractorModule , 'extractPageContent' ) . mockImplementation ( mockExtractPageContent ) ;
9393 // Reset mocks for pathUtils if we spy on it
9494 vi . spyOn ( pathUtils , 'resolvePath' ) . mockImplementation ( ( p ) => p ) ; // Simple mock for resolvePath
9595
@@ -164,6 +164,9 @@ describe('handleReadPdfFunc Integration Tests', () => {
164164 metadata : { 'dc:format' : 'application/pdf' } ,
165165 num_pages : 3 ,
166166 full_text : 'Mock page text 1\n\nMock page text 2\n\nMock page text 3' ,
167+ warnings : [
168+ 'No pages specified; processed available pages because the document is small. Specify pages or set allow_full_document=true to control full-document requests.' ,
169+ ] ,
167170 } ,
168171 } ,
169172 ] ,
@@ -316,6 +319,7 @@ describe('handleReadPdfFunc Integration Tests', () => {
316319 const args = {
317320 sources : [ { path : 'many-pages.pdf' } ] ,
318321 include_full_text : true ,
322+ allow_full_document : true ,
319323 } ;
320324
321325 const result = await handler ( args ) ;
@@ -467,6 +471,9 @@ describe('handleReadPdfFunc Integration Tests', () => {
467471 metadata : { 'dc:creator' : 'URL Author' } ,
468472 num_pages : 2 ,
469473 full_text : 'URL Mock page text 1\n\nURL Mock page text 2' ,
474+ warnings : [
475+ 'No pages specified; processed available pages because the document is small. Specify pages or set allow_full_document=true to control full-document requests.' ,
476+ ] ,
470477 } ,
471478 } ,
472479 ] ,
0 commit comments