Skip to content

Commit d73f212

Browse files
kvzclaude
andcommitted
test: add e2e test verifying download integrity via md5 hash
- Add test that verifies downloaded file md5 matches the md5hash from the assembly result - Return assembly status from job promises so tests can access result metadata like md5hash 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 60273d6 commit d73f212

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/cli/assemblies-create.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ export default async function run(
799799
await fsp.unlink(inPath)
800800
}
801801
}
802+
return assembly
802803
})()
803804

804805
jobsPromise.add(singleAssemblyPromise)
@@ -877,6 +878,7 @@ export default async function run(
877878
}
878879
}
879880
await completeJob()
881+
return assembly
880882
})()
881883

882884
jobsPromise.add(jobPromise)

test/e2e/cli/assemblies.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import crypto from 'node:crypto'
12
import fsp from 'node:fs/promises'
23
import process from 'node:process'
34
import { promisify } from 'node:util'
@@ -230,6 +231,39 @@ describe('assemblies', () => {
230231
}),
231232
)
232233

234+
it(
235+
'should download file with correct md5 hash',
236+
testCase(async (client) => {
237+
const infile = await imgPromise()
238+
const steps = await stepsPromise()
239+
240+
const output = new OutputCtl()
241+
const { results } = await assembliesCreate(output, client, {
242+
steps,
243+
inputs: [infile],
244+
output: 'out-md5.jpg',
245+
})
246+
247+
// Get the assembly result to find the expected md5hash
248+
// The results array contains assembly statuses
249+
const assemblyResult = results[0] as {
250+
results?: Record<string, Array<{ md5hash?: string }>>
251+
}
252+
expect(assemblyResult).to.have.property('results')
253+
const resultSteps = Object.values(assemblyResult.results ?? {})
254+
expect(resultSteps.length).to.be.greaterThan(0)
255+
const firstResult = resultSteps[0]?.[0]
256+
expect(firstResult).to.have.property('md5hash')
257+
const expectedMd5 = firstResult?.md5hash
258+
259+
// Calculate md5 of downloaded file
260+
const downloadedBuffer = await fsp.readFile('out-md5.jpg')
261+
const actualMd5 = crypto.createHash('md5').update(downloadedBuffer).digest('hex')
262+
263+
expect(actualMd5).to.equal(expectedMd5)
264+
}),
265+
)
266+
233267
it(
234268
'should handle multiple inputs',
235269
testCase(async (client) => {

0 commit comments

Comments
 (0)