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>
248 lines
11 KiB
TypeScript
248 lines
11 KiB
TypeScript
import { afterEach, beforeEach, expect, test } from 'bun:test';
|
|
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync, existsSync, realpathSync, symlinkSync, lstatSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join, resolve, dirname, basename, relative, isAbsolute } from 'node:path';
|
|
import { spawnSync } from 'node:child_process';
|
|
|
|
const ROOT = resolve(import.meta.dir, '..');
|
|
const template = readFileSync(join(ROOT, 'ship/SKILL.md.tmpl'), 'utf8');
|
|
const guard = template.match(/```bash\n(_REDACT_PREPUSH=[\s\S]*?)```/)![1];
|
|
let root: string;
|
|
let repo: string;
|
|
let hook: string;
|
|
let env: NodeJS.ProcessEnv;
|
|
|
|
function shell(code: string, input = '') {
|
|
return spawnSync('bash', ['-c', code], { cwd: repo, env, input, encoding: 'utf8', timeout: 10000 });
|
|
}
|
|
|
|
function git(...args: string[]) {
|
|
const result = spawnSync('git', args, { cwd: repo, env, encoding: 'utf8', timeout: 10000 });
|
|
expect(result.status, result.stderr).toBe(0);
|
|
return result.stdout.trim();
|
|
}
|
|
|
|
function writeFixture(file: string, content: string) {
|
|
const target = lstatSync(file, { throwIfNoEntry: false }) ? realpathSync(file) : join(realpathSync(dirname(file)), basename(file));
|
|
const within = relative(realpathSync(root), target);
|
|
expect(within.startsWith('..') || isAbsolute(within)).toBe(false);
|
|
writeFileSync(file, content, { mode: 0o755 });
|
|
}
|
|
|
|
beforeEach(() => {
|
|
root = mkdtempSync(join(tmpdir(), 'ship-hook-'));
|
|
repo = join(root, 'repo');
|
|
mkdirSync(repo);
|
|
env = { ...process.env, HOME: root, GSTACK_HOME: join(root, 'state'), GSTACK_STATE_ROOT: join(root, 'state'), CLAUDE_PLUGIN_DATA: '',
|
|
GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_COUNT: '0',
|
|
GIT_DIR: undefined, GIT_WORK_TREE: undefined, GIT_COMMON_DIR: undefined,
|
|
PATH: `${dirname(process.execPath)}:${process.env.PATH}` };
|
|
git('init', '-q');
|
|
hook = join(repo, '.git/hooks/pre-push');
|
|
const bin = join(root, '.claude/skills/gstack/bin');
|
|
mkdirSync(bin, { recursive: true });
|
|
writeFixture(join(bin, 'gstack-config'), `#!/bin/sh\nexec bash "${join(ROOT, 'bin/gstack-config')}" "$@"\n`);
|
|
writeFixture(join(bin, 'gstack-redact'), `#!/bin/sh\nexec "${process.execPath}" "${join(ROOT, 'bin/gstack-redact')}" "$@"\n`);
|
|
expect(shell('~/.claude/skills/gstack/bin/gstack-config set redact_prepush_hook true').status).toBe(0);
|
|
});
|
|
|
|
afterEach(() => rmSync(root, { recursive: true, force: true }));
|
|
|
|
const old = `#!/usr/bin/env bash
|
|
# gstack-redact pre-push (managed)
|
|
_input="$(cat)"
|
|
_local="$(git rev-parse --git-path hooks/pre-push.local)"
|
|
printf '%s' "$_input" | "$_local" "$@"
|
|
`;
|
|
const refs = 'refs/heads/a aaaa refs/heads/a bbbb\nrefs/heads/b cccc refs/heads/b dddd\n';
|
|
|
|
test('the generated ship caller matches the template block under test', () => {
|
|
const generated = readFileSync(join(ROOT, 'ship/SKILL.md'), 'utf8');
|
|
expect(generated.match(/```bash\n(_REDACT_PREPUSH=[\s\S]*?)```/)![1]).toBe(guard);
|
|
});
|
|
|
|
test('ship refreshes an opted-in old managed hook; local bytes and complete stdin survive', () => {
|
|
writeFixture(hook, old);
|
|
const local = '#!/bin/sh\nwhile IFS= read -r line; do printf "%s\\n" "$line" >> "$HOME/received"; done\ntest "$(wc -l < "$HOME/received")" -ne 2 || exit 42\n';
|
|
writeFixture(hook + '.local', local);
|
|
expect(shell('"$(git rev-parse --git-path hooks/pre-push)" origin synthetic', refs).status).toBe(0);
|
|
expect(readFileSync(join(root, 'received'), 'utf8')).toBe(refs.split('\n')[0] + '\n');
|
|
rmSync(join(root, 'received'));
|
|
const result = shell(guard);
|
|
expect(result.status, result.stderr).toBe(0);
|
|
expect(readFileSync(hook, 'utf8')).toContain('_input="$(cat; printf x)"');
|
|
expect(readFileSync(hook + '.local', 'utf8')).toBe(local);
|
|
const callback = shell('"$(git rev-parse --git-path hooks/pre-push)" origin synthetic', refs);
|
|
expect(callback.status).toBe(42);
|
|
expect(readFileSync(join(root, 'received'), 'utf8')).toBe(refs);
|
|
});
|
|
|
|
test('installer control already refreshes the old managed hook', () => {
|
|
writeFixture(hook, old);
|
|
expect(shell('~/.claude/skills/gstack/bin/gstack-redact install-prepush-hook').status).toBe(0);
|
|
expect(readFileSync(hook, 'utf8')).toContain('_input="$(cat; printf x)"');
|
|
});
|
|
|
|
test('missing hooks install and current managed wrappers remain byte-identical', () => {
|
|
const local = '#!/bin/sh\nexit 37\n';
|
|
writeFixture(hook + '.local', local);
|
|
expect(shell(guard).status).toBe(0);
|
|
const current = readFileSync(hook, 'utf8');
|
|
expect(current).toContain('_input="$(cat; printf x)"');
|
|
expect(shell(guard).status).toBe(0);
|
|
expect(readFileSync(hook, 'utf8')).toBe(current);
|
|
expect(readFileSync(hook + '.local', 'utf8')).toBe(local);
|
|
expect(shell('"$(git rev-parse --git-path hooks/pre-push)" origin synthetic', refs).status).toBe(37);
|
|
});
|
|
|
|
test.each(['false', 'invalid'])('non-opted-in value %s does not refresh', value => {
|
|
writeFixture(hook, old);
|
|
expect(shell(`~/.claude/skills/gstack/bin/gstack-config set redact_prepush_hook ${value}`).status).toBe(0);
|
|
expect(shell(guard).status).toBe(0);
|
|
expect(readFileSync(hook, 'utf8')).toBe(old);
|
|
});
|
|
|
|
test.each([
|
|
'#!/bin/sh\nexit 42\n',
|
|
'#!/bin/sh\n# optionally calls gstack-redact\nexit 42\n',
|
|
'#!/bin/sh\n# gstack-redact pre-push (managed) extra\nexit 42\n',
|
|
])('unmanaged policy remains unchanged: %s', policy => {
|
|
writeFixture(hook, policy);
|
|
const local = '#!/bin/sh\nexit 37\n';
|
|
writeFixture(hook + '.local', local);
|
|
const result = shell(guard);
|
|
expect(result.status).toBe(0);
|
|
expect(result.stdout).toContain('HOOK_STATE: unmanaged');
|
|
expect(readFileSync(hook, 'utf8')).toBe(policy);
|
|
expect(readFileSync(hook + '.local', 'utf8')).toBe(local);
|
|
});
|
|
|
|
test.each([
|
|
'# gstack-redact pre-push (managed) extra',
|
|
'# prefix # gstack-redact pre-push (managed)',
|
|
'# gstack-redact pre-push (managed)\r',
|
|
])('consented install preserves and chains non-owned marker line: %s', marker => {
|
|
const policy = `#!/bin/sh\n${marker}\ncat > "$HOME/received"\nprintf '%s\\n' "$@" > "$HOME/arguments"\nexit 37\n`;
|
|
writeFixture(hook, policy);
|
|
expect(existsSync(hook + '.local')).toBe(false);
|
|
const automatic = shell(guard);
|
|
expect(automatic.status).toBe(0);
|
|
expect(automatic.stdout).toContain('HOOK_STATE: unmanaged');
|
|
expect(readFileSync(hook, 'utf8')).toBe(policy);
|
|
expect(existsSync(hook + '.local')).toBe(false);
|
|
const install = shell('~/.claude/skills/gstack/bin/gstack-redact install-prepush-hook');
|
|
expect(install.status, install.stderr).toBe(0);
|
|
expect(existsSync(hook + '.local')).toBe(true);
|
|
expect(readFileSync(hook + '.local', 'utf8')).toBe(policy);
|
|
expect(readFileSync(hook, 'utf8')).toContain('_input="$(cat; printf x)"');
|
|
expect(shell('"$(git rev-parse --git-path hooks/pre-push)" origin synthetic', refs).status).toBe(37);
|
|
expect(readFileSync(join(root, 'received'), 'utf8')).toBe(refs);
|
|
expect(readFileSync(join(root, 'arguments'), 'utf8')).toBe('origin\nsynthetic\n');
|
|
});
|
|
|
|
test.each(['.husky', '.git/custom-hooks', '.git/hooks', ''])('explicit hooksPath %s never authorizes automatic refresh', hooksPath => {
|
|
git('config', 'core.hooksPath', hooksPath);
|
|
const custom = resolve(repo, hooksPath);
|
|
mkdirSync(custom, { recursive: true });
|
|
const customHook = join(custom, 'pre-push');
|
|
writeFixture(customHook, old);
|
|
const local = '#!/bin/sh\nexit 37\n';
|
|
writeFixture(customHook + '.local', local);
|
|
const result = shell(guard);
|
|
expect(result.status).toBe(0);
|
|
expect(result.stdout).toContain('HOOKS_IN_GIT_DIR: no');
|
|
expect(readFileSync(customHook, 'utf8')).toBe(old);
|
|
expect(readFileSync(customHook + '.local', 'utf8')).toBe(local);
|
|
});
|
|
|
|
test('global absolute hooksPath preserves managed wrapper and local policy', () => {
|
|
const custom = join(root, 'custom-hooks');
|
|
mkdirSync(custom);
|
|
env.GIT_CONFIG_GLOBAL = join(root, 'gitconfig');
|
|
git('config', '--global', 'core.hooksPath', custom);
|
|
writeFixture(join(custom, 'pre-push'), old);
|
|
const local = '#!/bin/sh\nexit 37\n';
|
|
writeFixture(join(custom, 'pre-push.local'), local);
|
|
expect(shell(guard).status).toBe(0);
|
|
expect(readFileSync(join(custom, 'pre-push'), 'utf8')).toBe(old);
|
|
expect(readFileSync(join(custom, 'pre-push.local'), 'utf8')).toBe(local);
|
|
expect(existsSync(hook)).toBe(false);
|
|
});
|
|
|
|
test('a config lookup error never authorizes automatic refresh', () => {
|
|
writeFixture(hook, old);
|
|
const bin = join(root, 'bin');
|
|
mkdirSync(bin);
|
|
writeFixture(join(bin, 'git'), `#!/bin/sh\nif [ "\${1}" = config ] && [ "\${2}" = --get ]; then exit 2; fi\nexec "${Bun.which('git')}" "$@"\n`);
|
|
env.PATH = `${bin}:${env.PATH}`;
|
|
const result = shell(guard);
|
|
expect(result.status).toBe(0);
|
|
expect(result.stdout).toContain('HOOKS_IN_GIT_DIR: no');
|
|
expect(readFileSync(hook, 'utf8')).toBe(old);
|
|
});
|
|
|
|
test('an invalid repository cannot invoke the installer', () => {
|
|
repo = root;
|
|
const result = shell(guard);
|
|
expect(result.status).toBe(0);
|
|
expect(result.stdout).toContain('HOOKS_IN_GIT_DIR: no');
|
|
expect(existsSync(join(root, 'hooks'))).toBe(false);
|
|
});
|
|
|
|
test.each([false, true])('a hook symlink is never followed, dangling=%s', dangling => {
|
|
const target = join(root, 'policy');
|
|
if (!dangling) writeFixture(target, old);
|
|
symlinkSync(target, hook);
|
|
if (!dangling) expect(realpathSync(hook)).toBe(realpathSync(target));
|
|
const result = shell(guard);
|
|
expect(result.status).toBe(0);
|
|
expect(result.stdout).toContain('HOOK_STATE: unmanaged');
|
|
expect(lstatSync(hook).isSymbolicLink()).toBe(true);
|
|
if (!dangling) expect(readFileSync(target, 'utf8')).toBe(old);
|
|
else expect(existsSync(target)).toBe(false);
|
|
});
|
|
|
|
test('a symlinked hooks directory is never refreshed', () => {
|
|
const target = join(root, 'linked-hooks');
|
|
mkdirSync(target);
|
|
writeFixture(join(target, 'pre-push'), old);
|
|
rmSync(dirname(hook), { recursive: true });
|
|
symlinkSync(target, dirname(hook));
|
|
expect(realpathSync(dirname(hook))).toBe(realpathSync(target));
|
|
const result = shell(guard);
|
|
expect(result.status).toBe(0);
|
|
expect(result.stdout).toContain('HOOKS_IN_GIT_DIR: no');
|
|
expect(readFileSync(join(target, 'pre-push'), 'utf8')).toBe(old);
|
|
});
|
|
|
|
test('a non-file hook is unmanaged', () => {
|
|
mkdirSync(hook);
|
|
const result = shell(guard);
|
|
expect(result.status).toBe(0);
|
|
expect(result.stdout).toContain('HOOK_STATE: unmanaged');
|
|
expect(lstatSync(hook).isDirectory()).toBe(true);
|
|
});
|
|
|
|
test('installer failure stops the caller before subsequent commands', () => {
|
|
const bin = join(root, '.claude/skills/gstack/bin/gstack-redact');
|
|
writeFixture(bin, '#!/bin/sh\nexit 31\n');
|
|
const result = shell(guard + '\nprintf CONTINUED\n');
|
|
expect(result.status).toBe(31);
|
|
expect(result.stdout).not.toContain('CONTINUED');
|
|
});
|
|
|
|
test('ordinary linked-worktree hooks refresh in the common git directory', () => {
|
|
const seed = spawnSync('git', ['-c', `core.hooksPath=${join(repo, '.git/hooks')}`, '-c', 'commit.gpgsign=false', 'commit', '--allow-empty', '-qm', 'fixture'], {
|
|
cwd: repo, env: { ...env, HOME: process.env.HOME, GIT_CONFIG_GLOBAL: process.env.GIT_CONFIG_GLOBAL, GIT_CONFIG_NOSYSTEM: undefined },
|
|
encoding: 'utf8', timeout: 10000,
|
|
});
|
|
expect(seed.status, seed.stderr).toBe(0);
|
|
const worktree = join(root, 'worktree');
|
|
git('worktree', 'add', '-q', '--detach', worktree);
|
|
writeFixture(hook, old);
|
|
repo = worktree;
|
|
expect(realpathSync(dirname(git('rev-parse', '--git-path', 'hooks/pre-push')))).toBe(realpathSync(dirname(hook)));
|
|
expect(shell(guard).status).toBe(0);
|
|
expect(readFileSync(hook, 'utf8')).toContain('_input="$(cat; printf x)"');
|
|
});
|