also looking at this
fix: hydrate durable registry snapshots before serving writes
#244
11 files
+202
-35
| @@ -0,0 +1,58 @@ | ||
| 1 | import type { S3Client } from './storage/aws-client' | |
| 2 | import { expect, it } from 'bun:test' | |
| 3 | import { S3RequestError } from './storage/aws-client' | |
| 4 | import { BuildStatusStore } from './storage/build-status' | |
| 5 | ||
| 6 | for (const failedKey of ['build-status/status.json', 'build-status/coverage.json']) { | |
| 7 | it(`preserves both snapshots when ${failedKey} cannot hydrate, then permits a healthy retry`, async () => { | |
| 8 | const objects = new Map<string, Buffer>() | |
| 9 | let unavailable = false | |
| 10 | let writes = 0 | |
| 11 | const client = { | |
| 12 | async getObjectBuffer(_bucket: string, key: string) { | |
| 13 | if (unavailable && key === failedKey) | |
| 14 | throw new S3RequestError('GET', 503, 'ServiceUnavailable') | |
| 15 | const value = objects.get(key) | |
| 16 | if (!value) throw new S3RequestError('GET', 404, 'NoSuchKey') | |
| 17 | return value | |
| 18 | }, | |
| 19 | async putObject(input: { key: string, body: string | Buffer }) { | |
| 20 | writes++ | |
| 21 | objects.set(input.key, Buffer.from(input.body)) | |
| 22 | }, | |
| 23 | async list() { | |
| 24 | return [{ Key: 'binaries/bun.sh/1.2.3/linux-arm64/bun.sh-1.2.3.tar.gz', LastModified: '2026-10-18T00:00:00Z' }] | |
| 25 | }, | |
| 26 | } as unknown as S3Client | |
| 27 | const original = new BuildStatusStore(client, 'registry') | |
| 28 | await original.load() | |
| 29 | await original.refreshCoverage(true) | |
| 30 | original.record({ domain: 'bun.sh', version: '1.2.3', platform: 'linux-arm64', state: 'built' }) | |
| 31 | await original.flush() | |
| 32 | const status = Buffer.from(objects.get('build-status/status.json')!) | |
| 33 | const coverage = Buffer.from(objects.get('build-status/coverage.json')!) | |
| 34 | const initialWrites = writes | |
| 35 | ||
| 36 | unavailable = true | |
| 37 | const restarted = new BuildStatusStore(client, 'registry') | |
| 38 | await expect(restarted.load()).rejects.toThrow('503') | |
| 39 | if (failedKey.endsWith('coverage.json')) { | |
| 40 | restarted.record({ domain: 'git-scm.org', version: '2.53.0', platform: 'linux-arm64', state: 'built' }) | |
| 41 | await expect(restarted.flush()).rejects.toThrow() | |
| 42 | } | |
| 43 | else { | |
| 44 | await expect(restarted.refreshCoverage(true)).rejects.toThrow() | |
| 45 | } | |
| 46 | expect(writes).toBe(initialWrites) | |
| 47 | expect(objects.get('build-status/status.json')).toEqual(status) | |
| 48 | expect(objects.get('build-status/coverage.json')).toEqual(coverage) | |
| 49 | ||
| 50 | unavailable = false | |
| 51 | await restarted.load() | |
| 52 | restarted.record({ domain: 'curl.se', version: '8.22.0', platform: 'linux-arm64', state: 'built' }) | |
| 53 | await restarted.flush() | |
| 54 | const recovered = JSON.parse(objects.get('build-status/status.json')!.toString()) | |
| 55 | expect(recovered.recent.map((event: { domain: string }) => event.domain)).toContain('bun.sh') | |
| 56 | expect(recovered.recent.map((event: { domain: string }) => event.domain)).toContain('curl.se') | |
| 57 | }) | |
| 58 | } | |