The Open Framework for Building Agents
fix(eve): bootstrap compiled vendors before CLI build (#2714)
prhafde3161e3033
diff --git a/.changeset/fix-selfmod-compiled-vendor-build.md b/.changeset/fix-selfmod-compiled-vendor-build.mdnew file mode 100644index 000000000..2d6d4c19c--- /dev/null+++ b/.changeset/fix-selfmod-compiled-vendor-build.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Ensure the workspace CLI restores missing compiled vendor modules before rebuilding itself.diff --git a/packages/eve/bin/eve.js b/packages/eve/bin/eve.jsindex 3f84f555a..d8546a2fd 100755--- a/packages/eve/bin/eve.js+++ b/packages/eve/bin/eve.js@@ -102,6 +102,7 @@ async function canBuildWorkspaceCli({ exists, packageRoot, postBuildScriptPathspackageRoot,}),resolve(packageRoot, "src"),+ vendorCompiledScriptPath({ packageRoot }),...postBuildScriptPaths,]) {if (!(await exists(requiredPath))) {@@ -274,6 +275,9 @@ export async function ensureBuiltCli(overrides = {}, dependencies = {}) {);}+ await executeCommand(process.execPath, [vendorCompiledScriptPath(options)], {+ cwd: options.packageRoot,+ });await executeCommand(process.execPath,[resolveTscCliPath({ tscCliPath: options.tscCliPath }), "-p", "tsconfig.json"],diff --git a/packages/eve/scripts/vendor-compiled/_shared.mjs b/packages/eve/scripts/vendor-compiled/_shared.mjsindex 73813ee88..a2ddcbe86 100644--- a/packages/eve/scripts/vendor-compiled/_shared.mjs+++ b/packages/eve/scripts/vendor-compiled/_shared.mjs@@ -427,7 +427,10 @@ export async function runVendor({const desiredStamp = await computeStamp({ scriptFiles, modules, packageRoot, toolVersions });- if (stampMatches(desiredStamp, await readExistingStamp(stampPath))) {+ if (+ stampMatches(desiredStamp, await readExistingStamp(stampPath)) &&+ (await compiledModuleEntrypointsExist({ compiledRoot, modules }))+ ) {console.log("Compiled vendor modules are already up to date.");return;}@@ -435,11 +438,19 @@ export async function runVendor({await acquireLock(lockPath);try {// A peer process may have completed while we waited for the lock.- if (stampMatches(desiredStamp, await readExistingStamp(stampPath))) {+ if (+ stampMatches(desiredStamp, await readExistingStamp(stampPath)) &&+ (await compiledModuleEntrypointsExist({ compiledRoot, modules }))+ ) {console.log("Compiled vendor modules are already up to date.");return;}+ // A matching stamp must not survive a repair attempt. Otherwise another+ // process could accept directories created by an incomplete build as a+ // valid cache hit while this process is writing, or after it fails.+ await rm(stampPath, { force: true });+const bundledModules = modules.filter((module) => module.typeOnly !== true);const typeOnlyModules = modules.filter((module) => module.typeOnly === true);@@ -461,6 +472,21 @@ export async function runVendor({}}+async function compiledModuleEntrypointsExist({ compiledRoot, modules }) {+ const paths = modules.flatMap((module) =>+ (module.entries ?? [{ outputPath: "index" }]).map((entry) =>+ join(compiledRoot, module.compiledPath, `${entry.outputPath}.js`),+ ),+ );+ const entries = await Promise.all(+ paths.map(async (path) => {+ const stats = await stat(path).catch(() => null);+ return stats?.isFile() ?? false;+ }),+ );+ return entries.every(Boolean);+}+/*** Removes top-level entries under `compiledRoot` that no configured module* claims, so output for vendored packages that were since removed (fordiff --git a/packages/eve/test/bin-bootstrap.test.ts b/packages/eve/test/bin-bootstrap.test.tsindex 8eb39ef68..78c07d2a0 100644--- a/packages/eve/test/bin-bootstrap.test.ts+++ b/packages/eve/test/bin-bootstrap.test.ts@@ -16,8 +16,26 @@ const workspaceBuildInputPaths = new Set([...bootstrapOptions.postBuildScriptPaths,`${bootstrapOptions.packageRoot}/bin`,`${bootstrapOptions.packageRoot}/src`,+ `${bootstrapOptions.packageRoot}/scripts/vendor-compiled.mjs`,`${bootstrapOptions.packageRoot}/tsconfig.json`,]);+const workspaceBuildCommands = [+ [+ process.execPath,+ [`${bootstrapOptions.packageRoot}/scripts/vendor-compiled.mjs`],+ { cwd: bootstrapOptions.packageRoot },+ ],+ [+ process.execPath,+ [bootstrapOptions.tscCliPath, "-p", "tsconfig.json"],+ { cwd: bootstrapOptions.packageRoot },+ ],+ ...bootstrapOptions.postBuildScriptPaths.map((scriptPath) => [+ process.execPath,+ [scriptPath],+ { cwd: bootstrapOptions.packageRoot },+ ]),+];describe("eve CLI bootstrap", () => {it("fails before bootstrapping when Node.js is older than 24", async () => {@@ -133,38 +151,7 @@ describe("eve CLI bootstrap", () => {runCommand,});- expect(runCommand).toHaveBeenNthCalledWith(- 1,- process.execPath,- [bootstrapOptions.tscCliPath, "-p", "tsconfig.json"],- {- cwd: bootstrapOptions.packageRoot,- },- );- expect(runCommand).toHaveBeenNthCalledWith(- 2,- process.execPath,- [bootstrapOptions.postBuildScriptPaths[0]],- {- cwd: bootstrapOptions.packageRoot,- },- );- expect(runCommand).toHaveBeenNthCalledWith(- 3,- process.execPath,- [bootstrapOptions.postBuildScriptPaths[1]],- {- cwd: bootstrapOptions.packageRoot,- },- );- expect(runCommand).toHaveBeenNthCalledWith(- 4,- process.execPath,- [bootstrapOptions.postBuildScriptPaths[2]],- {- cwd: bootstrapOptions.packageRoot,- },- );+ expect(runCommand.mock.calls).toEqual(workspaceBuildCommands);expect(importModule).toHaveBeenCalledWith("file:///workspace/packages/eve/dist/src/cli/run.js");expect(runCli).toHaveBeenCalledWith(["build"]);});@@ -187,38 +174,7 @@ describe("eve CLI bootstrap", () => {runCommand,});- expect(runCommand).toHaveBeenNthCalledWith(- 1,- process.execPath,- [bootstrapOptions.tscCliPath, "-p", "tsconfig.json"],- {- cwd: bootstrapOptions.packageRoot,- },- );- expect(runCommand).toHaveBeenNthCalledWith(- 2,- process.execPath,- [bootstrapOptions.postBuildScriptPaths[0]],- {- cwd: bootstrapOptions.packageRoot,- },- );- expect(runCommand).toHaveBeenNthCalledWith(- 3,- process.execPath,- [bootstrapOptions.postBuildScriptPaths[1]],- {- cwd: bootstrapOptions.packageRoot,- },- );- expect(runCommand).toHaveBeenNthCalledWith(- 4,- process.execPath,- [bootstrapOptions.postBuildScriptPaths[2]],- {- cwd: bootstrapOptions.packageRoot,- },- );+ expect(runCommand.mock.calls).toEqual(workspaceBuildCommands);expect(importModule).toHaveBeenCalledWith("file:///workspace/packages/eve/dist/src/cli/run.js");expect(runCli).toHaveBeenCalledWith(["dev"]);});@@ -248,6 +204,24 @@ describe("eve CLI bootstrap", () => {expect(runCli).toHaveBeenCalledWith(["info"]);});+ it("does not attempt a workspace build without the vendor script", async () => {+ const availablePaths = new Set(workspaceBuildInputPaths);+ availablePaths.delete(`${bootstrapOptions.packageRoot}/scripts/vendor-compiled.mjs`);+ const exists = vi.fn(async (path: string) => availablePaths.has(path));+ const runCommand = vi.fn(async () => {});++ await expect(+ ensureBuiltCli(bootstrapOptions, {+ exists,+ runCommand,+ }),+ ).rejects.toThrow(+ `eve package at ${bootstrapOptions.packageRoot} does not include the sources required to rebuild the CLI.`,+ );++ expect(runCommand).not.toHaveBeenCalled();+ });+it("fails when the CLI is missing from a packaged install", async () => {const exists = vi.fn(async () => false);const runCommand = vi.fn(async () => {});