Skip to content

Commit 689914a

Browse files
committed
refactor(extraction): decode documents from required buffers
Extract document decoding from PR #1999 as an independent prerequisite on main. Keep explicit path-only adapters and mandatory-buffer PDF/DOCX/IPYNB/XLSX decoding, preserve formatted output, and separate workbook formatting. Load XLSX buffers directly with precise typing and exact subarray boundaries. Include real PDF/DOCX fixtures and full per-file coverage, align the backend coverage provider with Vitest, and remove redundant conditions and legacy lint suppressions.
1 parent ecab519 commit 689914a

12 files changed

Lines changed: 595 additions & 83 deletions

‎pnpm-lock.yaml‎

Lines changed: 65 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/eslint-suppressions.json‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,11 +1184,6 @@
11841184
"count": 1
11851185
}
11861186
},
1187-
"integrations/misc/__tests__/extract-text.spec.ts": {
1188-
"@typescript-eslint/no-explicit-any": {
1189-
"count": 4
1190-
}
1191-
},
11921187
"integrations/misc/__tests__/line-counter.spec.ts": {
11931188
"@typescript-eslint/no-explicit-any": {
11941189
"count": 2
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import fs from "fs/promises"
2+
import path from "path"
3+
import { extractTextFromBuffer } from "../extract-text"
4+
5+
// Keep real parser fixtures separate from the mocked parser unit suite.
6+
describe("real document buffer decoding", () => {
7+
afterEach(() => vi.restoreAllMocks())
8+
9+
it("extracts numbered PDF text from fixture bytes without reopening the metadata pathname", async () => {
10+
const source = await fs.readFile(path.join(__dirname, "fixtures", "approved.pdf"))
11+
const access = vi.spyOn(fs, "access").mockRejectedValue(new Error("Unexpected pathname access"))
12+
const readFile = vi.spyOn(fs, "readFile").mockRejectedValue(new Error("Unexpected pathname read"))
13+
14+
// pdf-parse prefixes each page with two newlines, which retain their line numbers.
15+
expect(await extractTextFromBuffer(source, "metadata-only.PDF")).toBe(
16+
"1 | \n2 | \n3 | Approved PDF first line\n4 | Approved PDF second line\n",
17+
)
18+
expect(access).not.toHaveBeenCalled()
19+
expect(readFile).not.toHaveBeenCalled()
20+
})
21+
22+
it("extracts numbered DOCX paragraphs from fixture bytes without reopening the metadata pathname", async () => {
23+
const source = await fs.readFile(path.join(__dirname, "fixtures", "approved.docx"))
24+
const access = vi.spyOn(fs, "access").mockRejectedValue(new Error("Unexpected pathname access"))
25+
const readFile = vi.spyOn(fs, "readFile").mockRejectedValue(new Error("Unexpected pathname read"))
26+
27+
// Mammoth separates paragraphs with two newlines and decodes XML entities across runs.
28+
expect(await extractTextFromBuffer(source, "metadata-only.DOCX")).toBe(
29+
"1 | Approved DOCX first paragraph\n2 | \n3 | Approved DOCX second & final paragraph\n4 | \n",
30+
)
31+
expect(access).not.toHaveBeenCalled()
32+
expect(readFile).not.toHaveBeenCalled()
33+
})
34+
})

0 commit comments

Comments
 (0)