From 00462b048ec83c51a27ec60677ee5f912443c2d7 Mon Sep 17 00:00:00 2001 From: Dotta Date: Thu, 1 Oct 2026 22:03:21 -0500 Subject: [PATCH] fix(runner): preserve packaged daemon executability Co-Authored-By: Paperclip --- packages/paperclip-runner/package.json | 8 ++- .../scripts/check-clean-consumers.mjs | 59 ++++++++++++++++-- .../runner-package-executable.test.mjs | 61 +++++++++++++++++++ 3 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 packages/paperclip-runner/scripts/runner-package-executable.test.mjs diff --git a/packages/paperclip-runner/package.json b/packages/paperclip-runner/package.json index 619bc38338e..f850a302394 100644 --- a/packages/paperclip-runner/package.json +++ b/packages/paperclip-runner/package.json @@ -55,6 +55,12 @@ "styles.css", "README.md" ], + "publishConfig": { + "executableFiles": [ + "./dist/bin/paperclip-runnerd", + "./dist/bin/paperclip-runnerd.exe" + ] + }, "sideEffects": false, "scripts": { "build": "pnpm run check:protocol-manifest && pnpm run build:typescript && pnpm run check:capability-contract && pnpm run check:capability-inventory && pnpm run check:protocol-coverage && pnpm run check:semantic-contracts && pnpm run check:runner-workflow-traceability && pnpm run build:binary && node scripts/generate-replay-goldens.mjs --check && node scripts/generate-semantic-action-catalog.mjs --check", @@ -74,7 +80,7 @@ "typecheck:browser": "tsc -p tsconfig.browser.json --noEmit", "test": "pnpm run test:typescript && pnpm run test:rust", "test:typescript": "pnpm run test:typescript:prep && vitest run", - "test:typescript:prep": "pnpm run ensure:eval-build-deps && pnpm run build:rust && node --test test/protocol-contract.test.mjs test/acpx-sidecar-contract.test.mjs test/acpx-codex-package-contract.test.mjs test/acpx-message-boundaries-package-contract.test.mjs test/acpx-rich-extensions-package-contract.test.mjs test/acpx-pi-receipt-package-contract.test.mjs test/acpx-response-delivery-package-contract.test.mjs scripts/candidate-provider-pack.test.mjs scripts/aws-agentcore-provisioning.test.mjs scripts/build-verified-provider-entrypoints.test.mjs scripts/local-provider-smoke-environment.test.mjs scripts/materialize-opencode-binary.test.mjs scripts/installed-package-pack.test.mjs", + "test:typescript:prep": "pnpm run ensure:eval-build-deps && pnpm run build:rust && node --test test/protocol-contract.test.mjs test/acpx-sidecar-contract.test.mjs test/acpx-codex-package-contract.test.mjs test/acpx-message-boundaries-package-contract.test.mjs test/acpx-rich-extensions-package-contract.test.mjs test/acpx-pi-receipt-package-contract.test.mjs test/acpx-response-delivery-package-contract.test.mjs scripts/candidate-provider-pack.test.mjs scripts/aws-agentcore-provisioning.test.mjs scripts/build-verified-provider-entrypoints.test.mjs scripts/local-provider-smoke-environment.test.mjs scripts/materialize-opencode-binary.test.mjs scripts/installed-package-pack.test.mjs scripts/runner-package-executable.test.mjs", "test:typescript:vitest": "node ./scripts/run-pr-vitest-lane.mjs", "test:rust": "cargo test --release --manifest-path runner/Cargo.toml --locked --workspace", "test:codex": "cargo test --manifest-path runner/Cargo.toml --locked -p paperclip-runner-core --test codex_provider", diff --git a/packages/paperclip-runner/scripts/check-clean-consumers.mjs b/packages/paperclip-runner/scripts/check-clean-consumers.mjs index eeefd1a5e31..f3ad0550e5d 100644 --- a/packages/paperclip-runner/scripts/check-clean-consumers.mjs +++ b/packages/paperclip-runner/scripts/check-clean-consumers.mjs @@ -43,7 +43,8 @@ try { "--bin", "paperclip-runnerd", ], runnerRoot); - const runnerTarball = await pack(runnerRoot, artifactsRoot); + run(process.execPath, ["scripts/stage-runner-binary.mjs"], runnerRoot); + const runnerTarball = await pack(runnerRoot, artifactsRoot, { runner: true }); const runtimeDependencyTarballs = await packRunnerRuntimeDependencies(artifactsRoot); const runnerdArtifact = await stageRunnerdArtifact(artifactsRoot); const conformanceRecord = resolve(artifactsRoot, "paperclip-runner-consumer-conformance.json"); @@ -77,12 +78,19 @@ try { } } -async function pack(packageRoot, destination) { +async function pack(packageRoot, destination, { runner = false } = {}) { const before = new Set(await readdir(destination)); // These installed dependencies are pack inputs, not our development cwd. // Keep their publisher devEngines intact without adopting their toolchain; // normal tarball contents and clean-consumer runtime engine checks still apply. - run("npm", ["pack", resolve(packageRoot), "--ignore-scripts", "--pack-destination", destination], destination, { quiet: true }); + if (runner) { + // Exercise the pinned release packer, including executableFiles normalization. + run("pnpm", ["pack", "--pack-destination", destination], packageRoot, { + quiet: true, env: { npm_config_ignore_scripts: "true" }, + }); + } else { + run("npm", ["pack", resolve(packageRoot), "--ignore-scripts", "--pack-destination", destination], destination, { quiet: true }); + } const created = (await readdir(destination)) .filter((entry) => entry.endsWith(".tgz") && !before.has(entry)) .sort(); @@ -159,7 +167,7 @@ async function resolveInstalledDependencyRoot(packageRoot, dependencyName) { async function stageRunnerdArtifact(destination) { const suffix = process.platform === "win32" ? ".exe" : ""; - const source = resolve(runnerRoot, `runner/target/release/paperclip-runnerd${suffix}`); + const source = resolve(runnerRoot, `dist/bin/paperclip-runnerd${suffix}`); const executablePath = resolve(destination, `paperclip-runnerd-${process.platform}-${process.arch}${suffix}`); await copyFile(source, executablePath); if (process.platform !== "win32") await chmod(executablePath, 0o755); @@ -197,6 +205,40 @@ async function verifyRunnerConsumer({ }, pnpm: { overrides: localOverrides(runtimeDependencyTarballs) }, }, null, 2)}\n`); + await writeFile(resolve(consumerRoot, "verify-default-runnerd.mjs"), ` +import { execFileSync } from "node:child_process"; +import { constants } from "node:fs"; +import { access, readFile, realpath, writeFile } from "node:fs/promises"; +import { createHash } from "node:crypto"; +import { dirname, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +import { defaultCapabilityRunnerdBinary } from "@paperclipai/paperclip-runner"; +import { parsePaperclipRunnerdBuildMetadata, PAPERCLIP_RUNNER_BUILD_METADATA } from "@paperclipai/paperclip-runner/evals"; +// This is the installed package's default lookup. The separate eval artifact +// below must not hide an unusable bundled daemon or repair its permissions. +const bundledRunnerd = defaultCapabilityRunnerdBinary(); +const installedEntry = fileURLToPath(import.meta.resolve("@paperclipai/paperclip-runner")); +const expectedBundledRunnerd = resolve(dirname(installedEntry), "bin", + "paperclip-runnerd" + (process.platform === "win32" ? ".exe" : "")); +if (await realpath(bundledRunnerd) !== await realpath(expectedBundledRunnerd)) { + throw new Error("default runnerd escaped the installed package"); +} +await access(bundledRunnerd, constants.X_OK); +const bundledRunnerdDigest = "sha256:" + createHash("sha256") + .update(await readFile(bundledRunnerd)).digest("hex"); +if (bundledRunnerdDigest !== process.env.EXPECTED_RUNNERD_SHA256) { + throw new Error("installed default runnerd differs from the built binary"); +} +const bundledMetadata = JSON.parse(execFileSync(bundledRunnerd, ["--build-metadata"], { + encoding: "utf8", timeout: 15_000, maxBuffer: 1024 * 1024, + env: { PATH: process.env.PATH, HOME: process.cwd() }, +})); +if (parsePaperclipRunnerdBuildMetadata(bundledMetadata).binaryContractVersion !== PAPERCLIP_RUNNER_BUILD_METADATA.contracts.runnerdArtifact) { + throw new Error("installed default runnerd did not start with the expected contract"); +} + +await writeFile("bundled-runnerd-proof.json", JSON.stringify({ executable: true, started: true, binaryOverride: false, sha256: bundledRunnerdDigest }) + "\\n"); +`); await writeFile(resolve(consumerRoot, "verify.mjs"), ` import { createHash } from "node:crypto"; import { readFile, stat, writeFile } from "node:fs/promises"; @@ -349,6 +391,7 @@ await writeFile(process.env.PAPERCLIP_CONFORMANCE_RECORD, JSON.stringify({ mockControlPlaneConformance: report, harnessDriverConformance: driverConformance, runnerdDigest: true, + bundledDefaultRunnerd: JSON.parse(await readFile("bundled-runnerd-proof.json", "utf8")), semanticConformance: { schema: semanticConformance.schema, rowCount: semanticConformance.rows.length, @@ -393,17 +436,21 @@ function installAndRun(consumerRoot, extraEnv = {}) { "--config.auto-install-peers=false", "--reporter=append-only", ], consumerRoot, { env: { NODE_ENV: "development" } }); + run(process.execPath, ["verify-default-runnerd.mjs"], consumerRoot, { + inheritEnv: false, + env: { PATH: process.env.PATH, HOME: consumerRoot, EXPECTED_RUNNERD_SHA256: extraEnv.PAPERCLIP_RUNNERD_SHA256 }, + }); run(process.execPath, ["verify.mjs"], consumerRoot, { env: extraEnv }); } -function run(command, args, cwd, { quiet = false, env = {} } = {}) { +function run(command, args, cwd, { quiet = false, env = {}, inheritEnv = true } = {}) { const usesPnpm = command === "pnpm"; const executable = usesPnpm ? pnpmInvocation.executable : command; const effectiveArgs = usesPnpm ? [...pnpmInvocation.prefixArgs, ...args] : args; const result = spawnSync(executable, effectiveArgs, { cwd, encoding: "utf8", - env: { ...process.env, CI: "true", ...env }, + env: { ...(inheritEnv ? process.env : {}), CI: "true", ...env }, stdio: quiet ? ["ignore", "pipe", "pipe"] : ["ignore", "inherit", "inherit"], ...(quiet ? { maxBuffer: 32 * 1024 * 1024 } : {}), }); diff --git a/packages/paperclip-runner/scripts/runner-package-executable.test.mjs b/packages/paperclip-runner/scripts/runner-package-executable.test.mjs new file mode 100644 index 00000000000..a3605172d72 --- /dev/null +++ b/packages/paperclip-runner/scripts/runner-package-executable.test.mjs @@ -0,0 +1,61 @@ +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import { access, chmod, mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises"; +import { constants } from "node:fs"; +import { tmpdir } from "node:os"; +import { dirname, join, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +import { test } from "node:test"; + +const runnerRoot = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const manifest = JSON.parse(await readFile(join(runnerRoot, "package.json"), "utf8")); +const pnpmScript = process.env.npm_execpath; +const pnpm = pnpmScript?.replaceAll("\\", "/").endsWith("/pnpm.cjs") + ? [process.execPath, pnpmScript] : [process.platform === "win32" ? "pnpm.cmd" : "pnpm"]; + +// The full clean-consumer check packs this Runner package, installs it offline, +// then launches defaultCapabilityRunnerdBinary() without a binary override. +// This small actual pack/install regression isolates pnpm's mode normalization, +// including the absent alternate-platform executable and a negative control. +for (const declared of [true, false]) { + test(`pnpm installed native mode ${declared ? "honors executableFiles" : "rejects an undeclared executable"}`, + { skip: process.platform === "win32" ? "POSIX executable-bit contract" : false }, async t => { + const root = await mkdtemp(join(tmpdir(), "runner-executable-pack-")); + t.after(() => rm(root, { recursive: true, force: true })); + const source = join(root, "source"), output = join(root, "artifacts"), home = join(root, "home"); + const consumer = join(root, "consumer"); + for (const dir of [join(source, "dist/bin"), output, home, consumer]) await mkdir(dir, { recursive: true }); + for (const file of ["user.npmrc", "global.npmrc"]) await writeFile(join(home, file), ""); + const env = { PATH: process.env.PATH, HOME: home, TMPDIR: root, CI: "true", + npm_config_userconfig: join(home, "user.npmrc"), npm_config_globalconfig: join(home, "global.npmrc"), + npm_config_cache: join(home, "cache"), npm_config_ignore_scripts: "true", npm_config_offline: "true", + npm_config_audit: "false", npm_config_fund: "false", npm_config_update_notifier: "false" }; + const run = (command, args, cwd) => execFileSync(command, args, + { cwd, env, encoding: "utf8", timeout: 60_000, maxBuffer: 1024 * 1024 }); + assert.equal(run(pnpm[0], [...pnpm.slice(1), "--version"], source).trim(), "9.15.4"); + assert.deepEqual(manifest.publishConfig.executableFiles, + ["./dist/bin/paperclip-runnerd", "./dist/bin/paperclip-runnerd.exe"]); + await writeFile(join(source, "package.json"), JSON.stringify({ + name: "runner-executable-fixture", version: "1.0.0", files: ["dist"], + ...(declared ? { publishConfig: manifest.publishConfig } : {}), + })); + // Deliberately omit the Windows binary. Packing a platform-specific + // package must tolerate the other executableFiles entry being absent. + const executable = join(source, "dist/bin/paperclip-runnerd"); + await writeFile(executable, "#!/bin/sh\nprintf 'packaged-native-fixture\\n'\n"); + await chmod(executable, 0o755); + run(pnpm[0], [...pnpm.slice(1), "pack", "--pack-destination", output], source); + const archives = (await readdir(output)).filter(name => name.endsWith(".tgz")); + assert.equal(archives.length, 1); + await writeFile(join(consumer, "package.json"), JSON.stringify({ name: "runner-consumer", private: true })); + run("npm", ["install", "--offline", "--ignore-scripts", "--package-lock=false", join(output, archives[0])], consumer); + const installed = join(consumer, "node_modules/runner-executable-fixture/dist/bin/paperclip-runnerd"); + assert.deepEqual(await readFile(installed), await readFile(executable)); + if (declared) { + await access(installed, constants.X_OK); + assert.equal(run(installed, [], consumer).trim(), "packaged-native-fixture"); + } else { + await assert.rejects(access(installed, constants.X_OK), { code: "EACCES" }); + } + }); +}