fix(test): gbrain-detection-override drops mutate-then-git-restore

regenAndSnapshot renders --host claude --out-dir <mkdtemp> (+
--respect-detection) and snapshots probes from the out-dir. The
git-restore machinery is deleted outright — it restored only
PROBE_FILES of the 71 files each call wrote, so a stale tree kept the
other 68 dirty (the partial-restore bug), and its 'no output-path arg'
comment had been false since --out-dir landed. TREE_MUTATING entry
deleted.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-08-29 05:32:59 +00:00
co-authored by Claude Fable 5
parent 5c525c9aca
commit 39a0b61aaa
2 changed files with 18 additions and 26 deletions
-2
View File
@@ -391,8 +391,6 @@ export const TREE_MUTATING: Record<string, string> = {
'test/catalog-mode-full.test.ts': 'regenerates ALL SKILL.md in full-catalog mode, then restores', 'test/catalog-mode-full.test.ts': 'regenerates ALL SKILL.md in full-catalog mode, then restores',
'test/spec-template-sync.test.ts': 'regenerates all SKILL.md in place to compare spec/SKILL.md', 'test/spec-template-sync.test.ts': 'regenerates all SKILL.md in place to compare spec/SKILL.md',
'test/gen-skill-docs-idempotency.test.ts': 'regenerates all SKILL.md twice to prove idempotency', 'test/gen-skill-docs-idempotency.test.ts': 'regenerates all SKILL.md twice to prove idempotency',
'test/gbrain-detection-override.test.ts':
'regenerates SKILL.md in place with --respect-detection (gbrain variant), then git-restores — readers see inflated skeletons mid-window',
// Ratchet readers (measure the tree; need it quiet): // Ratchet readers (measure the tree; need it quiet):
'test/parity-suite.test.ts': 'RATCHET READER — parity caps measure live SKILL.md/section bytes', 'test/parity-suite.test.ts': 'RATCHET READER — parity caps measure live SKILL.md/section bytes',
'test/skill-size-budget.test.ts': 'RATCHET READER — per-skill and corpus size budgets measure the live tree', 'test/skill-size-budget.test.ts': 'RATCHET READER — per-skill and corpus size budgets measure the live tree',
+18 -24
View File
@@ -9,7 +9,8 @@
* factory, opencode, openclaw, cursor, kiro). * factory, opencode, openclaw, cursor, kiro).
* *
* Tests drive gen-skill-docs as a subprocess against a temp GSTACK_HOME * Tests drive gen-skill-docs as a subprocess against a temp GSTACK_HOME
* with each detection state, then assert what landed in the generated * with each detection state, rendering into an isolated --out-dir (never
* writing the working tree), then assert what landed in the rendered
* Claude-host SKILL.md. This is end-to-end through the actual override * Claude-host SKILL.md. This is end-to-end through the actual override
* pipeline — no mocking — so it catches regressions in either the loader * pipeline — no mocking — so it catches regressions in either the loader
* or the suppressedResolvers filter. * or the suppressedResolvers filter.
@@ -18,9 +19,9 @@
* generation against the real repo; --host claude scopes to one host). * generation against the real repo; --host claude scopes to one host).
*/ */
import { describe, test, expect, beforeAll, afterAll } from 'bun:test'; import { describe, test, expect } from 'bun:test';
import { execFileSync } from 'child_process'; import { execFileSync } from 'child_process';
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs'; import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
import { tmpdir } from 'os'; import { tmpdir } from 'os';
import { join } from 'path'; import { join } from 'path';
@@ -49,33 +50,29 @@ function makeFixture(detectionJson: string | null): FixtureEnv {
} }
/** /**
* Run gen-skill-docs with --respect-detection and an isolated GSTACK_HOME. * Run gen-skill-docs with --respect-detection and an isolated GSTACK_HOME,
* Returns the regenerated office-hours/SKILL.md content WITHOUT writing * rendering into a fresh --out-dir. The working tree is never written: the
* over the committed file: we use --dry-run to keep the working tree * generator reads its inputs (templates, resolvers) from the repo but lands
* clean, then parse the output via re-reading the committed file... no, * every output in the temp dir, which we snapshot and delete. This replaced
* that doesn't work for dry-run since dry-run doesn't write. * the old mutate-then-restore approach (which regenerated the committed
* * files in place and only restored the probe files, leaving every OTHER
* Approach: generate to a temp output dir by running gen-skill-docs in a * generated file rewritten — a partial-restore hazard for concurrent
* temp checkout. Simpler alternative: actually regenerate, snapshot the * readers).
* file content, then git-checkout the committed version back. We use this
* since gen-skill-docs doesn't expose an output-path arg.
*/ */
function regenAndSnapshot(opts: { function regenAndSnapshot(opts: {
respectDetection: boolean; respectDetection: boolean;
tmpHome: string; tmpHome: string;
files: string[]; files: string[];
}): Map<string, string> { }): Map<string, string> {
// Save committed content so we can restore after snapshotting. const outDir = mkdtempSync(join(tmpdir(), 'gbrain-detect-out-'));
const original = new Map<string, string>();
for (const f of opts.files) {
original.set(f, readFileSync(join(REPO_ROOT, f), 'utf-8'));
}
const args = [ const args = [
'run', 'run',
'scripts/gen-skill-docs.ts', 'scripts/gen-skill-docs.ts',
'--host', '--host',
'claude', 'claude',
'--out-dir',
outDir,
]; ];
if (opts.respectDetection) args.push('--respect-detection'); if (opts.respectDetection) args.push('--respect-detection');
@@ -87,17 +84,14 @@ function regenAndSnapshot(opts: {
timeout: 30_000, timeout: 30_000,
}); });
// Snapshot the regenerated content. // Snapshot the rendered content from the out-dir.
const snapshot = new Map<string, string>(); const snapshot = new Map<string, string>();
for (const f of opts.files) { for (const f of opts.files) {
snapshot.set(f, readFileSync(join(REPO_ROOT, f), 'utf-8')); snapshot.set(f, readFileSync(join(outDir, f), 'utf-8'));
} }
return snapshot; return snapshot;
} finally { } finally {
// Always restore so the test leaves the working tree clean. rmSync(outDir, { recursive: true, force: true });
for (const [f, content] of original) {
writeFileSync(join(REPO_ROOT, f), content);
}
} }
} }