Skip to content

Commit 158b3bf

Browse files
matt2eclaude
andauthored
test(scripts): stop file-size fixtures leaking git repos and fsmonitor daemons (#8727)
## Summary The file-size ratchet tests (`scripts/check-file-sizes-core.test.mjs`, run by `just file-size-check`) created fixture git repos under the OS tmpdir and never deleted them. When `core.fsmonitor=true` is set globally, every git call in a fixture also started a `git fsmonitor--daemon` that never exited. So every run left more temp repos and more daemons behind. - The test's `git()` helper now passes `-c core.fsmonitor=false`, next to the existing `core.hooksPath` override. - Fixture repos are now created through a new `createFixtureRepo()` helper, which records each path. An `after()` hook deletes them all with `rmSync(..., { recursive: true, force: true })`. The other scripts that create temp git repos (`scripts/ci-selection.test.mjs`, `scripts/flake-check.test.mjs`, `scripts/test-mobile-release-contract.sh`, `scripts/test-sprig-image.sh`) already clean up their temp directories and left no daemons running, so they are unchanged. ## Testing - `node --test scripts/check-file-sizes-core.test.mjs`: no `file-size-*` directories are left in the tmpdir afterwards, and no new `fsmonitor--daemon` processes are running. - The pre-push `file-size-check` lane passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Matt Toohey <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent fae3f03 commit 158b3bf

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

‎scripts/check-file-sizes-core.test.mjs‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import {
55
mkdirSync,
66
mkdtempSync,
77
realpathSync,
8+
rmSync,
89
symlinkSync,
910
writeFileSync,
1011
} from "node:fs";
1112
import { tmpdir } from "node:os";
1213
import path from "node:path";
13-
import test from "node:test";
14+
import test, { after } from "node:test";
1415
import { policy as desktopPolicy } from "../desktop/scripts/check-file-sizes.mjs";
1516
import { policy as mobilePolicy } from "../mobile/scripts/check-file-sizes.mjs";
1617
import { policy as webPolicy } from "../web/scripts/check-file-sizes.mjs";
@@ -24,18 +25,35 @@ import {
2425

2526
const repoRoot = path.resolve(import.meta.dirname, "..");
2627

28+
const fixtureRepos = [];
29+
after(() => {
30+
for (const repo of fixtureRepos)
31+
rmSync(repo, { recursive: true, force: true });
32+
});
33+
34+
function createFixtureRepo(prefix) {
35+
const repo = realpathSync(mkdtempSync(path.join(tmpdir(), prefix)));
36+
fixtureRepos.push(repo);
37+
return repo;
38+
}
39+
2740
function git(repo, ...args) {
2841
// These fixture repositories inherit both hook configuration and Git's
2942
// repository-local environment when this test runs from pre-push. Isolate
3043
// them completely so fixture commits cannot recurse into the real checkout.
44+
// A global core.fsmonitor would also leave a daemon running per fixture.
3145
const env = Object.fromEntries(
3246
Object.entries(process.env).filter(([key]) => !key.startsWith("GIT_")),
3347
);
34-
return execFileSync("git", ["-c", "core.hooksPath=/dev/null", ...args], {
35-
cwd: repo,
36-
encoding: "utf8",
37-
env,
38-
}).trim();
48+
return execFileSync(
49+
"git",
50+
["-c", "core.hooksPath=/dev/null", "-c", "core.fsmonitor=false", ...args],
51+
{
52+
cwd: repo,
53+
encoding: "utf8",
54+
env,
55+
},
56+
).trim();
3957
}
4058

4159
function createEntrypointFixture({
@@ -44,9 +62,7 @@ function createEntrypointFixture({
4462
lineDelta = 1,
4563
symlinkEntrypoint = false,
4664
}) {
47-
const repo = realpathSync(
48-
mkdtempSync(path.join(tmpdir(), `file-size-${surface}-`)),
49-
);
65+
const repo = createFixtureRepo(`file-size-${surface}-`);
5066
const scriptsDir = path.join(repo, "scripts");
5167
const surfaceScriptsDir = path.join(repo, surface, "scripts");
5268
mkdirSync(scriptsDir, { recursive: true });
@@ -95,7 +111,7 @@ function createEntrypointFixture({
95111
}
96112

97113
test("local base resolution uses the branch merge-base and fails without origin/main", () => {
98-
const repo = mkdtempSync(path.join(tmpdir(), "file-size-base-"));
114+
const repo = createFixtureRepo("file-size-base-");
99115
git(repo, "init", "-b", "main");
100116
git(repo, "config", "user.name", "Test");
101117
git(repo, "config", "user.email", "[email protected]");

0 commit comments

Comments
 (0)