diff --git a/src/check-gitignore.test.ts b/src/check-gitignore.test.ts index 69a0245a..d9590ef5 100644 --- a/src/check-gitignore.test.ts +++ b/src/check-gitignore.test.ts @@ -127,6 +127,27 @@ describe("patchGitignore", () => { rmSync(dir, { recursive: true, force: true }); } }); + + it("ignores .kit contents via .kit/* and re-includes the curated shared tier", async () => { + const dir = tmpRepo(); + try { + await patchGitignore(dir); + const text = readFileSync(join(dir, ".gitignore"), "utf-8"); + // Must use the descendable `.kit/*` form, never the wholesale `.kit/` + // (which would make the `!.kit/shared/` negation a no-op). + const lines = text.split("\n").map((l) => l.split("#")[0].trim()); + assert.ok(lines.includes(".kit/*"), "expected .kit/* contents-ignore"); + assert.ok(!lines.includes(".kit/"), "must not emit wholesale .kit/"); + assert.ok(lines.includes("!.kit/shared/"), "expected shared re-include"); + // Order matters: the negation must come AFTER .kit/*. + assert.ok( + lines.indexOf("!.kit/shared/") > lines.indexOf(".kit/*"), + "negation must follow .kit/*", + ); + } finally { + rmSync(dir, { recursive: true, force: true }); + } + }); }); describe("findCommittedSensitive", () => { diff --git a/src/check-gitignore.ts b/src/check-gitignore.ts index 7adcdf18..7381a811 100644 --- a/src/check-gitignore.ts +++ b/src/check-gitignore.ts @@ -34,7 +34,13 @@ const REQUIRED_PATTERNS: RequiredEntry[] = [ { pattern: ".env.local", reason: "local secrets materialized by kit secrets", aliases: [".env*"] }, { pattern: ".env.*.local", reason: "per-env local secrets", aliases: [".env*"] }, { pattern: "node_modules", reason: "dependency tree", aliases: ["node_modules/"] }, - { pattern: ".kit/", reason: "kit local state (elevation, env, runtime)", aliases: [".kit", ".kit/*"] }, + // Ignore kit's local-state CONTENTS via `.kit/*` (not the wholesale `.kit/`): + // git won't descend into a wholesale-excluded dir, so a later `!.kit/shared/` + // negation cannot re-include the curated, committed-by-design shared tier + // (.kit/shared/memory.jsonl). `.kit/*` ignores the contents while leaving the + // dir descendable, so the negation below works. + { pattern: ".kit/*", reason: "kit local state (elevation, env, runtime)", aliases: [".kit", ".kit/", ".kit/*"] }, + { pattern: "!.kit/shared/", reason: "keep curated shared memory tracked (committed by design)", aliases: ["!.kit/shared", "!.kit/shared/**"] }, { pattern: ".kit-audit.jsonl", reason: "audit log can contain secret labels + paths" }, { pattern: "*.pem", reason: "PEM keys / certs" }, { pattern: "*.key", reason: "private keys" }, diff --git a/src/status.test.ts b/src/status.test.ts index b5b4edef..2929fcd8 100644 --- a/src/status.test.ts +++ b/src/status.test.ts @@ -59,7 +59,8 @@ describe("kit status", () => { [ ".env*", "node_modules", - ".kit/", + ".kit/*", + "!.kit/shared/", ".kit-audit.jsonl", "*.pem", "*.key",