Skip to content

Commit 09314e3

Browse files
committed
test: cover managed binary cleanup boundaries
1 parent 28d81f9 commit 09314e3

3 files changed

Lines changed: 25 additions & 11 deletions

File tree

src/services/code-index/semble/__tests__/semble-downloader.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ describe("semble-downloader", () => {
925925
// excluded by the currentArchivePath guard). It is unlinked only by
926926
// the pre-download partial-archive cleanup and the post-install
927927
// archive cleanup steps. unrelated.txt is never touched.
928-
expect(fs.unlink).not.toHaveBeenCalledWith(path.join("/storage", "unrelated.txt"))
928+
expect(fs.rm).not.toHaveBeenCalledWith(path.join("/storage", "unrelated.txt"), expect.anything())
929929
// Sanity: the current archive path is never passed to the stale sweep.
930930
// It is unlinked exactly twice (pre-download cleanup + post-install
931931
// archive cleanup), never via cleanupStaleArchives.

src/services/managed-binary/__tests__/archive.spec.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,25 @@ describe("managed binary archive utilities", () => {
157157
it("builds a single-entry-validated PowerShell ZIP extraction", async () => {
158158
const child = createChild()
159159
mockSpawn.mockReturnValue(child as unknown as ReturnType<typeof spawn>)
160-
const extraction = extractSingleFileZipArchive("C:\\archive.zip", "C:\\output", "binary.exe", "Tool")
161-
child.emit("close", 0)
162-
await extraction
163-
164-
const args = mockSpawn.mock.calls[0][1]
165-
const script = args[3]
166-
expect(script).toContain("$entries.Count -ne 1")
167-
expect(script).not.toContain("C:\\archive.zip")
168-
expect(args.slice(4)).toEqual(["C:\\archive.zip", path.join("C:\\output", "binary.exe"), "binary.exe", "Tool"])
160+
const originalPlatform = Object.getOwnPropertyDescriptor(process, "platform")
161+
Object.defineProperty(process, "platform", { value: "win32", configurable: true })
162+
try {
163+
const extraction = extractSingleFileZipArchive("C:\\archive.zip", "C:\\output", "binary.exe", "Tool")
164+
child.emit("close", 0)
165+
await extraction
166+
167+
const args = mockSpawn.mock.calls[0][1]
168+
const script = args[3]
169+
expect(script).toContain("$entries.Count -ne 1")
170+
expect(script).not.toContain("C:\\archive.zip")
171+
expect(args.slice(4)).toEqual([
172+
"C:\\archive.zip",
173+
path.join("C:\\output", "binary.exe"),
174+
"binary.exe",
175+
"Tool",
176+
])
177+
} finally {
178+
if (originalPlatform) Object.defineProperty(process, "platform", originalPlatform)
179+
}
169180
})
170181
})

src/services/managed-binary/archive.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ export async function extractSingleFileZipArchive(
7070
expectedFile: string,
7171
archiveName: string,
7272
): Promise<void> {
73-
// This deliberately uses PowerShell because it is only called for Windows release archives.
73+
if (process.platform !== "win32") {
74+
throw new Error("Single-file ZIP extraction is only supported on Windows")
75+
}
76+
7477
const script = [
7578
"$ErrorActionPreference = 'Stop'",
7679
"$archivePath = $args[0]",

0 commit comments

Comments
 (0)