mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-17 05:41:50 +01:00
Merge remote-tracking branch 'origin/main' into fix/review-fix-range-rereview
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> # Conflicts: # CHANGELOG.md # test/fixtures/skill-md-size-allowlist.json
This commit is contained in:
commit
1a2aefc138
40 files changed
+1079
-93
No files matched your search
@@ -16,9 +16,9 @@ const ROOT = path.resolve(import.meta.dir, '..');
|
||||
let home: string;
|
||||
let remote: string;
|
||||
|
||||
function run(argv: string[]) {
|
||||
function run(argv: string[], extraEnv: Record<string, string> = {}) {
|
||||
const r = spawnSync(path.join(ROOT, 'bin', argv[0]), argv.slice(1), {
|
||||
env: { ...process.env, HOME: home, GSTACK_HOME: home },
|
||||
env: { ...process.env, HOME: home, GSTACK_HOME: home, ...extraEnv },
|
||||
encoding: 'utf-8',
|
||||
timeout: 60_000,
|
||||
});
|
||||
@@ -145,6 +145,24 @@ describe('artifacts_sync_removals', () => {
|
||||
expect(run(['gstack-brain-sync', '--publish-removals', '--yes']).stdout).toContain('no removals to publish');
|
||||
});
|
||||
|
||||
test('--publish-removals cleans up its temp files and lock on every exit path', () => {
|
||||
syncAll(['projects/p/designs/a.md', 'projects/p/designs/b.md']);
|
||||
fs.rmSync(path.join(home, 'projects/p/designs/a.md'));
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'brain-removals-tmp-'));
|
||||
try {
|
||||
for (const argv of [['--publish-removals'], ['--publish-removals', '--yes'], ['--publish-removals', '--yes']]) {
|
||||
const r = run(['gstack-brain-sync', ...argv], { TMPDIR: tmp });
|
||||
expect(r.stderr).not.toContain('unbound variable');
|
||||
expect(r.status).toBe(0);
|
||||
expect(fs.readdirSync(tmp)).toEqual([]);
|
||||
expect(fs.existsSync(path.join(home, '.brain-sync.lock.d'))).toBe(false);
|
||||
}
|
||||
expect(remoteFiles()).toEqual(['projects/p/designs/b.md']);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('config rejects values other than on and off', () => {
|
||||
const r = run(['gstack-config', 'set', 'artifacts_sync_removals', 'yes']);
|
||||
expect(r.stderr).toContain("artifacts_sync_removals 'yes' not recognized");
|
||||
|
||||
@@ -24,7 +24,7 @@ import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
|
||||
const ROOT = path.resolve(__dirname, '..');
|
||||
const DOCKERFILE = path.join(ROOT, '.github', 'docker', 'Dockerfile.ci');
|
||||
const DOCKERFILE = path.join(__dirname, '..', '.github', 'docker', 'Dockerfile.ci');
|
||||
|
||||
/** Package specs from every `npm i -g` / `npm install -g` in the Dockerfile. */
|
||||
export function globalNpmInstallSpecs(source: string): string[] {
|
||||
@@ -193,7 +193,7 @@ describe('other CI Bun installs match the image (#1713, #1706)', () => {
|
||||
test(`${rel} downloads the verified linux-x64 archive instead of piping an installer into a shell`, () => {
|
||||
expect(curlPipedToShell(source)).toEqual([]);
|
||||
const download = source.indexOf('/releases/download/bun-v$BUN_VERSION/bun-linux-x64.zip');
|
||||
const verify = source.indexOf('sha256sum -c');
|
||||
const verify = source.indexOf('sha256sum -c', download);
|
||||
const unpack = source.indexOf('unzip -q');
|
||||
expect(download).toBeGreaterThan(-1);
|
||||
expect(verify).toBeGreaterThan(download);
|
||||
@@ -216,3 +216,43 @@ describe('other CI Bun installs match the image (#1713, #1706)', () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe('CI Node.js installs match the image and are verified (#3354)', () => {
|
||||
const docker = fs.readFileSync(DOCKERFILE, 'utf-8');
|
||||
const imageVersion = docker.match(/^ENV NODE_VERSION=(\S+)$/m)?.[1];
|
||||
const imageSha = docker.match(/^ARG NODE_SHA256=(\S+)$/m)?.[1];
|
||||
const nodeRun = logicalLines(docker).find((line) => line.includes('nodejs.org/dist/v${NODE_VERSION}/')) ?? '';
|
||||
|
||||
test('Dockerfile.ci pins an exact Node.js version and the SHA-256 of its linux-x64 archive', () => {
|
||||
expect(imageVersion).toMatch(/^\d+\.\d+\.\d+$/);
|
||||
expect(imageSha).toMatch(/^[0-9a-f]{64}$/);
|
||||
});
|
||||
|
||||
test('Dockerfile.ci checks the Node.js archive before it is unpacked', () => {
|
||||
expect(nodeRun, 'Node.js must come from the nodejs.org release archive').not.toBe('');
|
||||
const download = nodeRun.indexOf('-o /tmp/node.tar.xz');
|
||||
const verify = nodeRun.indexOf('echo "${NODE_SHA256} /tmp/node.tar.xz" | sha256sum -c -');
|
||||
const unpack = nodeRun.indexOf('tar -xJ');
|
||||
expect(download).toBeGreaterThan(-1);
|
||||
expect(verify).toBeGreaterThan(download);
|
||||
expect(unpack).toBeGreaterThan(verify);
|
||||
});
|
||||
|
||||
const rel = 'scripts/ubicloud/setup-free-suite.sh';
|
||||
const source = fs.readFileSync(path.join(ROOT, rel), 'utf-8');
|
||||
|
||||
test(`${rel} pins the same Node.js version and SHA-256 as Dockerfile.ci`, () => {
|
||||
expect(imageSha).toMatch(/^[0-9a-f]{64}$/);
|
||||
expect(source.match(/^NODE_VERSION=(\S+)$/m)?.[1]).toBe(imageVersion!);
|
||||
expect(source.match(/^NODE_SHA256=(\S+)$/m)?.[1]).toBe(imageSha!);
|
||||
});
|
||||
|
||||
test(`${rel} checks the Node.js archive before it is unpacked`, () => {
|
||||
const download = source.indexOf('/node-v$NODE_VERSION-linux-x64.tar.xz" -o "$node_tmp/node.tar.xz"');
|
||||
const verify = source.indexOf('echo "$NODE_SHA256 $node_tmp/node.tar.xz" | sha256sum -c -');
|
||||
const unpack = source.indexOf('tar -xJ');
|
||||
expect(download).toBeGreaterThan(-1);
|
||||
expect(verify).toBeGreaterThan(download);
|
||||
expect(unpack).toBeGreaterThan(verify);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* #542: /office-hours in host plan mode leaves a plan-file copy of its design
|
||||
* doc. The doc stays the source of truth: office-hours writes plan-copy edits
|
||||
* through and records the pairing, and the discovery helper every plan review
|
||||
* runs names the copy and warns when it is newer than the doc.
|
||||
*/
|
||||
import { describe, expect, test } 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 FIND = path.join(ROOT, 'bin', 'gstack-design-doc-find');
|
||||
|
||||
function fixture(run: (dirs: { root: string; home: string; cwd: string; project: string }) => void): void {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'plan-copy-'));
|
||||
try {
|
||||
const home = path.join(root, 'home');
|
||||
const cwd = path.join(root, 'work');
|
||||
const project = path.join(home, '.gstack', 'projects', 'fixture');
|
||||
fs.mkdirSync(project, { recursive: true });
|
||||
fs.mkdirSync(cwd);
|
||||
run({ root, home, cwd, project });
|
||||
} finally { fs.rmSync(root, { recursive: true, force: true }); }
|
||||
}
|
||||
|
||||
function write(file: string, body: string, secondsAgo: number): void {
|
||||
fs.mkdirSync(path.dirname(file), { recursive: true });
|
||||
fs.writeFileSync(file, body);
|
||||
const t = new Date(Date.now() - secondsAgo * 1000);
|
||||
fs.utimesSync(file, t, t);
|
||||
}
|
||||
|
||||
function find(home: string, cwd: string): { stdout: string; stderr: string } {
|
||||
const r = spawnSync(FIND, ['fixture', 'main'], {
|
||||
cwd, env: { PATH: process.env.PATH!, HOME: home }, encoding: 'utf8', timeout: 10_000,
|
||||
});
|
||||
expect(r.status).toBe(0);
|
||||
return { stdout: r.stdout, stderr: r.stderr };
|
||||
}
|
||||
|
||||
describe('gstack-design-doc-find names the host plan copy (#542)', () => {
|
||||
test('no recorded copy: stdout is the doc and stderr stays empty', () => fixture(({ home, cwd, project }) => {
|
||||
const doc = path.join(project, 'u-main-design-1.md');
|
||||
write(doc, '# Design\n', 60);
|
||||
expect(find(home, cwd)).toEqual({ stdout: `${doc}\n`, stderr: '' });
|
||||
}));
|
||||
|
||||
test('a copy in sync is named with its write-through command and no warning', () => fixture(({ root, home, cwd, project }) => {
|
||||
const doc = path.join(project, 'u-main-design-1.md');
|
||||
const copy = path.join(root, 'plans', 'calm-otter.md');
|
||||
write(copy, '# Design\n', 120);
|
||||
write(doc, '# Design\n', 60);
|
||||
write(`${doc}.plan-copy`, `${copy}\n`, 60);
|
||||
const out = find(home, cwd);
|
||||
expect(out.stdout).toBe(`${doc}\n`);
|
||||
expect(out.stderr).toContain(`DESIGN_PLAN_COPY: ${copy} is the host plan-mode copy of ${doc}`);
|
||||
expect(out.stderr).toContain(`cp "${copy}" "${doc}"`);
|
||||
expect(out.stderr).not.toContain('STALE_DESIGN_DOC');
|
||||
}));
|
||||
|
||||
test('a newer, edited copy warns; running the printed write-through clears it', () => fixture(({ root, home, cwd, project }) => {
|
||||
const doc = path.join(project, 'u-main-design-1.md');
|
||||
const copy = path.join(root, 'plans', 'calm-otter.md');
|
||||
write(doc, '# Design\nold approach\n', 120);
|
||||
write(`${doc}.plan-copy`, `${copy}\n`, 120);
|
||||
write(copy, '# Design\nrefined approach\n', 30);
|
||||
const stale = find(home, cwd);
|
||||
expect(stale.stdout).toBe(`${doc}\n`);
|
||||
const warning = stale.stderr.split('\n').find(line => line.startsWith('STALE_DESIGN_DOC: '));
|
||||
expect(warning).toBe(`STALE_DESIGN_DOC: the plan copy is newer than ${doc}. Write it through now, then read ${doc}: cp "${copy}" "${doc}"`);
|
||||
const cp = spawnSync('bash', ['-c', warning!.slice(warning!.indexOf(': cp ') + 2)], { encoding: 'utf8', timeout: 10_000 });
|
||||
expect(cp.status).toBe(0);
|
||||
expect(fs.readFileSync(doc, 'utf8')).toBe('# Design\nrefined approach\n');
|
||||
expect(find(home, cwd).stderr).not.toContain('STALE_DESIGN_DOC');
|
||||
}));
|
||||
|
||||
test('a doc edited after the copy is not reported stale', () => fixture(({ root, home, cwd, project }) => {
|
||||
const doc = path.join(project, 'u-main-design-1.md');
|
||||
const copy = path.join(root, 'plans', 'calm-otter.md');
|
||||
write(copy, '# Design\nfirst draft\n', 120);
|
||||
write(doc, '# Design\nedited doc\n', 30);
|
||||
write(`${doc}.plan-copy`, `${copy}\n`, 30);
|
||||
const out = find(home, cwd);
|
||||
expect(out.stderr).toContain('DESIGN_PLAN_COPY: ');
|
||||
expect(out.stderr).not.toContain('STALE_DESIGN_DOC');
|
||||
}));
|
||||
|
||||
test('a relative, non-markdown or missing recorded path is ignored', () => fixture(({ root, home, cwd, project }) => {
|
||||
const doc = path.join(project, 'u-main-design-1.md');
|
||||
write(doc, '# Design\n', 120);
|
||||
write(path.join(root, 'notes.txt'), 'x\n', 10);
|
||||
for (const recorded of ['plans/calm-otter.md', path.join(root, 'notes.txt'), path.join(root, 'plans', 'gone.md')]) {
|
||||
write(`${doc}.plan-copy`, `${recorded}\n`, 120);
|
||||
expect(find(home, cwd)).toEqual({ stdout: `${doc}\n`, stderr: '' });
|
||||
}
|
||||
}));
|
||||
|
||||
test('when the repo copy wins discovery, the write-through still targets the state-root doc', () => fixture(({ root, home, cwd, project }) => {
|
||||
const init = spawnSync('git', ['init', '-q', '-b', 'main'], { cwd, timeout: 30_000 });
|
||||
expect(init.status).toBe(0);
|
||||
const doc = path.join(project, 'u-main-design-1.md');
|
||||
const repoDoc = path.join(cwd, 'docs', 'designs', 'pricing.md');
|
||||
const copy = path.join(root, 'plans', 'calm-otter.md');
|
||||
write(doc, '# Pricing\n', 120);
|
||||
write(`${doc}.plan-copy`, `${copy}\n`, 120);
|
||||
write(repoDoc, '# Pricing\n', 100);
|
||||
write(copy, '# Pricing\nedited in plan mode\n', 30);
|
||||
const out = find(home, cwd);
|
||||
expect(fs.realpathSync(out.stdout.trim())).toBe(fs.realpathSync(repoDoc));
|
||||
expect(out.stderr).toContain(`Write it through now, then read ${doc}: cp "${copy}" "${doc}"`);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('/office-hours writes the plan copy through before telemetry (#542)', () => {
|
||||
const skill = fs.readFileSync(path.join(ROOT, 'office-hours', 'SKILL.md'), 'utf8');
|
||||
const section = skill.slice(skill.indexOf("## Before telemetry: confirm this run's design doc"));
|
||||
const block = section.slice(section.indexOf('```bash\n') + 8, section.indexOf('\n```', section.indexOf('```bash\n') + 8));
|
||||
|
||||
function confirm(home: string, doc: string, plan: string): string {
|
||||
const script = block.replaceAll('~/.claude/skills/gstack/bin/', `${ROOT}/bin/`)
|
||||
.replace('DESIGN_DOC_PATH', doc).replace('HOST_PLAN_PATH', plan);
|
||||
const r = spawnSync('bash', ['-c', script], { env: { PATH: process.env.PATH!, HOME: home }, encoding: 'utf8', timeout: 10_000 });
|
||||
expect(r.status).toBe(0);
|
||||
return r.stdout;
|
||||
}
|
||||
|
||||
test('plan-mode edits land in the doc and the pairing is recorded', () => fixture(({ root, home, project }) => {
|
||||
const doc = path.join(project, 'u-main-design-1.md');
|
||||
const plan = path.join(root, 'plans', 'calm-otter.md');
|
||||
write(doc, '# Design\nas approved\n', 120);
|
||||
write(plan, '# Design\nrevised in plan mode\n', 30);
|
||||
expect(confirm(home, doc, plan)).toBe('DESIGN_DOC: ok\nPLAN_COPY: written through\n');
|
||||
expect(fs.readFileSync(doc, 'utf8')).toBe('# Design\nrevised in plan mode\n');
|
||||
expect(fs.readFileSync(`${doc}.plan-copy`, 'utf8')).toBe(`${plan}\n`);
|
||||
}));
|
||||
|
||||
test('an older plan file never overwrites the doc', () => fixture(({ root, home, project }) => {
|
||||
const doc = path.join(project, 'u-main-design-1.md');
|
||||
const plan = path.join(root, 'plans', 'calm-otter.md');
|
||||
write(plan, '# Design\nfirst draft\n', 120);
|
||||
write(doc, '# Design\nfinal\n', 30);
|
||||
expect(confirm(home, doc, plan)).toBe('DESIGN_DOC: ok\n');
|
||||
expect(fs.readFileSync(doc, 'utf8')).toBe('# Design\nfinal\n');
|
||||
}));
|
||||
|
||||
test('outside plan mode nothing is recorded', () => fixture(({ home, project }) => {
|
||||
const doc = path.join(project, 'u-main-design-1.md');
|
||||
write(doc, '# Design\n', 30);
|
||||
expect(confirm(home, doc, '')).toBe('DESIGN_DOC: ok\n');
|
||||
expect(fs.existsSync(`${doc}.plan-copy`)).toBe(false);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('plan reviews act on the helper lines (#542)', () => {
|
||||
for (const skill of ['plan-ceo-review', 'plan-eng-review']) {
|
||||
test(`${skill} follows DESIGN_PLAN_COPY and STALE_DESIGN_DOC`, () => {
|
||||
const text = fs.readFileSync(path.join(ROOT, skill, 'SKILL.md'), 'utf8');
|
||||
expect(text).toContain('DESIGN_PLAN_COPY');
|
||||
expect(text).toContain('STALE_DESIGN_DOC');
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -20,7 +20,7 @@ import * as path from 'node:path';
|
||||
import {
|
||||
CANONICAL_REPO, DISPATCH_FOLLOW_SECONDS, EVAL_BG_LANES, LANE_SPECS, LOCAL_CAP_SECONDS, UNRECORDED_SHARD_MS,
|
||||
chooseBackend, conclusionExitCode, dedupeKey, dispatchBlockers, dispatchPlan, findDuplicateRun, launchDetached,
|
||||
localCapSeconds, makeNonce, plannedSerialMs, statusOf, type CheckoutFacts, type RunSummary,
|
||||
launchLocal, localCapSeconds, localRunId, makeNonce, plannedSerialMs, statusOf, type CheckoutFacts, type RunSummary,
|
||||
} from '../scripts/eval-bg';
|
||||
import { buildRunManifest, loadPaidTestDurations, recordedShardMs } from '../scripts/test-paid-shards';
|
||||
|
||||
@@ -158,6 +158,35 @@ describe('completion contract on both backends (DX-2)', () => {
|
||||
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
||||
}, 40_000);
|
||||
|
||||
// GSTA-70: the native-capture cases (qa-callers, ship-docsync, qa-functional)
|
||||
// refuse to start without EVALS_RUN_ID. CI sets it per slice; the local lane
|
||||
// used to launch without it, so 17 of /ship's PR cases failed in 0 s.
|
||||
test('local: the lane exports a safe EVALS_RUN_ID named after its log, and keeps an exported one', async () => {
|
||||
const { dir, env } = sandbox();
|
||||
try {
|
||||
delete env.EVALS_RUN_ID;
|
||||
const probe = (out: string) => [process.execPath, '-e',
|
||||
`const id = process.env.EVALS_RUN_ID ?? ''; require('fs').writeFileSync(${JSON.stringify(out)}, id); process.exit(/^[\\w.-]+$/.test(id) ? 0 : 4)`];
|
||||
const log = path.join(dir, 'evals-pr-gstack-feature+x-20261024-200431-1.log');
|
||||
launchLocal({ log, label: 'evals-test', timeoutSeconds: 60, header: '[eval-bg] backend=local lane=pr tested=abc', env, command: probe(path.join(dir, 'id')) });
|
||||
const text = await waitForExit(log);
|
||||
expect(localRunId(log)).toBe('evals-pr-gstack-feature-x-20261024-200431-1');
|
||||
expect(fs.readFileSync(path.join(dir, 'id'), 'utf8')).toBe(localRunId(log));
|
||||
expect(text.split('\n').slice(0, 2)).toEqual(['[eval-bg] backend=local lane=pr tested=abc', `[eval-bg] EVALS_RUN_ID=${localRunId(log)}`]);
|
||||
expect(text).toMatch(/### gstack-detach EXIT=0 ###/);
|
||||
const kept = path.join(dir, 'kept.log');
|
||||
launchLocal({ log: kept, label: 'evals-test', timeoutSeconds: 60, header: 'h', env: { ...env, EVALS_RUN_ID: 'mine-1' }, command: probe(path.join(dir, 'kept')) });
|
||||
expect(await waitForExit(kept)).toMatch(/### gstack-detach EXIT=0 ###/);
|
||||
expect(fs.readFileSync(path.join(dir, 'kept'), 'utf8')).toBe('mine-1');
|
||||
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
||||
}, 40_000);
|
||||
|
||||
test('the local backend launches through launchLocal', () => {
|
||||
const source = fs.readFileSync(path.join(ROOT, 'scripts/eval-bg.ts'), 'utf8');
|
||||
expect(source).toMatch(/console\.log\(launchLocal\(\{ log, label, timeoutSeconds: cap\.seconds, header, command: \['bun', 'run', LANE_SPECS\[lane\]\.script\] \}\)\)/);
|
||||
expect(source.match(/launchDetached\(\{ log, label/g)?.length).toBe(1);
|
||||
});
|
||||
|
||||
for (const [conclusion, code, word] of [['failure', 1, 'failed'], ['cancelled', 130, 'cancelled'], ['success', 0, 'passed']] as const) {
|
||||
test(`dispatch: a followed run that ends ${conclusion} writes EXIT=${code}`, async () => {
|
||||
const { dir, env } = sandbox();
|
||||
|
||||
+15
-15
@@ -8,27 +8,27 @@
|
||||
"agy/gstack-land-and-deploy": 117722,
|
||||
"agy/gstack-plan-design-review": 140013,
|
||||
"agy/gstack-plan-devex-review": 135760,
|
||||
"agy/gstack-plan-eng-review": 152626,
|
||||
"agy/gstack-plan-eng-review": 152582,
|
||||
"agy/gstack-review": 124182,
|
||||
"claude/design-review": 136531,
|
||||
"codex/gstack-autoplan": 130628,
|
||||
"codex/gstack-design-consultation": 109452,
|
||||
"codex/gstack-design-review": 145028,
|
||||
"codex/gstack-land-and-deploy": 122272,
|
||||
"codex/gstack-office-hours": 102339,
|
||||
"codex/gstack-office-hours": 102308,
|
||||
"codex/gstack-plan-design-review": 142466,
|
||||
"codex/gstack-plan-devex-review": 138649,
|
||||
"codex/gstack-plan-eng-review": 155172,
|
||||
"codex/gstack-plan-eng-review": 155128,
|
||||
"codex/gstack-review": 125086,
|
||||
"copilot/gstack-autoplan": 131637,
|
||||
"copilot/gstack-codex": 100235,
|
||||
"copilot/gstack-design-consultation": 109536,
|
||||
"copilot/gstack-design-review": 144833,
|
||||
"copilot/gstack-land-and-deploy": 118977,
|
||||
"copilot/gstack-office-hours": 100495,
|
||||
"copilot/gstack-office-hours": 100464,
|
||||
"copilot/gstack-plan-design-review": 140884,
|
||||
"copilot/gstack-plan-devex-review": 136912,
|
||||
"copilot/gstack-plan-eng-review": 153351,
|
||||
"copilot/gstack-plan-eng-review": 153307,
|
||||
"copilot/gstack-review": 125453,
|
||||
"cursor/gstack-autoplan": 129278,
|
||||
"cursor/gstack-design-consultation": 107222,
|
||||
@@ -36,52 +36,52 @@
|
||||
"cursor/gstack-land-and-deploy": 116645,
|
||||
"cursor/gstack-plan-design-review": 138968,
|
||||
"cursor/gstack-plan-devex-review": 134591,
|
||||
"cursor/gstack-plan-eng-review": 151480,
|
||||
"cursor/gstack-plan-eng-review": 151436,
|
||||
"cursor/gstack-review": 140714,
|
||||
"factory/gstack-autoplan": 131562,
|
||||
"factory/gstack-codex": 100655,
|
||||
"factory/gstack-design-consultation": 108670,
|
||||
"factory/gstack-design-review": 144297,
|
||||
"factory/gstack-land-and-deploy": 120817,
|
||||
"factory/gstack-office-hours": 101374,
|
||||
"factory/gstack-office-hours": 101343,
|
||||
"factory/gstack-plan-design-review": 141749,
|
||||
"factory/gstack-plan-devex-review": 137960,
|
||||
"factory/gstack-plan-eng-review": 154594,
|
||||
"factory/gstack-plan-eng-review": 154550,
|
||||
"factory/gstack-review": 144493,
|
||||
"gbrain/gstack-autoplan": 129815,
|
||||
"gbrain/gstack-design-review": 132842,
|
||||
"gbrain/gstack-land-and-deploy": 117167,
|
||||
"gbrain/gstack-plan-design-review": 127855,
|
||||
"gbrain/gstack-plan-devex-review": 115129,
|
||||
"gbrain/gstack-plan-eng-review": 134212,
|
||||
"gbrain/gstack-plan-eng-review": 134168,
|
||||
"hermes/gstack-autoplan": 129905,
|
||||
"hermes/gstack-design-review": 132949,
|
||||
"hermes/gstack-land-and-deploy": 117269,
|
||||
"hermes/gstack-plan-design-review": 127964,
|
||||
"hermes/gstack-plan-devex-review": 115215,
|
||||
"hermes/gstack-plan-eng-review": 134297,
|
||||
"hermes/gstack-plan-eng-review": 134253,
|
||||
"kiro/gstack-autoplan": 129040,
|
||||
"kiro/gstack-design-consultation": 107064,
|
||||
"kiro/gstack-design-review": 142321,
|
||||
"kiro/gstack-land-and-deploy": 116533,
|
||||
"kiro/gstack-plan-design-review": 138808,
|
||||
"kiro/gstack-plan-devex-review": 134431,
|
||||
"kiro/gstack-plan-eng-review": 151330,
|
||||
"kiro/gstack-plan-eng-review": 151286,
|
||||
"kiro/gstack-review": 140526,
|
||||
"openclaw/gstack-autoplan": 129520,
|
||||
"openclaw/gstack-design-review": 131647,
|
||||
"openclaw/gstack-land-and-deploy": 116757,
|
||||
"openclaw/gstack-plan-design-review": 126706,
|
||||
"openclaw/gstack-plan-devex-review": 113968,
|
||||
"openclaw/gstack-plan-eng-review": 132609,
|
||||
"openclaw/gstack-plan-eng-review": 132565,
|
||||
"opencode/gstack-autoplan": 131640,
|
||||
"opencode/gstack-design-consultation": 109357,
|
||||
"opencode/gstack-design-review": 144705,
|
||||
"opencode/gstack-land-and-deploy": 118762,
|
||||
"opencode/gstack-office-hours": 100329,
|
||||
"opencode/gstack-office-hours": 100298,
|
||||
"opencode/gstack-plan-design-review": 140738,
|
||||
"opencode/gstack-plan-devex-review": 136812,
|
||||
"opencode/gstack-plan-eng-review": 153232,
|
||||
"opencode/gstack-plan-eng-review": 153188,
|
||||
"opencode/gstack-review": 142949,
|
||||
"slate/gstack-autoplan": 129159,
|
||||
"slate/gstack-design-consultation": 107143,
|
||||
@@ -89,7 +89,7 @@
|
||||
"slate/gstack-land-and-deploy": 116589,
|
||||
"slate/gstack-plan-design-review": 138888,
|
||||
"slate/gstack-plan-devex-review": 134511,
|
||||
"slate/gstack-plan-eng-review": 151405,
|
||||
"slate/gstack-plan-eng-review": 151361,
|
||||
"slate/gstack-review": 140620
|
||||
}
|
||||
}
|
||||
@@ -1139,3 +1139,53 @@ esac
|
||||
expect(r.stderr.length).toBeLessThan(64 * 1024);
|
||||
});
|
||||
});
|
||||
|
||||
// #1734: a refused code stage must leave the brain's source list untouched.
|
||||
describe("code stage autopilot refusal registers nothing (#1734)", () => {
|
||||
it.skipIf(process.platform === "win32")("refuses before `gbrain sources add` when an autopilot process is visible", () => {
|
||||
const home = makeTestHome();
|
||||
const gstackHome = join(home, ".gstack");
|
||||
const repo = mkdtempSync(join(tmpdir(), "gstack-ap-refuse-repo-"));
|
||||
const bindir = mkdtempSync(join(tmpdir(), "gstack-ap-refuse-bin-"));
|
||||
const commandLog = join(home, "gbrain-commands.log");
|
||||
mkdirSync(gstackHome, { recursive: true });
|
||||
mkdirSync(join(home, ".gbrain"), { recursive: true });
|
||||
writeFileSync(join(home, ".gbrain", "config.json"), JSON.stringify({ engine: "pglite", database_url: "pglite:///test" }));
|
||||
spawnSync("git", ["init", "--quiet", "-b", "main"], { cwd: repo, timeout: 30_000 });
|
||||
writeFileSync(join(bindir, "gbrain"), `#!/bin/sh
|
||||
printf '%s\\n' "$*" >> "$GSTACK_TEST_GBRAIN_LOG"
|
||||
case "$1 $2" in
|
||||
"--version ") echo 'gbrain 0.59.0.0' ;;
|
||||
"sources list") echo '{"sources":[]}' ;;
|
||||
"sources add"|"sources attach"|"sync --strategy") ;;
|
||||
*) echo "unexpected gbrain command: $*" >&2; exit 1 ;;
|
||||
esac
|
||||
`);
|
||||
chmodSync(join(bindir, "gbrain"), 0o755);
|
||||
writeFileSync(join(bindir, "pgrep"), "#!/bin/sh\necho 4242\nexit 0\n");
|
||||
chmodSync(join(bindir, "pgrep"), 0o755);
|
||||
const r = spawnSync("bun", [SCRIPT, "--code-only", "--quiet"], {
|
||||
encoding: "utf-8",
|
||||
timeout: 60000,
|
||||
cwd: repo,
|
||||
env: {
|
||||
...process.env,
|
||||
HOME: home,
|
||||
GSTACK_HOME: gstackHome,
|
||||
GBRAIN_HOME: "",
|
||||
GSTACK_TEST_GBRAIN_LOG: commandLog,
|
||||
PATH: `${bindir}:${process.env.PATH || ""}`,
|
||||
},
|
||||
});
|
||||
const commands = existsSync(commandLog) ? readFileSync(commandLog, "utf-8") : "";
|
||||
const state = JSON.parse(readFileSync(join(gstackHome, ".gbrain-sync-state.json"), "utf-8"));
|
||||
const code = state.last_stages.find((s: { name: string }) => s.name === "code");
|
||||
for (const d of [repo, bindir, home]) rmSync(d, { recursive: true, force: true });
|
||||
expect(r.status).toBe(1);
|
||||
expect(code.ok).toBe(false);
|
||||
expect(code.summary).toContain("refused: gbrain autopilot active (process:gbrain autopilot pid 4242 ");
|
||||
expect(code.summary).toContain("Stop autopilot, then re-run /sync-gbrain.");
|
||||
expect(commands).not.toMatch(/^sources (add|rename|remove) /m);
|
||||
expect(commands).not.toMatch(/^sync /m);
|
||||
});
|
||||
});
|
||||
@@ -119,6 +119,32 @@ describe('gstack-ship-receipt read', () => {
|
||||
expect(runBin(repo, 'gstack-ship-receipt', ['read', '--pr', '9'], env).status).toBe(EXIT.fail);
|
||||
expect(runBin(repo, 'gstack-ship-receipt', ['read']).status).toBe(EXIT.usage);
|
||||
});
|
||||
|
||||
test('the unattended handoff write lands in the file docs/unattended.md tells the parent to read --body, at HEAD and with no pr (GSTA-88)', () => {
|
||||
const root = path.resolve(import.meta.dir, '..');
|
||||
const tmpl = fs.readFileSync(path.join(root, 'ship/sections/handoff.md.tmpl'), 'utf8');
|
||||
const write = tmpl.match(/gstack-ship-receipt (write [^\n`]*)/)![1].trim();
|
||||
const out = write.match(/--out (\S+)/)?.[1];
|
||||
expect(out).toBe('.gstack/tmp/ship-receipt.md');
|
||||
expect(fs.readFileSync(path.join(root, 'ship/sections/handoff.md'), 'utf8')).toContain(write);
|
||||
const docs = fs.readFileSync(path.join(root, 'docs/unattended.md'), 'utf8').replace(/\s+/g, ' ');
|
||||
expect(docs).toContain(`gstack-ship-receipt read --body ${out} --json`);
|
||||
expect(docs).toMatch(/read --pr <n> --json` only once a PR exists/);
|
||||
|
||||
const repo = fixture();
|
||||
const env = { GSTACK_SESSION_KIND: 'unattended' };
|
||||
fs.mkdirSync(path.join(repo.work, '.gstack/tmp'), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo.work, '.gstack/tmp/ship-gate.json'), '{"free":{"pass":1,"fail":0,"skip":0}}');
|
||||
expect(runBin(repo, 'gstack-issue-links', ['--base', 'main', '--out', '.gstack/tmp/issues.json'], env).status).toBe(EXIT.ok);
|
||||
const w = runBin(repo, 'gstack-ship-receipt', write.replace('<base>', 'main').split(' '), env);
|
||||
expect(w.status).toBe(EXIT.ok);
|
||||
expect(fs.readFileSync(path.join(repo.work, out!), 'utf8')).toBe(w.out);
|
||||
const r = runBin(repo, 'gstack-ship-receipt', ['read', '--body', out!, '--json'], env);
|
||||
expect(r.status).toBe(EXIT.ok);
|
||||
const receipt = JSON.parse(r.out);
|
||||
expect(receipt).toMatchObject({ head: repo.git('rev-parse', 'HEAD'), base: 'main', session_kind: 'unattended' });
|
||||
expect(receipt).not.toHaveProperty('pr');
|
||||
});
|
||||
});
|
||||
|
||||
describe('gstack-ship-receipt census (P7)', () => {
|
||||
|
||||
@@ -418,6 +418,20 @@ describe('gstack-skill-start behavior', () => {
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
test('unattended /ship alone prints the UNATTENDED_SHIP status line naming the receipt file (GSTA-88)', () => {
|
||||
const line = /^UNATTENDED_SHIP: no push, no PR; Step 18 takes the handoff section; receipt at \.gstack\/tmp\/ship-receipt\.md$/gm;
|
||||
const ship = runStart(['--skill', 'ship'], { GSTACK_SESSION_KIND: 'unattended' });
|
||||
expect(ship.match(line)).toHaveLength(1);
|
||||
expect((ship.match(/^GSTACK_INSTRUCTION_BEGIN: (\S+)/gm) ?? []).map((h) => h.replace(/^GSTACK_INSTRUCTION_BEGIN: /, ''))).toEqual(['unattended-session']);
|
||||
expect(ship).toContain('.gstack/tmp/ship-receipt.md when nothing was pushed');
|
||||
for (const skill of ['review', 'qa', 'autoplan']) {
|
||||
expect(runStart(['--skill', skill], { GSTACK_SESSION_KIND: 'unattended' })).not.toContain('UNATTENDED_SHIP');
|
||||
}
|
||||
for (const kind of ['interactive', 'spawned', 'headless']) {
|
||||
expect(runStart(['--skill', 'ship'], { GSTACK_SESSION_KIND: kind })).not.toContain('UNATTENDED_SHIP');
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
test('unattended session makes no egress call even with telemetry and artifacts sync enabled and a queue pending (plan B1)', () => {
|
||||
// Shadow bin: every helper is the real one except the egress sinks, which
|
||||
// record their invocation. Bins resolve siblings through dirname "$0", so a
|
||||
|
||||
@@ -84,3 +84,80 @@ describe('gstack-team-init required: PreToolUse hook schema (#2413)', () => {
|
||||
expect(JSON.parse(stdout.trim())).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
// #3319: when the launcher itself cannot run, the hook prints nothing and exits
|
||||
// with neither 0 nor 2, which Claude Code treats as a non-blocking error. The
|
||||
// handler is registered with onFailure: block (Claude Code 2.1.295+) so those
|
||||
// failures block the Skill call instead of letting it through.
|
||||
describe('gstack-team-init required: the hook fails closed (#3319)', () => {
|
||||
let repo: string;
|
||||
let home: string;
|
||||
let noNodeBin: string;
|
||||
|
||||
beforeEach(() => {
|
||||
repo = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-team-init-closed-'));
|
||||
execFileSync('git', ['init', '-q'], { cwd: repo });
|
||||
home = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-team-init-closed-home-'));
|
||||
noNodeBin = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-team-init-no-node-'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
for (const dir of [repo, home, noNodeBin]) fs.rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
const init = () => execFileSync(TEAM_INIT, ['required'], { cwd: repo, encoding: 'utf-8', timeout: 30_000 });
|
||||
const settingsPath = () => path.join(repo, '.claude', 'settings.json');
|
||||
const ourHandlers = () => JSON.parse(fs.readFileSync(settingsPath(), 'utf-8')).hooks.PreToolUse
|
||||
.flatMap((e: { hooks: { command: string }[] }) => e.hooks)
|
||||
.filter((h: { command: string }) => h.command.includes('check-gstack'));
|
||||
|
||||
function runRegistered(pathEnv: string): { status: number; stdout: string } {
|
||||
const [{ command }] = ourHandlers();
|
||||
try {
|
||||
const stdout = execSync(command, {
|
||||
env: { PATH: pathEnv, HOME: home, CLAUDE_PROJECT_DIR: repo },
|
||||
encoding: 'utf-8',
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
timeout: 30_000,
|
||||
});
|
||||
return { status: 0, stdout };
|
||||
} catch (err) {
|
||||
const e = err as { status: number; stdout: string };
|
||||
return { status: e.status, stdout: e.stdout };
|
||||
}
|
||||
}
|
||||
|
||||
test('the check-gstack handler is registered with onFailure: block', () => {
|
||||
init();
|
||||
const handlers = ourHandlers();
|
||||
expect(handlers).toHaveLength(1);
|
||||
expect(handlers[0]).toEqual({ type: 'command', command: handlers[0].command, onFailure: 'block' });
|
||||
});
|
||||
|
||||
test('node missing from PATH: no output and exit 127, a failure only onFailure turns into a block', () => {
|
||||
init();
|
||||
const { status, stdout } = runRegistered(noNodeBin);
|
||||
expect(status).toBe(127);
|
||||
expect(stdout).toBe('');
|
||||
});
|
||||
|
||||
test('check-gstack.cjs missing: no output and exit 1, a failure only onFailure turns into a block', () => {
|
||||
init();
|
||||
fs.rmSync(path.join(repo, '.claude', 'hooks', 'check-gstack.cjs'));
|
||||
const { status, stdout } = runRegistered(process.env.PATH!);
|
||||
expect(status).toBe(1);
|
||||
expect(stdout).toBe('');
|
||||
});
|
||||
|
||||
test('re-running upgrades a handler registered without onFailure, keeping one handler', () => {
|
||||
init();
|
||||
const settings = JSON.parse(fs.readFileSync(settingsPath(), 'utf-8'));
|
||||
const [{ command }] = ourHandlers();
|
||||
settings.hooks.PreToolUse = [{ matcher: 'Skill|skill', hooks: [{ type: 'command', command }] }];
|
||||
fs.writeFileSync(settingsPath(), JSON.stringify(settings));
|
||||
|
||||
const out = init();
|
||||
expect(ourHandlers()).toEqual([{ type: 'command', command, onFailure: 'block' }]);
|
||||
expect(out).toContain('Claude Code 2.1.295 or later');
|
||||
});
|
||||
});
|
||||
@@ -342,6 +342,215 @@ describe('check-careful.sh', () => {
|
||||
expect(output.hookSpecificOutput?.permissionDecisionReason).toContain(reason);
|
||||
});
|
||||
|
||||
// --- Commit message false positives (#1060) ---
|
||||
|
||||
describe('commit message false positives (#1060)', () => {
|
||||
// Quoted -m content describes destructive patterns but does not run them.
|
||||
test.each([
|
||||
'git commit -m "fix: prevent accidental drop table in migration"',
|
||||
'git commit -m "docs: explain truncate vs delete semantics"',
|
||||
'git commit -m "feat: add guard for recursive delete patterns"',
|
||||
'git add . && git commit -m "fix: handle drop database edge case"',
|
||||
])('does not warn on descriptive text in commit message: %s', (command) => {
|
||||
const { exitCode, output } = runHook(CAREFUL_SCRIPT, carefulInput(command));
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBeUndefined();
|
||||
});
|
||||
|
||||
// Real destructive commands chained with a commit still warn.
|
||||
test('warns when a real DROP TABLE follows git commit in a chain', () => {
|
||||
const { exitCode, output } = runHook(
|
||||
CAREFUL_SCRIPT,
|
||||
carefulInput('git commit -m "release" && psql -c "DROP TABLE staging"'),
|
||||
);
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBe('ask');
|
||||
expect(output.hookSpecificOutput?.permissionDecisionReason).toContain('SQL DROP');
|
||||
});
|
||||
|
||||
test('warns when a real TRUNCATE follows git commit in a chain', () => {
|
||||
const { exitCode, output } = runHook(
|
||||
CAREFUL_SCRIPT,
|
||||
carefulInput('git commit -m "cleanup" && psql -c "TRUNCATE audit_log"'),
|
||||
);
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBe('ask');
|
||||
expect(output.hookSpecificOutput?.permissionDecisionReason).toContain('SQL TRUNCATE');
|
||||
});
|
||||
|
||||
// Quote-aware awk scanner: a single-quoted message whose content looks like
|
||||
// a flag boundary must not swallow real commands that follow via &&.
|
||||
test('warns when rm follows a single-quoted message that embeds a double-quote', () => {
|
||||
const { exitCode, output } = runHook(
|
||||
CAREFUL_SCRIPT,
|
||||
carefulInput(`git commit -m 'note -m "' && rm -rf build && echo '"'`),
|
||||
);
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBe('ask');
|
||||
expect(output.hookSpecificOutput?.permissionDecisionReason).toContain('recursive delete');
|
||||
});
|
||||
|
||||
// A double-quoted message containing $(...) is not masked — the substitution
|
||||
// content remains visible to the MEDIUM checks.
|
||||
test('warns when a commit message contains a command substitution with rm', () => {
|
||||
const { exitCode, output } = runHook(
|
||||
CAREFUL_SCRIPT,
|
||||
carefulInput('git commit -m "$(rm -rf build)"'),
|
||||
);
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBe('ask');
|
||||
expect(output.hookSpecificOutput?.permissionDecisionReason).toContain('recursive delete');
|
||||
});
|
||||
|
||||
// A force-push chained after a commit must still warn even after the message is masked.
|
||||
test('warns on force-push chained after git commit', () => {
|
||||
const { exitCode, output } = runHook(
|
||||
CAREFUL_SCRIPT,
|
||||
carefulInput('git commit -m "x" && git push --force'),
|
||||
);
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBe('ask');
|
||||
expect(output.hookSpecificOutput?.permissionDecisionReason).toContain('force-push');
|
||||
});
|
||||
|
||||
// -am shorthand: the message is masked, so "drop table" in the message text
|
||||
// does not trigger the SQL DROP warning.
|
||||
test('does not warn on drop-table text in -am commit message', () => {
|
||||
const { exitCode, output } = runHook(
|
||||
CAREFUL_SCRIPT,
|
||||
carefulInput('git commit -am "drop table notes"'),
|
||||
);
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBeUndefined();
|
||||
});
|
||||
|
||||
// bash 3.2 (macOS /bin/bash) mis-parses quote characters in a heredoc
|
||||
// inside $( ), so the awk program inline made the whole hook a syntax error
|
||||
// there. It is a file beside the hook, read with awk -f.
|
||||
test('the masking program is a file beside the hook, not a heredoc inside $( )', () => {
|
||||
const source = fs.readFileSync(CAREFUL_SCRIPT, 'utf8');
|
||||
expect(source).not.toMatch(/\$\(cat <</);
|
||||
expect(source).toContain('awk -f "$_MASK_AWK"');
|
||||
expect(fs.existsSync(path.join(path.dirname(CAREFUL_SCRIPT), 'mask-commit-message.awk'))).toBe(true);
|
||||
});
|
||||
|
||||
// Newlines separate commands, and quote state carries across them. The
|
||||
// per-line scanner joined lines (`-m xtruncate`) and restarted quote
|
||||
// state on every line, so a quoted line break could hide a real command.
|
||||
test.each([
|
||||
['git commit -m x\ntruncate -s 0 f', 'SQL TRUNCATE'],
|
||||
['git commit -m wip\nrm -rf build', 'recursive delete'],
|
||||
["git commit -m \"a\n-m 'x\" && rm -rf build && echo '", 'recursive delete'],
|
||||
])('a command on the next line still asks: %j', (command, reason) => {
|
||||
const { exitCode, output } = runHook(CAREFUL_SCRIPT, carefulInput(command));
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBe('ask');
|
||||
expect(output.hookSpecificOutput?.permissionDecisionReason).toContain(reason);
|
||||
});
|
||||
|
||||
test('a multi-line quoted message is masked as one message', () => {
|
||||
const { exitCode, output } = runHook(CAREFUL_SCRIPT, carefulInput('git commit -m "fix: guard migrations\n\nNo more drop table in the seed script."'));
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBeUndefined();
|
||||
});
|
||||
|
||||
// Only git commit's own message is masked: a -m argument of another
|
||||
// command in the chain, a commit whose output is piped into a shell, and
|
||||
// an escaped quote inside the message all stay visible.
|
||||
test.each([
|
||||
["git commit -m a && ls | parallel -m 'rm -rf build'", 'recursive delete'],
|
||||
["git commit -m 'rm -rf build' | sh", 'recursive delete'],
|
||||
["echo git commit -m 'drop table users'", 'SQL DROP'],
|
||||
['git commit -m "a\\"b" && rm -rf build', 'recursive delete'],
|
||||
["git commit -m wip \\\n&& rm -rf build", 'recursive delete'],
|
||||
])('text outside commit\'s own message still asks: %j', (command, reason) => {
|
||||
const { exitCode, output } = runHook(CAREFUL_SCRIPT, carefulInput(command));
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBe('ask');
|
||||
expect(output.hookSpecificOutput?.permissionDecisionReason).toContain(reason);
|
||||
});
|
||||
|
||||
test.each([
|
||||
'git -C repo commit --message="docs: truncate the changelog intro"',
|
||||
"git commit --message 'chore: drop database fixtures from the seed'",
|
||||
"git commit --amend -m 'fix: git reset --hard in the docs'",
|
||||
])('commit\'s own message is masked in every flag form: %s', (command) => {
|
||||
const { exitCode, output } = runHook(CAREFUL_SCRIPT, carefulInput(command));
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBeUndefined();
|
||||
});
|
||||
|
||||
// The form agents use most: a quoted-delimiter heredoc inside "$( )". Its
|
||||
// body is never expanded, so it is masked whole. Any other substitution,
|
||||
// backtick, $'...' or heredoc leaves the command unmasked.
|
||||
const heredocMessage = (body: string, delimiter = "'EOF'", end = 'EOF') =>
|
||||
`git commit -m "$(cat <<${delimiter}\n${body}\n${end}\n)"`;
|
||||
test.each([
|
||||
heredocMessage('fix: guard the migration that could drop table users\n\nCo-Authored-By: A <a@example.com>'),
|
||||
heredocMessage('docs: why we never truncate "audit" rows (see #12)'),
|
||||
heredocMessage('chore: git reset --hard is documented', '"MSG"', 'MSG'),
|
||||
heredocMessage('chore: rm -rf build in the clean script', "-'EOF'", '\tEOF'),
|
||||
])('a quoted-delimiter heredoc message is masked: %j', (command) => {
|
||||
const { exitCode, output } = runHook(CAREFUL_SCRIPT, carefulInput(command));
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBeUndefined();
|
||||
});
|
||||
|
||||
test.each([
|
||||
[heredocMessage('docs: drop table notes') + ' && git push --force', 'force-push'],
|
||||
[heredocMessage('drop table $(rm -rf build)', 'EOF'), 'recursive delete'],
|
||||
[`git commit -m "$(echo " -m 'x" ; rm -rf build ; echo ')"`, 'recursive delete'],
|
||||
['git commit -m "\`rm -rf build\`"', 'recursive delete'],
|
||||
["git commit -F - <<'EOF'\ndocs: drop table notes\nEOF", 'SQL DROP'],
|
||||
["git commit -m $'drop table notes\\n'", 'SQL DROP'],
|
||||
])('other substitutions and heredocs stay unmasked: %j', (command, reason) => {
|
||||
const { exitCode, output } = runHook(CAREFUL_SCRIPT, carefulInput(command));
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBe('ask');
|
||||
expect(output.hookSpecificOutput?.permissionDecisionReason).toContain(reason);
|
||||
});
|
||||
|
||||
// git prints the message on stdout, so any pipe after a masked message,
|
||||
// a process substitution or a parameter expansion leaves it unmasked; a
|
||||
// redirection's & is not a separator, and a comment's quote is not a quote.
|
||||
test.each([
|
||||
"git commit -m 'rm -rf build' 2>&1 | sh",
|
||||
"(git commit -m 'rm -rf build') | sh",
|
||||
"git commit -m 'rm -rf build' > >(sh)",
|
||||
'git commit -m "${MSG:-rm -rf build}"',
|
||||
])('a message that can reach a shell stays unmasked: %j', (command) => {
|
||||
const { exitCode, output } = runHook(CAREFUL_SCRIPT, carefulInput(command));
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBe('ask');
|
||||
expect(output.hookSpecificOutput?.permissionDecisionReason).toContain('recursive delete');
|
||||
});
|
||||
|
||||
test.each([
|
||||
"git commit -m 'drop table notes' 2>&1 && git log -1 --oneline",
|
||||
"git commit -m 'drop table notes' || echo failed",
|
||||
"git commit -m 'drop table notes' # it's the docs commit",
|
||||
])('redirections, || and comments keep the message masked: %j', (command) => {
|
||||
const { exitCode, output } = runHook(CAREFUL_SCRIPT, carefulInput(command));
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBeUndefined();
|
||||
});
|
||||
|
||||
test('a partial install without the masking program still asks on the message text', () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-careful-nomask-'));
|
||||
try {
|
||||
for (const file of ['check-careful.sh', 'hook-extract.sh']) {
|
||||
fs.copyFileSync(path.join(path.dirname(CAREFUL_SCRIPT), file), path.join(dir, file));
|
||||
}
|
||||
const { exitCode, output } = runHook(path.join(dir, 'check-careful.sh'), carefulInput('git commit -m "drop table notes"'));
|
||||
expect(exitCode).toBe(0);
|
||||
expect(output.hookSpecificOutput?.permissionDecision).toBe('ask');
|
||||
expect(output.hookSpecificOutput?.permissionDecisionReason).toContain('SQL DROP');
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// --- Shell obfuscation ---
|
||||
|
||||
describe('shell obfuscation', () => {
|
||||
|
||||
@@ -175,7 +175,6 @@ const STATE_ROOT_ALLOWLIST: Array<{ file: string; match: string; reason: string
|
||||
{ file: 'design-shotgun/SKILL.md.tmpl', match: 'v1 schema at `~/.gstack/projects/$SLUG/taste-profile.json`', reason: DESCRIPTION },
|
||||
{ file: 'land-and-deploy/sections/readiness-gate.md.tmpl', match: 'eval store (`~/.gstack/projects/<slug>/evals/`', reason: readinessEvalReason },
|
||||
{ file: 'land-and-deploy/sections/readiness-gate.md.tmpl', match: 'EVAL_DIR=~/.gstack/projects/$SLUG/evals', reason: readinessEvalReason },
|
||||
{ file: 'office-hours/SKILL.md.tmpl', match: "see each other's design docs in `~/.gstack/projects/`", reason: DESCRIPTION },
|
||||
{ file: 'office-hours/sections/design-and-handoff.md.tmpl', match: 'The design doc at `~/.gstack/projects/` is automatically discoverable', reason: DESCRIPTION },
|
||||
{ file: 'plan-ceo-review/sections/review-sections.md.tmpl', match: 'Keep in `~/.gstack/projects/` only (local, personal reference)', reason: DESCRIPTION },
|
||||
{ file: 'plan-tune/SKILL.md.tmpl', match: 'Logs stay local (`~/.gstack/projects/<slug>/question-log.jsonl`)', reason: DESCRIPTION },
|
||||
|
||||
@@ -53,6 +53,17 @@ describe('required team hook: shell-neutral registration', () => {
|
||||
expect(command).not.toContain('%');
|
||||
});
|
||||
|
||||
// #3319: without node the shell's own error is all the runner gets, which is
|
||||
// neither exit 0 nor 2, so the registration must carry onFailure: block.
|
||||
test('without node on PATH the default shell exits neither 0 nor 2, so the handler is registered with onFailure: block', () => {
|
||||
expect(TEAM_INIT).toContain("const handler = { type: 'command', command: process.env.GSTACK_HOOK_COMMAND, onFailure: 'block' };");
|
||||
const noNode = path.join(base, 'no-node-bin');
|
||||
fs.mkdirSync(noNode, { recursive: true });
|
||||
const failed = viaDefaultShell({ ...hookEnv({ HOME: elsewhere, USERPROFILE: elsewhere }), PATH: noNode, Path: noNode });
|
||||
expect(failed.stdout.trim()).toBe('');
|
||||
expect([0, 2]).not.toContain(failed.status);
|
||||
});
|
||||
|
||||
// `powershell -Command` reports a failing native command as exit 1, so only
|
||||
// the default shell sees the hook's own exit 2; the deny JSON is the same.
|
||||
for (const [name, runner, enabled, denyStatus] of [
|
||||
|
||||
@@ -329,7 +329,7 @@ describe('gstack-team-init', () => {
|
||||
|
||||
const pre = JSON.parse(fs.readFileSync(path.join(tmpDir, '.claude', 'settings.json'), 'utf-8')).hooks.PreToolUse;
|
||||
expect(pre).toEqual([
|
||||
{ matcher: 'Skill|skill', hooks: [{ type: 'command', command: 'team-audit' }, { type: 'command', command: registeredCommand() }] },
|
||||
{ matcher: 'Skill|skill', hooks: [{ type: 'command', command: 'team-audit' }, { type: 'command', command: registeredCommand(), onFailure: 'block' }] },
|
||||
{ matcher: 'Bash', hooks: [{ type: 'command', command: 'my-own-hook' }] },
|
||||
]);
|
||||
expect(registeredCommand()).not.toContain('$');
|
||||
|
||||
@@ -23,7 +23,8 @@ const native = load('native-qualification.yml');
|
||||
const WINDOWS_CURATED_FLOOR = 638;
|
||||
|
||||
test('the Windows lane plans, runs one strict shard per job and verifies every result', () => {
|
||||
expect(Object.keys(windows.on).sort()).toEqual(['pull_request', 'workflow_call', 'workflow_dispatch']);
|
||||
expect(Object.keys(windows.on).sort()).toEqual(['pull_request', 'push', 'workflow_call', 'workflow_dispatch']);
|
||||
expect(windows.on.push).toEqual({ branches: ['main'] });
|
||||
expect(Object.keys(windows.on.workflow_dispatch.inputs)).toEqual(['record_durations']);
|
||||
expect(Object.keys(windows.on.workflow_call.inputs)).toEqual(['record_durations']);
|
||||
const plan = windows.jobs['windows-plan'];
|
||||
|
||||
Reference in new issue
Block a user