From dc5f6c20fdd746a03ce5c40ee2f881870fbaa62a Mon Sep 17 00:00:00 2001 From: JUN <243035832+lidge-jun@users.noreply.github.com> Date: Thu, 29 Oct 2026 08:58:26 +0900 Subject: [PATCH] test(service): stabilize native recovery fixture compilation Keep rustup on the installed toolchain when HOME is sandboxed, retain compiler diagnostics, and use the existing bounded child-process budget. Co-authored-by: JUN <243035832+lidge-jun@users.noreply.github.com> --- .../service/service-desktop-recovery.test.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/service/service-desktop-recovery.test.ts b/tests/service/service-desktop-recovery.test.ts index bd137d8bc36..2f38e350029 100644 --- a/tests/service/service-desktop-recovery.test.ts +++ b/tests/service/service-desktop-recovery.test.ts @@ -2,13 +2,14 @@ import { describe, expect, test } from "bun:test"; import { ptr, toArrayBuffer } from "bun:ffi"; import { chmodSync, copyFileSync, mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs"; import { connect, createServer, type Socket } from "node:net"; -import { tmpdir } from "node:os"; +import { tmpdir, userInfo } from "node:os"; import { join } from "node:path"; import { inspectDesktopRecovery, parseRecoveryAnswer, recoveryHomeIdentity, type DesktopRecoveryIo } from "../../src/service/desktop-recovery"; import { linuxRecoveryBirth, linuxRecoveryListeners, linuxRecoverySocket, macRecoveryPaths, macRecoveryRequirement, parseMacRecoveryPath, recoveryImageCandidate, recoverySibling, verifyMacRecoveryImage } from "../../src/service/desktop-recovery-process"; import { repoPath } from "../helpers/repo-root"; +import { SPAWN_BUDGET_MS } from "../helpers/test-budget"; const instance = "a".repeat(32); const endpoint = { pid: 123, port: 12345 }; @@ -329,10 +330,18 @@ std::thread::park(); }`; import { runDesktopColdStart, productionDesktopColdStartDeps } from ${JSON.stringify(repoPath("src", "cli", "ensure-desktop-cold-start.ts"))}; const evidence = await inspectDesktopRecovery(); const result = await runDesktopColdStart({ ...productionDesktopColdStartDeps(async () => ({ fixture: true })), desktopRecovery: async () => evidence, info: () => {} }); console.log(JSON.stringify({ evidence, result }));`); - const rustBuild = Bun.spawnSync([Bun.which("rustc")!, "--edition=2021", nativeSource, "-o", app], { stdout: "pipe", stderr: "pipe", timeout: 30_000 }); - expect(rustBuild.exitCode).toBe(0); + // The preload sandboxes HOME; rustup must still find the installed toolchain (#7884). + const realHome = process.env.OCX_REAL_HOME?.trim() || userInfo().homedir; + const rustEnv = { ...process.env, + RUSTUP_HOME: process.env.RUSTUP_HOME || join(realHome, ".rustup"), + CARGO_HOME: process.env.CARGO_HOME || join(realHome, ".cargo"), + }; + // Hosted runs killed rustc at 30s while other heads passed. Keep a bounded + // real-child budget and report the compiler's output rather than only a null/1 exit. + const rustBuild = Bun.spawnSync([Bun.which("rustc")!, "--edition=2021", nativeSource, "-o", app], { env: rustEnv, stdout: "pipe", stderr: "pipe", timeout: SPAWN_BUDGET_MS }); + expect(rustBuild.exitCode, `rustc (signal=${rustBuild.signal}):\n${rustBuild.stderr.toString()}${rustBuild.stdout.toString()}`).toBe(0); const build = Bun.spawnSync([process.execPath, "build", "--compile", entry, "--outfile", cli], { stdout: "pipe", stderr: "pipe", timeout: 30_000 }); - expect(build.exitCode).toBe(0); + expect(build.exitCode, `bun build (signal=${build.signal}):\n${build.stderr.toString()}${build.stdout.toString()}`).toBe(0); const env = { ...process.env, XDG_CONFIG_HOME: join(root, "xdg"), OPENCODEX_HOME: config }; let child: ReturnType | undefined; const foreignSockets: Socket[] = []; @@ -403,4 +412,4 @@ console.log(JSON.stringify({ evidence, result }));`); await new Promise(resolve => foreign.close(() => resolve())); rmSync(root, { recursive: true, force: true }); } -}, 60_000); +}, SPAWN_BUDGET_MS + 30_000);