ReviewOS

also looking at this

stacks/drone

feat: enroll protected runtime trust anchors

#43
Merged chris wants to merge codex/runtime-trust-enrollment into main
33 files +1297 -18

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

tests/helpers/execution-browser-driver.tsmodified+9-11
Changes to tests/helpers/execution-browser-driver.ts
@@ -2,6 +2,7 @@ import assert from 'node:assert/strict'
22import { mkdir, readFile } from 'node:fs/promises'
33import { basename, join } from 'node:path'
44import { startWorkspaceBrowser } from './workspace-browser'
5import { settleExecutionDiagnostics } from './execution-diagnostics'
56
67// This driver owns only browser transport. Native credentials stay in a private fixture file.
78const root = process.cwd()
@@ -23,8 +24,6 @@ let diagnosticPage: Awaited<ReturnType<typeof browser.page>> | undefined
2324let startBaseline: number | null = null
2425async function failureDiagnostics() {
2526 const abort = new AbortController()
26 let timer: ReturnType<typeof setTimeout> | undefined
27 const timeout = new Promise<null>(resolve => { timer = setTimeout(() => resolve(null), 1000) })
2827 try {
2928 const snapshot = async () => {
3029 const response = await fetch(`${data.url}/__fixture/diagnostics`, { headers: { 'x-fixture-control': data.control }, signal: abort.signal })
@@ -46,19 +45,18 @@ async function failureDiagnostics() {
4645 hasSourceExists: !!document.querySelector('[data-execution-source-exists]'), hasExecutionError: !!document.querySelector('[data-execution-error]')
4746 };
4847 })()`) : Promise.resolve(null)
49 const collect = Promise.allSettled([snapshot(), dom]).then(([server, page]) => ({
48 const parts = await settleExecutionDiagnostics(snapshot(), dom)
49 const base = {
5050 label: 'execution-browser-failure-diagnostics', phase, startBaseline,
51 server: server.status === 'fulfilled' ? server.value : { available: false },
52 dom: page.status === 'fulfilled' ? page.value : null, browserErrorCount: diagnosticPage?.errors.length ?? null,
51 browserErrorCount: diagnosticPage?.errors.length ?? null,
52 executionStartRequests: diagnosticPage ? diagnosticPage.requests.filter(request => request.method === 'POST' && request.url.endsWith('/workspace/execution')).length : null,
5353 admissionRequests: diagnosticPage ? diagnosticPage.requests.filter(request => request.method === 'POST' && request.url.endsWith('/workspace/execution/admission')).length : null,
54 }))
55 const captured = await Promise.race([collect, timeout])
56 const text = `${JSON.stringify(captured ?? { label: 'execution-browser-failure-diagnostics', available: false })}\n`
57 console.error(Buffer.byteLength(text, 'utf8') <= 8192 ? text.trimEnd() : '{"label":"execution-browser-failure-diagnostics","available":false}')
54 }
55 const text = JSON.stringify({ ...base, ...parts })
56 console.error(Buffer.byteLength(text, 'utf8') <= 8192 ? text : JSON.stringify({ ...base, server: { available: false }, dom: null, byteBudgetExceeded: true }))
5857 }
59 catch { console.error('{"label":"execution-browser-failure-diagnostics","available":false}') }
58 catch { console.error(JSON.stringify({ label: 'execution-browser-failure-diagnostics', phase, available: false })) }
6059 finally {
61 clearTimeout(timer)
6260 abort.abort()
6361 // The owned socket close rejects pending CDP commands and clears their timers in the existing helper.
6462 diagnosticPage?.close()
tests/helpers/execution-diagnostics.tsadded+24-0
Changes to tests/helpers/execution-diagnostics.ts
@@ -0,0 +1,24 @@
1type DiagnosticStatus = 'pending' | 'fulfilled' | 'rejected'
2export interface ExecutionDiagnosticParts {
3 server: unknown
4 dom: unknown
5 serverStatus: DiagnosticStatus
6 domStatus: DiagnosticStatus
7}
8
9/** Preserve each completed observation within the existing one-second diagnostic budget. */
10export async function settleExecutionDiagnostics(server: Promise<unknown>, dom: Promise<unknown>): Promise<ExecutionDiagnosticParts> {
11 const parts: ExecutionDiagnosticParts = { server: { available: false }, dom: null, serverStatus: 'pending', domStatus: 'pending' }
12 let timer: ReturnType<typeof setTimeout> | undefined
13 const timeout = new Promise<void>(resolve => { timer = setTimeout(resolve, 1000) })
14 const tasks = [
15 server.then(value => { parts.server = value; parts.serverStatus = 'fulfilled' }, () => { parts.serverStatus = 'rejected' }),
16 dom.then(value => { parts.dom = value; parts.domStatus = 'fulfilled' }, () => { parts.domStatus = 'rejected' }),
17 ]
18 try {
19 await Promise.race([Promise.all(tasks), timeout])
20 // Late responses may update the private accumulator, never this returned observation.
21 return { ...parts }
22 }
23 finally { clearTimeout(timer) }
24}
tests/unit/public-safety-execution-diagnostics.test.tsadded+40-0
Changes to tests/unit/public-safety-execution-diagnostics.test.ts
@@ -0,0 +1,40 @@
1import { expect, test } from 'bun:test'
2import { settleExecutionDiagnostics } from '../helpers/execution-diagnostics'
3
4test('a pending DOM diagnostic cannot erase an already received server observation', async () => {
5 const result = await settleExecutionDiagnostics(Promise.resolve({ available: true, state: 'running' }), new Promise(() => {}))
6 expect(result?.server).toEqual({ available: true, state: 'running' })
7 expect(result?.dom).toBeNull()
8})
9
10
11test('a pending server diagnostic cannot erase an already received DOM observation', async () => {
12 const result = await settleExecutionDiagnostics(new Promise(() => {}), Promise.resolve({ executionPhase: 'completed' }))
13 expect(result.dom).toEqual({ executionPhase: 'completed' })
14 expect(result.serverStatus).toBe('pending')
15 expect(result.domStatus).toBe('fulfilled')
16})
17
18test('a rejected arm stays unavailable without discarding the other settled observation', async () => {
19 const result = await settleExecutionDiagnostics(Promise.reject(new Error('not logged')), Promise.resolve({ executionPhase: 'running' }))
20 expect(result.server).toEqual({ available: false })
21 expect(result.dom).toEqual({ executionPhase: 'running' })
22 expect(result.serverStatus).toBe('rejected')
23 expect(result.domStatus).toBe('fulfilled')
24})
25
26test('two stalled arms return explicit unavailability without inventing an observation', async () => {
27 const result = await settleExecutionDiagnostics(new Promise(() => {}), new Promise(() => {}))
28 expect(result).toEqual({ server: { available: false }, dom: null, serverStatus: 'pending', domStatus: 'pending' })
29})
30
31test('a response after the deadline cannot mutate the returned failure observation', async () => {
32 let resolveDom!: (value: unknown) => void
33 const dom = new Promise(resolve => { resolveDom = resolve })
34 const result = await settleExecutionDiagnostics(Promise.resolve({ available: true }), dom)
35 resolveDom({ executionPhase: 'completed' })
36 await dom
37 expect(result.dom).toBeNull()
38 expect(result.domStatus).toBe('pending')
39 expect(result.serverStatus).toBe('fulfilled')
40})