mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-19 19:02:29 +08:00
Three new regression tests guard the rename's blast radius (per codex Findings #1, #8, #9, #12): - test/no-stale-gstack-brain-refs.test.ts: greps bin/, scripts/, *.tmpl, test/ for forbidden identifiers (gstack-brain-init, gbrain_sync_mode); fails CI if any non-allowlisted file references them. - test/post-rename-doc-regen.test.ts: confirms gen-skill-docs output has no stale references in any */SKILL.md (the cross-product blind spot). - test/setup-gbrain-path4-structure.test.ts: structural lint over the Path 4 prose contract — STOP gates after verify failure, never-write- token rules, mode-aware CLAUDE.md block, bearer always via env-var. Two new gate-tier E2E tests (deterministic stub HTTP server, fixed inputs): - test/skill-e2e-setup-gbrain-remote.test.ts: Path 4 happy path. Stubs an HTTP MCP server, drives the skill via Agent SDK with a stubbed bearer, asserts claude.json gets the http MCP entry, CLAUDE.md gets the remote-http block, the secret token NEVER leaks to CLAUDE.md. - test/skill-e2e-setup-gbrain-bad-token.test.ts: stub server returns 401; asserts the AUTH classifier hint surfaces, no MCP registration occurs, CLAUDE.md is unchanged. Regression guard for the "verify failed → STOP" rule. touchfiles.ts: setup-gbrain-remote and setup-gbrain-bad-token added at gate-tier so CI catches Path 4 regressions on every PR. Plus a few comment refs flipped: bin/gstack-jsonl-merge, bin/gstack-timeline-log (legacy gstack-brain-init mentions in headers). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
75 lines
2.9 KiB
TypeScript
75 lines
2.9 KiB
TypeScript
// Post-rename doc-regen regression: after `bun run gen:skill-docs`, no
|
|
// `gstack-brain-init` or `gbrain_sync_mode` strings appear in any of the
|
|
// generated SKILL.md files (the cross-product blind spot codex
|
|
// Finding #12 flagged).
|
|
//
|
|
// The check runs against the canonical claude-host output already on
|
|
// disk. We don't shell out to gen-skill-docs again; the existing
|
|
// freshness check in gen-skill-docs.test.ts covers that. This test
|
|
// just verifies the rename actually propagated to the generated
|
|
// artifacts that users see.
|
|
|
|
import { describe, test, expect } from 'bun:test';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
|
|
const ROOT = path.resolve(import.meta.dir, '..');
|
|
|
|
const FORBIDDEN_PATTERNS = [
|
|
// Bare identifier — should NEVER appear in generated docs (if it does,
|
|
// a template still has the old call site).
|
|
/^.*\bgstack-brain-init\b.*$/m,
|
|
/^.*\bgbrain_sync_mode\b.*$/m,
|
|
];
|
|
|
|
// Per the preamble resolver: generated docs DO contain the
|
|
// "~/.gstack-brain-remote.txt" string in the migration-window fallback. We
|
|
// don't grep for that — it's intentional. We grep for the call-site
|
|
// identifiers only.
|
|
|
|
function findSkillMdFiles(): string[] {
|
|
const skillMd = path.join(ROOT, 'SKILL.md');
|
|
const files: string[] = [skillMd];
|
|
// Top-level skill directories with their own SKILL.md.
|
|
const entries = fs.readdirSync(ROOT, { withFileTypes: true });
|
|
for (const e of entries) {
|
|
if (e.isDirectory() && !e.name.startsWith('.') && !['node_modules', 'test'].includes(e.name)) {
|
|
const inner = path.join(ROOT, e.name, 'SKILL.md');
|
|
if (fs.existsSync(inner)) files.push(inner);
|
|
}
|
|
}
|
|
return files;
|
|
}
|
|
|
|
describe('post-rename doc-regen regression (codex Finding #12)', () => {
|
|
test('no generated SKILL.md contains "gstack-brain-init"', () => {
|
|
const offenders: string[] = [];
|
|
for (const file of findSkillMdFiles()) {
|
|
const content = fs.readFileSync(file, 'utf-8');
|
|
const m = content.match(/^.*\bgstack-brain-init\b.*$/m);
|
|
if (m) offenders.push(`${path.relative(ROOT, file)}: ${m[0].slice(0, 100)}`);
|
|
}
|
|
if (offenders.length > 0) {
|
|
console.error(`Stale "gstack-brain-init" in generated SKILL.md files:\n${offenders.map((o) => ' ' + o).join('\n')}`);
|
|
}
|
|
expect(offenders).toEqual([]);
|
|
});
|
|
|
|
test('no generated SKILL.md contains "gbrain_sync_mode"', () => {
|
|
const offenders: string[] = [];
|
|
for (const file of findSkillMdFiles()) {
|
|
const content = fs.readFileSync(file, 'utf-8');
|
|
const m = content.match(/^.*\bgbrain_sync_mode\b.*$/m);
|
|
if (m) offenders.push(`${path.relative(ROOT, file)}: ${m[0].slice(0, 100)}`);
|
|
}
|
|
if (offenders.length > 0) {
|
|
console.error(`Stale "gbrain_sync_mode" in generated SKILL.md files:\n${offenders.map((o) => ' ' + o).join('\n')}`);
|
|
}
|
|
expect(offenders).toEqual([]);
|
|
});
|
|
|
|
test('top-level SKILL.md exists and is regenerated', () => {
|
|
expect(fs.existsSync(path.join(ROOT, 'SKILL.md'))).toBe(true);
|
|
});
|
|
});
|