ReviewOS

also looking at this

stacks/drone

feat: own runtime firmware candidates

#49
Merged chris wants to merge codex/runtime-candidate-ownership into main
24 files +1245 -92
tests/unit/updates-candidates-cli.test.tsadded+43-0
Changes to tests/unit/updates-candidates-cli.test.ts
@@ -0,0 +1,43 @@
1import { afterEach, expect, test } from 'bun:test'
2import { command } from '@stacksjs/testing'
3import { mkdtemp, readFile, rm } from 'node:fs/promises'
4import { tmpdir } from 'node:os'
5import { join } from 'node:path'
6import { enrollRuntimeTrust } from '../../resources/functions/drone/updates/enrollment'
7import { createRuntimeTrustStore } from '../../resources/functions/drone/updates/store'
8import { platform, repository, target } from '../fixtures/updates/repository'
9
10const roots: string[] = []
11afterEach(async () => { for (const root of roots.splice(0)) await rm(root, { recursive: true, force: true }) })
12
13test('native candidate commands require pinned trust and clock, retain identity and preserve explicit retirement semantics', async () => {
14 const root = await mkdtemp(join(tmpdir(), 'drone-owned-candidate-cli-')); roots.push(root)
15 const source = join(root, 'repo'), fixture = await repository(source, { custom: { releaseSequence: 9 } })
16 const enrollment = join(root, 'enrollment'), directory = join(root, 'store')
17 const enrolled = enrollRuntimeTrust({ target, platform, trustedRootSha256: fixture.rootSha256, minimumReleaseSequence: 7, trustedRoot: fixture.rootPath, output: enrollment })
18 const created = await createRuntimeTrustStore({ enrollmentDirectory: enrollment, enrollmentSha256: enrolled.enrollmentSha256, output: directory })
19 const flags = ['--enrollment', enrollment, '--enrollment-sha256', enrolled.enrollmentSha256, '--store-sha256', created.storeSha256]
20 const reserve = await command(['updates:reserve', directory, ...flags, '--repository', source, '--trusted-system-clock-source', 'operator-managed-test-clock']).withTimeout(20000)
21 expect(reserve.exitCode).toBe(0)
22 const value = JSON.parse(reserve.stdout)
23 expect(value.candidate.phase).toBe('prepared')
24 expect(value.candidate.integrity).toBe('recorded-bytes-match')
25 expect(value.candidate.currentTrustValidated).toBe(false)
26 expect(value.store.releaseFloor).toBe(9)
27 expect(value.physicalDeploymentAllowed).toBe(false)
28 const status = await command(['updates:candidates', directory, ...flags]).withTimeout(20000)
29 expect(status.exitCode).toBe(0)
30 expect(JSON.parse(status.stdout)).toEqual(value)
31 const missingClock = await command(['updates:reserve', directory, ...flags, '--repository', source]).withTimeout(20000)
32 expect(missingClock.exitCode).toBe(1)
33 expect(missingClock.stdout).toBe('')
34 expect(missingClock.stderr).toBe('Runtime update store unavailable: invalid trust, clock, state or storage failure\n')
35 const wrong = await command(['updates:retire', directory, ...flags, '--candidate', '0'.repeat(32)]).withTimeout(20000)
36 expect(wrong.exitCode).toBe(1)
37 expect(wrong.stdout).toBe('')
38 const retired = await command(['updates:retire', directory, ...flags, '--candidate', value.candidate.id]).withTimeout(20000)
39 expect(retired.exitCode).toBe(0)
40 expect(JSON.parse(retired.stdout).candidate).toBeNull()
41 expect(JSON.parse(retired.stdout).store.releaseFloor).toBe(9)
42 expect(await readFile(join(value.candidate.directory, 'image.bin'))).toEqual(fixture.image)
43}, 120000)