Skip to content

Instantly share code, notes, and snippets.

@Pyseph
Last active November 6, 2026 14:08
Show Gist options
  • Select an option

  • Save Pyseph/63801ce52a9e6075c9731e73656b74ac to your computer and use it in GitHub Desktop.

Select an option

Save Pyseph/63801ce52a9e6075c9731e73656b74ac to your computer and use it in GitHub Desktop.
t3code check:changed: listing ignored inputs without walking node_modules (size:M revision of #30736), timings and equivalence rows

check:changed ignored-input listing, size:M revision: raw rows

Branch perf/check-changed-skip-node-modules, commits 6e8168a03f and 24412204d4 (batches sized from the longest path) on 6577c6b618 (pingdotgg/t3code main). It replaces #30736 (a8f1b5b852); the raw rows for that revision are in https://gist.github.com/Pyseph/39d10df5712b73c447479995f4f029e0.

Machine: Windows 11 Home 10.0.26200, NTFS, AMD Ryzen 9 9950X (16 cores, 32 threads), git 2.47.0.windows.1, Node 26.12.1 via vp env exec --node 26.12.1. Timed runs ran under an exclusive lock that kept this project's other benchmarks and tests off the machine, at below-normal priority. Other unrelated work on the machine was not stopped.

Files

File What
timings.jsonl vp run check:changed HEAD in a worktree with a completed vp i, one new docs/zz-bench-note.md and nothing else changed, cache file deleted before each cold run. k: branch-cold (n=5), branch-cached-rerun (inputs unchanged after a pass), main-cold (n=1, the same worktree checked out at 6577c6b618), branch-after-main-cold (n=2). tooLongWarnings counts Filename too long lines in the output.
e2e.cjs the driver: node e2e.cjs <worktree> <vp> <label> <runs> <cachedRerun 0/1> <out.jsonl>
fuzz-seed1.jsonl, fuzz-seed2.jsonl random repositories, old pathspec command against the new function: 300 with seed 1, 100 with seed 2. Only the summary line is printed when no case differs.
targeted.jsonl 22 targeted cases: state A, a mutation to state B, both lists and whether the full cache key changed. STALE means the old key changed and the new one did not.
collapsed-listing.jsonl 5 variants of git's listing of an untracked directory whose contents are all ignored, combined with replaced and flagged paths.
batch-check.mjs, batch-check.jsonl 300 ignored directories with 140-character names, so the expansion takes two calls at 24412204d4; the old command and the new function list the same 300 paths.
fuzz.mjs, targeted.mjs, quirk.mjs, lib.mjs the harness from #30736, unchanged. NEW_TS=<worktree>/scripts/check-changed.ts node fuzz.mjs <out dir> <cases> <seed>; targeted.mjs <out dir>; quirk.mjs <out dir>.

Summary

  • check:changed with one new docs file: main 2,500.3 s (n=1, exit 0); this branch 5.0 s median (n=7: 7.7, 4.5, 4.6, 4.6, 5.1 before the main run, 6.0 and 5.0 after it; min 4.5, max 7.7; all exit 0). Rerun with unchanged inputs: 4.2 s, Nothing changed since the last passing run.

  • The main run lists the ignored inputs twice (before the checks and after the pass); git's Filename too long warnings go to its stderr, which check:changed doesn't print, so tooLongWarnings is 0 for every row and says nothing about the walk.

  • #30736's earlier rows measured main at 696.6 to 833.7 s (median 740.1 s, n=5) in another worktree on 2026-11-03 with the same listing code.

  • Fuzz: 400 repositories, 0 missing, 0 extra, 0 errors (391 with a non-empty list).

  • Targeted: 22 cases, lists and key changes equal except nested-in-node_modules-create (a nested repository created inside node_modules: the old command printed its name, the new function doesn't list it).

  • Collapsed listing: 5 variants, lists equal, no stale key.

{"head":"24412204d4","dirs":300,"longest":140,"old":300,"new":300,"equal":true}
// usage: NEW_TS=<worktree>/scripts/check-changed.ts node batch-check.mjs <scratch dir>
// 300 ignored directories with 140-character names force two expansion calls; compare with the old command.
import * as fs from "node:fs";
import * as path from "node:path";
const { git, write, newList, oldList } = await import("./lib.mjs");
const root = process.argv[2];
fs.rmSync(root, { recursive: true, force: true });
fs.mkdirSync(root, { recursive: true });
git(root, "init", "-q");
write(root, ".gitignore", "d*/\nnode_modules/\n");
write(root, "src/a.ts", "a");
git(root, "add", "."); git(root, "commit", "-qm", "base");
for (let i = 0; i < 300; i++) {
const dir = `d${String(i).padStart(3, "0")}${"x".repeat(136)}`;
write(root, `${dir}/index.d.ts`, String(i));
if (i % 7 === 0) write(root, `${dir}/node_modules/p/i.d.ts`, "nm");
}
const oldL = oldList(root).sort();
const newL = await newList(root);
console.log(JSON.stringify({ dirs: 300, longest: 140, old: oldL.length, new: newL.length, equal: JSON.stringify(oldL) === JSON.stringify(newL) }));
fs.rmSync(root, { recursive: true, force: true });
{"name":"replaced-allignored-deep","old":["p/x/a.d.ts","p/x/deep/er/b.d.ts"],"new":["p/x/a.d.ts","p/x/deep/er/b.d.ts"],"stale":[]}
{"name":"flagS-replaced-allignored-deep","old":["p/x/a.d.ts","p/x/deep/er/b.d.ts"],"new":["p/x/a.d.ts","p/x/deep/er/b.d.ts"],"stale":[]}
{"name":"flagh-replaced-only-ignored-dirs","old":["p/x/build/c.d.ts","p/x/dist/deep/b.d.ts"],"new":["p/x/build/c.d.ts","p/x/dist/deep/b.d.ts"],"stale":[]}
{"name":"untracked-only-ignored-dirs-deep","old":["u/dist/a/b/c.d.ts","u/v/build/.env"],"new":["u/dist/a/b/c.d.ts","u/v/build/.env"],"stale":[]}
{"name":"untracked-allignored-with-stale-nm","old":["u/a.d.ts","u/deep/er/b.d.ts"],"new":["u/a.d.ts","u/deep/er/b.d.ts"],"stale":[]}
// Times `vp run check:changed HEAD` with one new docs file in the worktree, cache file deleted before each run.
// Adapted from B001/bundle/bench/e2e-new.cjs: a label, and the cached rerun only when asked.
// usage: node e2e.cjs <worktree> <vp binary> <label> <runs> <cachedRerun 0|1> <out.jsonl>
const cp = require("child_process"), fs = require("fs"), os = require("os"), path = require("path");
os.setPriority(process.pid, os.constants.priority.PRIORITY_BELOW_NORMAL);
const [wt, vp, label, runs, cachedRerun, outFile] = process.argv.slice(2);
const doc = path.join(wt, "docs", "zz-bench-note.md");
const cache = path.join(wt, "node_modules", ".cache", "check-changed.json");
const head = cp.execFileSync("git", ["-C", wt, "rev-parse", "--short=10", "HEAD"], { encoding: "utf8" }).trim();
const row = (o) => { fs.appendFileSync(outFile, JSON.stringify(o) + "\n"); console.log(JSON.stringify(o)); };
const once = (k, i) => {
const start = new Date().toISOString();
const t = process.hrtime.bigint();
const r = cp.spawnSync(vp, ["env", "exec", "--node", "26.12.1", "vp", "run", "check:changed", "HEAD"], { cwd: wt, encoding: "utf8", maxBuffer: 1 << 28 });
const seconds = Math.round(Number(process.hrtime.bigint() - t) / 1e8) / 10;
const text = r.stdout + r.stderr;
const tooLong = (text.match(/Filename too long/g) || []).length;
row({ k, head, run: i, start, seconds, exit: r.status, tooLongWarnings: tooLong, summary: (text.match(/Nothing changed since the last passing run\.|pass {2}format/g) || []).join(" | ") });
};
try {
fs.writeFileSync(doc, "# bench note\n");
for (let i = 1; i <= Number(runs); i++) { fs.rmSync(cache, { force: true }); once(label + "-cold", i); }
if (cachedRerun === "1") once(label + "-cached-rerun", 1);
} finally { fs.rmSync(doc, { force: true }); fs.rmSync(cache, { force: true }); }
{"summary":true,"seed":"1","cases":300,"withMissing":0,"withExtra":0,"errors":0,"nonEmpty":293}
{"summary":true,"seed":"2","cases":100,"withMissing":0,"withExtra":0,"errors":0,"nonEmpty":98}
// Differential fuzz: random repos, old pathspec command vs real new function. Prints one JSON row per case.
import * as fs from "node:fs";
import * as path from "node:path";
import { git, write, newList, oldList } from "./lib.mjs";
const [outDir, nStr, seedStr, budgetStr] = process.argv.slice(2);
let seed = Number(seedStr ?? 1);
const rnd = () => ((seed = (seed * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff);
const pick = (a) => a[Math.floor(rnd() * a.length)];
const DIRS = ["", "a", "a/b", "dist", "a/dist", "build", "u", "u/v", "node_modules", "a/node_modules", "a/node_modules/pkg", "vendored", "a/vendored", ".generated", "a/.generated", "a/.astro", "gen", "Dist", "a b", "x[1]", "ΓΌ"];
const NAMES = ["x.d.ts", "y.ts", ".env", ".env.local", "z.txt", "index.d.ts", "q.js", "node_modules", "r.D.TS"];
const RULES = ["dist/", "build", "*.d.ts", ".env*", ".generated/", "node_modules/", "vendored/", "!a/dist/", "u/v/", "gen/*", "!gen/keep.d.ts", "*.txt", "/a/b/", "x*"];
const rows = [];
const budget = budgetStr ? Number(budgetStr) : undefined;
for (let i = 0; i < Number(nStr); i++) {
const root = path.join(outDir, `c${seedStr}-${i}`);
fs.rmSync(root, { recursive: true, force: true }); fs.mkdirSync(root, { recursive: true });
git(root, "init", "-q");
const rules = RULES.filter(() => rnd() < 0.5);
write(root, ".gitignore", rules.join("\n") + "\n");
if (rnd() < 0.3) write(root, `${pick(["a", "u", "dist"])}/.gitignore`, pick(["*\n", "!*.d.ts\n", "*.env\n", "inner/\n"]));
const tracked = [];
for (let k = 0; k < 8; k++) { const f = path.posix.join(pick(DIRS), pick(NAMES)); try { write(root, f, "t" + k); tracked.push(f); } catch {} }
for (const f of ["p/dist", "a/dist2", "build", "t/file"]) if (rnd() < 0.4) { try { write(root, f, "file"); tracked.push(f); } catch {} }
try { git(root, "add", "-f", "--", ...tracked.filter((f) => fs.existsSync(path.join(root, f)) && fs.statSync(path.join(root, f)).isFile()), ".gitignore"); git(root, "commit", "-qm", "b", "--allow-empty"); } catch (e) { }
const ops = [];
// untracked / ignored files
for (let k = 0; k < 12; k++) { const f = path.posix.join(pick(DIRS), pick(["", "deep", "deep/er"]), pick(NAMES)); try { write(root, f, "u" + k); ops.push("w " + f); } catch {} }
// replace tracked files by directories, maybe flagged
for (const f of tracked) {
const r = rnd();
if (r < 0.15) {
const flag = pick(["", "--assume-unchanged", "--skip-worktree", "both"]);
try {
if (flag === "both") git(root, "update-index", "--assume-unchanged", "--skip-worktree", "--", f);
else if (flag) git(root, "update-index", flag, "--", f);
fs.rmSync(path.join(root, f), { force: true });
write(root, `${f}/${pick(NAMES)}`, "rep"); write(root, `${f}/sub/${pick(NAMES)}`, "rep2");
ops.push(`replace ${flag} ${f}`);
} catch {}
} else if (r < 0.25) {
const flag = pick(["--assume-unchanged", "--skip-worktree"]);
try { git(root, "update-index", flag, "--", f); if (rnd() < 0.5) { fs.rmSync(path.join(root, f), { force: true }); ops.push(`flagdel ${flag} ${f}`); } else ops.push(`flag ${flag} ${f}`); } catch {}
}
}
// nested repos
for (let k = 0; k < 2; k++) if (rnd() < 0.5) {
const d = path.posix.join(pick(DIRS), pick(["r", "vendored", "dist", "deep/r"]));
try { fs.mkdirSync(path.join(root, d), { recursive: true }); git(path.join(root, d), "init", "-q"); write(root, `${d}/inner.d.ts`, "n"); ops.push("repo " + d); } catch {}
}
let oldL, newL, err;
try { oldL = oldList(root); } catch (e) { err = "old: " + String(e.stderr ?? e).slice(0, 200); }
try { newL = await newList(root, budget); } catch (e) { err = (err ?? "") + " new: " + String(e?.message ?? e).slice(0, 300); }
const known = (p) => p.endsWith("/") && p.split("/").includes("node_modules");
const oldS = new Set((oldL ?? []).filter((p) => !known(p))), newS = new Set(newL ?? []);
const missing = [...oldS].filter((p) => !newS.has(p)), extra = [...newS].filter((p) => !oldS.has(p));
const row = { case: i, seed: seedStr, rules, ops, oldN: oldS.size, newN: newS.size, missing, extra, err };
rows.push(row);
if (missing.length || extra.length || err) console.log(JSON.stringify(row));
fs.rmSync(root, { recursive: true, force: true });
}
const bad = rows.filter((r) => r.missing.length || r.err);
console.log(JSON.stringify({ summary: true, seed: seedStr, cases: rows.length, withMissing: rows.filter((r) => r.missing.length).length, withExtra: rows.filter((r) => r.extra.length).length, errors: rows.filter((r) => r.err).length, nonEmpty: rows.filter((r) => r.oldN > 0).length }));
// Shared helpers: real ignoredCheckInputs (new), the old pathspec command, and a full-key replica of inputKey.
import * as fs from "node:fs";
import * as cp from "node:child_process";
import * as path from "node:path";
import * as crypto from "node:crypto";
import { createRequire } from "node:module";
import { pathToFileURL, fileURLToPath } from "node:url";
const here = path.dirname(fileURLToPath(import.meta.url));
const mod = process.env.NEW_TS ?? path.join(here, "../src/scripts/check-changed.ts");
const req = createRequire(mod);
const load = (s) => import(pathToFileURL(req.resolve(s)).href);
const M = await import(pathToFileURL(mod).href);
const NodeServices = await load("@effect/platform-node/NodeServices");
const Effect = await load("effect/Effect");
export const chunkByCommandLength = M.chunkByCommandLength;
export const emptyConfig = path.join(here, "empty-gitconfig");
fs.writeFileSync(emptyConfig, "");
for (const k of Object.keys(process.env)) if (k.startsWith("GIT_")) delete process.env[k];
Object.assign(process.env, {
GIT_CONFIG_GLOBAL: emptyConfig, GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_COUNT: "3",
GIT_CONFIG_KEY_0: "user.name", GIT_CONFIG_VALUE_0: "r", GIT_CONFIG_KEY_1: "user.email",
GIT_CONFIG_VALUE_1: "[email protected]", GIT_CONFIG_KEY_2: "core.autocrlf", GIT_CONFIG_VALUE_2: "false",
});
export const git = (root, ...args) => cp.execFileSync("git", args, { cwd: root, encoding: "utf8", maxBuffer: 1 << 28, stdio: ["ignore", "pipe", "pipe"] });
export const newList = (root, budget) =>
Effect.runPromise(M.ignoredCheckInputs(root, budget).pipe(Effect.provide(NodeServices.layer)));
export const oldList = (root) =>
git(root, "-c", "core.quotePath=false", "ls-files", "--others", "--ignored", "--exclude-standard", "--",
":(glob)**/.generated/**", ":(glob)**/.astro/**", ":(glob)**/*.d.ts", ":(glob)**/.env*",
":(exclude,glob)**/node_modules/**").split("\n").filter(Boolean);
// Replica of inputKey with base = HEAD.
export const fullKey = (root, ignored) => {
const h = crypto.createHash("sha256");
h.update(`v\0HEAD\0\0`);
h.update(cp.execFileSync("git", ["-c", "core.quotePath=false", "diff", "--binary", "--no-renames", "--no-ext-diff", "--no-textconv", "HEAD", "--"], { cwd: root, maxBuffer: 1 << 28 }));
const changed = git(root, "-c", "core.quotePath=false", "diff", "--name-only", "--no-renames", "HEAD", "--").split("\n").filter(Boolean);
const untracked = git(root, "-c", "core.quotePath=false", "ls-files", "--others", "--exclude-standard").split("\n").filter(Boolean);
for (const file of [...changed, ...untracked, ...ignored, "node_modules/.modules.yaml", "node_modules/.pnpm/lock.yaml"]) {
h.update(`\0${file}\0`);
try { const st = fs.statSync(path.join(root, file)); if (st.isFile()) h.update(fs.readFileSync(path.join(root, file))); } catch {}
}
return h.digest("hex");
};
export const write = (root, file, content = "x") => {
const t = path.join(root, file); fs.mkdirSync(path.dirname(t), { recursive: true }); fs.writeFileSync(t, content);
};
export const fresh = (root, files = {}, ignore = "dist/\nbuild/\n*.d.ts\n.env*\n.generated/\nnode_modules/\nvendored/\n") => {
fs.rmSync(root, { recursive: true, force: true }); fs.mkdirSync(root, { recursive: true });
git(root, "init", "-q"); write(root, ".gitignore", ignore);
for (const [f, c] of Object.entries(files)) write(root, f, c);
git(root, "add", "-f", "."); git(root, "commit", "-qm", "base");
};
// The "untracked directory whose contents are all ignored" listing quirk, combined with replaced/flagged paths.
import * as fs from "node:fs";
import * as path from "node:path";
import { git, write, fresh, newList, oldList, fullKey } from "./lib.mjs";
const out = process.argv[2];
const variants = {
"replaced-allignored-deep": (r) => { fs.rmSync(path.join(r, "p/x")); write(r, "p/x/a.d.ts", "1"); write(r, "p/x/deep/er/b.d.ts", "1"); },
"flagS-replaced-allignored-deep": (r) => { git(r, "update-index", "--skip-worktree", "p/x"); fs.rmSync(path.join(r, "p/x")); write(r, "p/x/a.d.ts", "1"); write(r, "p/x/deep/er/b.d.ts", "1"); },
"flagh-replaced-only-ignored-dirs": (r) => { git(r, "update-index", "--assume-unchanged", "p/x"); fs.rmSync(path.join(r, "p/x")); write(r, "p/x/dist/deep/b.d.ts", "1"); write(r, "p/x/build/c.d.ts", "1"); },
"untracked-only-ignored-dirs-deep": (r) => { write(r, "u/dist/a/b/c.d.ts", "1"); write(r, "u/v/build/.env", "1"); },
"untracked-allignored-with-stale-nm": (r) => { write(r, "u/a.d.ts", "1"); write(r, "u/node_modules/q/b.d.ts", "1"); write(r, "u/deep/er/b.d.ts", "1"); },
};
for (const [name, setup] of Object.entries(variants)) {
const r = path.join(out, name);
fresh(r, { "p/x": "f", "s.ts": "s" }); setup(r);
const files = oldList(r).filter((f) => !f.endsWith("/"));
const o1 = fullKey(r, oldList(r)), n1 = fullKey(r, await newList(r));
const res = [];
for (const f of files) { write(r, f, "edited " + f); const o2 = fullKey(r, oldList(r)), n2 = fullKey(r, await newList(r)); res.push({ f, oldChanged: o1 !== o2, newChanged: n1 !== n2 }); write(r, f, "1"); }
console.log(JSON.stringify({ name, old: oldList(r).sort(), new: await newList(r), stale: res.filter((x) => x.oldChanged && !x.newChanged) }));
}
{"name":"submodule-h","oldA":[],"newA":[],"oldB":[],"newB":[],"oldKeyChanged":false,"newKeyChanged":false,"STALE":false}
{"name":"submodule-S","oldA":[],"newA":[],"oldB":[],"newB":[],"oldKeyChanged":false,"newKeyChanged":false,"STALE":false}
{"name":"flag-h-file-to-dir","oldA":["p/dist/i.d.ts"],"newA":["p/dist/i.d.ts"],"oldB":["p/dist/i.d.ts"],"newB":["p/dist/i.d.ts"],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"flag-S-file-to-dir-deep","oldA":["p/x/a/b/.env"],"newA":["p/x/a/b/.env"],"oldB":["p/x/a/b/.env"],"newB":["p/x/a/b/.env"],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"flag-s-both-dir-not-ignored","oldA":["p/x/k.d.ts"],"newA":["p/x/k.d.ts"],"oldB":["p/x/k.d.ts"],"newB":["p/x/k.d.ts"],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"flag-h-dir-with-nm","oldA":["p/x/o.d.ts"],"newA":["p/x/o.d.ts"],"oldB":["p/x/o.d.ts"],"newB":["p/x/o.d.ts"],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"deleted-plain-file","oldA":["p/x/o.d.ts"],"newA":["p/x/o.d.ts"],"oldB":["p/x/o.d.ts"],"newB":["p/x/o.d.ts"],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"flag-in-ignored-dir-tracked","oldA":["dist/keep.js/i.d.ts","dist/other.d.ts"],"newA":["dist/keep.js/i.d.ts","dist/other.d.ts"],"oldB":["dist/keep.js/i.d.ts","dist/other.d.ts"],"newB":["dist/keep.js/i.d.ts","dist/other.d.ts"],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"nested-ignored-parent-create","oldA":[],"newA":[],"oldB":["dist/a/b/r/"],"newB":["dist/a/b/r/"],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"nested-ignored-parent-delete","oldA":["dist/a/b/r/"],"newA":["dist/a/b/r/"],"oldB":[],"newB":[],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"nested-untracked-parent-create","oldA":[],"newA":[],"oldB":["u/vendored/"],"newB":["u/vendored/"],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"nested-untracked-allignored-parent","oldA":["u/a.d.ts"],"newA":["u/a.d.ts"],"oldB":["u/a.d.ts","u/vendored/"],"newB":["u/a.d.ts","u/vendored/"],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"nested-tracked-parent-delete","oldA":["a/vendored/"],"newA":["a/vendored/"],"oldB":[],"newB":[],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"nested-in-node_modules-create","oldA":[],"newA":[],"oldB":["node_modules/pkg/"],"newB":[],"oldKeyChanged":true,"newKeyChanged":false,"STALE":true}
{"name":"nested-repo-at-ignored-dist","oldA":[],"newA":[],"oldB":["dist/"],"newB":["dist/"],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"nested-repo-not-ignored","oldA":[],"newA":[],"oldB":[],"newB":[],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"nested-inside-flagged-replaced","oldA":[],"newA":[],"oldB":[],"newB":[],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"tracked-file-replaced-by-nested-repo","oldA":["p/x/y.d.ts"],"newA":["p/x/y.d.ts"],"oldB":[],"newB":[],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"flagged-file-replaced-by-nested-repo","oldA":["p/x/y.d.ts"],"newA":["p/x/y.d.ts"],"oldB":[],"newB":[],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"surrogate-dir","oldA":["dist/πŸ˜€πŸŽ‰/deep/a.d.ts"],"newA":["dist/πŸ˜€πŸŽ‰/deep/a.d.ts"],"oldB":["dist/πŸ˜€πŸŽ‰/deep/a.d.ts"],"newB":["dist/πŸ˜€πŸŽ‰/deep/a.d.ts"],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
{"name":"dot-git-named-file","oldA":[],"newA":[],"oldB":[],"newB":[],"oldKeyChanged":false,"newKeyChanged":false,"STALE":false}
{"name":"ignored-dir-named-.git-file-entry","oldA":["dist/sub/a.d.ts"],"newA":["dist/sub/a.d.ts"],"oldB":["dist/sub/a.d.ts"],"newB":["dist/sub/a.d.ts"],"oldKeyChanged":true,"newKeyChanged":true,"STALE":false}
// Targeted attacks: each case builds state A, runs mutation to B; reports old/new lists and whether each key changed.
import * as fs from "node:fs";
import * as path from "node:path";
import { git, write, fresh, newList, oldList, fullKey } from "./lib.mjs";
const out = process.argv[2];
const only = process.argv[3];
const tryList = async (f, r) => { try { return await f(r); } catch (e) { return "ERR " + String(e?.stderr ?? e?.message ?? e).split("\n")[0].slice(0, 200); } };
const keyOf = (r, l) => (typeof l === "string" ? l : fullKey(r, l).slice(0, 10));
const cases = {
"submodule-h": { files: { "s.ts": "s" }, setup: (r) => { const s = path.join(r, "sub"); fs.mkdirSync(s); git(s, "init", "-q"); write(r, "sub/f.txt"); git(s, "add", "."); git(s, "commit", "-qm", "s"); git(r, "add", "sub"); git(r, "commit", "-qm", "add sub"); write(r, "sub/gen.d.ts"); git(r, "update-index", "--assume-unchanged", "sub"); }, edit: (r) => write(r, "sub/gen.d.ts", "y") },
"submodule-S": { files: { "s.ts": "s" }, setup: (r) => { const s = path.join(r, "sub"); fs.mkdirSync(s); git(s, "init", "-q"); write(r, "sub/f.txt"); git(s, "add", "."); git(s, "commit", "-qm", "s"); git(r, "add", "sub"); git(r, "commit", "-qm", "add sub"); git(r, "update-index", "--skip-worktree", "sub"); }, edit: (r) => write(r, "sub/gen.d.ts", "y") },
"flag-h-file-to-dir": { files: { "p/dist": "f" }, setup: (r) => { git(r, "update-index", "--assume-unchanged", "p/dist"); fs.rmSync(path.join(r, "p/dist")); write(r, "p/dist/i.d.ts", "1"); }, edit: (r) => write(r, "p/dist/i.d.ts", "2") },
"flag-S-file-to-dir-deep": { files: { "p/x": "f" }, setup: (r) => { git(r, "update-index", "--skip-worktree", "p/x"); fs.rmSync(path.join(r, "p/x")); write(r, "p/x/a/b/.env", "1"); }, edit: (r) => write(r, "p/x/a/b/.env", "2") },
"flag-s-both-dir-not-ignored": { files: { "p/x": "f" }, setup: (r) => { git(r, "update-index", "--skip-worktree", "--assume-unchanged", "p/x"); fs.rmSync(path.join(r, "p/x")); write(r, "p/x/k.d.ts", "1"); write(r, "p/x/plain.ts", "1"); }, edit: (r) => write(r, "p/x/k.d.ts", "2") },
"flag-h-dir-with-nm": { files: { "p/x": "f" }, setup: (r) => { git(r, "update-index", "--assume-unchanged", "p/x"); fs.rmSync(path.join(r, "p/x")); write(r, "p/x/node_modules/q/i.d.ts", "1"); write(r, "p/x/o.d.ts", "1"); }, edit: (r) => write(r, "p/x/o.d.ts", "2") },
"deleted-plain-file": { files: { "p/x": "f" }, setup: (r) => { fs.rmSync(path.join(r, "p/x")); write(r, "p/x/o.d.ts", "1"); }, edit: (r) => write(r, "p/x/o.d.ts", "2") },
"flag-in-ignored-dir-tracked": { files: { "dist/keep.js": "k" }, setup: (r) => { git(r, "update-index", "--skip-worktree", "dist/keep.js"); fs.rmSync(path.join(r, "dist/keep.js")); write(r, "dist/keep.js/i.d.ts", "1"); write(r, "dist/other.d.ts", "1"); }, edit: (r) => write(r, "dist/keep.js/i.d.ts", "2") },
"nested-ignored-parent-create": { files: { "s.ts": "s" }, setup: (r) => write(r, "dist/a/b/r/x.txt"), edit: (r) => git(path.join(r, "dist/a/b/r"), "init", "-q") },
"nested-ignored-parent-delete": { files: { "s.ts": "s" }, setup: (r) => { write(r, "dist/a/b/r/x.txt"); git(path.join(r, "dist/a/b/r"), "init", "-q"); }, edit: (r) => fs.rmSync(path.join(r, "dist/a/b/r/.git"), { recursive: true, force: true }) },
"nested-untracked-parent-create": { files: { "s.ts": "s" }, setup: (r) => { write(r, "u/vendored/x.txt"); write(r, "u/plain.ts"); }, edit: (r) => git(path.join(r, "u/vendored"), "init", "-q") },
"nested-untracked-allignored-parent": { files: { "s.ts": "s" }, setup: (r) => { write(r, "u/a.d.ts"); write(r, "u/vendored/x.txt"); }, edit: (r) => git(path.join(r, "u/vendored"), "init", "-q") },
"nested-tracked-parent-delete": { files: { "a/s.ts": "s" }, setup: (r) => { write(r, "a/vendored/x.txt"); git(path.join(r, "a/vendored"), "init", "-q"); }, edit: (r) => fs.rmSync(path.join(r, "a/vendored/.git"), { recursive: true, force: true }) },
"nested-in-node_modules-create": { files: { "s.ts": "s" }, setup: (r) => write(r, "node_modules/pkg/x.txt"), edit: (r) => git(path.join(r, "node_modules/pkg"), "init", "-q") },
"nested-repo-at-ignored-dist": { files: { "s.ts": "s" }, setup: (r) => write(r, "dist/x.txt"), edit: (r) => git(path.join(r, "dist"), "init", "-q") },
"nested-repo-not-ignored": { files: { "s.ts": "s" }, setup: (r) => write(r, "lib2/x.txt"), edit: (r) => git(path.join(r, "lib2"), "init", "-q") },
"nested-inside-flagged-replaced": { files: { "p/x": "f" }, setup: (r) => { git(r, "update-index", "--skip-worktree", "p/x"); fs.rmSync(path.join(r, "p/x")); write(r, "p/x/r/y.txt"); }, edit: (r) => git(path.join(r, "p/x/r"), "init", "-q") },
"tracked-file-replaced-by-nested-repo": { files: { "p/x": "f" }, setup: (r) => { fs.rmSync(path.join(r, "p/x")); write(r, "p/x/y.d.ts", "1"); }, edit: (r) => git(path.join(r, "p/x"), "init", "-q") },
"flagged-file-replaced-by-nested-repo": { files: { "p/x": "f" }, setup: (r) => { git(r, "update-index", "--skip-worktree", "p/x"); fs.rmSync(path.join(r, "p/x")); write(r, "p/x/y.d.ts", "1"); }, edit: (r) => git(path.join(r, "p/x"), "init", "-q") },
"surrogate-dir": { files: { "s.ts": "s" }, setup: (r) => write(r, "dist/πŸ˜€πŸŽ‰/deep/a.d.ts", "1"), edit: (r) => write(r, "dist/πŸ˜€πŸŽ‰/deep/a.d.ts", "2") },
"dot-git-named-file": { files: { "s.ts": "s" }, setup: (r) => write(r, "dist/.git/a.d.ts", "1"), edit: (r) => write(r, "dist/.git/a.d.ts", "2") },
"ignored-dir-named-.git-file-entry": { files: { "s.ts": "s" }, setup: (r) => { write(r, "dist/sub/.git", "gitdir: nowhere\n"); write(r, "dist/sub/a.d.ts", "1"); }, edit: (r) => write(r, "dist/sub/a.d.ts", "2") },
};
for (const [name, c] of Object.entries(cases)) {
if (only && !name.includes(only)) continue;
const r = path.join(out, name);
let row = { name };
try {
fresh(r, c.files);
c.setup(r);
const oA = await tryList(oldList, r), nA = await tryList(newList, r);
const koA = keyOf(r, oA), knA = keyOf(r, nA);
c.edit(r);
const oB = await tryList(oldList, r), nB = await tryList(newList, r);
const koB = keyOf(r, oB), knB = keyOf(r, nB);
row = { name, oldA: oA, newA: nA, oldB: oB, newB: nB, oldKeyChanged: koA !== koB, newKeyChanged: knA !== knB, STALE: koA !== koB && knA === knB };
} catch (e) { row.harnessError = String(e?.stderr ?? e?.message ?? e).slice(0, 300); }
console.log(JSON.stringify(row));
}
{"k":"branch-cold","head":"6e8168a03f","run":1,"start":"2026-11-06T13:02:12.588Z","seconds":7.7,"exit":0,"tooLongWarnings":0,"summary":"pass format"}
{"k":"branch-cold","head":"6e8168a03f","run":2,"start":"2026-11-06T13:02:20.293Z","seconds":4.5,"exit":0,"tooLongWarnings":0,"summary":"pass format"}
{"k":"branch-cold","head":"6e8168a03f","run":3,"start":"2026-11-06T13:02:24.817Z","seconds":4.6,"exit":0,"tooLongWarnings":0,"summary":"pass format"}
{"k":"branch-cold","head":"6e8168a03f","run":4,"start":"2026-11-06T13:02:29.461Z","seconds":4.6,"exit":0,"tooLongWarnings":0,"summary":"pass format"}
{"k":"branch-cold","head":"6e8168a03f","run":5,"start":"2026-11-06T13:02:34.030Z","seconds":5.1,"exit":0,"tooLongWarnings":0,"summary":"pass format"}
{"k":"branch-cached-rerun","head":"6e8168a03f","run":1,"start":"2026-11-06T13:02:39.160Z","seconds":4.2,"exit":0,"tooLongWarnings":0,"summary":"Nothing changed since the last passing run. | pass format"}
{"k":"main-cold","head":"6577c6b618","run":1,"start":"2026-11-06T13:02:45.252Z","seconds":2500.3,"exit":0,"tooLongWarnings":0,"summary":"pass format"}
{"k":"branch-after-main-cold","head":"6e8168a03f","run":1,"start":"2026-11-06T13:44:27.052Z","seconds":6,"exit":0,"tooLongWarnings":0,"summary":"pass format"}
{"k":"branch-after-main-cold","head":"6e8168a03f","run":2,"start":"2026-11-06T13:44:33.059Z","seconds":5,"exit":0,"tooLongWarnings":0,"summary":"pass format"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment