mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-22 08:01:32 +01:00
Pre-commit /verify fails on a timeout, and the review collector stops reading reviewers' scope lists as findings (GST-3201) (#4527)
Pre-commit /verify now fails a check that times out and runs its checks on one time budget; a reviewer's scope-list bullets no longer need an owner ruling to clear; stack tests fail when git can't list a PR's tests. Why: each let a result read clean with nothing proving it, or block on nothing (#4518, #4519). Goal: gates never pass on missing evidence. Nothing to do; `gstack-checks quick --timeout` is now one budget the checks share (540 s default). Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/outside-voice#1 reader=outside-voice Review-Finding: p1/outside-voice#2 reader=outside-voice
This commit is contained in:
1 parent
3cccf074ad
commit
bd449234aa
14 files changed
+197
-26
No files matched your search
+10
-5
@@ -16,7 +16,9 @@
|
||||
* (GST-3150). Same checks and selection as run, but it never asks for consent:
|
||||
* an untrusted command set, a missing policy source or the verify_before_commit
|
||||
* switch ends it with one `VERIFY skipped: <reason>` line, and a not-run result
|
||||
* (ENV, TIMEOUT, UNMAPPED, TOO_BROAD) is named, never a red.
|
||||
* (ENV, UNMAPPED, TOO_BROAD) is named, never a red. A TIMEOUT is a red: a check
|
||||
* that never finished proved nothing. The checks share one deadline, and the
|
||||
* test stage starts with what is left (its runner can still run past it).
|
||||
*/
|
||||
import { createHash } from 'node:crypto';
|
||||
import * as fs from 'node:fs';
|
||||
@@ -255,7 +257,8 @@ export function testVerdict(r: CheckResult): Pick<Outcome, 'verdict' | 'detail'
|
||||
return { verdict: 'INCOMPLETE', detail };
|
||||
}
|
||||
|
||||
export interface RunOptions { root: string; only?: string[]; timeoutMs: number; env?: NodeJS.ProcessEnv }
|
||||
/** deadline (epoch ms) bounds the whole run: each check gets the time left, and one that cannot start before it is a TIMEOUT. */
|
||||
export interface RunOptions { root: string; only?: string[]; timeoutMs: number; deadline?: number; env?: NodeJS.ProcessEnv }
|
||||
export interface Loaded { ctx: PregateContext; checks: Check[]; set: string }
|
||||
const basisOf = (ctx: PregateContext) => sha256(JSON.stringify([ctx.baseRef, ctx.baseSha, ctx.configLabel, ctx.configDigest ?? '']));
|
||||
|
||||
@@ -302,8 +305,10 @@ export async function runChecks(l: Loaded, o: RunOptions): Promise<{ outcomes: O
|
||||
const dir = path.join(path.dirname(file), 'logs');
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
const outcomes: Outcome[] = [];
|
||||
for (const check of l.checks) if (want(check.name)) outcomes.push(await runCommand(l.ctx, check, dir, o.timeoutMs));
|
||||
if (want(TESTS)) outcomes.push(await runTests(l.ctx));
|
||||
const left = () => Math.min(o.timeoutMs, (o.deadline ?? Infinity) - Date.now());
|
||||
const spent = (name: string): Outcome => ({ name, verdict: 'TIMEOUT', ms: 0, detail: 'not started: the run\'s time budget ran out', lines: [] });
|
||||
for (const check of l.checks) if (want(check.name)) outcomes.push(left() > 0 ? await runCommand(l.ctx, check, dir, left()) : spent(check.name));
|
||||
if (want(TESTS)) outcomes.push(left() > 0 ? await runTests({ ...l.ctx, timeoutMs: Math.min(l.ctx.timeoutMs, left()) }) : spent(TESTS));
|
||||
const after = wtreeFingerprint({ cwd: o.root, env: o.env });
|
||||
const moved = 'error' in after || after.tree !== l.ctx.wtree;
|
||||
const final = moved ? outcomes.map(x => (x.verdict === 'PASS' ? { ...x, verdict: 'INCOMPLETE' as Verdict, detail: 'the working tree changed during the run; rerun' } : x)) : outcomes;
|
||||
@@ -321,7 +326,7 @@ export async function runChecks(l: Loaded, o: RunOptions): Promise<{ outcomes: O
|
||||
|
||||
/** The quick pass's last line: FAIL on a red, PASS when something passed and nothing is red, else skipped. */
|
||||
export function quickLine(outcomes: readonly Outcome[]): { line: string; red: Outcome[] } {
|
||||
const red = outcomes.filter(o => o.verdict === 'FAIL' || o.verdict === 'ZERO_RUN' || o.verdict === 'INCOMPLETE');
|
||||
const red = outcomes.filter(o => o.verdict === 'FAIL' || o.verdict === 'ZERO_RUN' || o.verdict === 'INCOMPLETE' || o.verdict === 'TIMEOUT');
|
||||
const passed = outcomes.filter(o => o.verdict === 'PASS');
|
||||
const notRun = outcomes.filter(o => o.verdict !== 'PASS' && !red.includes(o)).map(o => `${o.name} ${o.verdict}`);
|
||||
const secs = (outcomes.reduce((sum, o) => sum + o.ms, 0) / 1000).toFixed(1);
|
||||
|
||||
@@ -329,6 +329,7 @@ export function parseFindings(reader: string, output: string, fixableRaises = tr
|
||||
|
||||
export interface VerdictCheck { state: 'valid' | 'missing' | 'malformed'; parsed: number; declared?: number; agrees?: boolean; why?: string }
|
||||
export interface ReplyFinding { label: string; raw: string; summary?: true; synthetic?: true }
|
||||
const FINDING_KIND = new RegExp(`(?<![A-Za-z0-9])${SEV_LIST}\\s+findings?(?![A-Za-z0-9])(?!\\s*:)`, 'g');
|
||||
const blockingRow = (f: { label: string; raw: string }) => (rank(f.label) ?? 0) >= 4 && !statesNoBlocks(f.raw);
|
||||
|
||||
/**
|
||||
@@ -337,7 +338,10 @@ const blockingRow = (f: { label: string; raw: string }) => (rank(f.label) ?? 0)
|
||||
* line lowers nothing by itself. Declared more than parsed adds CRITICAL rows, one per unmatched at= location and one for the
|
||||
* rest; declared fewer marks each blocking row with no anchor (no list item, heading, field, lead label or JSON; a file:line in prose
|
||||
* is not one, and in a NO FINDINGS reply a list item is not one either, GST-2972) and no Blocks: yes a summary candidate, whether a CRITICAL or P0 word or the native voice's FIXABLE raise made it block. It still
|
||||
* blocks until lead judgment lowers it with a reason.
|
||||
* blocks until lead judgment lowers it with a reason. A reply whose valid line declares blocking=0 marks the same way, at its own label,
|
||||
* each single-line bullet with no structure, no file:line and no label beyond severities naming findings as a kind (`- a HIGH finding still
|
||||
* refused;`, `- \`missing_verdict\` can't occur alongside P0 or P1 findings.`, #4518 and #4519): a scope list or passed check the lead
|
||||
* may lower with a reason, though `- Two P0 findings remain unfixed.` has the same shape, so it still blocks until judged.
|
||||
*/
|
||||
export function parseReply(reader: string, output: string, fixableRaises = true, asked = false): { findings: ReplyFinding[]; verdict?: VerdictCheck } {
|
||||
const verdict = asked ? parseVerdict(output) : undefined;
|
||||
@@ -350,7 +354,8 @@ export function parseReply(reader: string, output: string, fixableRaises = true,
|
||||
}
|
||||
const n = verdict.blocking;
|
||||
const parsed = rows.filter(blockingRow).length;
|
||||
const findings: ReplyFinding[] = rows.map(f => ({ label: f.label, raw: f.raw, ...(n < parsed && blockingRow(f) && !f.anchored && !BLOCKS_YES.test(f.raw) ? { summary: true as const } : {}) }));
|
||||
const kindOnly = (f: { raw: string; shaped: boolean }) => n === 0 && !f.shaped && /^[-*+]\s/.test(f.raw) && !f.raw.includes(' | ') && !ANY_LABEL.test(f.raw.replace(FINDING_KIND, ' '));
|
||||
const findings: ReplyFinding[] = rows.map(f => ({ label: f.label, raw: f.raw, ...((n < parsed && blockingRow(f) && !f.anchored && !BLOCKS_YES.test(f.raw)) || kindOnly(f) ? { summary: true as const } : {}) }));
|
||||
if (n > parsed) {
|
||||
const loci = new Set(rows.filter(blockingRow).map(f => lineLocus(f.raw)));
|
||||
const unmatched = verdict.at.map(a => a.replace(/^\.\//, '')).filter(a => !loci.has(a)).slice(0, n - parsed);
|
||||
|
||||
Reference in new issue
Block a user