Skip to content

Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.

test: specify --include-dir persisted override + shouldSkipDir override contract

Alex Matthews8e7711c613e2
diff --git a/test/graph-scopes.test.ts b/test/graph-scopes.test.ts
index b6b1fdca..8dd229a5 100644
--- a/test/graph-scopes.test.ts
+++ b/test/graph-scopes.test.ts
@@ -13,6 +13,7 @@ import {
import { buildGraph } from "../src/graph/build.js";
import { readGraph, wiringPath, writeGraph } from "../src/graph/write.js";
import { loadGraphCached } from "../src/graph/load.js";
+import { writeBuildConfig } from "../src/util/state.js";
import type { GraphV1 } from "../src/graph/types.js";
function fx(layout: Record<string, string>): string {
@@ -170,6 +171,16 @@ test("discoverWorkspaceChildren finds immediate git children only", () => {
rmSync(d, { recursive: true, force: true });
});
+test("A5: discoverScopes finds a marker under a SKIP_DIRS name once persisted via --include-dir state, absent otherwise", () => {
+ const d = fx({ "build/package.json": "{}" });
+ assert.deepEqual(discoverScopes(d), [{ prefix: "", label: "", markers: [] }], "build/ is skipped by default — no scope found");
+
+ writeBuildConfig(d, { includeDirs: ["build"] });
+ const prefixes = discoverScopes(d).map((s) => s.prefix);
+ assert.deepEqual(prefixes, ["build"], "once persisted, build/'s own marker is discovered as a scope");
+ rmSync(d, { recursive: true, force: true });
+});
+
function tsFns(n: number): string {
return Array.from({ length: n }, (_, i) => `export function fn${i}() { return ${i}; }`).join("\n");
}
diff --git a/test/ingest-fs.test.ts b/test/ingest-fs.test.ts
index 64cbe72e..4596a41c 100644
--- a/test/ingest-fs.test.ts
+++ b/test/ingest-fs.test.ts
@@ -18,8 +18,8 @@ function write(root: string, path: string, content = "export const value = 1;\n"
writeFileSync(join(root, path), content);
}
-function walked(root: string): string[] {
- return walkDir(root)
+function walked(root: string, includes?: ReadonlySet<string>): string[] {
+ return walkDir(root, includes)
.map((path) => relative(root, path).replace(/\\/g, "/"))
.sort();
}
@@ -75,16 +75,21 @@ test("walkDir retains fixed skips and filesystem fallback outside Git", () => {
});
/**
- * A4 — shouldSkipDir consolidation.
+ * A5 — `shouldSkipDir` and its `--include-dir` override.
*
* "Is this name dot-prefixed or in SKIP_DIRS" is re-implemented by hand in
* three places: `skippedPath`'s per-segment predicate and `walkFilesystem`'s
* directory check (both src/ingest/fs.ts), and `discoverWorkspaceChildren`'s
- * git-child filter (src/graph/scopes.ts). `shouldSkipDir` is the single
- * source of truth now; these tests pin the predicate's contract and prove
- * every consumer — the file walk, marker-scope discovery and workspace-glob
- * resolution (both derived from the walked file set), and git-child
- * discovery — agrees on exactly the same skip set.
+ * git-child filter (src/graph/scopes.ts). This introduces `shouldSkipDir` as
+ * the single source of truth, with an optional `includes` param: a name in it
+ * is removed from the effective skip set for this repo's walks (persisted via
+ * `graft build --include-dir`), while a dot-directory stays non-overridable
+ * regardless.
+ *
+ * `--include-dir` lifts only graft's OWN skip list. In a Git repo, Git's
+ * ignore rules stay authoritative: an ignored directory remains excluded even
+ * when named — un-ignore it (or `git add -f`) to index it, the same contract
+ * the walker already applies to tracked-but-ignored files.
*/
test("shouldSkipDir: every SKIP_DIRS name and any dot-prefixed name is skipped; an ordinary name is not", () => {
@@ -96,6 +101,59 @@ test("shouldSkipDir: every SKIP_DIRS name and any dot-prefixed name is skipped;
assert.equal(shouldSkipDir("app"), false);
});
+test("A5: shouldSkipDir(name, includes) removes a SKIP_DIRS name from the skip set, but never a dot-dir", () => {
+ const includes = new Set(["build", ".git"]);
+ assert.equal(shouldSkipDir("build", includes), false, "an included SKIP_DIRS name is no longer skipped");
+ assert.equal(shouldSkipDir("vendor", includes), true, "a SKIP_DIRS name NOT in includes is still skipped");
+ assert.equal(shouldSkipDir(".git", includes), true, "a dot-dir is never overridable, even if explicitly included");
+ assert.equal(shouldSkipDir("src", includes), false);
+});
+
+test("A5: walkDir(dir, includes) descends into an included SKIP_DIRS-named directory (filesystem fallback)", () => {
+ const dir = mkdtempSync(join(tmpdir(), "graft-walkdir-include-"));
+ try {
+ mkdirSync(join(dir, "build"), { recursive: true });
+ writeFileSync(join(dir, "build", "real.ts"), "export const X = 1;\n");
+ mkdirSync(join(dir, "vendor"), { recursive: true });
+ writeFileSync(join(dir, "vendor", "other.ts"), "export const Y = 1;\n");
+
+ const withoutIncludes = walkDir(dir).map((f) => f.slice(dir.length + 1));
+ assert.ok(!withoutIncludes.some((f) => f.startsWith("build")), "default: build/ is skipped");
+
+ const withIncludes = walkDir(dir, new Set(["build"])).map((f) => f.slice(dir.length + 1));
+ assert.ok(withIncludes.some((f) => f.startsWith("build")), "build/ is walked once included");
+ assert.ok(!withIncludes.some((f) => f.startsWith("vendor")), "vendor/ stays skipped — only the named dir is included");
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
+test("A5: in a Git repo, --include-dir lifts the built-in skip for git-visible files", () => {
+ const dir = fixture("include-git");
+ try {
+ write(dir, "src/app.ts");
+ write(dir, "vendor/lib.ts"); // vendored dep committed to the repo — visible to git, skipped by the built-in list
+
+ assert.ok(!walked(dir).includes("vendor/lib.ts"), "default: vendor/ is skipped by the built-in list");
+ assert.deepEqual(walked(dir, new Set(["vendor"])), ["src/app.ts", "vendor/lib.ts"]);
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
+test("A5: --include-dir does not override gitignore — an ignored directory stays excluded even when named", () => {
+ const dir = fixture("include-ignored");
+ try {
+ write(dir, ".gitignore", "build/\n");
+ write(dir, "src/app.ts");
+ write(dir, "build/gen.ts");
+
+ assert.deepEqual(walked(dir, new Set(["build"])), [".gitignore", "src/app.ts"]);
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
/** One subdirectory per SKIP_DIRS name, plus a dot-directory and a normal
* directory — each holding a package.json marker, a source file, and a
* nested .git, so every check under test (file walk, marker-scope discovery,
diff --git a/test/util-state.test.ts b/test/util-state.test.ts
new file mode 100644
index 00000000..165e6aa9
--- /dev/null
+++ b/test/util-state.test.ts
@@ -0,0 +1,41 @@
+/**
+ * A5 — persisted --include-dir override.
+ *
+ * `graft build --include-dir <name>` needs a per-repo, persisted record of
+ * which SKIP_DIRS names to include, so a LATER no-flag build (or the hooks/
+ * refresh path, which never sees CLI flags at all) behaves identically to the
+ * invocation that set it. These tests pin the round-trip contract directly,
+ * independent of the CLI wiring (covered end-to-end in
+ * test/graph-include-dir.test.ts).
+ */
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { mkdtempSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { readBuildConfig, writeBuildConfig, readIncludeDirs } from "../src/util/state.js";
+
+function fresh(): string {
+ return mkdtempSync(join(tmpdir(), "graft-buildconfig-"));
+}
+
+test("readBuildConfig returns null when nothing was ever persisted", () => {
+ const d = fresh();
+ assert.equal(readBuildConfig(d), null);
+ assert.equal(readIncludeDirs(d), undefined, "no persisted config -> today's default (no includes)");
+});
+
+test("writeBuildConfig + readBuildConfig round-trip includeDirs", () => {
+ const d = fresh();
+ writeBuildConfig(d, { includeDirs: ["build", "vendor"] });
+ assert.deepEqual(readBuildConfig(d), { includeDirs: ["build", "vendor"] });
+});
+
+test("readIncludeDirs turns a persisted list into a Set; an empty persisted list reads as undefined (default behavior)", () => {
+ const d = fresh();
+ writeBuildConfig(d, { includeDirs: ["build"] });
+ assert.deepEqual(readIncludeDirs(d), new Set(["build"]));
+
+ writeBuildConfig(d, { includeDirs: [] });
+ assert.equal(readIncludeDirs(d), undefined, "an empty list must read exactly like no list at all");
+});