Skip to content

Commit e1a0c39

Browse files
committed
test: strengthen DCG binary service coverage
1 parent 3460748 commit e1a0c39

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/services/destructive-command-guard/__tests__/manager.spec.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe("Destructive Command Guard manager", () => {
6868

6969
it("rejects untrusted download URLs before opening a destination", async () => {
7070
await expect(downloadFile("https://example.com/dcg", path.join(tempDir, "archive"))).rejects.toThrow(
71-
"DCG download redirected to an untrusted host",
71+
"DCG download URL is not a trusted HTTPS host",
7272
)
7373
})
7474

@@ -81,7 +81,7 @@ describe("Destructive Command Guard manager", () => {
8181
"Too many DCG download redirects",
8282
)
8383
expect(() => resolveTrustedRedirect("https://github.com/release", undefined, 5)).toThrow(
84-
"Too many DCG download redirects",
84+
"DCG download redirect is missing a Location header",
8585
)
8686
})
8787

@@ -113,7 +113,14 @@ describe("Destructive Command Guard manager", () => {
113113
const expectedExecutable = process.platform === "win32" ? "powershell" : "unzip"
114114
const expectedArgs =
115115
process.platform === "win32"
116-
? ["-NoProfile", "-Command", "Expand-Archive -Path 'C:\\dcg.zip' -DestinationPath 'C:\\staging' -Force"]
116+
? [
117+
"-NoProfile",
118+
"-NonInteractive",
119+
"-Command",
120+
"$archivePath = $args[0]; $destination = $args[1]; Expand-Archive -LiteralPath $archivePath -DestinationPath $destination -Force",
121+
"C:\\dcg.zip",
122+
"C:\\staging",
123+
]
117124
: ["-o", "C:\\dcg.zip", "-d", "C:\\staging"]
118125

119126
expect(mockSpawn).toHaveBeenCalledWith(expectedExecutable, expectedArgs, {
@@ -136,11 +143,9 @@ describe("Destructive Command Guard manager", () => {
136143

137144
await expect(extraction).resolves.toBeUndefined()
138145
expect(mockSpawn).toHaveBeenCalledTimes(1)
139-
expect(mockSpawn).toHaveBeenCalledWith(
140-
"tar",
141-
expect.arrayContaining(["-xJf", "/tmp/dcg.tar.xz", "-C", tempDir, "--no-same-owner"]),
142-
expect.objectContaining({ shell: false }),
143-
)
146+
const expectedArgs = ["-xJf", "/tmp/dcg.tar.xz", "-C", tempDir, "--no-same-owner"]
147+
if (process.platform === "linux") expectedArgs.push("--no-overwrite-dir")
148+
expect(mockSpawn).toHaveBeenCalledWith("tar", expectedArgs, { shell: false, stdio: ["ignore", "pipe", "pipe"] })
144149
})
145150

146151
it("surfaces process failures during extraction", async () => {

src/services/destructive-command-guard/__tests__/runner.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ describe("runDcg", () => {
6262
emitResult(child, payload, code)
6363

6464
await expect(result).resolves.toEqual(expected)
65+
expect(mockSpawn).toHaveBeenCalledWith(
66+
"/dcg",
67+
expect.any(Array),
68+
expect.objectContaining({ cwd: "/workspace" }),
69+
)
6570
})
6671

6772
it.each([

0 commit comments

Comments
 (0)