mirror of
https://github.com/garrytan/gstack.git
synced 2026-10-31 14:06:50 +01:00
* fix(upgrade): accept a Git Bash checkout whose toplevel Git spells C:/… bin/gstack-upgrade compared `git rev-parse --show-toplevel` (C:/x from Git for Windows) with `pwd -P` (/c/x in Git Bash) as strings, so every Windows Git Bash install was refused as "not a gstack checkout", and the doctor's recovery line points at this command. Compare the two through gstack_path_same (bin/gstack-path-spelling.sh); a tree nested inside another repository is still refused. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(redact): a catalog field named <schema word>_key is not a credential (#3208) env.kv accepted every separated name ending in _key, so a catalog entry `"input_key": "expected_media_rate_bits_per_second_ingress"` failed pregate's never-downgradable secrets check as MEDIUM env.kv [secret]. The camelCase twins (cacheKey, sortKey, partitionKey, idempotencyKey) were already rejected for having no credential prefix; the snake/kebab/dotted forms of those data-model words now are too. ALL-CAPS env names (INPUT_KEY=) and credential-word names (signing_key, stripe_key, input_secret) still fire. Reported by @brentyates-swx. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test(cso): build the git-hardening fixture repo once per file Each test built its fixture repo with five /usr/bin/git spawns inside its own 5 s budget. On macOS that binary is the Xcode shim, and on a cold runner those spawns cost far more than the code under test: in run 38800592772 the first test timed out at 5 s before readGitMetadata got past its first lstat, and afterEach then tore the fixture down under it. Build the repo once in beforeAll, under the same 30 s bound each fixture spawn already declares, and give every test a fresh copy. The assertions and the code under test are unchanged, and each test keeps its full 5 s for the code under test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(browse): rule 3 treats wizard steps as writes and reads back sets before saving (#3216) On a non-local target a wizard or dialog step (Next, Step N, a menu item that opens a dialog) now counts as mutating until its handler or network effect shows otherwise, and its Cancel proves nothing. Before any Save or Submit, every programmatic set is read back and the flow stops on a mismatch. The cookbook's silent-failures list adds the skip-path precondition probe. Redundant clauses in rules 2, 3, 7, 8, 9, 10 and READY are tightened so the shared setup grows by 3 bytes and every browsing skill stays under its parity cap. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(plan-design-review): keep the Completion Summary out of the regenerated report (#3219) The design review saved its Completion Summary inside the terminal GSTACK REVIEW REPORT section, which the next plan review deletes from its heading to the next "## " heading. The summary, deferred list and unresolved decisions now go in their own "## Design Review Completion Summary" section above the report, and the template says everything under the report heading is regenerated by the next review. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(redact): exempt a schema field only when its name and value both say so (#3208) Review (GPT-6.1 Sol outside voice): the name-only exemption also silenced real secrets, e.g. Azure's cosmosdb_primary_key and any longer name such as api_cache_key. Now the whole name must be one data-model word plus _key (primary/secondary dropped) and the value two or more lowercase identifier words; an entropic value, a longer name or a credential name still fires in .env, YAML, JSON and TOML. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test(upgrade): the Git shim delegates with the unshimmed PATH A PATH-searching git wrapper found the shim again and recursed until the test timed out. The shim now restores the host PATH before running git. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(pregate): secrets scans each file with its type and never reads an emptied diff as clean (#3211) addedLines() flattened every file into one added.txt, so gstack-redact never saw a .ts path and the #3048 source-expression exemption never ran: TS properties such as `token: credentials.token,` failed the gate as MEDIUM env.kv. Two false negatives predate this wave: the `+++` header filter dropped added content lines that begin with "++", and `git diff` honoured diff.external/textconv, so an external driver that prints nothing made a branch carrying a real AWS key pass with "no added lines". Added lines are now parsed hunk-aware per file (the pre-push hook's rules), with --no-ext-diff --no-textconv, and each file is scanned as <tmp>/<i>/<basename> so its type survives; findings name the file. Reported by @brentyates-swx. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(plan-devex-review): keep the DX Scorecard out of the regenerated report (#3219) The DX Scorecard had the same placement gap as the design Completion Summary: with no rule, it could land inside GSTACK REVIEW REPORT, which the next plan review deletes. It now goes in its own "## DX Review Scorecard" section above the report. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * v1.91.109.0 fix: wave 5 — pregate secrets false negatives (#3211), Windows gstack-upgrade, env.kv schema keys (#3208), browse rule 3 (#3216), review summaries (#3219) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Co-authored-by: Scott Gigante <scott@gethubflow.ai> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
81 lines
3.9 KiB
TypeScript
81 lines
3.9 KiB
TypeScript
/**
|
|
* pregate `secrets` scans each file's added lines with that file's type (#3211)
|
|
* and never reads an empty or rewritten diff as clean: a `+++` content line
|
|
* inside a hunk is scanned, and diff.external / textconv drivers are ignored.
|
|
*/
|
|
import { afterEach, 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';
|
|
import { parseAddedLines } from '../lib/pregate/checks/secrets';
|
|
|
|
const PREGATE = path.resolve(import.meta.dir, '..', 'bin', 'gstack-pregate');
|
|
const AWS = 'AKIA' + 'ZQ3XN7P2LM4RT8WV';
|
|
const roots: string[] = [];
|
|
afterEach(() => { for (const r of roots.splice(0)) fs.rmSync(r, { recursive: true, force: true }); });
|
|
|
|
function repo(files: Record<string, string>) {
|
|
const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'pregate-secrets-')));
|
|
roots.push(root);
|
|
const dir = path.join(root, 'work');
|
|
const env = { ...process.env, HOME: root, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' };
|
|
const git = (...args: string[]) => {
|
|
const r = spawnSync('git', args, { cwd: dir, encoding: 'utf8', env, timeout: 30_000 });
|
|
if (r.status !== 0) throw new Error(`git ${args.join(' ')}: ${r.stderr}`);
|
|
};
|
|
fs.mkdirSync(dir);
|
|
git('init', '-q', '-b', 'main');
|
|
git('config', 'user.email', 'fixture@example.test');
|
|
git('config', 'user.name', 'Fixture');
|
|
fs.writeFileSync(path.join(dir, 'README'), 'base\n');
|
|
git('add', '.');
|
|
git('commit', '-qm', 'base');
|
|
git('init', '-q', '--bare', path.join(root, 'remote.git'));
|
|
git('remote', 'add', 'origin', path.join(root, 'remote.git'));
|
|
git('push', '-q', 'origin', 'main');
|
|
git('fetch', '-q', 'origin');
|
|
git('checkout', '-qb', 'feat');
|
|
for (const [rel, text] of Object.entries(files)) fs.writeFileSync(path.join(dir, rel), text);
|
|
git('add', '.');
|
|
git('commit', '-qm', 'feat');
|
|
const secrets = () => {
|
|
const r = spawnSync(PREGATE, ['--base', 'main', '--only', 'secrets', '--json'], { cwd: dir, encoding: 'utf8', env, timeout: 120_000 });
|
|
const check = JSON.parse(r.stdout).checks.find((c: { id: string }) => c.id === 'secrets');
|
|
return { status: check.status as string, detail: check.detail as string, lines: (check.lines ?? []) as string[] };
|
|
};
|
|
return { dir, git, secrets };
|
|
}
|
|
|
|
describe('pregate secrets: source context and diff integrity', () => {
|
|
test('parseAddedLines groups by file and keeps a "+++" content line inside a hunk', () => {
|
|
const diff = ['diff --git a/a.ts b/a.ts', '--- a/a.ts', '+++ b/a.ts', '@@ -0,0 +1,2 @@', '+one', '+++two', 'diff --git a/b.env b/b.env', '--- /dev/null', '+++ b/b.env', '@@ -0,0 +1 @@', '+three'].join('\n');
|
|
expect([...parseAddedLines(diff)]).toEqual([['a.ts', ['one', '++two']], ['b.env', ['three']]]);
|
|
});
|
|
|
|
test('a TS object property that reads a credential at runtime is code, not a secret (#3211)', () => {
|
|
const f = repo({ 'app.ts': 'const cfg = {\n token: credentials.token,\n apiKey: settings.apiKey,\n};\n' });
|
|
expect(f.secrets().status).toBe('pass');
|
|
});
|
|
|
|
test('the same assignment in a .env file still fails, naming the file', () => {
|
|
const f = repo({ 'deploy.env': 'API_TOKEN=8Fk2pQ9vXz4wL7mN3rT6yB1cD5eG0hJ\n' });
|
|
const r = f.secrets();
|
|
expect(r.status).toBe('fail');
|
|
expect(r.lines.join('\n')).toContain('deploy.env, added line 1');
|
|
});
|
|
|
|
test('an added line whose text starts with "++" is scanned', () => {
|
|
const f = repo({ 'notes.txt': `++aws_access_key_id = ${AWS}\n` });
|
|
expect(f.secrets().status).toBe('fail');
|
|
});
|
|
|
|
test('a diff.external driver that prints nothing does not make the branch clean', () => {
|
|
const f = repo({ 'notes.txt': `aws_access_key_id = ${AWS}\n` });
|
|
const driver = path.join(path.dirname(f.dir), 'empty-diff.sh');
|
|
fs.writeFileSync(driver, '#!/bin/sh\nexit 0\n', { mode: 0o755 });
|
|
f.git('config', 'diff.external', driver);
|
|
expect(f.secrets().status).toBe('fail');
|
|
});
|
|
});
|