Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/diffci-cli/src/client/agent-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 });
}
});
1 change: 1 addition & 0 deletions release-files.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading