diff --git a/package.json b/package.json index a07877884d..008aa6165c 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "bridge/agentenv/solve.py", "bridge/agentenv/solve_cleanup.py", "scripts/rea.mjs", + "scripts/lib/cli-compiled-runtime.mjs", "scripts/lib/cli-process-environment.mjs", "scripts/lib/runtime-admission.mjs", "scripts/rea-android-workspace-guardian.mjs", diff --git a/scripts/ci/scopes.mjs b/scripts/ci/scopes.mjs index 334e631344..e6da9e335f 100644 --- a/scripts/ci/scopes.mjs +++ b/scripts/ci/scopes.mjs @@ -23,6 +23,14 @@ const CAPTURE_SHARED_INPUTS = [ const UBUNTU_ARCHIVE_ACTION = ".github/actions/ubuntu-archive/action.{yml,yaml}"; +const CLI_LAUNCHER_INPUTS = [ + "scripts/rea.mjs", + "scripts/lib/cli-compiled-runtime.mjs", + "scripts/lib/cli-process-environment.mjs", + "scripts/lib/runtime-admission.mjs", + "scripts/lib/runtime-admission.d.mts", +]; + // Ownership of the native-host, real-provider and website verification lanes. // Shared build inputs are classified once in plan.mjs rather than repeated in // every workflow. @@ -270,10 +278,7 @@ const PATH_SCOPES = { "scripts/lib/release-pull-request.mjs", "patches/release-please+17.11.2.patch", "tests/boundary/filesystem/releaseProposal.test.ts", - "scripts/rea.mjs", - "scripts/lib/cli-process-environment.mjs", - "scripts/lib/runtime-admission.mjs", - "scripts/lib/runtime-admission.d.mts", + ...CLI_LAUNCHER_INPUTS, "install.sh", "src/config/**", "src/hopperPaths/**", @@ -546,10 +551,7 @@ const PATH_SCOPES = { "src/contracts/cliCommandNames.ts", "src/contracts/toolContracts.ts", "src/contracts/toolEffects.ts", - "scripts/rea.mjs", - "scripts/lib/cli-process-environment.mjs", - "scripts/lib/runtime-admission.mjs", - "scripts/lib/runtime-admission.d.mts", + ...CLI_LAUNCHER_INPUTS, "src/process/**", "src/resources/SafeOutputTree.ts", "scripts/verify/javascript/recovery.mjs", diff --git a/scripts/lib/cli-compiled-runtime.mjs b/scripts/lib/cli-compiled-runtime.mjs new file mode 100644 index 0000000000..8b85785e2c --- /dev/null +++ b/scripts/lib/cli-compiled-runtime.mjs @@ -0,0 +1,28 @@ +import { access } from "node:fs/promises"; +import { resolve } from "node:path"; + +/** + * @param {string} packageRoot + * @param {readonly string[]} paths + */ +export async function compiledRuntimeExists(packageRoot, paths) { + for (const path of paths) { + try { + await access(resolve(packageRoot, path)); + } catch (cause) { + if ( + typeof cause === "object" && + cause !== null && + "code" in cause && + cause.code === "ENOENT" + ) + return false; + throw cause; + } + } + return true; +} + +/** @param {string} packageRoot */ +export const missingCompiledRuntimeMessage = (packageRoot) => + `REA's compiled runtime is missing. Run \`npm ci && npm run build:cached\` in ${packageRoot} to install dependencies and build REA, then restart it. If this is an installed package, reinstall rea-agents.\n`; diff --git a/scripts/prepack.mjs b/scripts/prepack.mjs index 25d1c60f50..375aa11906 100644 --- a/scripts/prepack.mjs +++ b/scripts/prepack.mjs @@ -49,6 +49,7 @@ if (await pathExists(join(root, "src"))) { ]); } else { for (const path of [ + "scripts/lib/cli-compiled-runtime.mjs", "scripts/lib/cli-process-environment.mjs", "scripts/lib/runtime-admission.mjs", "dist/main.js", diff --git a/scripts/rea.mjs b/scripts/rea.mjs index eeb36db113..f9a2d33187 100755 --- a/scripts/rea.mjs +++ b/scripts/rea.mjs @@ -1,9 +1,12 @@ #!/usr/bin/env node -import { access } from "node:fs/promises"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; +import { + compiledRuntimeExists, + missingCompiledRuntimeMessage, +} from "./lib/cli-compiled-runtime.mjs"; import { prepareCliProcessEnvironment } from "./lib/cli-process-environment.mjs"; import { unsupportedRuntimeMessage } from "./lib/runtime-admission.mjs"; @@ -34,7 +37,9 @@ prepareCliProcessEnvironment( ); const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), ".."); const builtinArgumentRuntime = "dist/cli-runtime/cliBuiltinArguments.js"; -const builtinArguments = (await compiledRuntimeExists([builtinArgumentRuntime])) +const builtinArguments = (await compiledRuntimeExists(packageRoot, [ + builtinArgumentRuntime, +])) ? await import("../dist/cli-runtime/cliBuiltinArguments.js") : undefined; const entry = builtinArguments?.classifyCliEntrypoint(args, process.env); @@ -57,10 +62,8 @@ const runtimeFiles = [ ]), ]; -if (!(await compiledRuntimeExists(runtimeFiles))) { - process.stderr.write( - `REA's compiled runtime is missing. Run \`npm ci && npm run build:cached\` in ${packageRoot} to install dependencies and build REA, then restart it. If this is an installed package, reinstall rea-agents.\n`, - ); +if (!(await compiledRuntimeExists(packageRoot, runtimeFiles))) { + process.stderr.write(missingCompiledRuntimeMessage(packageRoot)); process.exitCode = 1; } else if (entry?.kind === "mcp-stdio") { const { runEntrypoint } = await import("../dist/mcp/main.js"); @@ -226,24 +229,3 @@ function isClosedReaderFailure(cause) { function writeStdout(output) { if (!stdoutClosed) process.stdout.write(output); } - -async function compiledRuntimeExists(paths) { - for (const path of paths) { - try { - await access(resolve(packageRoot, path)); - } catch (cause) { - if (isMissing(cause)) return false; - throw cause; - } - } - return true; -} - -function isMissing(cause) { - return ( - typeof cause === "object" && - cause !== null && - "code" in cause && - cause.code === "ENOENT" - ); -} diff --git a/scripts/verify-package-pack.mjs b/scripts/verify-package-pack.mjs index 1b2d9c5022..9b6d8c8d79 100644 --- a/scripts/verify-package-pack.mjs +++ b/scripts/verify-package-pack.mjs @@ -212,6 +212,8 @@ export async function verifyPackagePack({ root, workspace, commands }) { packedManifest.bin?.["rea-agents"] !== "scripts/rea.mjs" ) throw new Error("package did not expose both rea command entry points"); + if (!packedFiles.includes("package/scripts/lib/cli-compiled-runtime.mjs")) + throw new Error("package omitted the compiled CLI runtime check"); if (!packedFiles.includes("package/scripts/lib/cli-process-environment.mjs")) throw new Error("package omitted the CLI process environment owner"); if (!packedFiles.includes("package/scripts/lib/runtime-admission.mjs")) diff --git a/tests/boundary/filesystem/ciChangeScope.test.ts b/tests/boundary/filesystem/ciChangeScope.test.ts index 334aa0487c..78890cfbaa 100644 --- a/tests/boundary/filesystem/ciChangeScope.test.ts +++ b/tests/boundary/filesystem/ciChangeScope.test.ts @@ -2090,36 +2090,6 @@ it.each([ package: false, }, ], - [ - "scripts/lib/cli-process-environment.mjs", - { - code: true, - package: true, - runtime: true, - javascript_recovery: true, - readiness: false, - }, - ], - [ - "scripts/lib/runtime-admission.mjs", - { - code: true, - package: true, - runtime: true, - javascript_recovery: true, - readiness: false, - }, - ], - [ - "scripts/lib/runtime-admission.d.mts", - { - code: true, - package: true, - runtime: true, - javascript_recovery: true, - readiness: false, - }, - ], [ "tests/conformance/readiness/report/reconstructionReadiness.ts", { @@ -2152,6 +2122,21 @@ it.each([ expect(await classifyPaths([path])).toMatchObject(expected); }); +it.each([ + "scripts/lib/cli-compiled-runtime.mjs", + "scripts/lib/cli-process-environment.mjs", + "scripts/lib/runtime-admission.mjs", + "scripts/lib/runtime-admission.d.mts", +])("selects packaged CLI runtime checks for %s", async (path) => { + expect(await classifyPaths([path])).toMatchObject({ + code: true, + package: true, + runtime: true, + javascript_recovery: true, + readiness: false, + }); +}); + it("unions provider scopes across mixed changes and deletions", async () => { const { directory } = await fixture(); const base = await change(directory, ["src/evm/client.ts"]); diff --git a/tests/support/cli/cliCommandSessionWorker.mjs b/tests/support/cli/cliCommandSessionWorker.mjs index 5b020ceae5..a9a074e58f 100644 --- a/tests/support/cli/cliCommandSessionWorker.mjs +++ b/tests/support/cli/cliCommandSessionWorker.mjs @@ -1,8 +1,11 @@ import { Readable, Writable } from "node:stream"; -import { access } from "node:fs/promises"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; +import { + compiledRuntimeExists, + missingCompiledRuntimeMessage, +} from "../../../scripts/lib/cli-compiled-runtime.mjs"; import { prepareCliProcessEnvironment } from "../../../scripts/lib/cli-process-environment.mjs"; import { withVerifierCleanup } from "../../../scripts/lib/verifier-cleanup.mjs"; import { @@ -35,10 +38,8 @@ prepareCliProcessEnvironment( process.platform, packageJson.version, ); -if (!(await compiledRuntimeExists(runtimeFiles))) { - process.stderr.write( - `REA's compiled runtime is missing. Run \`npm ci && npm run build:cached\` in ${packageRoot} to install dependencies and build REA, then restart it. If this is an installed package, reinstall rea-agents.\n`, - ); +if (!(await compiledRuntimeExists(packageRoot, runtimeFiles))) { + process.stderr.write(missingCompiledRuntimeMessage(packageRoot)); process.exit(1); } @@ -253,24 +254,3 @@ function captureWrite(chunks) { return true; }; } - -async function compiledRuntimeExists(paths) { - for (const path of paths) { - try { - await access(resolve(packageRoot, path)); - } catch (cause) { - if (isMissing(cause)) return false; - throw cause; - } - } - return true; -} - -function isMissing(cause) { - return ( - typeof cause === "object" && - cause !== null && - "code" in cause && - cause.code === "ENOENT" - ); -}