Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): fail fast on unsupported microsandbox versions (#4888)

roboeve[bot]2de401193b73
diff --git a/.changeset/microsandbox-unsupported-version.md b/.changeset/microsandbox-unsupported-version.md
new file mode 100644
index 000000000..52d518a16
--- /dev/null
+++ b/.changeset/microsandbox-unsupported-version.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Fail fast with an actionable error when the project has an unsupported `microsandbox` version (such as 0.7), instead of every sandbox operation throwing `isInstalled is not a function`.
diff --git a/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.integration.test.ts b/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.integration.test.ts
index 70301da3f..a2b7129ef 100644
--- a/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.integration.test.ts
+++ b/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.integration.test.ts
@@ -24,7 +24,7 @@ describe("loadMicrosandboxModule", () => {
// Regression for #3420: a project that already has microsandbox@^0.7
// loads a module that exports `isRuntimeInstalled` but not `isInstalled`
// or `setup`.
- it.fails("rejects an incompatible microsandbox API with the installed version and fix", async () => {
+ it("rejects an incompatible microsandbox API with the installed version and fix", async () => {
const appRoot = await mkdtemp(join(tmpdir(), "eve-microsandbox-07-"));
appRoots.push(appRoot);
const packageRoot = join(appRoot, "node_modules", "microsandbox");
diff --git a/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.ts b/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.ts
index 97da22484..d61597970 100644
--- a/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.ts
+++ b/packages/eve/src/execution/sandbox/bindings/microsandbox-runtime.ts
@@ -28,6 +28,7 @@ import {
importInstalledEnginePackage,
isEveDevEnvironment,
} from "#internal/application/optional-package-install.js";
+import { readInstalledPackageVersion } from "#internal/application/optional-package-import.js";
import { withDevelopmentSandboxTags } from "#execution/sandbox/development-run.js";
import { SANDBOX_AGENT_ENV } from "#execution/sandbox/session.js";
import { WORKSPACE_ROOT } from "#runtime/workspace/types.js";
@@ -500,6 +501,8 @@ export async function loadMicrosandboxModule(input: {
}),
);
+ await assertSupportedMicrosandboxApi(module, input.host);
+
input.log?.("checking microsandbox VM runtime");
if (!module.isInstalled()) {
if (!input.options.setup.autoInstall || !isEveDevEnvironment()) {
@@ -519,6 +522,32 @@ export async function loadMicrosandboxModule(input: {
return module;
}
+/**
+ * microsandbox 0.7 renamed `isInstalled` and removed `setup`. Projects that
+ * already depend on it would otherwise fail every sandbox operation with a
+ * bare `TypeError`.
+ */
+async function assertSupportedMicrosandboxApi(
+ module: MicrosandboxModule,
+ host: SandboxProviderHost,
+): Promise<void> {
+ const loaded = module as Partial<Pick<MicrosandboxModule, "isInstalled" | "setup">>;
+ if (typeof loaded.isInstalled === "function" && typeof loaded.setup === "function") {
+ return;
+ }
+
+ const version = await readInstalledPackageVersion({
+ appRoot: host.resolveProjectPath("."),
+ packageName: MICROSANDBOX_PACKAGE_NAME,
+ }).catch(() => undefined);
+ const installed =
+ version === undefined ? "The installed `microsandbox`" : `\`microsandbox@${version}\``;
+ throw new Error(
+ `${installed} is not supported by eve. Install the supported version with ` +
+ `\`pnpm add -D ${MICROSANDBOX_INSTALL_SPECIFIER}\`, or use DockerSandbox or VercelSandbox instead.`,
+ );
+}
+
async function withProgressHeartbeat<T>(
message: string,
log: ((message: string) => void) | undefined,
diff --git a/packages/eve/src/internal/application/optional-package-import.ts b/packages/eve/src/internal/application/optional-package-import.ts
index 16ad73ef3..9e03d9e91 100644
--- a/packages/eve/src/internal/application/optional-package-import.ts
+++ b/packages/eve/src/internal/application/optional-package-import.ts
@@ -30,6 +30,18 @@ export async function resolveInstalledEnginePackageEntrypointHref(input: {
return pathToFileURL(join(packageRoot, entry)).href;
}
+/** Reads the version of an optional package installed in the application. */
+export async function readInstalledPackageVersion(input: {
+ readonly appRoot: string;
+ readonly packageName: string;
+}): Promise<string | undefined> {
+ const packageJsonPath = join(findInstalledPackageRoot(input), "package.json");
+ const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8")) as {
+ readonly version?: unknown;
+ };
+ return typeof packageJson.version === "string" ? packageJson.version : undefined;
+}
+
function findInstalledPackageRoot(input: {
readonly appRoot: string;
readonly packageName: string;