add update functionality

This commit is contained in:
Joey Kimsey
2026-09-12 21:45:37 -04:00
parent 1ee2774241
commit 188702e516
7 changed files with 63 additions and 24 deletions

View File

@ -6,7 +6,7 @@ import { join } from 'node:path'
import { stringify } from 'yaml'
import { createBuildConfig, validateFeedUrl, APP_ID } from '../build/config.mjs'
import { digest, writeReleaseManifest, verifyRelease } from '../scripts/releaseArtifacts.mjs'
import { uploadRelease } from '../scripts/uploadRelease.mjs'
import { uploadRelease, UPLOAD_CHUNK_SIZE } from '../scripts/uploadRelease.mjs'
const feed = 'https://downloads.thetempusproject.com/capsule/windows/x64/'
const env = { CAPSULE_UPDATE_URL: feed, CAPSULE_PUBLISHER_NAME: 'Test Publisher', CSC_NAME: 'Test Publisher' }
@ -100,3 +100,22 @@ test('upload stops before metadata on failed upload or mismatched public artifac
assert.ok(calls.every((path) => !path.endsWith('latest.yml')))
}
})
test('large artifacts use contiguous bounded chunks and verify the assembled public file', async () => {
const data = Buffer.alloc(UPLOAD_CHUNK_SIZE * 2 + 17, 42)
const requests = []
await uploadRelease({ feedUrl: feed, files: [{ name: 'Capsule-0.1.1-x64-Setup.exe', data }] }, {
uploadUrl: 'https://upload.thetempusproject.com/capsule/upload/', token: 'test-token', log: () => {},
fetchImpl: async (_url, options) => {
if (options.method !== 'PUT') return { ok: true, arrayBuffer: async () => data }
requests.push(options)
return { ok: true, status: requests.length < 3 ? 202 : 201 }
}
})
assert.equal(requests.length, 3)
assert.deepEqual(requests.map((request) => request.headers['Content-Range']), [
`bytes 0-524287/${data.length}`, `bytes 524288-1048575/${data.length}`, `bytes 1048576-1048592/${data.length}`
])
assert.equal(new Set(requests.map((request) => request.headers['X-Capsule-Upload-Id'])).size, 1)
assert.deepEqual(Buffer.concat(requests.map((request) => request.body)), data)
})