Skip to content

Commit e783c1b

Browse files
authored
test(read): cover fractional PDF page ranges
Add a regression test for rejecting fractional PDF page ranges.
1 parent f50b974 commit e783c1b

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

packages/core/src/tests/tool-handlers.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,22 @@ test("Read returns an acknowledgement for images and attaches the image as a fol
998998
);
999999
});
10001000

1001+
test("Read rejects fractional PDF page ranges", async () => {
1002+
const workspace = createTempWorkspace();
1003+
const filePath = path.join(workspace, "sample.pdf");
1004+
fs.writeFileSync(filePath, makePdfWithPages(4), "utf8");
1005+
1006+
for (const pages of ["1.9", "2.1-3.9"]) {
1007+
const readResult = await handleReadTool(
1008+
{ file_path: filePath, pages },
1009+
createContext("pdf-fractional-pages", workspace)
1010+
);
1011+
1012+
assert.equal(readResult.ok, false);
1013+
assert.match(readResult.error ?? "", /must be an integer/);
1014+
}
1015+
});
1016+
10011017
function createContext(
10021018
sessionId: string,
10031019
projectRoot: string,
@@ -1024,6 +1040,11 @@ function createTempWorkspace(): string {
10241040
return dir;
10251041
}
10261042

1043+
function makePdfWithPages(pageCount: number): string {
1044+
const pages = Array.from({ length: pageCount }, (_, index) => `${index + 1} 0 obj << /Type /Page >> endobj`);
1045+
return ["%PDF-1.4", ...pages, "%%EOF", ""].join("\n");
1046+
}
1047+
10271048
async function readSnippet(
10281049
filePath: string,
10291050
sessionId: string,

0 commit comments

Comments
 (0)