|
| 1 | +import assert from "node:assert/strict" |
| 2 | +import fs from "node:fs" |
| 3 | +import os from "node:os" |
| 4 | +import path from "node:path" |
| 5 | +import { spawnSync } from "node:child_process" |
| 6 | + |
| 7 | +const guard = path.resolve(path.dirname(new URL(import.meta.url).pathname), "codex-windows-desktop-bootstrap-continuity-guard.mjs") |
| 8 | +const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "codex-windows-bootstrap-guard-")) |
| 9 | + |
| 10 | +function baseEvidence() { |
| 11 | + return { |
| 12 | + operation_id: "op-win-001", |
| 13 | + desktop: { |
| 14 | + platform: "windows", |
| 15 | + package_version: "26.721.11231.0", |
| 16 | + signature_valid: true, |
| 17 | + launch_attempted: true, |
| 18 | + exit_code: "0", |
| 19 | + chromium_initialized: true, |
| 20 | + sandbox_setup_launched: true, |
| 21 | + sandbox_setup_succeeded: true, |
| 22 | + clean_profile_tested: true, |
| 23 | + reinstall_count: 0, |
| 24 | + corrected_build: true, |
| 25 | + cold_start_canary_passed: true, |
| 26 | + sandbox_canary_passed: true, |
| 27 | + multi_task_restart_canary_passed: true, |
| 28 | + }, |
| 29 | + state: { |
| 30 | + task_state_preserved: true, |
| 31 | + external_writes_reconciled: true, |
| 32 | + reinstall_requested: false, |
| 33 | + app_state_deletion_requested: false, |
| 34 | + broad_host_shutdown_requested: false, |
| 35 | + }, |
| 36 | + continuity_route: { |
| 37 | + type: "direct_openai_cli", |
| 38 | + verified: true, |
| 39 | + canary_passed: true, |
| 40 | + operation_binding_matches: true, |
| 41 | + workspace_head_verified: true, |
| 42 | + }, |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +function runCase(name, mutate, expectedCode, expectedReason) { |
| 47 | + const evidence = baseEvidence() |
| 48 | + mutate(evidence) |
| 49 | + const file = path.join(tempDir, `${name}.json`) |
| 50 | + fs.writeFileSync(file, JSON.stringify(evidence)) |
| 51 | + const result = spawnSync(process.execPath, [guard, "--input", file, "--json"], { encoding: "utf8" }) |
| 52 | + assert.equal(result.status, expectedCode, `${name}: ${result.stderr || result.stdout}`) |
| 53 | + const output = JSON.parse((result.stdout || result.stderr).trim()) |
| 54 | + assert.equal(output.reason, expectedReason, name) |
| 55 | +} |
| 56 | + |
| 57 | +runCase("healthy", () => {}, 0, "windows_desktop_bootstrap_verified") |
| 58 | +runCase("broad-shutdown", (e) => { e.state.broad_host_shutdown_requested = true }, 64, "broad_host_shutdown_rejected") |
| 59 | +runCase("unsafe-delete", (e) => { e.state.app_state_deletion_requested = true; e.state.external_writes_reconciled = false }, 64, "destructive_app_state_recovery_rejected_before_reconciliation") |
| 60 | +runCase("blind-reinstall", (e) => { e.desktop.chromium_initialized = false; e.desktop.exit_code = "0xC0000001"; e.desktop.corrected_build = false; e.state.reinstall_requested = true; e.desktop.reinstall_count = 2 }, 77, "blind_reinstall_loop_rejected") |
| 61 | +runCase("failure-unreconciled", (e) => { e.desktop.chromium_initialized = false; e.desktop.exit_code = "0xC0000001"; e.desktop.corrected_build = false; e.state.external_writes_reconciled = false }, 75, "desktop_failure_requires_state_and_write_reconciliation") |
| 62 | +runCase("failure-no-route", (e) => { e.desktop.chromium_initialized = false; e.desktop.exit_code = "0xC0000001"; e.desktop.corrected_build = false; e.continuity_route.canary_passed = false }, 75, "desktop_unavailable_without_verified_continuity_route") |
| 63 | +runCase("failure-rerouted", (e) => { e.desktop.chromium_initialized = false; e.desktop.exit_code = "0xC0000001"; e.desktop.corrected_build = false }, 77, "windows_desktop_surface_quarantined") |
| 64 | +runCase("sandbox-failure", (e) => { e.desktop.sandbox_setup_succeeded = false; e.desktop.corrected_build = false }, 77, "windows_desktop_surface_quarantined") |
| 65 | +runCase("resume-canary-missing", (e) => { e.desktop.multi_task_restart_canary_passed = false }, 75, "desktop_resume_canaries_incomplete") |
| 66 | +runCase("unapproved-route", (e) => { e.continuity_route.type = "unapproved_route"; e.desktop.chromium_initialized = false; e.desktop.exit_code = "0xC0000001"; e.desktop.corrected_build = false }, 75, "desktop_unavailable_without_verified_continuity_route") |
| 67 | + |
| 68 | +fs.rmSync(tempDir, { recursive: true, force: true }) |
| 69 | +console.log("codex-windows-desktop-bootstrap-continuity-guard: 10 fixtures passed") |
0 commit comments