mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-28 07:32:14 +02:00
* fix(memory-ingest): --scan-secrets scans the rendered page and fails closed --scan-secrets ran gitleaks on the raw transcript .jsonl, then imported a page rendered from it. gitleaks' assignment rules don't match across a JSON-escaped quote (KEY=\"v\" on disk), so a secret the rendered page shows as KEY="v" was imported unflagged. And the gate skipped a file only on scanner "gitleaks" with findings, so a scan that errored (non-zero exit, 16MB maxBuffer overflow on a file with many findings, unparseable report) or could not run (gitleaks missing, slow-probe cooldown) imported the file unscanned. Scan the rendered page body, the exact bytes writeStaged() writes, via a new secretScanText() helper, and skip the file whenever the scan did not complete. Skipped files stay out of the state file, so the next run retries them. Reword the helper warnings and setup-gbrain/memory.md, which described the fail-open as intended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(test): reconcile Bun failure markers and footer counts * fix(sync-gbrain): verify source-scoped reads without mutation * fix(test): recognize grounded TTHW target choices structurally * fix(aside): make the readiness probe work under zsh and report why it failed The probe built its deadline into `_T` and expanded it unquoted, so `$_T aside repl …` only worked in a shell that word-splits. zsh does not: it looked for a command literally named "gtimeout 30", the probe answered ASIDE_NOT_RUNNING with Aside installed and ready, and every browsing skill fell back to the bundled Chromium in silence. zsh is the macOS default and Aside is macOS-only, so on a stock Mac the probe could never report READY. The deadline becomes a function, `_gs_d`. It receives the command as "$@", already split, so sh, bash and zsh all behave the same, and the gtimeout → timeout → perl alarm chain is unchanged. A 4th arm runs the call unbounded when none of the three is present, which is what the empty `_T` did before. Not `eval`: it re-parses the string, so the parens and `;` of the perl arm become syntax and that arm dies in bash *and* zsh — on a stock Mac, the arm that actually runs. On failure the probe now prints the CLI's reason after ASIDE_NOT_RUNNING:, the shape gstack-render already uses: the first line that starts with a capital letter, i.e. the CLI's own sentence or Node's `Error:` line below its loader frame. "Not running" covers states with different fixes — no window open for the profile, a NODE_OPTIONS preload that kills the CLI — and a bare verdict sent all of them to "open the Aside app". The BROWSER SETUP prose quotes that reason before asking the user to open the app. The text pin asserted the broken invocation verbatim, so it now pins the function and asserts neither `$_T aside repl` nor an eval form comes back. A second test executes the rendered probe in sh, bash and zsh on each of the four deadline arms with stubbed binaries on a narrowed PATH, plus two failing CLIs: one that prints its own sentence, one that crashes like Node with the useful line below the frame. The deadline function costs zero bytes against the lines it replaces; the reason costs 53 per copy of the probe (44 where the reworded BROWSER SETUP line gives 9 back). That moves four guards by the measured amount: plan-devex-review's skeleton cap to 68,550 (measured 68,544), plan-ceo-review's skeleton cap to 80,150 (measured 80,111) and union ratio to 1.081 (measured 1.0803), and plan-eng-review's union ratio to 1.151 (measured 1.1504). Fixes #2842, #2941. * Clarify engineering review startup and decision flow * Fix Windows readiness fixture PATH and command shim * fix(test): recognize grounded TTHW target choices structurally * Clarify engineering review startup and decision flow * fix(test): restrict QA-only fixture tools to its no-Edit contract * v1.90.0.0 fix(sync-gbrain): guard readiness verdicts and refresh metadata * fix(browse): validate canonical upload targets * fix(gbrain): classify structured PGLite busy response * fix(browse): preserve native extension runtime APIs * Fix displayless browser handoff ownership * Accept unique installed autoplan methodology aliases * fix(skills): preserve positional literals during installation * fix(browse): checksum installer contents through stdin * fix(test): normalize Windows checksum fixture paths * test: emulate unavailable shasum in Windows checksum fixture * fix(investigate): preserve owned freeze lifecycle * fix(review): preserve N+1 retry and Red Team completion * fix: bound Aside readiness and preserve safe fallback * test: exercise setup and Chromium on native ARM * fix: preserve install ownership and ARM browser selection * Fix gbrain ingest scan boundaries and seed observation * Refresh managed ship hooks and supervise expanded paid census * Reject resumed gbrain pages excluded by current policy * Recover zombie agent locks safely and enable CI Python venv * Repair paid actor declarations and Aside pitch assertions * Bump consolidated wave to next free minor release * Clarify CEO review admin choices and option tradeoffs * Preserve CEO mode handoff anchors in clarified workflow * Make Windows portability fixtures use shell-native paths * Restore ARM Bun alias and clarify ship review gates * Refresh ship workflow golden snapshots * Fix Windows DX documentation controls without piped stdin * Decode Codex child pipes without Bun's encoded-stream stall * Bound DX pre-review audit before product questions * Clarify trusted review-start read in paid revalidation * Bump consolidated wave to next free minor release * Clarify CEO review admin choices and option tradeoffs * Preserve CEO mode handoff anchors in clarified workflow * Make Windows portability fixtures use shell-native paths * Restore ARM Bun alias and clarify ship review gates * Refresh ship workflow golden snapshots * Fix Windows DX documentation controls without piped stdin * Decode Codex child pipes without Bun's encoded-stream stall * Bound DX pre-review audit before product questions * Clarify trusted review-start read in paid revalidation * Reconcile new main planning flow and paid judge census * fix: reconcile rebased planning and source-bound validation * test: pin cookie workflow judge to scored Sonnet model * fix: keep terminal agent boot out of module imports * fix: preserve pending-question uncertainty in engineering review * fix: stabilize Windows reliability-wave fixtures * fix: clarify design consultation research workflow * fix: preserve independent design consultation inputs * fix: resolve design taste scope and browser research guidance * fix: make consultation opt-in preflight unambiguous * test: await native Edge owner readiness or terminal result --------- Co-authored-by: Bruce Krysiak <brucek@alum.mit.edu> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Antonio Vitalic <antoninte99@gmail.com>
185 lines
11 KiB
TypeScript
185 lines
11 KiB
TypeScript
/**
|
|
* gen-skill-docs prunes stale external-host renders.
|
|
*
|
|
* The generator only ever wrote outputs, so a skill deleted from the source
|
|
* tree stayed rendered under every host's skills/ dir (and setup kept linking
|
|
* it). Now a render removes `gstack-*` dirs it did not write — but only those
|
|
* carrying the generated banner (proof it was ours), never after a host's
|
|
* generation failed (a partial rendered set must not delete the rest), never
|
|
* under --dry-run (a freshness check writes nothing and deletes nothing), and
|
|
* never in ANOTHER host's skills/ dir (a `--host codex` run has no rendered
|
|
* set for factory, so it has no basis to judge factory's entries).
|
|
*/
|
|
import { describe, test, expect } from 'bun:test';
|
|
import { spawnSync } from 'child_process';
|
|
import * as fs from 'fs';
|
|
import * as os from 'os';
|
|
import * as path from 'path';
|
|
|
|
const ROOT = path.resolve(import.meta.dir, '..');
|
|
const BANNER = '<!-- AUTO-GENERATED from SKILL.md.tmpl — do not edit directly -->';
|
|
|
|
/** A stale RENDER: the generator's banner is the proof of ownership the prune requires. */
|
|
function staleRender(name: string, body: string): string {
|
|
return `---\nname: ${name}\n---\n${BANNER}\n${body}\n`;
|
|
}
|
|
|
|
function gen(out: string, ...extra: string[]) {
|
|
return spawnSync('bun', ['run', 'scripts/gen-skill-docs.ts', '--host', 'codex', '--out-dir', out, ...extra], {
|
|
cwd: ROOT, encoding: 'utf-8', timeout: 180_000,
|
|
env: { ...process.env, GSTACK_DEFER_CLAUDE_RENAME_PRUNE: '0' },
|
|
});
|
|
}
|
|
|
|
describe('gen-skill-docs stale-render prune', () => {
|
|
test('a gstack-* render for a skill that no longer exists is removed; the sidecar symlink, real skills, un-bannered gstack-* dirs, and other hosts\' trees stay', () => {
|
|
const out = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-prune-'));
|
|
// Keep the sidecar's source disposable: a broken symlink-loop guard must
|
|
// never overwrite this checkout's SKILL.md and poison parallel readers.
|
|
const source = path.join(out, 'source');
|
|
fs.mkdirSync(path.join(source, 'scripts'), { recursive: true });
|
|
fs.copyFileSync(path.join(ROOT, 'scripts', 'gen-skill-docs.ts'), path.join(source, 'scripts', 'gen-skill-docs.ts'));
|
|
for (const file of ['discover-skills.ts', 'external-skill-names.ts', 'gen-llms-txt.ts', 'gen-agents-digest.ts', 'models.ts']) {
|
|
fs.symlinkSync(path.join(ROOT, 'scripts', file), path.join(source, 'scripts', file), 'file');
|
|
}
|
|
fs.symlinkSync(path.join(ROOT, 'scripts', 'resolvers'), path.join(source, 'scripts', 'resolvers'), 'dir');
|
|
for (const dir of ['hosts', 'lib']) fs.symlinkSync(path.join(ROOT, dir), path.join(source, dir), 'dir');
|
|
for (const skill of ['', 'ship']) {
|
|
fs.mkdirSync(path.join(source, skill), { recursive: true });
|
|
fs.writeFileSync(path.join(source, skill, 'SKILL.md.tmpl'), `---\nname: ${skill || 'gstack'}\ndescription: Fixture skill.\n---\nFixture body.\n`);
|
|
}
|
|
const canonical = path.join(source, 'SKILL.md');
|
|
const metadata = path.join(source, 'agents', 'openai.yaml');
|
|
fs.mkdirSync(path.dirname(metadata), { recursive: true });
|
|
fs.writeFileSync(canonical, 'canonical skill sentinel\n');
|
|
fs.writeFileSync(metadata, 'canonical metadata sentinel\n');
|
|
const skills = path.join(out, '.agents', 'skills');
|
|
fs.mkdirSync(path.join(skills, 'gstack-retired-zzz'), { recursive: true });
|
|
fs.writeFileSync(path.join(skills, 'gstack-retired-zzz', 'SKILL.md'), staleRender('gstack-retired-zzz', 'stale'));
|
|
// Someone's own skill that happens to use the gstack- prefix: no banner, never touched (#2119).
|
|
fs.mkdirSync(path.join(skills, 'gstack-mine'), { recursive: true });
|
|
fs.writeFileSync(path.join(skills, 'gstack-mine', 'SKILL.md'), '---\nname: gstack-mine\n---\nuser skill\n');
|
|
// Two more shapes the banner gate must keep: a dir with no SKILL.md at all,
|
|
// and a look-alike comment that is NOT the generator's exact banner.
|
|
fs.mkdirSync(path.join(skills, 'gstack-nomd'), { recursive: true });
|
|
fs.writeFileSync(path.join(skills, 'gstack-nomd', 'README.md'), 'no SKILL.md here\n');
|
|
fs.mkdirSync(path.join(skills, 'gstack-lookalike'), { recursive: true });
|
|
fs.writeFileSync(path.join(skills, 'gstack-lookalike', 'SKILL.md'), '---\nname: gstack-lookalike\n---\n<!-- auto-generated by someone else — do not edit -->\nmine\n');
|
|
fs.mkdirSync(path.join(skills, 'not-ours'), { recursive: true });
|
|
fs.symlinkSync(source, path.join(skills, 'gstack'), 'dir');
|
|
// Host isolation: a bannered stale-looking render under ANOTHER host's tree
|
|
// in the same out-dir is not a codex run's to prune (or to touch at all).
|
|
const factorySkills = path.join(out, '.factory', 'skills');
|
|
fs.mkdirSync(path.join(factorySkills, 'gstack-zzz'), { recursive: true });
|
|
fs.writeFileSync(path.join(factorySkills, 'gstack-zzz', 'SKILL.md'), staleRender('gstack-zzz', 'stale factory'));
|
|
try {
|
|
const r = spawnSync('bun', ['run', path.join(source, 'scripts', 'gen-skill-docs.ts'), '--host', 'codex', '--out-dir', out], {
|
|
cwd: source, encoding: 'utf-8', timeout: 180_000,
|
|
env: { ...process.env, GSTACK_DEFER_CLAUDE_RENAME_PRUNE: '0' },
|
|
});
|
|
expect(r.status, r.stderr).toBe(0);
|
|
// On Windows the old realpath + '/' comparison missed this alias,
|
|
// rewriting BOTH source artifacts through the sidecar.
|
|
expect(r.stdout.replace(/\\/g, '/')).toContain('SKIPPED (symlink loop): .agents/skills/gstack/SKILL.md');
|
|
expect(fs.readFileSync(canonical, 'utf-8')).toBe('canonical skill sentinel\n');
|
|
expect(fs.readFileSync(metadata, 'utf-8')).toBe('canonical metadata sentinel\n');
|
|
expect(r.stdout).toContain('pruned stale codex render: gstack-retired-zzz');
|
|
expect(fs.existsSync(path.join(skills, 'gstack-retired-zzz'))).toBe(false);
|
|
// Exactly one prune in this run: the bannered stale render and nothing else.
|
|
expect(r.stdout.match(/pruned stale /g)).toHaveLength(1);
|
|
// Banner gate: three un-bannered gstack-* dirs survive, each named in the log.
|
|
for (const kept of ['gstack-mine', 'gstack-nomd', 'gstack-lookalike']) {
|
|
expect(r.stdout).toContain(`kept codex skills/${kept}: not a gstack render (no generated banner)`);
|
|
}
|
|
expect(fs.readFileSync(path.join(skills, 'gstack-mine', 'SKILL.md'), 'utf-8')).toContain('user skill');
|
|
expect(fs.readFileSync(path.join(skills, 'gstack-nomd', 'README.md'), 'utf-8')).toContain('no SKILL.md here');
|
|
expect(fs.readFileSync(path.join(skills, 'gstack-lookalike', 'SKILL.md'), 'utf-8')).toContain('mine');
|
|
expect(fs.existsSync(path.join(skills, 'not-ours'))).toBe(true);
|
|
expect(fs.lstatSync(path.join(skills, 'gstack')).isSymbolicLink()).toBe(true);
|
|
expect(fs.existsSync(path.join(skills, 'gstack-ship', 'SKILL.md'))).toBe(true);
|
|
// Host isolation: the factory tree is byte-identical to how we left it, and the log never mentions it.
|
|
expect(fs.readFileSync(path.join(factorySkills, 'gstack-zzz', 'SKILL.md'), 'utf-8')).toBe(staleRender('gstack-zzz', 'stale factory'));
|
|
expect(fs.readdirSync(factorySkills)).toEqual(['gstack-zzz']);
|
|
expect(r.stdout).not.toContain('pruned stale factory');
|
|
expect(r.stdout).not.toContain('gstack-zzz');
|
|
} finally {
|
|
fs.rmSync(out, { recursive: true, force: true });
|
|
}
|
|
}, 200_000);
|
|
|
|
test('a failed host render keeps generated directories outside its partial inventory', () => {
|
|
const out = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-prune-failed-'));
|
|
const skills = path.join(out, '.agents', 'skills');
|
|
const stale = path.join(skills, 'gstack-retired-zzz', 'SKILL.md');
|
|
fs.mkdirSync(path.dirname(stale), { recursive: true });
|
|
fs.writeFileSync(stale, staleRender('gstack-retired-zzz', 'retain after failure'));
|
|
// An expected artifact that cannot be written interrupts the host render.
|
|
fs.mkdirSync(path.join(skills, 'gstack-autoplan', 'SKILL.md'), { recursive: true });
|
|
try {
|
|
const r = gen(out);
|
|
expect(r.status).toBe(1);
|
|
expect(r.stderr).toContain('ERROR (codex)');
|
|
expect(r.stderr).toContain('EISDIR');
|
|
expect(r.stdout).not.toContain('pruned stale');
|
|
expect(fs.readFileSync(stale, 'utf-8')).toBe(staleRender('gstack-retired-zzz', 'retain after failure'));
|
|
} finally {
|
|
fs.rmSync(out, { recursive: true, force: true });
|
|
}
|
|
}, 200_000);
|
|
|
|
test('--dry-run never prunes: a bannered stale render stays byte-identical, no SKILL.md is written, and the run reports STALE', () => {
|
|
const out = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-prune-dry-'));
|
|
const skills = path.join(out, '.agents', 'skills');
|
|
const stale = path.join(skills, 'gstack-retired-zzz', 'SKILL.md');
|
|
fs.mkdirSync(path.dirname(stale), { recursive: true });
|
|
fs.writeFileSync(stale, staleRender('gstack-retired-zzz', 'stale'));
|
|
try {
|
|
const r = gen(out, '--dry-run');
|
|
// An empty out-dir is stale by definition: dry-run says so and exits 1 instead of writing.
|
|
expect(r.status).toBe(1);
|
|
expect(r.stdout).toContain('STALE: ');
|
|
expect(r.stdout).not.toContain('GENERATED: ');
|
|
expect(fs.existsSync(path.join(skills, 'gstack-ship', 'SKILL.md'))).toBe(false);
|
|
// The prune step is skipped wholesale — no deletions, no "kept" verdicts either.
|
|
expect(r.stdout).not.toContain('pruned stale');
|
|
expect(r.stdout).not.toContain('kept codex skills/');
|
|
expect(fs.readFileSync(stale, 'utf-8')).toBe(staleRender('gstack-retired-zzz', 'stale'));
|
|
} finally {
|
|
fs.rmSync(out, { recursive: true, force: true });
|
|
}
|
|
}, 200_000);
|
|
|
|
test('setup can defer the renamed render only; standalone generation retires it without changing installed links', () => {
|
|
const out = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-rename-prune-'));
|
|
const skills = path.join(out, '.agents', 'skills');
|
|
const old = path.join(skills, 'gstack-claude');
|
|
const stale = path.join(skills, 'gstack-retired-zzz');
|
|
const home = path.join(out, 'home');
|
|
const installed = path.join(home, '.codex', 'skills', 'gstack-claude');
|
|
for (const dir of [old, stale]) {
|
|
fs.mkdirSync(dir, { recursive: true });
|
|
fs.writeFileSync(path.join(dir, 'SKILL.md'), staleRender(path.basename(dir), 'old output'));
|
|
}
|
|
fs.mkdirSync(path.dirname(installed), { recursive: true });
|
|
fs.symlinkSync(old, installed);
|
|
try {
|
|
const deferred = spawnSync('bun', ['run', 'scripts/gen-skill-docs.ts', '--host', 'codex', '--out-dir', out], {
|
|
cwd: ROOT, encoding: 'utf8', timeout: 180_000,
|
|
env: { ...process.env, HOME: home, GSTACK_DEFER_CLAUDE_RENAME_PRUNE: '1' },
|
|
});
|
|
expect(deferred.status).toBe(0);
|
|
expect(fs.existsSync(path.join(old, 'SKILL.md'))).toBe(true);
|
|
expect(fs.existsSync(stale)).toBe(false);
|
|
expect(fs.existsSync(path.join(skills, 'gstack-claude-code', 'SKILL.md'))).toBe(true);
|
|
expect(fs.readlinkSync(installed)).toBe(old);
|
|
const standalone = gen(out);
|
|
expect(standalone.status).toBe(0);
|
|
expect(fs.existsSync(old)).toBe(false);
|
|
expect(standalone.stdout).toContain('Run ./setup to migrate installed skill links');
|
|
// Rendering has no authority to rewrite any user's installed skill tree.
|
|
expect(fs.lstatSync(installed).isSymbolicLink()).toBe(true);
|
|
expect(fs.readlinkSync(installed)).toBe(old);
|
|
} finally { fs.rmSync(out, { recursive: true, force: true }); }
|
|
}, 200_000);
|
|
});
|