Files
gstack/test/dev-setup-render-isolation.test.ts
T
Garry Tan 8241949357 v1.57.9.0 feat: source-clean gbrain render (dev-setup --out-dir + machine-wide gbrain-refresh) (#1951)
* feat(gbrain-detect): add --is-ok live-detection exit-code gate

Single source of truth for 'is gbrain usable'. Runs live detection (never
reads the possibly-stale gbrain-detection.json) and exits 0 iff status is ok,
so setup, bin/dev-setup, and gstack-config can gate brain-aware rendering on
one shared check instead of re-grepping the JSON.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(gen-skill-docs): add --out-dir with surgical section-path rewrite

--out-dir <abs-dir> mirrors the Claude skill tree (SKILL.md + sections) into a
separate directory instead of writing in place, and rewrites the literal
section-base path (~/.claude/skills/gstack/<skill>/sections/) in generated
content to point at the out-dir. The rewrite is surgical: only /sections/ paths
move; bin/, browse/, docs/ references stay pointed at the global install.
Global extras (proactive-suggestions.json) are skipped in out-dir mode. Default
(no flag) behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(dev-setup): render gbrain :user variant to an untracked workspace dir

Stops the dev/Conductor workspace from dirtying tracked SKILL.md source. setup
honors GSTACK_SKIP_GBRAIN_REGEN (passed inline by dev-setup, never exported) and
skips the in-place :user regen; detection is still persisted (PID-unique tmp so
concurrent workspaces can't clobber it). dev-setup instead renders the :user
variant into .claude/gstack-rendered (gitignored, per-workspace) and repoints
the workspace SKILL.md symlinks at it, so the workspace gets brain-aware blocks
while the worktree stays canonical. dev-teardown removes the render.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(dev-skill): refresh the untracked brain-aware render on template change

After the default in-place regen (which keeps the worktree canonical and runs
validation), also re-render the :user variant into .claude/gstack-rendered when
it exists, so live template edits reflect at the workspace's runtime. Never
creates the render dir during plain template dev.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(gstack-config): gbrain-refresh renders brain-aware blocks into the install

Extends gbrain-refresh to render the :user variant into the global install
(~/.claude/skills/gstack) so every project's Claude sessions get brain-aware
blocks, not just the gstack dev workspace. Guarded against mutating the wrong
directory: the target must exist, not be a symlink (a symlinked install points
at a dev worktree), and look like a real gstack clone (VERSION + package.json).
Idempotent and self-documenting. CLAUDE.md's deploy section now notes that
'git reset --hard' reverts the blocks and to re-run gbrain-refresh.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test: cover gstack-gbrain-detect --is-ok + dev-skill render refresh

Fills the two automated-coverage gaps from the eng review: --is-ok exit-code
gate (no-cli -> nonzero, healthy -> 0, plus an agrees-with-JSON no-skew check
reusing the deterministic fake-gbrain harness) and a static tripwire that
dev-skill re-renders the :user variant into the workspace render dir only when
it already exists.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* chore: bump version and changelog (v1.57.9.0)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs: document brain-aware dev-setup render for v1.57.9.0

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 22:29:23 -07:00

92 lines
3.4 KiB
TypeScript

import { describe, test, expect } from 'bun:test';
import * as path from 'path';
import * as fs from 'fs';
// Static tripwires for the B2 render-isolation wiring. These fail CI if a
// refactor drops a load-bearing line, re-introducing the "dev-setup dirties
// tracked SKILL.md" drift (or worse, leaks the skip-guard into real installs).
const ROOT = path.resolve(import.meta.dir, '..');
const read = (rel: string) => fs.readFileSync(path.join(ROOT, rel), 'utf-8');
describe('dev-setup: worktree stays canonical', () => {
const devSetup = read('bin/dev-setup');
test('passes GSTACK_SKIP_GBRAIN_REGEN inline on the nested setup call', () => {
expect(devSetup).toContain('GSTACK_SKIP_GBRAIN_REGEN=1 "$GSTACK_LINK/setup"');
});
test('never exports GSTACK_SKIP_GBRAIN_REGEN (would leak into other setup paths)', () => {
expect(devSetup).not.toMatch(/export\s+GSTACK_SKIP_GBRAIN_REGEN/);
});
test('renders the :user variant into an out-dir, not in place', () => {
expect(devSetup).toContain('--out-dir');
expect(devSetup).toContain('.claude/gstack-rendered');
});
test('gates the render on gstack-gbrain-detect --is-ok', () => {
expect(devSetup).toContain('--is-ok');
});
});
describe('setup: honors GSTACK_SKIP_GBRAIN_REGEN', () => {
const setup = read('setup');
test('skips the in-place :user regen when the guard is set', () => {
expect(setup).toContain('${GSTACK_SKIP_GBRAIN_REGEN:-}');
// The guard must wrap the in-place render, not the detection persist.
const idx = setup.indexOf('GSTACK_SKIP_GBRAIN_REGEN');
const after = setup.slice(idx, idx + 600);
expect(after).toContain('leaving tracked SKILL.md canonical');
});
test('uses a PID-unique detection tmp (no concurrent clobber)', () => {
expect(setup).toContain('$DETECTION_FILE.$$.tmp');
});
test('gates detection on the shared --is-ok check', () => {
expect(setup).toContain('"$DETECT_BIN" --is-ok');
});
});
describe('gen-skill-docs: section rewrite is gated on --out-dir', () => {
const gen = read('scripts/gen-skill-docs.ts');
test('rewriteSectionBase is a no-op without --out-dir', () => {
expect(gen).toContain('function rewriteSectionBase');
const idx = gen.indexOf('function rewriteSectionBase');
const body = gen.slice(idx, idx + 400);
expect(body).toContain('if (!OUT_DIR) return content');
expect(body).toContain('sections'); // surgical: regex targets only /sections/ paths
});
});
describe('dev-teardown: removes the untracked render', () => {
const teardown = read('bin/dev-teardown');
test('rm -rf the gstack-rendered dir', () => {
expect(teardown).toContain('gstack-rendered');
expect(teardown).toMatch(/rm -rf .*RENDER_DIR/);
});
});
describe('.gitignore: render dir is declared untracked', () => {
test('.claude/gstack-rendered/ is ignored', () => {
expect(read('.gitignore')).toContain('.claude/gstack-rendered/');
});
});
describe('dev-skill: refreshes the render on template change', () => {
const devSkill = read('scripts/dev-skill.ts');
test('re-renders the :user variant into the workspace render dir', () => {
expect(devSkill).toContain('gstack-rendered');
expect(devSkill).toContain('--out-dir');
expect(devSkill).toContain('--respect-detection');
});
test('only refreshes when the render dir already exists (never creates it during plain dev)', () => {
expect(devSkill).toContain('fs.existsSync(RENDER_DIR)');
});
});