From 064bf51ed6a3807873071d8729a25ce2489a5cfe Mon Sep 17 00:00:00 2001 From: Guillaume Loret <686630+yomgui@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:09:05 -0500 Subject: [PATCH] test(desktop): Intel macOS ships no unsigned Apple silicon microsandbox runtime (#7550) * fix(desktop): stage the target CPU's sandbox runtime when cross-packaging Release jobs package Windows ARM64 on an x64 runner. The runtime staging step chose the microsandbox native package by the build host's CPU, so the ARM64 app carried the x64 runtime and the after-pack check rejected it: Missing unpacked microsandbox runtime asset ... win32-arm64-msvc.node. Pick the CPU from TARGET, as the sidecar and guest image steps already do. Signed-off-by: Guillaume Loret * test(evals): prove a Windows x64 runner stages the ARM64 sandbox runtime Runs the real staging CLI that build:electron runs, as the Windows x64 release runner, for both Windows targets. OPENWORK_STAGING_SCRIPT_REF runs a git ref's script as the control. Signed-off-by: Guillaume Loret * test(desktop): prove Intel macOS packages no unsigned Apple silicon msb Release v0.18.70's Intel macOS jobs failed afterSign because the x64 app, cross-packaged on Apple silicon, staged microsandbox-darwin-arm64. Cover the target-arch staging fix with an @openwork/testkit spec, including the negative half: Apple silicon still ships msb and afterSign still rejects ad-hoc. --------- Signed-off-by: Guillaume Loret --- scenarios/intel-macos-packaging/unit.test.ts | 90 ++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 scenarios/intel-macos-packaging/unit.test.ts diff --git a/scenarios/intel-macos-packaging/unit.test.ts b/scenarios/intel-macos-packaging/unit.test.ts new file mode 100644 index 0000000000..1d3bc33b4f --- /dev/null +++ b/scenarios/intel-macos-packaging/unit.test.ts @@ -0,0 +1,90 @@ +import assert from "node:assert/strict"; +import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { createRequire } from "node:module"; +import { tmpdir } from "node:os"; +import { dirname, join } from "node:path"; +import { test } from "@openwork/testkit"; +import { stageRuntimeNodeModules, targetArch } from "../../apps/desktop/scripts/prepare-runtime-node-modules.mjs"; + +type Spawn = (command: string, args: string[]) => { status: number; stdout: string; stderr: string }; +const { verifyMicrosandboxRuntime } = createRequire(import.meta.url)("../../apps/desktop/scripts/electron-after-sign.cjs") as { + verifyMicrosandboxRuntime(appPath: string, options: { runCommand(command: string, args: string[]): void; spawn: Spawn }): void; +}; + +const native = "@superradcompany/microsandbox-darwin-arm64"; + +// The release's Intel macOS jobs run `build:electron` on an Apple silicon +// runner with TARGET=x86_64-apple-darwin. pnpm installs both CPU variants, so +// only the build target, never the runner, may decide which runtime ships. +function stageFor(target: string) { + const root = mkdtempSync(join(tmpdir(), "intel-macos-packaging-")); + const write = (file: string, value: unknown) => { + mkdirSync(dirname(join(root, file)), { recursive: true }); + writeFileSync(join(root, file), typeof value === "string" ? value : JSON.stringify(value)); + }; + const pkg = (name: string, dependencies = {}, optionalDependencies = {}) => { + write(`node_modules/${name}/package.json`, { name, version: "0.7.15", type: "module", main: "./dist/index.js", dependencies, optionalDependencies }); + write(`node_modules/${name}/dist/index.js`, "export const fixture = true;"); + }; + write("package.json", { private: true }); + pkg("@openwork/sandbox-microsandbox", { microsandbox: "0.7.15" }); + pkg("microsandbox", {}, { [native]: "0.7.15" }); + write("node_modules/microsandbox/dist/internal/resolve-binary.js", 'function msbPath(root) { return root ? join(root, "bin", msbFileName()) : null; }'); + pkg(native); + write(`node_modules/${native}/bin/msb`, "Apple silicon executable"); + const app = join(root, "OpenWork.app"); + // The CLI passes targetArch() with the job's TARGET; the host is the arm64 runner. + const staged = stageRuntimeNodeModules(join(app, "Contents/Resources/app.asar.unpacked/node_modules"), { + roots: [{ name: "@openwork/sandbox-microsandbox", fromPackageJson: join(root, "package.json") }], platform: "darwin", arch: targetArch(target, "arm64"), + }); + return { root, app, staged }; +} + +function afterSign(app: string, signature: string) { + const calls: string[] = []; + const spawn: Spawn = (command, args) => { + calls.push(`${command} ${args.join(" ")}`); + return { status: 0, stdout: "com.apple.security.hypervisor", stderr: signature }; + }; + let error: unknown = null; + try { + verifyMicrosandboxRuntime(app, { runCommand: (command, args) => calls.push(`${command} ${args.join(" ")}`), spawn }); + } catch (caught) { + error = caught; + } + return { calls, error }; +} + +test("an Intel macOS release built on Apple silicon ships no Apple silicon microsandbox runtime", ({ evidence }) => { + const intel = stageFor("x86_64-apple-darwin"); + const appleSilicon = stageFor("aarch64-apple-darwin"); + try { + const intelShipsArm = existsSync(join(intel.app, "Contents/Resources/app.asar.unpacked/node_modules", native)); + const intelSign = afterSign(intel.app, "Signature=adhoc"); + evidence.recordAssertionEvidence( + "Intel staging omits the Apple silicon runtime, so afterSign has no unsigned msb to reject", + `staged: ${intel.staged.join(", ")}; codesign calls: ${intelSign.calls.length}; error: ${String(intelSign.error)}`, + !intelShipsArm && intel.staged.includes("microsandbox") && intelSign.calls.length === 0 && intelSign.error === null, + ); + assert.equal(intelShipsArm, false); + assert.ok(intel.staged.includes("microsandbox")); + assert.deepEqual(intelSign.calls, []); + assert.equal(intelSign.error, null); + + const armMsb = join(appleSilicon.app, "Contents/Resources/app.asar.unpacked/node_modules", native, "bin/msb"); + const adhoc = afterSign(appleSilicon.app, "Signature=adhoc"); + const developerId = afterSign(appleSilicon.app, "Authority=Developer ID Application: fixture"); + evidence.recordAssertionEvidence( + "Apple silicon still ships msb and afterSign still rejects an ad-hoc signature", + `staged: ${appleSilicon.staged.join(", ")}; adhoc: ${String(adhoc.error)}; Developer ID: ${String(developerId.error)}`, + existsSync(armMsb) && /requires a Developer ID signature/.test(String(adhoc.error)) && developerId.error === null, + ); + assert.ok(existsSync(armMsb)); + assert.match(String(adhoc.error), /Notarized microsandbox runtime requires a Developer ID signature/); + assert.ok(adhoc.calls.some((call) => call.startsWith("codesign --verify") && call.endsWith(armMsb))); + assert.equal(developerId.error, null); + } finally { + rmSync(intel.root, { recursive: true, force: true }); + rmSync(appleSilicon.root, { recursive: true, force: true }); + } +});