also looking at this
feat: add bounded VTOL wind braking
#88
13 files
+447
-25
| @@ -5,6 +5,7 @@ import { mkdir, writeFile } from 'node:fs/promises' | ||
| 5 | 5 | import { join, resolve } from 'node:path' |
| 6 | 6 | import { randomUUID } from 'node:crypto' |
| 7 | 7 | import { setupHandoverFixture } from './handover-setup' |
| 8 | import { createExecutionCallbackObserver } from '../../helpers/execution-worker-observation' | |
| 8 | 9 | |
| 9 | 10 | // Real native setup owns the guarded disposable SQLite file before any application boot. |
| 10 | 11 | const fixture = await setupHandoverFixture() |
| @@ -43,6 +44,14 @@ let nextOrdinal = 0 | ||
| 43 | 44 | const scalar = (value: unknown) => typeof value === 'number' && Number.isFinite(value) && Math.abs(value) <= Number.MAX_SAFE_INTEGER ? value : null |
| 44 | 45 | const field = (value: unknown, name: string): unknown => value && typeof value === 'object' ? Object.getOwnPropertyDescriptor(value, name)?.value : undefined |
| 45 | 46 | const choice = <T extends string>(value: unknown, values: readonly T[]): T | null => values.find(item => item === value) ?? null |
| 47 | const callbackObserver = createExecutionCallbackObserver(value => console.log(JSON.stringify(value))) | |
| 48 | function observeAcceptedWorker(acceptedOrdinal: number) { | |
| 49 | try { | |
| 50 | const worker = field(executionOwner().slot, 'worker') | |
| 51 | if (worker instanceof Worker) callbackObserver.observe(worker, acceptedOrdinal) | |
| 52 | } | |
| 53 | catch { /* Private observation must not change an accepted native response. */ } | |
| 54 | } | |
| 46 | 55 | const ordinal = (slot: object) => { |
| 47 | 56 | const existing = ordinals.get(slot) |
| 48 | 57 | if (existing !== undefined) return existing |
| @@ -61,7 +70,7 @@ function diagnosticSnapshot() { | ||
| 61 | 70 | return typeof value === 'number' ? scalar(value - now) : null |
| 62 | 71 | } |
| 63 | 72 | return { |
| 64 | available: true, pendingChecks: scalar(owner.pendingChecks), | |
| 73 | available: true, pendingChecks: scalar(owner.pendingChecks), workerCallbacks: callbackObserver.snapshot(), | |
| 65 | 74 | fixture: { startRequests, admissionRequests, streamStarts, holdArmed, held, holdUsed, holdWorkspace, workspaceHeld, preAdmissionRenewalArmed, preAdmissionRenewed, preAdmissionHeldReads: preAdmissionReads.size, preAdmissionHoldExpired }, lastStart, lastAdmission, responses: responses.slice(), |
| 66 | 75 | slot: slot === null ? null : { |
| 67 | 76 | ordinal: ordinal(slot), |
| @@ -123,6 +132,7 @@ const control = async (request: Request) => { | ||
| 123 | 132 | if (request.headers.get('x-fixture-control') !== secret) return new Response(null, { status: 404 }) |
| 124 | 133 | const action = new URL(request.url).pathname.slice('/__fixture/'.length) |
| 125 | 134 | if (action === 'status') return Response.json({ held, streamStarts, startRequests, startResponseReady: !!releaseStart, workspaceHeld, preAdmissionRenewed, preAdmissionHeldReads: preAdmissionReads.size, preAdmissionHoldExpired, admissionRequests }) |
| 135 | if (action === 'worker-callback-timings') return Response.json(callbackObserver.snapshot()) | |
| 126 | 136 | if (action === 'diagnostics') { |
| 127 | 137 | try { |
| 128 | 138 | const text = `${JSON.stringify(diagnosticSnapshot())}\n` |
| @@ -212,6 +222,9 @@ route.use(async (request: Request, next: () => Promise<Response | null> | Respon | ||
| 212 | 222 | } |
| 213 | 223 | const response = await next() |
| 214 | 224 | status = response?.status ?? null |
| 225 | // The genuine core Worker is already constructed. No constructor or frame is replaced. | |
| 226 | // Observation precedes the accepted response and the later native consumer attachment. | |
| 227 | if (startOrdinal !== null && status === 202) observeAcceptedWorker(startOrdinal) | |
| 215 | 228 | if (delayStart && request.method === 'POST' && pathname.endsWith('/workspace/execution') && response?.ok) { delayStart = false; await new Promise<void>(resolve => { releaseStart = resolve }) } |
| 216 | 229 | const executionEvents = /\/workspace\/execution\/[a-f0-9-]+\/events$/.test(pathname), workspaceEvents = pathname.endsWith('/workspace/events') |
| 217 | 230 | if (request.method !== 'GET' || !(executionEvents || workspaceEvents) || !response?.ok || !response.body) return response |
| @@ -247,7 +260,7 @@ route.use(async (request: Request, next: () => Promise<Response | null> | Respon | ||
| 247 | 260 | }) |
| 248 | 261 | const page = () => new Response(html, { headers: { 'content-type': 'text/html', 'cache-control': 'no-store' } }) |
| 249 | 262 | route.get('/incidents', page) |
| 250 | for (const action of ['status', 'diagnostics', 'release-start', 'arm-before-return', 'before-return', 'release-and-renew', 'before-admission', 'hold-completion-read-renewal', 'arm-pre-admission-renewal', 'renew-pre-admission-held-read', 'verify-admitted', 'release-workspace', 'read-only', 'revoke']) route.get(`/__fixture/${action}`, control) | |
| 263 | for (const action of ['status', 'diagnostics', 'worker-callback-timings', 'release-start', 'arm-before-return', 'before-return', 'release-and-renew', 'before-admission', 'hold-completion-read-renewal', 'arm-pre-admission-renewal', 'renew-pre-admission-held-read', 'verify-admitted', 'release-workspace', 'read-only', 'revoke']) route.get(`/__fixture/${action}`, control) | |
| 251 | 264 | const server = await route.serve({ hostname: '127.0.0.1', port: 0, nativeRoutes: false }) |
| 252 | 265 | if (process.env.EXECUTION_BROWSER_EVIDENCE) { await mkdir(process.env.EXECUTION_BROWSER_EVIDENCE, { recursive: true }); await writeFile(join(process.env.EXECUTION_BROWSER_EVIDENCE, 'compiled.html'), html) } |
| 253 | 266 | await writeFile(join(root, 'execution-credentials.json'), JSON.stringify({ url: `http://127.0.0.1:${server.port}`, key: seeded.key, sourceDigest: seeded.source.digest, token: fixture.senderToken, control: secret }), { mode: 0o600 }) |