Skip to content

Commit ef79ee2

Browse files
committed
Merge branch 'feat/managed-binary-infrastructure' into feat/dcg-binary-service
2 parents 5f3854a + 1f1af77 commit ef79ee2

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,14 @@ describe("managed binary downloads", () => {
149149
})
150150
await new Promise<void>((resolve) => setImmediate(resolve))
151151
await new Promise<void>((resolve) => setImmediate(resolve))
152+
let resolved = false
153+
void download.then(() => {
154+
resolved = true
155+
})
152156
output.emit("finish")
157+
await Promise.resolve()
158+
expect(resolved).toBe(false)
159+
output.emit("close")
153160
await download
154161

155162
expect(mockGet).toHaveBeenNthCalledWith(2, "https://github.com/asset", expect.any(Function))

src/services/managed-binary/archive.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,17 @@ export async function extractSingleFileTarXzArchive(
112112
.split(/\r?\n/)
113113
.map((entry) => entry.trim())
114114
.filter(Boolean)
115+
if (entries.length !== 1) {
116+
throw new Error(`${archiveName} archive has an unexpected layout`)
117+
}
115118
const archiveEntry = entries[0]
116119
const entryName = archiveEntry?.split(/\s+/).at(-1)
117-
if (entries.length !== 1 || !archiveEntry.startsWith("-") || entryName?.replace(/^\.\//, "") !== expectedFile) {
120+
if (
121+
!archiveEntry ||
122+
!entryName ||
123+
!archiveEntry.startsWith("-") ||
124+
entryName.replace(/^\.\//, "") !== expectedFile
125+
) {
118126
throw new Error(`${archiveName} archive has an unexpected layout`)
119127
}
120128

src/services/managed-binary/download.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,8 @@ function downloadBinaryFileWithRedirects(
144144
})
145145
response.on("error", abort)
146146
response.pipe(output)
147-
output.on("finish", () => {
148-
output.close()
149-
resolve()
150-
})
147+
output.on("finish", () => output.close())
148+
output.on("close", resolve)
151149
output.on("error", abort)
152150
})
153151

0 commit comments

Comments
 (0)