Harden workspace git indexing against repo-configured fsmonitor execution (#1873)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-04-10 01:07:05 -07:00
1 parent 1a05d8ca1a
commit 1cba2f64d3
2 files changed
+57 -5

No files matched your search

+33 -1
View File
@@ -219,7 +219,10 @@ it.layer(TestLayer)("git integration", (it) => {
const seenChunks: string[][] = [];
const core = yield* makeIsolatedGitCore((input) => {
if (input.args.join(" ") !== "check-ignore --no-index -z --stdin") {
if (
input.args.join(" ") !==
"-c core.fsmonitor=false -c core.untrackedCache=false check-ignore --no-index -z --stdin"
) {
return Effect.fail(
new GitCommandError({
operation: input.operation,
@@ -252,6 +255,35 @@ it.layer(TestLayer)("git integration", (it) => {
expect(result).toEqual(expectedPaths);
}),
);
it.effect("listWorkspaceFiles disables fsmonitor and untracked cache helpers", () =>
Effect.gen(function* () {
const core = yield* makeIsolatedGitCore((input) => {
expect(input.args).toEqual([
"-c",
"core.fsmonitor=false",
"-c",
"core.untrackedCache=false",
"ls-files",
"--cached",
"--others",
"--exclude-standard",
"-z",
]);
return Effect.succeed({
code: 0,
stdout: "src/index.ts\0README.md\0",
stderr: "",
stdoutTruncated: false,
stderrTruncated: false,
});
});
const result = yield* core.listWorkspaceFiles("/virtual/repo");
expect(result.paths).toEqual(["src/index.ts", "README.md"]);
expect(result.truncated).toBe(false);
}),
);
});
// ── listGitBranches ──
+24 -4
View File
@@ -47,6 +47,12 @@ const RANGE_DIFF_SUMMARY_MAX_OUTPUT_BYTES = 19_000;
const RANGE_DIFF_PATCH_MAX_OUTPUT_BYTES = 59_000;
const WORKSPACE_FILES_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
const GIT_CHECK_IGNORE_MAX_STDIN_BYTES = 256 * 1024;
const WORKSPACE_GIT_HARDENED_CONFIG_ARGS = [
"-c",
"core.fsmonitor=false",
"-c",
"core.untrackedCache=false",
] as const;
const STATUS_UPSTREAM_REFRESH_INTERVAL = Duration.seconds(15);
const STATUS_UPSTREAM_REFRESH_TIMEOUT = Duration.seconds(5);
const STATUS_UPSTREAM_REFRESH_FAILURE_COOLDOWN = Duration.seconds(5);
@@ -1619,7 +1625,14 @@ export const makeGitCore = Effect.fn("makeGitCore")(function* (options?: {
executeGit(
"GitCore.listWorkspaceFiles",
cwd,
["ls-files", "--cached", "--others", "--exclude-standard", "-z"],
[
...WORKSPACE_GIT_HARDENED_CONFIG_ARGS,
"ls-files",
"--cached",
"--others",
"--exclude-standard",
"-z",
],
{
allowNonZeroExit: true,
timeoutMs: 20_000,
@@ -1637,7 +1650,14 @@ export const makeGitCore = Effect.fn("makeGitCore")(function* (options?: {
createGitCommandError(
"GitCore.listWorkspaceFiles",
cwd,
["ls-files", "--cached", "--others", "--exclude-standard", "-z"],
[
...WORKSPACE_GIT_HARDENED_CONFIG_ARGS,
"ls-files",
"--cached",
"--others",
"--exclude-standard",
"-z",
],
result.stderr.trim().length > 0 ? result.stderr.trim() : "git ls-files failed",
),
),
@@ -1657,7 +1677,7 @@ export const makeGitCore = Effect.fn("makeGitCore")(function* (options?: {
const result = yield* executeGit(
"GitCore.filterIgnoredPaths",
cwd,
["check-ignore", "--no-index", "-z", "--stdin"],
[...WORKSPACE_GIT_HARDENED_CONFIG_ARGS, "check-ignore", "--no-index", "-z", "--stdin"],
{
stdin: `${chunk.join("\0")}\0`,
allowNonZeroExit: true,
@@ -1671,7 +1691,7 @@ export const makeGitCore = Effect.fn("makeGitCore")(function* (options?: {
return yield* createGitCommandError(
"GitCore.filterIgnoredPaths",
cwd,
["check-ignore", "--no-index", "-z", "--stdin"],
[...WORKSPACE_GIT_HARDENED_CONFIG_ARGS, "check-ignore", "--no-index", "-z", "--stdin"],
result.stderr.trim().length > 0 ? result.stderr.trim() : "git check-ignore failed",
);
}