mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 08:31:44 +01:00
Pull requests get a Test changes summary of deleted or skipped tests and edits to their own checks (GST-3386) (#4645)
Every gstack pull request now gets a flag-only Test changes check listing removed or skipped tests, loosened limits and edits to the files that run its own checks. Why: agents write most of our tests, and a pull request shouldn't be able to quietly weaken them or grade itself with an edited checker; this two-week trial measures how often that happens. Nothing to do: the check isn't required, and a flag never turns it red. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/red-team#1 reader=red-team Review-Finding: lib/gate-diff/git.ts:314:stale-comment reader=core Review-Finding: p3/outside-voice#1 reader=outside-voice
This commit is contained in:
1 parent
abdc09dad1
commit
973b49eabb
11 files changed
+451
-15
No files matched your search
@@ -1 +1 @@
|
||||
{"blob":"c1d0b8ffabc86df40aa8785a7af87b0dae64f3f2","since":7}
|
||||
{"blob":"7de8d1dd5060bc0ec25fca1f3b348c354e5938a1","since":7,"nonBehavioral":"GST-3386 adds .github/workflows/test-changes.yml to FREE_ONLY_PR_FILES in scripts/test-pr-profile.ts: the new workflow is a free, flag-only check, so it only classifies that file as free-lane in the workflow inventory; no paid case's selection, prompt, threshold, samples or verdict can change"}
|
||||
Executable
+91
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
||||
/**
|
||||
* test-changes-report — what a pull request does to its own tests and gate, for the
|
||||
* flag-only Test changes check (.github/workflows/test-changes.yml, docs/ship-policy.md#test-changes).
|
||||
*
|
||||
* bun scripts/test-changes-report.ts --base <ref> --head <sha> [--summary-file <path>]
|
||||
* bun scripts/test-changes-report.ts --commit <sha>
|
||||
*
|
||||
* Runs this checkout's bin/gstack-gate-diff over merge-base(<base>, <sha>)..<sha> (or one commit's
|
||||
* first-parent delta) from commit objects only, so a fetched pull request is read as data and never
|
||||
* checked out. Prints one line,
|
||||
*
|
||||
* TEST_CHANGES: tagged={RH-1:2} tests_added=N tests_removed=N gate_files=N unread=N candidate=<c>
|
||||
*
|
||||
* and, with --summary-file, appends a Markdown report naming paths, tags and hunk ids only (no PR
|
||||
* text). Exit 0 whatever it finds; 1 when gate-diff or git fails, so a broken run is never counted
|
||||
* as a quiet pull request.
|
||||
*/
|
||||
import * as path from 'node:path';
|
||||
import * as fs from 'node:fs';
|
||||
import { spawnSync } from '../lib/spawn-sync';
|
||||
import { TEST_DECLARATION } from '../lib/gate-diff/classify';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
const gateDiffBin = path.join(ROOT, 'bin', 'gstack-gate-diff');
|
||||
const WATCHED = [/^\.github\/workflows\//, /^\.gstack\//, /^package\.json$/, /^bun\.lockb?$/, /^bunfig\.toml$/,
|
||||
/^scripts\/test-free-shards\.ts$/, /^scripts\/lib\/shard-engine\.ts$/, /^scripts\/ci-tree-reuse\.ts$/,
|
||||
/^lib\/run-evidence\.ts$/, /^test\/land-merged-checks\.txt$/];
|
||||
const COUNTED = ['RH-1', 'RH-13', 'RH-14', 'RH-15'];
|
||||
const DATA_FILE = /\.(?:json|jsonl|ndjson|csv|tsv|log|out|md|mdx|txt)(?:\.tmpl)?$/i;
|
||||
|
||||
interface Hunk { id: string; path: string; old_path?: string; tags: string[]; old: string[]; new: string[]; unsupported?: string }
|
||||
|
||||
function fail(msg: string): never {
|
||||
process.stderr.write(`test-changes-report: ${msg}\n`);
|
||||
process.stdout.write('TEST_CHANGES: error\n');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function run(cmd: string, args: string[]): string {
|
||||
const r = spawnSync(cmd, args, { cwd: process.cwd(), encoding: 'utf-8', timeout: 300_000, maxBuffer: 256 * 1024 * 1024 });
|
||||
if (r.error || r.status !== 0) fail(`${args.includes(gateDiffBin) ? 'gstack-gate-diff' : `git ${args[0]}`} failed (${r.error?.message ?? `exit ${r.status}`}): ${(r.stdout ?? '').split('\n')[0]} ${(r.stderr ?? '').trim().slice(0, 400)}`);
|
||||
return r.stdout;
|
||||
}
|
||||
|
||||
function arg(argv: string[], name: string): string | undefined {
|
||||
const i = argv.indexOf(name);
|
||||
if (i === -1) return undefined;
|
||||
const v = argv[i + 1];
|
||||
if (!v || v.startsWith('--')) fail(`${name} needs a value`);
|
||||
return v;
|
||||
}
|
||||
|
||||
const cell = (s: string) => '`' + s.replace(/[^\x20-\x7e]/g, '?').replace(/[`|]/g, '?') + '`';
|
||||
|
||||
const argv = process.argv.slice(2);
|
||||
const base = arg(argv, '--base'), head = arg(argv, '--head'), commit = arg(argv, '--commit'), summaryFile = arg(argv, '--summary-file');
|
||||
if (commit ? base || head : !base || !head) fail('use --base <ref> --head <sha>, or --commit <sha>');
|
||||
|
||||
const out = run(process.execPath, ['--no-env-file', '--config=/dev/null', gateDiffBin, ...(commit ? ['--commit', commit] : [base!, '--head', head!]), '--format', 'jsonl']);
|
||||
const [first, ...rest] = out.split('\n');
|
||||
const summary = /^GATE_SUMMARY: .*unread=(\d+) .*candidate=(\S+) /.exec(first);
|
||||
if (!summary) fail(`gate-diff printed no GATE_SUMMARY line: ${first.slice(0, 200)}`);
|
||||
const hunks: Hunk[] = rest.filter(Boolean).map((l) => JSON.parse(l));
|
||||
|
||||
const range = commit ? [`${commit}^`, commit] : [summary[2].split('..')[0], head!];
|
||||
const changed = run('git', ['diff', '--name-only', '-z', '--no-renames', range[0], range[1], '--']).split('\0').filter(Boolean);
|
||||
const gateFiles = changed.filter((p) => WATCHED.some((re) => re.test(p)));
|
||||
|
||||
const tagged: Record<string, number> = {};
|
||||
const flagged = hunks.filter((h) => h.tags.some((t) => COUNTED.includes(t)));
|
||||
for (const h of flagged) for (const t of h.tags) if (COUNTED.includes(t)) tagged[t] = (tagged[t] ?? 0) + 1;
|
||||
const declarations = (lines: string[]) => lines.filter((l) => TEST_DECLARATION.test(l)).length;
|
||||
const code = hunks.filter((h) => !DATA_FILE.test(h.path));
|
||||
const added = code.reduce((n, h) => n + declarations(h.new), 0);
|
||||
const removed = code.reduce((n, h) => n + declarations(h.old), 0);
|
||||
const tagText = COUNTED.filter((t) => tagged[t]).map((t) => `${t}:${tagged[t]}`).join(',');
|
||||
|
||||
process.stdout.write(`TEST_CHANGES: tagged={${tagText}} tests_added=${added} tests_removed=${removed} gate_files=${gateFiles.length} unread=${summary[1]} candidate=${summary[2]}\n`);
|
||||
|
||||
if (summaryFile) {
|
||||
const md = ['## Test changes (flags never fail this check)', '',
|
||||
`Tests added: ${added}. Tests removed: ${removed}. Hunks that remove or skip a test (RH-1), add a suppression (RH-13), bypass a gate (RH-14) or relax a gate value (RH-15): ${flagged.length}.`];
|
||||
if (+summary[1] > 0) md.push('', `Partial read: ${summary[1]} eligible hunks past the reading cap were not tagged.`);
|
||||
const unreadable = hunks.filter((h) => h.unsupported);
|
||||
if (unreadable.length) md.push('', `Not read as text, so tests removed in them are not counted: ${unreadable.map((h) => `${cell(h.path)} (${h.unsupported})`).join(', ')}.`);
|
||||
if (gateFiles.length) md.push('', '**This pull request edits files that run or define its own checks:**', '', ...gateFiles.map((p) => `- ${cell(p)}`));
|
||||
if (flagged.length) md.push('', '| Hunk | Path | Tags |', '|---|---|---|', ...flagged.map((h) => `| ${cell(h.id)} | ${cell(h.path)} | ${h.tags.join(', ')} |`));
|
||||
md.push('', 'Each flag needs a reason in the pull request, or a reviewer ruling. See docs/ship-policy.md#test-changes.', '');
|
||||
fs.appendFileSync(summaryFile, md.join('\n'));
|
||||
}
|
||||
@@ -287,6 +287,7 @@ export const FREE_ONLY_PR_FILES = [
|
||||
'.github/workflows/quality-gate.yml',
|
||||
'.github/workflows/scorecard.yml',
|
||||
'.github/workflows/skill-docs.yml',
|
||||
'.github/workflows/test-changes.yml',
|
||||
'.github/workflows/test-health.yml',
|
||||
'.github/workflows/trunk-flaky-tests.yml',
|
||||
'.github/workflows/eval-sweep.yml', // The weekly off-ship sweep on main; no PR-gate case reads it, and it never gates a PR.
|
||||
|
||||
Reference in new issue
Block a user