Skip to content

Commit 4c721a0

Browse files
Merge branch 'main' into feat/github-copilot-provider
2 parents 7f08ab0 + af28417 commit 4c721a0

13 files changed

Lines changed: 753 additions & 72 deletions

‎.github/workflows/label-pr-review-state.yml‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,11 +848,26 @@ jobs:
848848
849849
// While CI is running or has failed, remove state labels and move on.
850850
// CI failure is its own signal; the label would add noise, not clarity.
851+
// Exception (issue #2025): while GitHub is still computing
852+
// mergeability, a missing required check can simply mean a
853+
// conflicting PR got no merge-ref CI run — not that its
854+
// conflicts went away. Keep an existing has-conflicts label
855+
// through this branch instead of stripping it with the other
856+
// state labels. Known-clean mergeability keeps the strip, and
857+
// known-dirty never reaches here (the conflict check above
858+
// handles it first).
851859
if (ciPending || ciFailed) {
852-
core.info(`PR #${pr.number}: CI ${ciPending ? 'pending' : 'failed'} — stripping state labels`);
860+
const mergeabilityUnknown =
861+
prDetail.mergeable === null || prDetail.mergeable_state === 'unknown';
862+
const keepHasConflicts = mergeabilityUnknown &&
863+
pr.labels.some(label => label.name === 'has-conflicts');
864+
core.info(
865+
`PR #${pr.number}: CI ${ciPending ? 'pending' : 'failed'} — stripping state labels` +
866+
(keepHasConflicts ? ' (keeping has-conflicts while mergeability is unknown)' : '')
867+
);
853868
await updateReviewGate(pr, ciPending ? 'ci-pending' : 'ci-failed', false);
854869
await setCodeRabbitReviewActive(pr, false);
855-
await reconcileLabels(pr, null);
870+
await reconcileLabels(pr, keepHasConflicts ? 'has-conflicts' : null);
856871
await reconcileCommunityApproval(pr, 'remove');
857872
await updateReviewGuide(
858873
pr,

‎src/eslint-suppressions.json‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,11 +1174,6 @@
11741174
"count": 1
11751175
}
11761176
},
1177-
"integrations/misc/__tests__/extract-text.spec.ts": {
1178-
"@typescript-eslint/no-explicit-any": {
1179-
"count": 4
1180-
}
1181-
},
11821177
"integrations/misc/__tests__/line-counter.spec.ts": {
11831178
"@typescript-eslint/no-explicit-any": {
11841179
"count": 2
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import fs from "fs/promises"
2+
import path from "path"
3+
import { createHash } from "node:crypto"
4+
import { extractTextFromBuffer } from "../extract-text"
5+
6+
// Keep real parser fixtures separate from the mocked parser unit suite.
7+
describe("real document buffer decoding", () => {
8+
afterEach(() => vi.restoreAllMocks())
9+
10+
it.each([
11+
{
12+
filename: "approved.pdf",
13+
sha256: "11b19aed8bc2e40b9eda9d18b7bfe36e0bbc41c4383d7e30141927992790f411",
14+
},
15+
{
16+
filename: "approved.docx",
17+
sha256: "732d827ad38ff51c24983c773bcb964ba53ca29bb055ea73aa9fbed820ae3a9b",
18+
},
19+
])("matches the documented SHA-256 for $filename", async ({ filename, sha256 }) => {
20+
const source = await fs.readFile(path.join(__dirname, "fixtures", filename))
21+
expect(createHash("sha256").update(source).digest("hex")).toBe(sha256)
22+
})
23+
24+
it("extracts numbered PDF text from fixture bytes without reopening the metadata pathname", async () => {
25+
const source = await fs.readFile(path.join(__dirname, "fixtures", "approved.pdf"))
26+
const access = vi.spyOn(fs, "access").mockRejectedValue(new Error("Unexpected pathname access"))
27+
const readFile = vi.spyOn(fs, "readFile").mockRejectedValue(new Error("Unexpected pathname read"))
28+
29+
// pdf-parse prefixes each page with two newlines, which retain their line numbers.
30+
expect(await extractTextFromBuffer(source, "metadata-only.PDF")).toBe(
31+
"1 | \n2 | \n3 | Approved PDF first line\n4 | Approved PDF second line\n",
32+
)
33+
expect(access).not.toHaveBeenCalled()
34+
expect(readFile).not.toHaveBeenCalled()
35+
})
36+
37+
it("extracts numbered DOCX paragraphs from fixture bytes without reopening the metadata pathname", async () => {
38+
const source = await fs.readFile(path.join(__dirname, "fixtures", "approved.docx"))
39+
const access = vi.spyOn(fs, "access").mockRejectedValue(new Error("Unexpected pathname access"))
40+
const readFile = vi.spyOn(fs, "readFile").mockRejectedValue(new Error("Unexpected pathname read"))
41+
42+
// Mammoth separates paragraphs with two newlines and decodes XML entities across runs.
43+
expect(await extractTextFromBuffer(source, "metadata-only.DOCX")).toBe(
44+
"1 | Approved DOCX first paragraph\n2 | \n3 | Approved DOCX second & final paragraph\n4 | \n",
45+
)
46+
expect(access).not.toHaveBeenCalled()
47+
expect(readFile).not.toHaveBeenCalled()
48+
})
49+
})
Lines changed: 86 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,50 @@
11
import ExcelJS from "exceljs"
2-
import { extractTextFromXLSX } from "../extract-text-from-xlsx"
2+
import { extractTextFromXLSX, formatWorkbook } from "../extract-text-from-xlsx"
3+
import { extractTextFromFile } from "../extract-text"
4+
5+
describe("XLSX buffer decoding", () => {
6+
it("preserves empty columns in a populated row from real XLSX bytes", async () => {
7+
const workbook = new ExcelJS.Workbook()
8+
const worksheet = workbook.addWorksheet("Sparse")
9+
worksheet.getCell("A1").value = null
10+
worksheet.getCell("B1").value = "middle"
11+
worksheet.getCell("C1").value = undefined
12+
worksheet.getCell("D1").value = "end"
13+
14+
const expected = "--- Sheet: Sparse ---\n\tmiddle\t\tend"
15+
expect(formatWorkbook(workbook)).toBe(expected)
16+
const source = Buffer.from(await workbook.xlsx.writeBuffer())
17+
expect(await extractTextFromXLSX(source)).toBe(expected)
18+
})
19+
20+
it("decodes only the selected buffer view when another workbook follows in the backing buffer", async () => {
21+
const approved = new ExcelJS.Workbook()
22+
const worksheet = approved.addWorksheet("Selected")
23+
worksheet.getCell("A1").value = "approved cell"
24+
worksheet.getCell("B1").value = 42
25+
const approvedBytes = Buffer.from(await approved.xlsx.writeBuffer())
26+
27+
const unapproved = new ExcelJS.Workbook()
28+
unapproved.addWorksheet("Unapproved").getCell("A1").value = "outside selected bytes"
29+
const unapprovedBytes = Buffer.from(await unapproved.xlsx.writeBuffer())
30+
const prefix = Buffer.from("unapproved prefix")
31+
const backing = Buffer.concat([prefix, approvedBytes, unapprovedBytes])
32+
const source = backing.subarray(prefix.length, prefix.length + approvedBytes.length)
33+
34+
// Passing source.buffer would expose the later, unapproved ZIP archive to the decoder.
35+
expect(source.byteOffset).toBeGreaterThan(0)
36+
expect(source.byteLength).toBeLessThan(source.buffer.byteLength)
37+
expect(await extractTextFromXLSX(source)).toBe("--- Sheet: Selected ---\napproved cell\t42")
38+
})
339

4-
describe("extractTextFromXLSX", () => {
40+
it("rejects invalid workbook bytes instead of returning empty workbook text", async () => {
41+
await expect(extractTextFromXLSX(Buffer.from("not an XLSX archive"))).rejects.toThrow()
42+
})
43+
})
44+
45+
describe("formatWorkbook", () => {
546
describe("basic functionality", () => {
6-
it("should extract text with proper formatting", async () => {
47+
it("should extract text with proper formatting", () => {
748
const workbook = new ExcelJS.Workbook()
849
const worksheet = workbook.addWorksheet("Sheet1")
950

@@ -12,22 +53,22 @@ describe("extractTextFromXLSX", () => {
1253
worksheet.getCell("A2").value = "Test"
1354
worksheet.getCell("B2").value = 123
1455

15-
const result = await extractTextFromXLSX(workbook)
56+
const result = formatWorkbook(workbook)
1657

1758
expect(result).toContain("--- Sheet: Sheet1 ---")
1859
expect(result).toContain("Hello\tWorld")
1960
expect(result).toContain("Test\t123")
2061
})
2162

22-
it("should skip rows with no content", async () => {
63+
it("should skip rows with no content", () => {
2364
const workbook = new ExcelJS.Workbook()
2465
const worksheet = workbook.addWorksheet("Sheet1")
2566

2667
worksheet.getCell("A1").value = "Row 1"
2768
// Row 2 is completely empty
2869
worksheet.getCell("A3").value = "Row 3"
2970

30-
const result = await extractTextFromXLSX(workbook)
71+
const result = formatWorkbook(workbook)
3172

3273
expect(result).toContain("Row 1")
3374
expect(result).toContain("Row 3")
@@ -37,7 +78,7 @@ describe("extractTextFromXLSX", () => {
3778
})
3879

3980
describe("sheet handling", () => {
40-
it("should process multiple sheets", async () => {
81+
it("should process multiple sheets", () => {
4182
const workbook = new ExcelJS.Workbook()
4283

4384
const sheet1 = workbook.addWorksheet("First Sheet")
@@ -46,15 +87,15 @@ describe("extractTextFromXLSX", () => {
4687
const sheet2 = workbook.addWorksheet("Second Sheet")
4788
sheet2.getCell("A1").value = "Sheet 2 Data"
4889

49-
const result = await extractTextFromXLSX(workbook)
90+
const result = formatWorkbook(workbook)
5091

5192
expect(result).toContain("--- Sheet: First Sheet ---")
5293
expect(result).toContain("Sheet 1 Data")
5394
expect(result).toContain("--- Sheet: Second Sheet ---")
5495
expect(result).toContain("Sheet 2 Data")
5596
})
5697

57-
it("should skip hidden sheets", async () => {
98+
it("should skip hidden sheets", () => {
5899
const workbook = new ExcelJS.Workbook()
59100

60101
const visibleSheet = workbook.addWorksheet("Visible Sheet")
@@ -64,15 +105,15 @@ describe("extractTextFromXLSX", () => {
64105
hiddenSheet.getCell("A1").value = "Hidden Data"
65106
hiddenSheet.state = "hidden"
66107

67-
const result = await extractTextFromXLSX(workbook)
108+
const result = formatWorkbook(workbook)
68109

69110
expect(result).toContain("--- Sheet: Visible Sheet ---")
70111
expect(result).toContain("Visible Data")
71112
expect(result).not.toContain("--- Sheet: Hidden Sheet ---")
72113
expect(result).not.toContain("Hidden Data")
73114
})
74115

75-
it("should skip very hidden sheets", async () => {
116+
it("should skip very hidden sheets", () => {
76117
const workbook = new ExcelJS.Workbook()
77118

78119
const visibleSheet = workbook.addWorksheet("Visible Sheet")
@@ -82,7 +123,7 @@ describe("extractTextFromXLSX", () => {
82123
veryHiddenSheet.getCell("A1").value = "Very Hidden Data"
83124
veryHiddenSheet.state = "veryHidden"
84125

85-
const result = await extractTextFromXLSX(workbook)
126+
const result = formatWorkbook(workbook)
86127

87128
expect(result).toContain("--- Sheet: Visible Sheet ---")
88129
expect(result).toContain("Visible Data")
@@ -92,7 +133,7 @@ describe("extractTextFromXLSX", () => {
92133
})
93134

94135
describe("formatCellValue logic", () => {
95-
it("should handle null and undefined values", async () => {
136+
it("should handle null and undefined values", () => {
96137
const workbook = new ExcelJS.Workbook()
97138
const worksheet = workbook.addWorksheet("Sheet1")
98139

@@ -101,7 +142,7 @@ describe("extractTextFromXLSX", () => {
101142
worksheet.getCell("A3").value = undefined
102143
worksheet.getCell("A4").value = "After"
103144

104-
const result = await extractTextFromXLSX(workbook)
145+
const result = formatWorkbook(workbook)
105146

106147
expect(result).toContain("Before")
107148
expect(result).toContain("After")
@@ -111,43 +152,43 @@ describe("extractTextFromXLSX", () => {
111152
expect(dataLines).toHaveLength(2) // Only 'Before' and 'After' should create content
112153
})
113154

114-
it("should format dates correctly", async () => {
155+
it("should format dates correctly", () => {
115156
const workbook = new ExcelJS.Workbook()
116157
const worksheet = workbook.addWorksheet("Sheet1")
117158

118159
const testDate = new Date("2023-12-25")
119160
worksheet.getCell("A1").value = testDate
120161

121-
const result = await extractTextFromXLSX(workbook)
162+
const result = formatWorkbook(workbook)
122163

123164
expect(result).toContain("2023-12-25")
124165
})
125166

126-
it("should handle error values", async () => {
167+
it("should handle error values", () => {
127168
const workbook = new ExcelJS.Workbook()
128169
const worksheet = workbook.addWorksheet("Sheet1")
129170

130171
worksheet.getCell("A1").value = { error: "#DIV/0!" }
131172

132-
const result = await extractTextFromXLSX(workbook)
173+
const result = formatWorkbook(workbook)
133174

134175
expect(result).toContain("[Error: #DIV/0!]")
135176
})
136177

137-
it("should handle rich text", async () => {
178+
it("should handle rich text", () => {
138179
const workbook = new ExcelJS.Workbook()
139180
const worksheet = workbook.addWorksheet("Sheet1")
140181

141182
worksheet.getCell("A1").value = {
142183
richText: [{ text: "Hello " }, { text: "World", font: { bold: true } }],
143184
}
144185

145-
const result = await extractTextFromXLSX(workbook)
186+
const result = formatWorkbook(workbook)
146187

147188
expect(result).toContain("Hello World")
148189
})
149190

150-
it("should handle hyperlinks", async () => {
191+
it("should handle hyperlinks", () => {
151192
const workbook = new ExcelJS.Workbook()
152193
const worksheet = workbook.addWorksheet("Sheet1")
153194

@@ -156,45 +197,58 @@ describe("extractTextFromXLSX", () => {
156197
hyperlink: "https://roocode.com/",
157198
}
158199

159-
const result = await extractTextFromXLSX(workbook)
200+
const result = formatWorkbook(workbook)
160201

161202
expect(result).toContain("Roo Code (https://roocode.com/)")
162203
})
163204

164-
it("should handle formulas with and without results", async () => {
205+
it("should handle formulas with and without results", () => {
165206
const workbook = new ExcelJS.Workbook()
166207
const worksheet = workbook.addWorksheet("Sheet1")
167208

168209
worksheet.getCell("A1").value = { formula: "A2+A3", result: 30 }
169210
worksheet.getCell("A2").value = { formula: "SUM(B1:B10)" }
170211

171-
const result = await extractTextFromXLSX(workbook)
212+
const result = formatWorkbook(workbook)
172213

173214
expect(result).toContain("30") // Formula with result
174215
expect(result).toContain("[Formula: SUM(B1:B10)]") // Formula without result
175216
})
176217
})
177218

178219
describe("edge cases", () => {
179-
it("should handle empty workbook", async () => {
220+
it("includes row 50000, marks row 50001 as truncated, and still formats the next sheet", () => {
221+
const workbook = new ExcelJS.Workbook()
222+
const worksheet = workbook.addWorksheet("Large")
223+
worksheet.getCell("A50000").value = "last included row"
224+
worksheet.getCell("A50001").value = "excluded row content"
225+
workbook.addWorksheet("Next").getCell("A1").value = "next sheet content"
226+
227+
expect(formatWorkbook(workbook)).toBe(
228+
"--- Sheet: Large ---\nlast included row\n[... truncated at row 50001 ...]\n\n" +
229+
"--- Sheet: Next ---\nnext sheet content",
230+
)
231+
})
232+
233+
it("should handle empty workbook", () => {
180234
const workbook = new ExcelJS.Workbook()
181235
workbook.addWorksheet("Empty Sheet")
182236

183-
const result = await extractTextFromXLSX(workbook)
237+
const result = formatWorkbook(workbook)
184238

185239
expect(result).toContain("--- Sheet: Empty Sheet ---")
186240
expect(result.trim()).toBe("--- Sheet: Empty Sheet ---")
187241
})
188242

189-
it("should handle workbook with only empty cells", async () => {
243+
it("should handle workbook with only empty cells", () => {
190244
const workbook = new ExcelJS.Workbook()
191245
const worksheet = workbook.addWorksheet("Sheet1")
192246

193247
// Set cells but leave them empty
194248
worksheet.getCell("A1").value = ""
195249
worksheet.getCell("B1").value = ""
196250

197-
const result = await extractTextFromXLSX(workbook)
251+
const result = formatWorkbook(workbook)
198252

199253
expect(result).toContain("--- Sheet: Sheet1 ---")
200254
// Should not contain any data rows since empty strings don't count as content
@@ -203,19 +257,19 @@ describe("extractTextFromXLSX", () => {
203257
})
204258
})
205259

206-
describe("function overloads", () => {
207-
it("should work with workbook objects", async () => {
260+
describe("workbook formatting and path adapter", () => {
261+
it("should work with workbook objects", () => {
208262
const workbook = new ExcelJS.Workbook()
209263
const worksheet = workbook.addWorksheet("Test")
210264
worksheet.getCell("A1").value = "Test Data"
211265

212-
const result = await extractTextFromXLSX(workbook)
266+
const result = formatWorkbook(workbook)
213267

214268
expect(result).toContain("Test Data")
215269
})
216270

217271
it("should reject invalid file paths", async () => {
218-
await expect(extractTextFromXLSX("/non/existent/file.xlsx")).rejects.toThrow()
272+
await expect(extractTextFromFile("/non/existent/file.xlsx")).rejects.toThrow()
219273
})
220274
})
221275
})

0 commit comments

Comments
 (0)