Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

Preserve inherited package command output (#2202)

OwenKephart1473e2a78abb
diff --git a/.changeset/structured-package-process.md b/.changeset/structured-package-process.md
new file mode 100644
index 000000000..0a0a07029
--- /dev/null
+++ b/.changeset/structured-package-process.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Capture package-manager command identity, termination, bounded in-memory output, and workspace probes as structured process results for consistent setup diagnostics.
diff --git a/packages/eve/src/cli/commands/deploy.integration.test.ts b/packages/eve/src/cli/commands/deploy.integration.test.ts
index af0994415..c00c12571 100644
--- a/packages/eve/src/cli/commands/deploy.integration.test.ts
+++ b/packages/eve/src/cli/commands/deploy.integration.test.ts
@@ -5,6 +5,7 @@ import { join } from "node:path";
import { afterEach, describe, expect, test, vi } from "vitest";
import { createFakePrompter } from "#internal/testing/fake-prompter.js";
+import { packageInstallResult } from "#internal/testing/package-process.js";
import type { DeployProjectDeps } from "#setup/boxes/deploy-project.js";
import type { DeploymentInfo } from "#setup/project-resolution.js";
@@ -49,8 +50,8 @@ function createDeployProjectDeps() {
kind: "pnpm",
source: "default",
})),
- runPackageManagerInstall: vi.fn<DeployProjectDeps["runPackageManagerInstall"]>(
- async () => true,
+ runPackageManagerInstall: vi.fn<DeployProjectDeps["runPackageManagerInstall"]>(async () =>
+ packageInstallResult(),
),
detectDeployment: vi.fn<DeployProjectDeps["detectDeployment"]>(async () => DEPLOYED),
syncHostFrameworkPreset: vi.fn<DeployProjectDeps["syncHostFrameworkPreset"]>(async () => {}),
diff --git a/packages/eve/src/cli/commands/extension-init.integration.test.ts b/packages/eve/src/cli/commands/extension-init.integration.test.ts
index d1775157a..7bfb47c47 100644
--- a/packages/eve/src/cli/commands/extension-init.integration.test.ts
+++ b/packages/eve/src/cli/commands/extension-init.integration.test.ts
@@ -4,6 +4,7 @@ import { join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
+import { packageInstallResult } from "#internal/testing/package-process.js";
import { detectPackageManager } from "#setup/package-manager.js";
import {
scaffoldExtensionProject,
@@ -66,7 +67,7 @@ function dependencies(
};
return scaffoldExtensionProject(merged);
},
- runPackageManagerInstall: vi.fn(async () => true),
+ runPackageManagerInstall: vi.fn(async () => packageInstallResult()),
tryInitializeGit: vi.fn(async () => gitResult),
};
}
diff --git a/packages/eve/src/cli/commands/extension-init.ts b/packages/eve/src/cli/commands/extension-init.ts
index 29344a6e4..ca8cde9fe 100644
--- a/packages/eve/src/cli/commands/extension-init.ts
+++ b/packages/eve/src/cli/commands/extension-init.ts
@@ -17,7 +17,11 @@ import {
} from "#setup/package-manager.js";
import { pathExists } from "#setup/path-exists.js";
import { parseProjectName } from "#setup/project-name.js";
-import { runPackageManagerInstall } from "#setup/primitives/index.js";
+import {
+ packageManagerInstallFailureMessage,
+ packageManagerInstallSucceeded,
+ runPackageManagerInstall,
+} from "#setup/primitives/index.js";
import type { ProcessOutputLine } from "#setup/primitives/process-output.js";
import { blockingCreateInPlaceEntries } from "#setup/scaffold/create-in-place.js";
import {
@@ -280,7 +284,7 @@ export async function runExtensionInitCommand(
const installStartedAt = dependencies.now();
const installFailureOutput: string[] = [];
const recentInstallOutput: string[] = [];
- const installed = await dependencies.runPackageManagerInstall(packageManager, projectPath, {
+ const installResult = await dependencies.runPackageManagerInstall(packageManager, projectPath, {
bypassMinimumReleaseAge: true,
progressDetails: process.stdout.isTTY === true && !debug,
onOutput: (line) => {
@@ -299,12 +303,16 @@ export async function runExtensionInitCommand(
},
});
installElapsedMs = dependencies.now() - installStartedAt;
- if (!installed) {
+ if (!packageManagerInstallSucceeded(installResult)) {
initLog.debug("dependency installation failed", { ms: installElapsedMs });
progress.stop();
const failureOutput =
installFailureOutput.length > 0 ? installFailureOutput : recentInstallOutput;
for (const line of failureOutput) logger.error(line);
+ if (failureOutput.length === 0) {
+ const message = packageManagerInstallFailureMessage(installResult);
+ if (message !== undefined) logger.error(message);
+ }
throw new Error(`Failed to install dependencies in "${projectPath}".`);
}
initLog.debug("dependencies installed", { ms: installElapsedMs });
diff --git a/packages/eve/src/cli/commands/init.integration.test.ts b/packages/eve/src/cli/commands/init.integration.test.ts
index 28ae69420..b9b7ac2f8 100644
--- a/packages/eve/src/cli/commands/init.integration.test.ts
+++ b/packages/eve/src/cli/commands/init.integration.test.ts
@@ -6,6 +6,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { MockScreen } from "#cli/dev/tui/test/mock-terminal.js";
import { stripAnsi } from "#cli/ui/terminal-text.js";
+import { packageInstallResult, packageProcessResult } from "#internal/testing/package-process.js";
import { DEFAULT_AGENT_MODEL_ID } from "#shared/default-agent-model.js";
import { detectPackageManager } from "#setup/package-manager.js";
import {
@@ -111,10 +112,10 @@ function dependencies(
...options,
webPackageVersions: { ...WEB_VERSIONS, ...options.webPackageVersions },
}),
- runPackageManagerInstall: vi.fn(async () => true),
+ runPackageManagerInstall: vi.fn(async () => packageInstallResult()),
selectInitHandoff: vi.fn(async () => "eve-dev"),
spawnCodingAgentRepl: vi.fn(async () => true),
- spawnPackageManager: vi.fn(async () => true),
+ spawnPackageManager: vi.fn(async () => packageProcessResult()),
tryInitializeGit: vi.fn(async () => gitResult),
validateModelSlug: vi.fn(async () => null),
};
@@ -953,7 +954,7 @@ describe("runInitCommand", () => {
await mkdir(projectRoot, { recursive: true });
const output = logger();
const deps = dependencies();
- deps.runPackageManagerInstall.mockResolvedValue(false);
+ deps.runPackageManagerInstall.mockResolvedValue(packageInstallResult(1));
await expect(runInitCommand(output, projectRoot, ".", {}, deps)).rejects.toThrow("restored");
@@ -1184,7 +1185,7 @@ describe("runInitCommand", () => {
deps.runPackageManagerInstall.mockImplementation(async (_kind, _projectPath, options) => {
options?.onOutput?.({ stream: "stdout", text: "Packages: +12" });
options?.onOutput?.({ stream: "stderr", text: "ERR_PNPM_FETCH_404 not found" });
- return false;
+ return packageInstallResult(1);
});
await expect(runInitCommand(output, parentDirectory, "my-agent", {}, deps)).rejects.toThrow(
@@ -1213,12 +1214,32 @@ describe("runInitCommand", () => {
);
});
+ it("prints a spawn failure when installation produces no child output", async () => {
+ const parentDirectory = await mkdtemp(join(tmpdir(), "eve-init-spawn-fail-"));
+ const output = logger();
+ const deps = dependencies();
+ deps.runPackageManagerInstall.mockResolvedValue({
+ kind: "installed",
+ result: {
+ command: { executable: "pnpm", args: ["install"], cwd: parentDirectory },
+ termination: { kind: "spawn-error", code: "ENOENT", message: "spawn pnpm ENOENT" },
+ stdout: "",
+ },
+ });
+
+ await expect(runInitCommand(output, parentDirectory, "my-agent", {}, deps)).rejects.toThrow(
+ "Failed to install dependencies",
+ );
+
+ expect(output.errors).toEqual(["pnpm was not found. Install it before running this step."]);
+ });
+
it("preserves an existing host after install failure and prints the retry command", async () => {
const parentDirectory = await mkdtemp(join(tmpdir(), "eve-init-host-install-fail-"));
const projectRoot = await createHostProject(parentDirectory);
const output = logger();
const deps = dependencies();
- deps.runPackageManagerInstall.mockResolvedValue(false);
+ deps.runPackageManagerInstall.mockResolvedValue(packageInstallResult(1));
await expect(runInitCommand(output, projectRoot, ".", {}, deps)).rejects.toThrow(
`install dependencies with pnpm in "${projectRoot}"`,
@@ -1247,7 +1268,7 @@ describe("runInitCommand", () => {
stream: "stderr",
text: "npm error ERESOLVE unable to resolve dependency tree",
});
- return false;
+ return packageInstallResult(1);
});
await expect(runInitCommand(output, parentDirectory, "my-agent", {}, deps)).rejects.toThrow(
@@ -1270,7 +1291,7 @@ describe("runInitCommand", () => {
options?.onOutput?.({ stream: "stderr", text: `npm silly step ${index}` });
}
options?.onOutput?.({ stream: "stderr", text: "" });
- return false;
+ return packageInstallResult(1);
});
await expect(runInitCommand(output, parentDirectory, "my-agent", {}, deps)).rejects.toThrow(
@@ -1288,7 +1309,7 @@ describe("runInitCommand", () => {
const deps = dependencies();
deps.runPackageManagerInstall.mockImplementation(async (_kind, _projectPath, options) => {
options?.onOutput?.({ stream: "stdout", text: "Progress: resolved 62, reused 62, done" });
- return true;
+ return packageInstallResult();
});
const previous = process.env.EVE_LOG_LEVEL;
@@ -1322,7 +1343,7 @@ describe("runInitCommand", () => {
const parentDirectory = await mkdtemp(join(tmpdir(), "eve-init-debug-failure-"));
const output = logger();
const deps = dependencies();
- deps.runPackageManagerInstall.mockResolvedValue(false);
+ deps.runPackageManagerInstall.mockResolvedValue(packageInstallResult(1));
const previous = process.env.EVE_LOG_LEVEL;
process.env.EVE_LOG_LEVEL = "debug";
@@ -1374,7 +1395,7 @@ describe("runInitCommand", () => {
text: "npm http fetch GET https://registry.npmjs.org/@vercel%2fconnect attempt 1 failed with ENOTFOUND",
});
options?.onOutput?.({ stream: "stdout", text: `Downloading ${"package".repeat(20)}` });
- return true;
+ return packageInstallResult();
});
try {
diff --git a/packages/eve/src/cli/commands/init.ts b/packages/eve/src/cli/commands/init.ts
index 970835366..a79bfcaba 100644
--- a/packages/eve/src/cli/commands/init.ts
+++ b/packages/eve/src/cli/commands/init.ts
@@ -20,6 +20,9 @@ import {
import { pathExists } from "#setup/path-exists.js";
import {
eveDevArguments,
+ packageManagerInstallFailureMessage,
+ packageManagerInstallSucceeded,
+ resultSucceeded,
runPackageManagerInstall,
spawnPackageManager,
} from "#setup/primitives/index.js";
@@ -429,7 +432,7 @@ async function runInitSteps(input: {
const installStartedAt = dependencies.now();
const installFailureOutput: string[] = [];
const recentInstallOutput: string[] = [];
- const installed = await dependencies.runPackageManagerInstall(
+ const installResult = await dependencies.runPackageManagerInstall(
project.packageManager,
project.projectPath,
{
@@ -454,12 +457,16 @@ async function runInitSteps(input: {
},
);
const installElapsedMs = dependencies.now() - installStartedAt;
- if (!installed) {
+ if (!packageManagerInstallSucceeded(installResult)) {
initLog.debug("dependency installation failed", { ms: installElapsedMs });
progress.stop();
const failureOutput =
installFailureOutput.length > 0 ? installFailureOutput : recentInstallOutput;
for (const line of failureOutput) logger.error(line);
+ if (failureOutput.length === 0) {
+ const message = packageManagerInstallFailureMessage(installResult);
+ if (message !== undefined) logger.error(message);
+ }
if (project.failurePolicy !== "preserve") {
const cleaned = await cleanupFreshInitTarget(
@@ -623,11 +630,13 @@ export async function runInitCommand(
logger.log(pc.dim(freshScaffold ? "$ eve dev --input /model" : "$ eve dev"));
if (
- !(await dependencies.spawnPackageManager(
- result.packageManager,
- result.projectPath,
- devArguments,
- ))
+ !resultSucceeded(
+ await dependencies.spawnPackageManager(
+ result.packageManager,
+ result.projectPath,
+ devArguments,
+ ),
+ )
) {
throw new Error(`Development server exited unsuccessfully in "${result.projectPath}".`);
}
diff --git a/packages/eve/src/internal/testing/package-process.ts b/packages/eve/src/internal/testing/package-process.ts
new file mode 100644
index 000000000..c92684821
--- /dev/null
+++ b/packages/eve/src/internal/testing/package-process.ts
@@ -0,0 +1,16 @@
+import type {
+ PackageManagerInstallResult,
+ PackageManagerProcessResult,
+} from "#setup/primitives/index.js";
+
+export function packageProcessResult(code = 0): PackageManagerProcessResult {
+ return {
+ command: { executable: "pnpm", args: ["install"], cwd: "/app" },
+ termination: { kind: "exit", code },
+ stdout: "",
+ };
+}
+
+export function packageInstallResult(code = 0): PackageManagerInstallResult {
+ return { kind: "installed", result: packageProcessResult(code) };
+}
diff --git a/packages/eve/src/setup/boxes/deploy-project.test.ts b/packages/eve/src/setup/boxes/deploy-project.test.ts
index 6f59287e3..8bdb6d215 100644
--- a/packages/eve/src/setup/boxes/deploy-project.test.ts
+++ b/packages/eve/src/setup/boxes/deploy-project.test.ts
@@ -4,6 +4,7 @@ import { HumanActionRequiredError } from "#setup/human-action.js";
import type { DeploymentInfo } from "#setup/project-resolution.js";
import { createFakePrompter } from "#internal/testing/fake-prompter.js";
+import { packageInstallResult } from "#internal/testing/package-process.js";
import type { Prompter } from "../prompter.js";
import { createDefaultSetupState, type SetupState } from "../state.js";
@@ -30,8 +31,8 @@ function createDeps() {
kind: "pnpm",
source: "default",
})),
- runPackageManagerInstall: vi.fn<DeployProjectDeps["runPackageManagerInstall"]>(
- async () => true,
+ runPackageManagerInstall: vi.fn<DeployProjectDeps["runPackageManagerInstall"]>(async () =>
+ packageInstallResult(),
),
detectDeployment: vi.fn<DeployProjectDeps["detectDeployment"]>(async () => DEPLOYED),
syncHostFrameworkPreset: vi.fn<DeployProjectDeps["syncHostFrameworkPreset"]>(async () => {}),
@@ -271,7 +272,7 @@ describe("deployProject box", () => {
it("surfaces failed dependency installation before any deploy", async () => {
const deps = createDeps();
- deps.runPackageManagerInstall.mockResolvedValue(false);
+ deps.runPackageManagerInstall.mockResolvedValue(packageInstallResult(1));
const box = headlessBox({ deps });
await expect(runHeadless([box], pendingState(), silentSink)).rejects.toThrow(
diff --git a/packages/eve/src/setup/boxes/deploy-project.ts b/packages/eve/src/setup/boxes/deploy-project.ts
index 1f61b54e4..4426c09c3 100644
--- a/packages/eve/src/setup/boxes/deploy-project.ts
+++ b/packages/eve/src/setup/boxes/deploy-project.ts
@@ -1,7 +1,10 @@
import { createPromptCommandOutput, withPhase, type ChannelSetupLog } from "#setup/cli/index.js";
import { HumanActionRequiredError } from "#setup/human-action.js";
import { detectPackageManager } from "#setup/package-manager.js";
-import { runPackageManagerInstall } from "#setup/primitives/pm/run.js";
+import {
+ packageManagerInstallSucceeded,
+ runPackageManagerInstall,
+} from "#setup/primitives/pm/run.js";
import { runVercel } from "#setup/primitives/run-vercel.js";
import {
@@ -155,13 +158,13 @@ export function deployProject(
if (!state.deploymentDependenciesInstalled) {
const packageManager = await deps.detectPackageManager(projectPath);
- const installed = await withPhase(
+ const installResult = await withPhase(
log,
`Installing project dependencies before deployment (${packageManager.kind} install)...`,
() =>
deps.runPackageManagerInstall(packageManager.kind, projectPath, { onOutput, signal }),
);
- if (!installed) {
+ if (!packageManagerInstallSucceeded(installResult)) {
signal?.throwIfAborted();
throw new Error("Dependency installation failed. Deployment did not start.");
}
diff --git a/packages/eve/src/setup/flows/deploy.test.ts b/packages/eve/src/setup/flows/deploy.test.ts
index 02168da96..8be1f3d58 100644
--- a/packages/eve/src/setup/flows/deploy.test.ts
+++ b/packages/eve/src/setup/flows/deploy.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it, vi } from "vitest";
import { createFakePrompter } from "#internal/testing/fake-prompter.js";
+import { packageInstallResult } from "#internal/testing/package-process.js";
import type { DeployProjectDeps } from "#setup/boxes/deploy-project.js";
import type { LinkProjectDeps } from "#setup/boxes/link-project.js";
import type { ResolveProvisioningDeps } from "#setup/boxes/resolve-provisioning.js";
@@ -26,8 +27,8 @@ function createDeployProjectDeps(probe: DeploymentInfo = DEPLOYED) {
kind: "pnpm",
source: "default",
})),
- runPackageManagerInstall: vi.fn<DeployProjectDeps["runPackageManagerInstall"]>(
- async () => true,
+ runPackageManagerInstall: vi.fn<DeployProjectDeps["runPackageManagerInstall"]>(async () =>
+ packageInstallResult(),
),
detectDeployment: vi.fn<DeployProjectDeps["detectDeployment"]>(async () => probe),
syncHostFrameworkPreset: vi.fn<DeployProjectDeps["syncHostFrameworkPreset"]>(async () => {}),
diff --git a/packages/eve/src/setup/flows/install-vercel-cli.test.ts b/packages/eve/src/setup/flows/install-vercel-cli.test.ts
index a6ea3de7b..40bac239d 100644
--- a/packages/eve/src/setup/flows/install-vercel-cli.test.ts
+++ b/packages/eve/src/setup/flows/install-vercel-cli.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it, vi } from "vitest";
import { createFakePrompter } from "#internal/testing/fake-prompter.js";
+import { packageProcessResult } from "#internal/testing/package-process.js";
import type { DetectedPackageManager } from "#setup/package-manager.js";
import { runInstallVercelCliFlow, type InstallVercelCliDeps } from "./install-vercel-cli.js";
@@ -36,8 +37,8 @@ function run(
describe("runInstallVercelCliFlow", () => {
it("short-circuits when the CLI already resolves and never installs", async () => {
- const spawnPackageManager = vi.fn<InstallVercelCliDeps["spawnPackageManager"]>(
- async () => true,
+ const spawnPackageManager = vi.fn<InstallVercelCliDeps["spawnPackageManager"]>(async () =>
+ packageProcessResult(),
);
await expect(
run({ getVercelAuthStatus: statusProbe("logged-out") }, spawnPackageManager),
@@ -46,8 +47,8 @@ describe("runInstallVercelCliFlow", () => {
});
it("installs globally with the project's package manager, then re-probes", async () => {
- const spawnPackageManager = vi.fn<InstallVercelCliDeps["spawnPackageManager"]>(
- async () => true,
+ const spawnPackageManager = vi.fn<InstallVercelCliDeps["spawnPackageManager"]>(async () =>
+ packageProcessResult(),
);
// cli-missing before; logged-out (i.e. CLI now present) after.
await expect(
@@ -66,8 +67,8 @@ describe("runInstallVercelCliFlow", () => {
async (): Promise<DetectedPackageManager> => ({ kind: "yarn", source: "lockfile" }),
);
const runVercel = vi.fn<InstallVercelCliDeps["runVercel"]>(async () => true);
- const spawnPackageManager = vi.fn<InstallVercelCliDeps["spawnPackageManager"]>(
- async () => true,
+ const spawnPackageManager = vi.fn<InstallVercelCliDeps["spawnPackageManager"]>(async () =>
+ packageProcessResult(),
);
await expect(
@@ -123,8 +124,8 @@ describe("runInstallVercelCliFlow", () => {
});
it("reports failed when the install exits non-zero", async () => {
- const spawnPackageManager = vi.fn<InstallVercelCliDeps["spawnPackageManager"]>(
- async () => false,
+ const spawnPackageManager = vi.fn<InstallVercelCliDeps["spawnPackageManager"]>(async () =>
+ packageProcessResult(1),
);
await expect(
run({ getVercelAuthStatus: statusProbe("cli-missing") }, spawnPackageManager),
@@ -132,8 +133,8 @@ describe("runInstallVercelCliFlow", () => {
});
it("reports failed when the install exits clean but the CLI still isn't on PATH", async () => {
- const spawnPackageManager = vi.fn<InstallVercelCliDeps["spawnPackageManager"]>(
- async () => true,
+ const spawnPackageManager = vi.fn<InstallVercelCliDeps["spawnPackageManager"]>(async () =>
+ packageProcessResult(),
);
// Still cli-missing after a "successful" global install (bin not on PATH).
await expect(
@@ -142,8 +143,8 @@ describe("runInstallVercelCliFlow", () => {
});
it("uses the npm global form for an npm project", async () => {
- const spawnPackageManager = vi.fn<InstallVercelCliDeps["spawnPackageManager"]>(
- async () => true,
+ const spawnPackageManager = vi.fn<InstallVercelCliDeps["spawnPackageManager"]>(async () =>
+ packageProcessResult(),
);
await run(
{
diff --git a/packages/eve/src/setup/flows/install-vercel-cli.ts b/packages/eve/src/setup/flows/install-vercel-cli.ts
index 6aaabdf2e..eeb1b5aaa 100644
--- a/packages/eve/src/setup/flows/install-vercel-cli.ts
+++ b/packages/eve/src/setup/flows/install-vercel-cli.ts
@@ -1,6 +1,6 @@
import { createPromptCommandOutput } from "#setup/cli/index.js";
import { detectPackageManager, type PackageManagerKind } from "#setup/package-manager.js";
-import { runVercel, spawnPackageManager } from "#setup/primitives/index.js";
+import { resultSucceeded, runVercel, spawnPackageManager } from "#setup/primitives/index.js";
import { getVercelAuthStatus } from "#setup/vercel-project.js";
import type { Prompter } from "../prompter.js";
@@ -119,14 +119,21 @@ export async function runInstallVercelCliFlow(input: {
});
} else {
const manager = await deps.detectPackageManager(appRoot);
- ok = await withSpinner(prompter, `Installing the Vercel CLI with ${manager.kind}…`, () =>
- deps.spawnPackageManager(manager.kind, appRoot, globalInstallArguments(manager.kind), {
- onOutput,
- signal,
- // A global install never prompts; closing stdin keeps it from contending
- // with the TUI's raw-mode key consumer.
- nonInteractive: true,
- }),
+ ok = await withSpinner(prompter, `Installing the Vercel CLI with ${manager.kind}…`, async () =>
+ resultSucceeded(
+ await deps.spawnPackageManager(
+ manager.kind,
+ appRoot,
+ globalInstallArguments(manager.kind),
+ {
+ onOutput,
+ signal,
+ // A global install never prompts; closing stdin keeps it from contending
+ // with the TUI's raw-mode key consumer.
+ nonInteractive: true,
+ },
+ ),
+ ),
);
}
if (signal?.aborted === true) return { kind: "cancelled" };
diff --git a/packages/eve/src/setup/integrations/shared/scaffold.ts b/packages/eve/src/setup/integrations/shared/scaffold.ts
index 233e8436e..065adfe52 100644
--- a/packages/eve/src/setup/integrations/shared/scaffold.ts
+++ b/packages/eve/src/setup/integrations/shared/scaffold.ts
@@ -1,6 +1,9 @@
import { createPromptCommandOutput, withPhase, type ChannelSetupLog } from "#setup/cli/index.js";
import { detectPackageManager } from "#setup/package-manager.js";
-import { runPackageManagerInstall } from "#setup/primitives/pm/run.js";
+import {
+ packageManagerInstallSucceeded,
+ runPackageManagerInstall,
+} from "#setup/primitives/pm/run.js";
/** Effects used to install dependencies added by an integration scaffold. */
export interface IntegrationScaffoldDeps {
@@ -22,7 +25,7 @@ export async function installScaffoldDependencies(input: {
if (!input.changed || input.skip) return;
const deps = input.deps ?? defaultDeps;
const packageManager = await deps.detectPackageManager(input.projectPath);
- const installed = await withPhase(
+ const installResult = await withPhase(
input.log,
`Installing channel dependencies (${packageManager.kind} install)...`,
() =>
@@ -31,7 +34,7 @@ export async function installScaffoldDependencies(input: {
signal: input.signal,
}),
);
- if (installed) return;
+ if (packageManagerInstallSucceeded(installResult)) return;
input.log.warning(
`Dependency installation failed. The new channel stays unloadable until \`${packageManager.kind} install\` or a deploy succeeds.`,
);
diff --git a/packages/eve/src/setup/primitives/index.ts b/packages/eve/src/setup/primitives/index.ts
index 812f038cf..176b8b1f0 100644
--- a/packages/eve/src/setup/primitives/index.ts
+++ b/packages/eve/src/setup/primitives/index.ts
@@ -1,13 +1,21 @@
export {
eveDevArguments,
+ packageManagerInstallFailureMessage,
+ packageManagerInstallSucceeded,
runPackageManagerInstall,
runPnpmInstall,
spawnPackageManager,
spawnPnpm,
+ type PackageManagerInstallResult,
type RunInstallOptions,
type RunPackageManagerOptions,
type RunPnpmOptions,
} from "./pm/run.js";
+export {
+ resultSucceeded,
+ type PackageManagerProcessResult,
+ type PackageManagerProcessTermination,
+} from "./pm/process-result.js";
export {
getPackageManagerStrategy,
type PackageManagerConfigurationResult,
diff --git a/packages/eve/src/setup/primitives/pm/process-result.test.ts b/packages/eve/src/setup/primitives/pm/process-result.test.ts
new file mode 100644
index 000000000..373bffe81
--- /dev/null
+++ b/packages/eve/src/setup/primitives/pm/process-result.test.ts
@@ -0,0 +1,45 @@
+import { describe, expect, it } from "vitest";
+
+import { createPackageProcessStdoutCollector, resultSucceeded } from "./process-result.js";
+
+const command = { executable: "npm", args: ["install"], cwd: "/app" };
+
+function collect(options: { maxCapturedBytes?: number } = {}) {
+ return createPackageProcessStdoutCollector({ command, ...options });
+}
+
+describe("package process results", () => {
+ it("preserves split UTF-8 code points", () => {
+ const collector = collect();
+ const encoded = Buffer.from("ready 🚀\n");
+
+ collector.write(encoded.subarray(0, 8));
+ collector.write(encoded.subarray(8));
+ collector.end();
+
+ expect(collector.result({ kind: "exit", code: 0 }).stdout).toBe("ready 🚀\n");
+ });
+
+ it("bounds captured stdout without splitting a UTF-8 code point", () => {
+ const collector = collect({ maxCapturedBytes: 7 });
+ collector.write(Buffer.from("ready 🚀"));
+ collector.end();
+
+ expect(collector.result({ kind: "exit", code: 0 }).stdout).toBe("ready ");
+ });
+
+ it("distinguishes every termination kind from success", () => {
+ const collector = collect();
+ collector.end();
+
+ expect(resultSucceeded(collector.result({ kind: "exit", code: 0 }))).toBe(true);
+ expect(resultSucceeded(collector.result({ kind: "exit", code: 1 }))).toBe(false);
+ expect(resultSucceeded(collector.result({ kind: "signal", signal: "SIGTERM" }))).toBe(false);
+ expect(resultSucceeded(collector.result({ kind: "aborted" }))).toBe(false);
+ expect(
+ resultSucceeded(
+ collector.result({ kind: "spawn-error", code: "ENOENT", message: "missing" }),
+ ),
+ ).toBe(false);
+ });
+});
diff --git a/packages/eve/src/setup/primitives/pm/process-result.ts b/packages/eve/src/setup/primitives/pm/process-result.ts
new file mode 100644
index 000000000..e66145db0
--- /dev/null
+++ b/packages/eve/src/setup/primitives/pm/process-result.ts
@@ -0,0 +1,57 @@
+import { StringDecoder } from "node:string_decoder";
+
+const MAX_CAPTURED_STDOUT_BYTES = 64 * 1024;
+
+export type PackageManagerProcessTermination =
+ | { kind: "exit"; code: number }
+ | { kind: "signal"; signal: string }
+ | { kind: "aborted"; reason?: string }
+ | { kind: "spawn-error"; code?: string; message: string };
+
+export interface PackageManagerProcessResult {
+ command: { executable: string; args: readonly string[]; cwd: string };
+ termination: PackageManagerProcessTermination;
+ /** Byte-bounded stdout for commands whose caller needs to interpret it. */
+ stdout: string;
+}
+
+export function resultSucceeded(result: PackageManagerProcessResult): boolean {
+ return result.termination.kind === "exit" && result.termination.code === 0;
+}
+
+export interface PackageProcessStdoutCollector {
+ end(): void;
+ result(termination: PackageManagerProcessTermination): PackageManagerProcessResult;
+ write(chunk: Buffer): void;
+}
+
+export function createPackageProcessStdoutCollector(input: {
+ command: PackageManagerProcessResult["command"];
+ maxCapturedBytes?: number;
+}): PackageProcessStdoutCollector {
+ const maxCapturedBytes = input.maxCapturedBytes ?? MAX_CAPTURED_STDOUT_BYTES;
+ const decoder = new StringDecoder("utf8");
+ let stdout = "";
+ let capturedBytes = 0;
+
+ function capture(text: string): void {
+ for (const character of text) {
+ const characterBytes = Buffer.byteLength(character);
+ if (capturedBytes + characterBytes > maxCapturedBytes) return;
+ stdout += character;
+ capturedBytes += characterBytes;
+ }
+ }
+
+ return {
+ write(chunk) {
+ capture(decoder.write(chunk));
+ },
+ end() {
+ capture(decoder.end());
+ },
+ result(termination) {
+ return { command: input.command, termination, stdout };
+ },
+ };
+}
diff --git a/packages/eve/src/setup/primitives/pm/run.scenario.test.ts b/packages/eve/src/setup/primitives/pm/run.scenario.test.ts
index 647a690f3..0e8eda490 100644
--- a/packages/eve/src/setup/primitives/pm/run.scenario.test.ts
+++ b/packages/eve/src/setup/primitives/pm/run.scenario.test.ts
@@ -6,7 +6,7 @@ import { describe, expect, it } from "vitest";
import { useTemporaryDirectories } from "#internal/testing/use-temporary-app-roots.js";
import { pathExists } from "#setup/path-exists.js";
-import { runPackageManagerInstall } from "./run.js";
+import { packageManagerInstallSucceeded, runPackageManagerInstall } from "./run.js";
const createScratchDirectory = useTemporaryDirectories();
@@ -53,10 +53,12 @@ describe("runPackageManagerInstall (real pnpm)", () => {
});
const { lines, onOutput } = collectOutput();
- await expect(
- runPackageManagerInstall("pnpm", memberRoot, { onOutput }),
+ expect(
+ packageManagerInstallSucceeded(
+ await runPackageManagerInstall("pnpm", memberRoot, { onOutput }),
+ ),
lines.join("\n"),
- ).resolves.toBe(true);
+ ).toBe(true);
await expect(pathExists(join(memberRoot, "node_modules", "scratch-lib"))).resolves.toBe(true);
// The workspace owns the lockfile; a standalone (`--ignore-workspace`)
@@ -93,10 +95,12 @@ describe("runPackageManagerInstall (real pnpm)", () => {
await mkdir(join(nestedRoot, "node_modules"), { recursive: true });
const { lines, onOutput } = collectOutput();
- await expect(
- runPackageManagerInstall("pnpm", nestedRoot, { onOutput }),
+ expect(
+ packageManagerInstallSucceeded(
+ await runPackageManagerInstall("pnpm", nestedRoot, { onOutput }),
+ ),
lines.join("\n"),
- ).resolves.toBe(true);
+ ).toBe(true);
await expect(pathExists(join(nestedRoot, "node_modules", "scratch-local-dep"))).resolves.toBe(
true,
diff --git a/packages/eve/src/setup/primitives/pm/run.ts b/packages/eve/src/setup/primitives/pm/run.ts
index 3ea8dcf5f..1a6b992e4 100644
--- a/packages/eve/src/setup/primitives/pm/run.ts
+++ b/packages/eve/src/setup/primitives/pm/run.ts
@@ -4,6 +4,12 @@ import type { PackageManagerKind } from "../../package-manager.js";
import { armProcessAbort } from "../process-abort.js";
import { createProcessOutputBuffer, type ProcessOutputHandler } from "../process-output.js";
import { getPackageManagerStrategy } from "./index.js";
+import {
+ createPackageProcessStdoutCollector,
+ type PackageManagerProcessResult,
+ type PackageManagerProcessTermination,
+ resultSucceeded,
+} from "./process-result.js";
import {
hasAncestorPnpmWorkspace,
PNPM_WORKSPACE_MEMBERSHIP_ARGUMENTS,
@@ -13,189 +19,138 @@ import type { PackageManagerInstallOptions } from "./types.js";
/** Output routing options for setup-owned package manager commands. */
export interface RunPackageManagerOptions {
- /** Streams command output to a parent-owned renderer instead of writing outside it. */
+ /** Streams raw command output to a parent-owned local renderer. */
onOutput?: ProcessOutputHandler;
/** Aborts the package-manager subprocess when setup is interrupted. */
signal?: AbortSignal;
- /**
- * Closes stdin so the child cannot prompt — required when a repainting TUI
- * owns the terminal in raw mode, where an inherited stdin would let the child
- * contend for keystrokes.
- */
+ /** Retains bounded stdout for a caller that must interpret a command's output. */
+ captureStdout?: boolean;
+ /** Closes stdin so the child cannot contend with a parent-owned TUI. */
nonInteractive?: boolean;
}
-/**
- * stdin is closed under {@link RunPackageManagerOptions.nonInteractive}; stdout
- * and stderr pipe to `onOutput` when present, else inherit the terminal. The
- * fully-inherited default keeps its `"inherit"` shorthand so it stays identical
- * to the prior behavior.
- */
-function stdioForRun(
- options: RunPackageManagerOptions,
-): "inherit" | ["ignore" | "inherit", "pipe" | "inherit", "pipe" | "inherit"] {
- if (options.onOutput) {
- return [options.nonInteractive ? "ignore" : "inherit", "pipe", "pipe"];
- }
- return options.nonInteractive ? ["ignore", "inherit", "inherit"] : "inherit";
-}
-
/** @deprecated Use {@link RunPackageManagerOptions}. */
export type RunPnpmOptions = RunPackageManagerOptions;
-/** Runs the selected package manager in `projectRoot`. */
+function abortedTermination(signal: AbortSignal | undefined): PackageManagerProcessTermination {
+ const reason = signal?.reason;
+ return reason === undefined
+ ? { kind: "aborted" }
+ : { kind: "aborted", reason: reason instanceof Error ? reason.message : String(reason) };
+}
+
+/** Runs one package-manager command and returns its complete process evidence. */
export function spawnPackageManager(
kind: PackageManagerKind,
projectRoot: string,
args: readonly string[],
options: RunPackageManagerOptions = {},
-): Promise<boolean> {
- if (options.signal?.aborted === true) return Promise.resolve(false);
- return new Promise<boolean>((resolvePromise) => {
- const strategy = getPackageManagerStrategy(kind);
- const managerArgs = strategy.prepareArguments(projectRoot, args);
- const invocation = strategy.resolveInvocation(managerArgs);
- const outputBuffer = options.onOutput && createProcessOutputBuffer(options.onOutput);
- const child = spawn(invocation.command, [...invocation.args], {
- cwd: projectRoot,
- stdio: stdioForRun(options),
- shell: invocation.shell,
- signal: options.signal,
+): Promise<PackageManagerProcessResult> {
+ const strategy = getPackageManagerStrategy(kind);
+ const managerArgs = strategy.prepareArguments(projectRoot, args);
+ const invocation = strategy.resolveInvocation(managerArgs);
+ const command = {
+ executable: invocation.command,
+ args: [...invocation.args],
+ cwd: projectRoot,
+ };
+ if (options.signal?.aborted === true) {
+ return Promise.resolve({
+ command,
+ termination: abortedTermination(options.signal),
+ stdout: "",
});
+ }
+
+ return new Promise((resolvePromise) => {
+ const captureOutput = options.onOutput !== undefined || options.nonInteractive === true;
+ const lineBuffer = options.onOutput && createProcessOutputBuffer(options.onOutput);
+ const stdoutCollector =
+ options.captureStdout === true ? createPackageProcessStdoutCollector({ command }) : undefined;
+ let child;
+ try {
+ child = spawn(invocation.command, [...invocation.args], {
+ cwd: projectRoot,
+ stdio: captureOutput
+ ? [options.nonInteractive ? "ignore" : "inherit", "pipe", "pipe"]
+ : "inherit",
+ shell: invocation.shell,
+ signal: options.signal,
+ });
+ } catch (error) {
+ lineBuffer?.flush();
+ const failure = error as NodeJS.ErrnoException;
+ resolvePromise({
+ command,
+ termination: { kind: "spawn-error", code: failure.code, message: failure.message },
+ stdout: "",
+ });
+ return;
+ }
const disarmAbort = armProcessAbort(child, options.signal);
- child.stdout?.on("data", (chunk: Buffer) => outputBuffer?.write("stdout", chunk));
- child.stderr?.on("data", (chunk: Buffer) => outputBuffer?.write("stderr", chunk));
+ child.stdout?.on("data", (chunk: Buffer) => {
+ stdoutCollector?.write(chunk);
+ lineBuffer?.write("stdout", chunk);
+ });
+ child.stderr?.on("data", (chunk: Buffer) => lineBuffer?.write("stderr", chunk));
let settled = false;
- function settle(ok: boolean): void {
+ function settle(termination: PackageManagerProcessTermination): void {
if (settled) return;
settled = true;
- outputBuffer?.flush();
- resolvePromise(ok);
- }
- function reportFailure(message: string): void {
- if (options.onOutput) {
- options.onOutput({ stream: "stderr", text: message });
- } else {
- process.stderr.write(`\n${message}\n`);
- }
+ disarmAbort();
+ stdoutCollector?.end();
+ lineBuffer?.flush();
+ resolvePromise(stdoutCollector?.result(termination) ?? { command, termination, stdout: "" });
}
child.on("error", (error: NodeJS.ErrnoException) => {
if (options.signal?.aborted === true || error.name === "AbortError") {
- return;
- } else if (error.code === "ENOENT") {
- disarmAbort();
- reportFailure(`${kind} not found. Install it before running this step.`);
- settle(false);
+ settle(abortedTermination(options.signal));
} else {
- disarmAbort();
- reportFailure(`${kind} ${args.join(" ")} failed: ${error.message}`);
- settle(false);
+ settle({ kind: "spawn-error", code: error.code, message: error.message });
}
});
- child.on("close", (code) => {
- disarmAbort();
- settle(options.signal?.aborted === true ? false : code === 0);
+ child.on("close", (code, signal) => {
+ if (options.signal?.aborted === true) settle(abortedTermination(options.signal));
+ else if (typeof signal === "string") settle({ kind: "signal", signal });
+ else settle({ kind: "exit", code: code ?? 1 });
});
});
}
export interface RunInstallOptions extends RunPackageManagerOptions, PackageManagerInstallOptions {}
-interface PackageManagerCaptureResult {
- ok: boolean;
- stdout: string;
+export type PackageManagerInstallResult =
+ | { kind: "installed"; result: PackageManagerProcessResult }
+ | { kind: "workspace-probe-failed"; result: PackageManagerProcessResult }
+ | { kind: "workspace-probe-unrecognized"; result: PackageManagerProcessResult };
+
+export function packageManagerInstallSucceeded(result: PackageManagerInstallResult): boolean {
+ return result.kind === "installed" && resultSucceeded(result.result);
}
-function capturePackageManager(
- kind: PackageManagerKind,
- projectRoot: string,
- args: readonly string[],
- options: RunPackageManagerOptions,
-): Promise<PackageManagerCaptureResult> {
- if (options.signal?.aborted === true) {
- return Promise.resolve({ ok: false, stdout: "" });
+/** Returns an actionable explanation when a package-manager command produced no output. */
+export function packageManagerInstallFailureMessage(
+ result: PackageManagerInstallResult,
+): string | undefined {
+ if (result.result.termination.kind === "spawn-error") {
+ return result.result.termination.code === "ENOENT"
+ ? `${result.result.command.executable} was not found. Install it before running this step.`
+ : `Could not start ${result.result.command.executable}: ${result.result.termination.message}`;
}
- return new Promise<PackageManagerCaptureResult>((resolvePromise) => {
- const strategy = getPackageManagerStrategy(kind);
- const managerArgs = strategy.prepareArguments(projectRoot, args);
- const invocation = strategy.resolveInvocation(managerArgs);
- const child = spawn(invocation.command, [...invocation.args], {
- cwd: projectRoot,
- stdio: ["ignore", "pipe", "pipe"],
- shell: invocation.shell,
- signal: options.signal,
- });
- const disarmAbort = armProcessAbort(child, options.signal);
- const stdout: Buffer[] = [];
- const outputBuffer = options.onOutput && createProcessOutputBuffer(options.onOutput);
- child.stdout?.on("data", (chunk: Buffer) => stdout.push(chunk));
- child.stderr?.on("data", (chunk: Buffer) => outputBuffer?.write("stderr", chunk));
-
- let settled = false;
- function settle(ok: boolean): void {
- if (settled) return;
- settled = true;
- outputBuffer?.flush();
- resolvePromise({ ok, stdout: Buffer.concat(stdout).toString("utf8") });
- }
- function reportFailure(message: string): void {
- if (options.onOutput) {
- options.onOutput({ stream: "stderr", text: message });
- } else {
- process.stderr.write(`\n${message}\n`);
- }
- }
- function replayCapturedStdout(): void {
- const captured = Buffer.concat(stdout);
- if (captured.length === 0) return;
- if (outputBuffer) {
- outputBuffer.write("stdout", captured);
- outputBuffer.flush();
- } else {
- process.stdout.write(captured);
- }
- }
-
- child.on("error", (error: NodeJS.ErrnoException) => {
- if (options.signal?.aborted === true || error.name === "AbortError") {
- return;
- } else {
- disarmAbort();
- replayCapturedStdout();
- reportFailure(
- error.code === "ENOENT"
- ? `${kind} not found. Install it before running this step.`
- : `${kind} ${args.join(" ")} failed: ${error.message}`,
- );
- settle(false);
- }
- });
- child.on("close", (code) => {
- disarmAbort();
- if (!settled && code !== 0 && options.signal?.aborted !== true) {
- replayCapturedStdout();
- reportFailure(`${kind} ${args.join(" ")} exited with code ${code ?? "unknown"}.`);
- }
- settle(options.signal?.aborted === true ? false : code === 0);
- });
- });
+ if (result.kind === "workspace-probe-unrecognized") {
+ return "Could not determine whether the ancestor pnpm workspace includes this project.";
+ }
+ return undefined;
}
-/**
- * Installs project dependencies using the selected package-manager strategy.
- *
- * pnpm resolves an unclaimed nested project as part of an ancestor workspace,
- * where `install` can exit successfully without touching the project and can
- * run the ancestor's lifecycle scripts. Membership is therefore established
- * before installation, so exactly one correctly scoped install runs.
- */
+/** Installs project dependencies and keeps workspace-probe evidence distinct. */
export async function runPackageManagerInstall(
kind: PackageManagerKind,
projectRoot: string,
options: RunInstallOptions = {},
-): Promise<boolean> {
+): Promise<PackageManagerInstallResult> {
const strategy = getPackageManagerStrategy(kind);
let installOptions = options;
if (
@@ -203,26 +158,26 @@ export async function runPackageManagerInstall(
options.ignoreWorkspace !== true &&
hasAncestorPnpmWorkspace(projectRoot)
) {
- const membership = await capturePackageManager(
+ const probe = await spawnPackageManager(
kind,
projectRoot,
PNPM_WORKSPACE_MEMBERSHIP_ARGUMENTS,
- options,
+ { ...options, captureStdout: true, nonInteractive: true },
);
- if (!membership.ok) return false;
- const claimed = pnpmWorkspaceClaimsProject(membership.stdout, projectRoot);
- if (claimed === undefined) {
- options.onOutput?.({
- stream: "stderr",
- text: "Could not determine whether the ancestor pnpm workspace includes this project.",
- });
- return false;
- }
- if (!claimed) {
- installOptions = { ...options, ignoreWorkspace: true };
- }
+ if (!resultSucceeded(probe)) return { kind: "workspace-probe-failed", result: probe };
+ const claimed = pnpmWorkspaceClaimsProject(probe.stdout, projectRoot);
+ if (claimed === undefined) return { kind: "workspace-probe-unrecognized", result: probe };
+ if (!claimed) installOptions = { ...options, ignoreWorkspace: true };
}
- return spawnPackageManager(kind, projectRoot, strategy.installArguments(installOptions), options);
+ return {
+ kind: "installed",
+ result: await spawnPackageManager(
+ kind,
+ projectRoot,
+ strategy.installArguments(installOptions),
+ options,
+ ),
+ };
}
/** The argv that runs the locally installed eve binary's `dev` command. */
@@ -230,19 +185,17 @@ export function eveDevArguments(kind: PackageManagerKind): readonly string[] {
return getPackageManagerStrategy(kind).devArguments();
}
-/** Compatibility wrapper for callers that still explicitly require pnpm. */
export function spawnPnpm(
projectRoot: string,
args: readonly string[],
options: RunPackageManagerOptions = {},
-): Promise<boolean> {
+): Promise<PackageManagerProcessResult> {
return spawnPackageManager("pnpm", projectRoot, args, options);
}
-/** Compatibility wrapper for callers that still explicitly require pnpm. */
export function runPnpmInstall(
projectRoot: string,
options: RunPackageManagerOptions = {},
-): Promise<boolean> {
+): Promise<PackageManagerInstallResult> {
return runPackageManagerInstall("pnpm", projectRoot, options);
}
diff --git a/packages/eve/src/setup/primitives/run-pnpm.test.ts b/packages/eve/src/setup/primitives/run-pnpm.test.ts
index 205b77186..95311463b 100644
--- a/packages/eve/src/setup/primitives/run-pnpm.test.ts
+++ b/packages/eve/src/setup/primitives/run-pnpm.test.ts
@@ -9,6 +9,8 @@ import {
runPnpmInstall,
spawnPnpm,
} from "./run-pnpm.js";
+import { packageManagerInstallSucceeded } from "./pm/run.js";
+import { resultSucceeded } from "./pm/process-result.js";
import { pnpmPackageManager } from "./pm/pnpm.js";
vi.mock("node:child_process", async (importOriginal) => ({
@@ -64,7 +66,7 @@ afterEach(() => {
describe("runPnpmInstall", () => {
test("updates an existing lockfile after scaffolded dependencies change", async () => {
- await expect(runPnpmInstall("/tmp/eve-agent")).resolves.toBe(true);
+ expect(packageManagerInstallSucceeded(await runPnpmInstall("/tmp/eve-agent"))).toBe(true);
expect(mockedSpawn).toHaveBeenCalledTimes(1);
expect(mockedSpawn).toHaveBeenCalledWith(
@@ -78,7 +80,7 @@ describe("runPnpmInstall", () => {
mockedExistsSync.mockImplementation((path) => path === "/tmp/pnpm-workspace.yaml");
mockMembershipProbe(["/tmp", "/tmp/eve-agent"]);
- await expect(runPnpmInstall("/tmp/eve-agent")).resolves.toBe(true);
+ expect(packageManagerInstallSucceeded(await runPnpmInstall("/tmp/eve-agent"))).toBe(true);
expect(mockedSpawn).toHaveBeenCalledTimes(2);
expect(mockedSpawn).toHaveBeenLastCalledWith(
@@ -92,7 +94,7 @@ describe("runPnpmInstall", () => {
mockedExistsSync.mockImplementation((path) => path === "/tmp/pnpm-workspace.yaml");
mockMembershipProbe(["/tmp"]);
- await expect(runPnpmInstall("/tmp/eve-agent")).resolves.toBe(true);
+ expect(packageManagerInstallSucceeded(await runPnpmInstall("/tmp/eve-agent"))).toBe(true);
expect(mockedSpawn).toHaveBeenCalledTimes(2);
expect(mockedSpawn).toHaveBeenLastCalledWith(
@@ -112,7 +114,7 @@ describe("runPnpmInstall", () => {
child.stderr.emit("data", Buffer.from("WARN deprecated package\n"));
child.emit("close", 0);
- await expect(result).resolves.toBe(true);
+ expect(packageManagerInstallSucceeded(await result)).toBe(true);
expect(mockedSpawn).toHaveBeenCalledWith(
"pnpm",
["--dir", "/tmp/eve-agent", "install", "--no-frozen-lockfile"],
@@ -134,10 +136,11 @@ describe("runPnpmInstall", () => {
child.stdout.emit("data", Buffer.from("workspace parse failed\n"));
child.emit("close", 1);
- await expect(result).resolves.toBe(false);
+ const install = await result;
+ expect(install.kind).toBe("workspace-probe-failed");
+ expect(install.result.stdout).toBe("workspace parse failed\n");
expect(onOutput.mock.calls.map(([line]) => line)).toEqual([
{ stream: "stdout", text: "workspace parse failed" },
- { stream: "stderr", text: "pnpm list --depth -1 --json exited with code 1." },
]);
});
});
@@ -153,9 +156,11 @@ describe("runPackageManagerInstall", () => {
["yarn", ["install"]],
["bun", ["install"]],
] as const)("maps the release-age bypass onto %s", async (kind, expectedArgs) => {
- await expect(
- runPackageManagerInstall(kind, "/tmp/app", { bypassMinimumReleaseAge: true }),
- ).resolves.toBe(true);
+ expect(
+ packageManagerInstallSucceeded(
+ await runPackageManagerInstall(kind, "/tmp/app", { bypassMinimumReleaseAge: true }),
+ ),
+ ).toBe(true);
expect(mockedSpawn).toHaveBeenCalledWith(
kind,
@@ -165,9 +170,11 @@ describe("runPackageManagerInstall", () => {
});
test("requests npm output before registry operations complete", async () => {
- await expect(
- runPackageManagerInstall("npm", "/tmp/app", { progressDetails: true }),
- ).resolves.toBe(true);
+ expect(
+ packageManagerInstallSucceeded(
+ await runPackageManagerInstall("npm", "/tmp/app", { progressDetails: true }),
+ ),
+ ).toBe(true);
expect(mockedSpawn).toHaveBeenCalledWith(
"npm",
@@ -214,10 +221,10 @@ describe("pnpmPackageManager", () => {
});
describe("spawnPnpm", () => {
- test("runs the given pnpm argv in the project directory", async () => {
- await expect(spawnPnpm("/tmp/eve-agent", ["exec", "eve", "dev", "--no-ui"])).resolves.toBe(
- true,
- );
+ test("inherits output when no parent renderer is supplied", async () => {
+ expect(
+ resultSucceeded(await spawnPnpm("/tmp/eve-agent", ["exec", "eve", "dev", "--no-ui"])),
+ ).toBe(true);
expect(mockedSpawn).toHaveBeenCalledWith(
"pnpm",
@@ -226,6 +233,16 @@ describe("spawnPnpm", () => {
);
});
+ test("pipes output when stdin is non-interactive without a parent renderer", async () => {
+ await spawnPnpm("/tmp/eve-agent", ["install"], { nonInteractive: true });
+
+ expect(mockedSpawn).toHaveBeenCalledWith(
+ "pnpm",
+ ["--dir", "/tmp/eve-agent", "install"],
+ expect.objectContaining({ stdio: ["ignore", "pipe", "pipe"] }),
+ );
+ });
+
test("passes cancellation to the child and settles as unsuccessful", async () => {
const child = createMockChildProcess();
mockedSpawn.mockReturnValueOnce(child);
@@ -245,14 +262,7 @@ describe("spawnPnpm", () => {
error.name = "AbortError";
error.code = "ABORT_ERR";
child.emit("error", error);
- let settled = false;
- void result.then(() => {
- settled = true;
- });
- await Promise.resolve();
- expect(settled).toBe(false);
+ await expect(result).resolves.toMatchObject({ termination: { kind: "aborted" } });
child.emit("close", null);
-
- await expect(result).resolves.toBe(false);
});
});