Skip to content

Commit 7d2fc7d

Browse files
committed
test(ripgrep diagnostic): add Windows-path coverage + appRoot validation
Two polish items from review: - getRipgrepDiagnostic now early-returns an explanatory message when vscode.env.appRoot is empty, instead of silently producing a report with a meaningless path probe. Closes the input- validation gap surfaced in re-reading the diagnostic. - New test exercises the .asar->.asar.unpacked substitution on Windows-style backslash paths. The regex already handles both separators via [\\/], this just pins it.
1 parent 3c10668 commit 7d2fc7d

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/services/ripgrep/__tests__/diagnostic.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,27 @@ describe("getRipgrepDiagnostic", () => {
130130
}
131131
expect(report).not.toContain("✓ ")
132132
})
133+
134+
it("rewrites node_modules.asar to node_modules.asar.unpacked on Windows paths (backslash separator)", async () => {
135+
// Pure string-substitution test: the literal `win32-x64` segment is
136+
// not derived from process.platform/arch, so this runs on any host.
137+
const rgPath = "C:\\app\\node_modules.asar\\@vscode\\ripgrep-universal\\bin\\win32-x64\\rg.exe"
138+
const substituted = "C:\\app\\node_modules.asar.unpacked\\@vscode\\ripgrep-universal\\bin\\win32-x64\\rg.exe"
139+
ripgrepMock.value = { rgPath }
140+
fsMock.existing = new Set([substituted])
141+
142+
const report = await getRipgrepDiagnostic("C:\\app")
143+
144+
expect(report).toContain(`after .asar→.asar.unpacked: ${substituted}`)
145+
expect(report).toContain("fileExistsAtPath: true")
146+
})
147+
148+
it("returns an explanatory report when vscode.env.appRoot is empty", async () => {
149+
const report = await getRipgrepDiagnostic("")
150+
151+
expect(report).toContain("vscode.env.appRoot: (empty)")
152+
expect(report).toContain("Cannot run diagnostic")
153+
// path probe should NOT have run
154+
expect(report).not.toContain("--- step 2: path probe under appRoot ---")
155+
})
133156
})

src/services/ripgrep/diagnostic.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ function probeCandidates(vscodeAppRoot: string): readonly string[] {
3737
* reports which ones exist on disk.
3838
*/
3939
export async function getRipgrepDiagnostic(vscodeAppRoot: string): Promise<string> {
40+
if (!vscodeAppRoot || vscodeAppRoot.trim() === "") {
41+
return [
42+
`Zoo Code Ripgrep Diagnostic (${new Date().toISOString()})`,
43+
`vscode.version: ${vscode.version}`,
44+
`vscode.env.appRoot: (empty)`,
45+
``,
46+
`Cannot run diagnostic: vscode.env.appRoot is empty. This usually means`,
47+
`the extension activated outside a VS Code-style host (e.g., a remote`,
48+
`extension host that doesn't expose appRoot). The require-interceptor`,
49+
`path may still work; the path-probe step requires a valid appRoot.`,
50+
].join("\n")
51+
}
4052
const lines: string[] = [
4153
`Zoo Code Ripgrep Diagnostic (${new Date().toISOString()})`,
4254
`vscode.version: ${vscode.version}`,

0 commit comments

Comments
 (0)