mirror of
https://github.com/garrytan/gstack.git
synced 2026-08-31 10:20:42 +02:00
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:
co-authored by
Claude Fable 5
parent
5c525c9aca
commit
39a0b61aaa
@@ -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/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/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):
|
||||
'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',
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
* factory, opencode, openclaw, cursor, kiro).
|
||||
*
|
||||
* 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
|
||||
* pipeline — no mocking — so it catches regressions in either the loader
|
||||
* or the suppressedResolvers filter.
|
||||
@@ -18,9 +19,9 @@
|
||||
* 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 { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs';
|
||||
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
|
||||
import { tmpdir } from 'os';
|
||||
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.
|
||||
* Returns the regenerated office-hours/SKILL.md content WITHOUT writing
|
||||
* over the committed file: we use --dry-run to keep the working tree
|
||||
* clean, then parse the output via re-reading the committed file... no,
|
||||
* that doesn't work for dry-run since dry-run doesn't write.
|
||||
*
|
||||
* Approach: generate to a temp output dir by running gen-skill-docs in a
|
||||
* temp checkout. Simpler alternative: actually regenerate, snapshot the
|
||||
* file content, then git-checkout the committed version back. We use this
|
||||
* since gen-skill-docs doesn't expose an output-path arg.
|
||||
* Run gen-skill-docs with --respect-detection and an isolated GSTACK_HOME,
|
||||
* rendering into a fresh --out-dir. The working tree is never written: the
|
||||
* generator reads its inputs (templates, resolvers) from the repo but lands
|
||||
* every output in the temp dir, which we snapshot and delete. This replaced
|
||||
* the old mutate-then-restore approach (which regenerated the committed
|
||||
* files in place and only restored the probe files, leaving every OTHER
|
||||
* generated file rewritten — a partial-restore hazard for concurrent
|
||||
* readers).
|
||||
*/
|
||||
function regenAndSnapshot(opts: {
|
||||
respectDetection: boolean;
|
||||
tmpHome: string;
|
||||
files: string[];
|
||||
}): Map<string, string> {
|
||||
// Save committed content so we can restore after snapshotting.
|
||||
const original = new Map<string, string>();
|
||||
for (const f of opts.files) {
|
||||
original.set(f, readFileSync(join(REPO_ROOT, f), 'utf-8'));
|
||||
}
|
||||
const outDir = mkdtempSync(join(tmpdir(), 'gbrain-detect-out-'));
|
||||
|
||||
const args = [
|
||||
'run',
|
||||
'scripts/gen-skill-docs.ts',
|
||||
'--host',
|
||||
'claude',
|
||||
'--out-dir',
|
||||
outDir,
|
||||
];
|
||||
if (opts.respectDetection) args.push('--respect-detection');
|
||||
|
||||
@@ -87,17 +84,14 @@ function regenAndSnapshot(opts: {
|
||||
timeout: 30_000,
|
||||
});
|
||||
|
||||
// Snapshot the regenerated content.
|
||||
// Snapshot the rendered content from the out-dir.
|
||||
const snapshot = new Map<string, string>();
|
||||
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;
|
||||
} finally {
|
||||
// Always restore so the test leaves the working tree clean.
|
||||
for (const [f, content] of original) {
|
||||
writeFileSync(join(REPO_ROOT, f), content);
|
||||
}
|
||||
rmSync(outDir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user