One child per test, carrying every hostile git setting at once (improvise-eahe)

tests/shipped_documents_load.rs re-ran itself in 18 child processes, one
per hostile setting, and each child spawns several gits. So the binary
took 2.1-3.3s against design-principles 7's 2s-per-binary tripwire.

The six per-setting tests (53zz x2, vwjj, pr3i, a0i3 and 2iws/vav0) are
now one test, a_hostile_git_environment_changes_nothing. It has two
children: the gzip shape test and every_shipped_document_loads. Each
carries every setting at once:
- the template dir;
- the global and system config (with trace2 targets);
- XDG_CONFIG_HOME;
- GIT_DIR and GIT_INDEX_FILE;
- the five pathspec and attribute settings;
- the six trace variables.

Afterwards the test asserts the outer index is still empty.

Each setting breaks the walk on its own, so a rival that drops one
defence leaves that setting live, and the child fails. Every rival that
was red against the per-setting tests is red against the combined one.
The rivals that were green before are green now:
- ICASE;
- the trace2 names under the 0 override;
- the GIT_CONFIG_GLOBAL and NOSYSTEM nulls, whose excludes witness vwjj's
  -c override masks. That last pair is filed as improvise-3j70.

Measured on an Apple M4 Max, three workspace runs each: this binary went
from 2.10-3.31s (load 37-39) to 0.57-0.91s (load 30-33). It is now
below the next-largest binary in every run.

The evidence sections keep their reasoning, under prose headings.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VdfEGXA7aJ6ftMsCc9PJze
This commit is contained in:
Edward Langley
2026-09-23 18:22:54 -07:00
parent fbfe37802f
commit 5b8bdc19b1
2 changed files with 94 additions and 139 deletions
+57 -133
View File
@@ -211,41 +211,70 @@ fn told(out: &std::process::Output) -> String {
format!("\n--- stdout\n{stdout}\n--- stderr\n{stderr}")
}
/// improvise-pr3i: `git init` copies `GIT_TEMPLATE_DIR`, which no config null
/// reaches. Evidence: `context/test-evidence/tui.md`.
/// Every hostile git setting these tests have met, at once, in one child per
/// test (improvise-eahe). Each setting's own witness is a rival: `context/test-evidence/tui.md`.
#[test]
fn a_scratch_repo_ignores_the_users_template_dir() {
fn a_hostile_git_environment_changes_nothing() {
// improvise-pr3i: a template whose `info/exclude` refuses `*.gz`.
let templates = tempfile::tempdir().expect("a temp dir");
write(templates.path(), "info/exclude", "*.gz\n");
let out = rerun_with_env(
"a_gzipped_document_is_walked",
&[("GIT_TEMPLATE_DIR", templates.path())],
// improvise-53zz: a global and a system config whose excludes refuse `*.gz`.
let home = tempfile::tempdir().expect("a temp dir");
let excludes = home.path().join("ignore");
std::fs::write(&excludes, "*.gz\n").expect("writes");
let config = home.path().join("gitconfig");
// improvise-vav0: the same config also sends every trace2 target to stdout.
let text = format!(
"[core]\n\texcludesFile = {}\n[trace2]\n\tnormalTarget = /dev/stdout\n\teventTarget = /dev/stdout\n\tperfTarget = /dev/stdout\n",
excludes.display()
);
assert!(
out.status.success(),
"the gzip shape test fails under a template info/exclude: {}",
told(&out)
std::fs::write(&config, text).expect("writes");
// improvise-vwjj: git's default ignore and attributes files, no config line.
let xdg = tempfile::tempdir().expect("a temp dir");
write(xdg.path(), "git/ignore", "*.gz\n");
write(
xdg.path(),
"git/attributes",
"*.gz working-tree-encoding=UTF-16\n",
);
}
/// improvise-53zz: a hook in a linked worktree exports `GIT_DIR`, which beats
/// `-C`. Evidence: `context/test-evidence/tui.md`.
#[test]
fn a_scratch_repo_ignores_an_inherited_git_dir() {
// improvise-53zz: an inherited `GIT_DIR`, which beats `-C`.
let outer = scratch_repo();
let dot_git = outer.path().join(".git");
let out = rerun_with_env(
"a_single_file_un_ignore_is_walked",
&[
("GIT_DIR", &dot_git),
("GIT_INDEX_FILE", &dot_git.join("index")),
],
);
assert!(
out.status.success(),
"the shape test fails under an inherited GIT_DIR: {}",
told(&out)
);
let index = dot_git.join("index");
let stdout = Path::new("/dev/stdout");
let one = Path::new("1");
let hostile: Vec<(&str, &Path)> = vec![
("GIT_TEMPLATE_DIR", templates.path()),
("GIT_CONFIG_GLOBAL", &config),
("GIT_CONFIG_SYSTEM", &config),
("XDG_CONFIG_HOME", xdg.path()),
("GIT_DIR", &dot_git),
("GIT_INDEX_FILE", &index),
// improvise-a0i3: process-wide pathspec and attribute settings.
("GIT_LITERAL_PATHSPECS", one),
("GIT_GLOB_PATHSPECS", one),
("GIT_NOGLOB_PATHSPECS", one),
("GIT_ICASE_PATHSPECS", one),
("GIT_ATTR_SOURCE", Path::new("HEAD")),
// improvise-2iws: every trace that writes to its target on git 2.55.
("GIT_TRACE", stdout),
("GIT_TRACE_SETUP", stdout),
("GIT_TRACE_PERFORMANCE", stdout),
("GIT_TRACE2", stdout),
("GIT_TRACE2_EVENT", stdout),
("GIT_TRACE2_PERF", stdout),
];
for test in [
"a_gzipped_document_is_walked",
"every_shipped_document_loads",
] {
let out = rerun_with_env(test, &hostile);
assert!(
out.status.success(),
"{test} fails in a hostile git environment: {}",
told(&out)
);
}
let staged = git(outer.path())
.args(["ls-files"])
.output()
@@ -256,108 +285,3 @@ fn a_scratch_repo_ignores_an_inherited_git_dir() {
String::from_utf8_lossy(&staged.stdout)
);
}
/// improvise-53zz: a user's `*.gz` exclude refused the gzip shape test's `add`.
/// Evidence: `context/test-evidence/tui.md`.
#[test]
fn a_scratch_repo_ignores_the_users_global_and_system_excludes() {
let home = tempfile::tempdir().expect("a temp dir");
let excludes = home.path().join("ignore");
std::fs::write(&excludes, "*.gz\n").expect("writes");
let config = home.path().join("gitconfig");
let text = format!("[core]\n\texcludesFile = {}\n", excludes.display());
std::fs::write(&config, text).expect("writes");
for scope in ["GIT_CONFIG_GLOBAL", "GIT_CONFIG_SYSTEM"] {
let out = rerun_with_env("a_gzipped_document_is_walked", &[(scope, &config)]);
assert!(
out.status.success(),
"the gzip shape test fails under a `*.gz` exclude in {scope}: {}",
told(&out)
);
}
}
/// improvise-vwjj: git's DEFAULT ignore and attributes files need no config line.
/// Evidence: `context/test-evidence/tui.md`.
#[test]
fn a_scratch_repo_ignores_the_users_default_ignore_and_attributes_files() {
let files = [
("ignore", "*.gz\n"),
("attributes", "*.gz working-tree-encoding=UTF-16\n"),
];
for (name, text) in files {
let xdg = tempfile::tempdir().expect("a temp dir");
write(xdg.path(), &format!("git/{name}"), text);
let out = rerun_with_env(
"a_gzipped_document_is_walked",
&[("XDG_CONFIG_HOME", xdg.path())],
);
assert!(
out.status.success(),
"the gzip shape test fails under a default git/{name}: {}",
told(&out)
);
}
}
/// improvise-a0i3: pathspec magic and an attribute source are process-wide git
/// settings, and `--local-env-vars` lists none. Evidence: `context/test-evidence/tui.md`.
#[test]
fn the_walk_ignores_the_users_pathspec_and_attribute_settings() {
let settings = [
("GIT_LITERAL_PATHSPECS", "1"),
("GIT_GLOB_PATHSPECS", "1"),
("GIT_NOGLOB_PATHSPECS", "1"),
("GIT_ICASE_PATHSPECS", "1"),
("GIT_ATTR_SOURCE", "HEAD"),
];
let mut failed = Vec::new();
for (name, value) in settings {
for test in [
"a_gzipped_document_is_walked",
"every_shipped_document_loads",
] {
let out = rerun_with_env(test, &[(name, Path::new(value))]);
if !out.status.success() {
failed.push(format!("{test} under {name}={value}: {}", told(&out)));
}
}
}
assert!(failed.is_empty(), "{}", failed.join("\n"));
}
/// improvise-2iws: a git trace sent to stdout lands in `ls-files -z`'s output
/// and is read as paths. Evidence: `context/test-evidence/tui.md`.
#[test]
fn the_walk_ignores_a_git_trace_sent_to_stdout() {
// Every variable of the family that writes to its target on git 2.55, so a
// fixed list of names shorter than the family leaves one behind.
let stdout = Path::new("/dev/stdout");
let mut traces: Vec<(&str, &Path)> = [
"GIT_TRACE",
"GIT_TRACE_SETUP",
"GIT_TRACE_PERFORMANCE",
"GIT_TRACE2",
"GIT_TRACE2_EVENT",
"GIT_TRACE2_PERF",
]
.map(|name| (name, stdout))
.to_vec();
// improvise-vav0: the same targets set in config, where no removal reaches.
let home = tempfile::tempdir().expect("a temp dir");
let config = home.path().join("gitconfig");
let text = "[trace2]\n\tnormalTarget = /dev/stdout\n\teventTarget = /dev/stdout\n\tperfTarget = /dev/stdout\n";
std::fs::write(&config, text).expect("writes");
traces.push(("GIT_CONFIG_GLOBAL", &config));
for test in [
"a_gzipped_document_is_walked",
"every_shipped_document_loads",
] {
let out = rerun_with_env(test, &traces);
assert!(
out.status.success(),
"{test} under a trace to stdout: {}",
told(&out)
);
}
}