Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

Track renames properly in flaky tests and a11y checks (#8575)

James Brunton5073ec3f68e9
diff --git a/frontend/.storybook/a11y-changed.mjs b/frontend/.storybook/a11y-changed.mjs
index f6daef5dbb..eff8bd5b51 100644
--- a/frontend/.storybook/a11y-changed.mjs
+++ b/frontend/.storybook/a11y-changed.mjs
@@ -18,9 +18,11 @@ const base = process.argv[2] || "origin/main";
const git = (...args) =>
execFileSync("git", args, { encoding: "utf8" })
.split("\n")
- .map((l) => l.trim().replace(/^frontend\//, ""))
+ .map((l) => l.trim())
.filter(Boolean);
+const fromFrontend = (path) => path.replace(/^frontend\//, "");
+
const STORY = /\.stories\.tsx?$/;
const TEST = /\.test\.tsx?$/;
const SOURCE = /\.(ts|tsx|css)$/;
@@ -28,11 +30,22 @@ const SOURCE = /\.(ts|tsx|css)$/;
// Committed changes vs the base, plus working-tree changes, plus untracked
// files — so the gate covers exactly what the branch would merge and what a
// developer is about to commit.
+// A pure rename (R100) renders exactly as before; counting it would turn a
+// folder move into a scan of every story.
const changed = [
- ...git("diff", "--name-only", "--diff-filter=d", `${base}...HEAD`),
+ ...git(
+ "diff",
+ "--name-status",
+ "--find-renames",
+ "--diff-filter=d",
+ `${base}...HEAD`,
+ )
+ .map((line) => line.split("\t"))
+ .filter(([status]) => status !== "R100")
+ .map((columns) => columns.at(-1)),
...git("diff", "--name-only", "--diff-filter=d"),
...git("ls-files", "--others", "--exclude-standard"),
-];
+].map(fromFrontend);
const stories = new Set();
for (const f of changed) {
diff --git a/frontend/editor/scripts/report-flaky-tests.mts b/frontend/editor/scripts/report-flaky-tests.mts
index 0a04c33ecb..820dd28269 100644
--- a/frontend/editor/scripts/report-flaky-tests.mts
+++ b/frontend/editor/scripts/report-flaky-tests.mts
@@ -31,8 +31,11 @@ function computeChangedLines(
): ChangedLines {
const ranges: ChangedLines = new Map();
if (files.length === 0) return ranges;
+ const wanted = new Set(files);
let diff: string;
try {
+ // No pathspec: limiting the diff to `files` hides a moved file's old path,
+ // so git reports the move as an add and every test in it reads as new.
diff = execFileSync(
"git",
[
@@ -43,10 +46,9 @@ function computeChangedLines(
"diff",
"-w",
"--unified=0",
+ "--find-renames",
"--diff-filter=AMR",
`${baseSha}...HEAD`,
- "--",
- ...files,
],
{ cwd: workspace, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 },
);
@@ -61,7 +63,7 @@ function computeChangedLines(
if (rawLine.startsWith("+++ ")) {
// "+++ b/path", or "+++ /dev/null" for a deletion (no new side).
const path = rawLine.slice(4).replace(/^b\//, "");
- current = path === "/dev/null" ? null : path;
+ current = wanted.has(path) ? path : null;
if (current && !ranges.has(current)) ranges.set(current, []);
continue;
}