fix(coding-agent): omit devDependencies when installing packages (fixes #3009)

This commit is contained in:
Mario Zechner
2026-04-17 01:21:31 +02:00
parent 36bffc1d13
commit ef1fcfcec2
4 changed files with 50 additions and 3 deletions

View File

@@ -441,6 +441,51 @@ Content`,
);
});
it("should install git package dependencies with --omit=dev", async () => {
const source = "git:github.com/user/repo";
const targetDir = join(agentDir, "git", "github.com", "user", "repo");
const runCommandSpy = vi
.spyOn(packageManager as any, "runCommand")
.mockImplementation(async (...callArgs: unknown[]) => {
const [command, args] = callArgs as [string, string[]];
if (command === "git" && args[0] === "clone") {
mkdirSync(targetDir, { recursive: true });
writeFileSync(join(targetDir, "package.json"), JSON.stringify({ name: "repo", version: "1.0.0" }));
}
});
await packageManager.install(source);
expect(runCommandSpy).toHaveBeenCalledWith("npm", ["install", "--omit=dev"], { cwd: targetDir });
});
it("should update git package dependencies with --omit=dev", async () => {
const source = "git:github.com/user/repo";
const targetDir = join(tempDir, ".pi", "git", "github.com", "user", "repo");
mkdirSync(targetDir, { recursive: true });
writeFileSync(join(targetDir, "package.json"), JSON.stringify({ name: "repo", version: "1.0.0" }));
settingsManager.setProjectPackages([source]);
vi.spyOn(packageManager as any, "runCommandCapture").mockImplementation(async (...callArgs: unknown[]) => {
const [_command, args] = callArgs as [string, string[]];
if (args[0] === "rev-parse" && args[1] === "--abbrev-ref" && args[2] === "@{upstream}") {
return "origin/main";
}
if (args[0] === "rev-parse" && args[1] === "@{upstream}") {
return "remote-head";
}
if (args[0] === "rev-parse" && args[1] === "HEAD") {
return "local-head";
}
throw new Error(`Unexpected runCommandCapture args: ${args.join(" ")}`);
});
const runCommandSpy = vi.spyOn(packageManager as any, "runCommand").mockResolvedValue(undefined);
await packageManager.update(source);
expect(runCommandSpy).toHaveBeenCalledWith("npm", ["install", "--omit=dev"], { cwd: targetDir });
});
it("should use npmCommand argv for npm root lookup and invalidate cached root when npmCommand changes", () => {
settingsManager = SettingsManager.inMemory({
npmCommand: ["mise", "exec", "node@20", "--", "npm"],