fix(coding-agent): skip no-op git package reinstalls

closes #2503
This commit is contained in:
Mario Zechner
2026-03-22 19:19:28 +01:00
parent 3bcbae490c
commit 74073e5227
3 changed files with 79 additions and 6 deletions

View File

@@ -107,6 +107,45 @@ describe("DefaultPackageManager git update", () => {
}
describe("normal updates (no force-push)", () => {
it("should skip reset, clean, and install when already up to date", async () => {
mkdirSync(remoteDir, { recursive: true });
git(["init"], remoteDir);
git(["config", "--local", "user.email", "test@test.com"], remoteDir);
git(["config", "--local", "user.name", "Test"], remoteDir);
writeFileSync(join(remoteDir, "package.json"), JSON.stringify({ name: "test-extension", version: "1.0.0" }));
createCommit(remoteDir, "extension.ts", "// v1", "Initial commit");
mkdirSync(join(agentDir, "git", "github.com", "test"), { recursive: true });
git(["clone", remoteDir, installedDir], tempDir);
settingsManager.setPackages([gitSource]);
const executedCommands: string[] = [];
const managerWithInternals = packageManager as unknown as {
runCommand: (command: string, args: string[], options?: { cwd?: string }) => Promise<void>;
};
managerWithInternals.runCommand = async (command, args, options) => {
executedCommands.push(`${command} ${args.join(" ")}`);
if (command === "npm") {
return;
}
const result = spawnSync(command, args, {
cwd: options?.cwd,
encoding: "utf-8",
});
if (result.status !== 0) {
throw new Error(`Command failed: ${command} ${args.join(" ")}\n${result.stderr}`);
}
};
await packageManager.update();
expect(executedCommands).toContain("git fetch --prune origin");
expect(executedCommands).not.toContain("git reset --hard @{upstream}");
expect(executedCommands).not.toContain("git reset --hard origin/HEAD");
expect(executedCommands).not.toContain("git clean -fdx");
expect(executedCommands).not.toContain("npm install");
});
it("should update to latest commit when remote has new commits", async () => {
setupRemoteAndInstall();
expect(getFileContent(installedDir, "extension.ts")).toBe("// v1");
@@ -269,6 +308,7 @@ describe("DefaultPackageManager git update", () => {
const executedCommands: string[] = [];
const managerWithInternals = packageManager as unknown as {
runCommand: (command: string, args: string[], options?: { cwd?: string }) => Promise<void>;
runCommandCapture: (command: string, args: string[], options?: { cwd?: string }) => Promise<string>;
};
managerWithInternals.runCommand = async (command, args) => {
executedCommands.push(`${command} ${args.join(" ")}`);
@@ -276,6 +316,15 @@ describe("DefaultPackageManager git update", () => {
writeFileSync(extensionFile, "// fresh");
}
};
managerWithInternals.runCommandCapture = async (_command, args) => {
if (args[0] === "rev-parse" && args[1] === "HEAD") {
return "local-head";
}
if (args[0] === "rev-parse" && args[1] === "@{upstream}") {
return "remote-head";
}
return "";
};
await packageManager.resolveExtensionSources([gitSource], { temporary: true });