diff --git a/packages/diffci-cli/src/client/agent-selection.ts b/packages/diffci-cli/src/client/agent-selection.ts index bc6ff035..6816fd24 100644 --- a/packages/diffci-cli/src/client/agent-selection.ts +++ b/packages/diffci-cli/src/client/agent-selection.ts @@ -10,8 +10,9 @@ import { requireDiffciPackageIdentity } from "./package-identity.js"; import { executableSelection, scopedChanges } from "./verify.js"; import { captureScopedTree, captureWorkingTreeSnapshot, type VerificationTreeScope, type WorkingTreeSnapshot } from "./working-tree.js"; +/** A rename is its old path and its new one: whatever imported the old path is affected too. */ function changedPaths(repoPath: string, snapshot: WorkingTreeSnapshot): string[] { - return execFileSync("git", ["diff", "--name-only", "-z", snapshot.baseSha, snapshot.commitSha], { + return execFileSync("git", ["diff", "--name-only", "--no-renames", "-z", snapshot.baseSha, snapshot.commitSha], { cwd: repoPath, encoding: "utf8", windowsHide: true, }).split("\0").filter(Boolean); } diff --git a/packages/diffci-cli/tests/client/agent-changed-files-renames.test.ts b/packages/diffci-cli/tests/client/agent-changed-files-renames.test.ts new file mode 100644 index 00000000..177aa753 --- /dev/null +++ b/packages/diffci-cli/tests/client/agent-changed-files-renames.test.ts @@ -0,0 +1,30 @@ +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { test } from "node:test"; +import { agentChangedFiles } from "../../src/client/agent-selection.js"; + +test("diffci_changed_files lists both paths of a renamed file", () => { + const dir = mkdtempSync(join(tmpdir(), "diffci-agent-renames-")); + const git = (...args: string[]) => execFileSync("git", args, { cwd: dir, stdio: "pipe" }); + try { + git("init", "--quiet"); + git("config", "user.email", "test@diffci.local"); + git("config", "user.name", "Test"); + // Rename detection is on by default; set it explicitly so a global diff.renames=false cannot hide the bug. + git("config", "diff.renames", "true"); + mkdirSync(join(dir, "src")); + writeFileSync(join(dir, "src", "old.ts"), Array.from({ length: 40 }, (_, line) => `export const v${line} = ${line};\n`).join("")); + git("add", "-A"); + git("commit", "--quiet", "-m", "initial"); + git("mv", "src/old.ts", "src/new.ts"); + const changes = agentChangedFiles(dir); + assert.equal(changes.status, "observed"); + // The old path is gone: anything that imports it is affected, so it is a changed file too. + assert.deepEqual([...changes.changed_files].sort(), ["src/new.ts", "src/old.ts"]); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); diff --git a/release-files.json b/release-files.json index 685f2f19..a5b91267 100644 --- a/release-files.json +++ b/release-files.json @@ -298,6 +298,7 @@ "packages/diffci-cli/src/client/enforce-policy.ts", "packages/diffci-cli/src/client/telemetry.ts", "packages/diffci-cli/src/client/feedback-prompt.ts", + "packages/diffci-cli/tests/client/agent-changed-files-renames.test.ts", "packages/diffci-cli/tests/client/agent-default-path.test.ts", "packages/diffci-cli/tests/client/check.test.ts", "packages/diffci-cli/tests/client/cli-agent.test.ts",