mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 00:21:14 +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
@@ -9,7 +9,8 @@
|
||||
* with the test command (`bun --no-env-file --config=/dev/null test` by
|
||||
* default; `--stack-tests-command "<cmd>"` for another runner, the files
|
||||
* appended), and the worktree is removed. A PR that adds no test file is
|
||||
* reported as such and never fails.
|
||||
* reported as such and never fails; one whose added files git cannot list
|
||||
* fails, since an unread list is not an empty one.
|
||||
*/
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
@@ -25,10 +26,11 @@ const TEST_FILE = /[._](?:test|spec)\.[cm]?[jt]sx?$/;
|
||||
|
||||
export interface StackTestResult { pr: string; prefix: number; files: string[]; ok: boolean; detail: string }
|
||||
|
||||
/** Test files the PR adds relative to the base (added, not modified). */
|
||||
export function newTestFiles(repoRoot: string, baseSha: string, head: string): string[] {
|
||||
/** Test files the PR adds relative to the base (added, not modified), or git's error when it cannot list them. */
|
||||
export function newTestFiles(repoRoot: string, baseSha: string, head: string): { files: string[] } | { error: string } {
|
||||
const r = git(repoRoot, ['diff', '--name-only', '--diff-filter=A', `${baseSha}...${head}`]);
|
||||
return r.ok ? r.out.split('\n').map(s => s.trim()).filter(f => f && TEST_FILE.test(f)) : [];
|
||||
if (!r.ok) return { error: r.err.slice(0, 160) || `git diff exited ${r.status}` };
|
||||
return { files: r.out.split('\n').map(s => s.trim()).filter(f => f && TEST_FILE.test(f)) };
|
||||
}
|
||||
|
||||
export function stackTests(repoRoot: string, baseSha: string, slots: TrainSlot[], prefixes: TrainPrefix[], command: string[] = DEFAULT_STACK_TEST_COMMAND, timeoutMs = 600_000): StackTestResult[] {
|
||||
@@ -36,7 +38,9 @@ export function stackTests(repoRoot: string, baseSha: string, slots: TrainSlot[]
|
||||
for (const [i, slot] of slots.entries()) {
|
||||
const prefix = prefixes[i + 1];
|
||||
if (!prefix) break;
|
||||
const files = newTestFiles(repoRoot, baseSha, slot.head);
|
||||
const listed = newTestFiles(repoRoot, baseSha, slot.head);
|
||||
if ('error' in listed) { results.push({ pr: slot.pr, prefix: prefix.index, files: [], ok: false, detail: `cannot list the test files it adds: ${listed.error}` }); continue; }
|
||||
const { files } = listed;
|
||||
if (!files.length) { results.push({ pr: slot.pr, prefix: prefix.index, files, ok: true, detail: 'no new test files' }); continue; }
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-stack-tests-'));
|
||||
try {
|
||||
@@ -58,6 +62,7 @@ export function stackTests(repoRoot: string, baseSha: string, slots: TrainSlot[]
|
||||
|
||||
/** One `STACK_TESTS:` line per slot. */
|
||||
export function stackTestLine(r: StackTestResult): string {
|
||||
if (!r.ok && !r.files.length) return `STACK_TESTS: #${r.pr} T${r.prefix} FAIL: ${r.detail}`;
|
||||
if (!r.files.length) return `STACK_TESTS: #${r.pr} T${r.prefix} no new test files`;
|
||||
return `STACK_TESTS: #${r.pr} T${r.prefix} ${r.files.length} new test file(s) ${r.ok ? 'pass' : 'FAIL'} (${r.files.join(', ')})${r.ok ? '' : `: ${r.detail}`}`;
|
||||
}
|
||||
@@ -575,7 +575,7 @@ export async function buildTrain(ctx: QueueContext, o: BuildOptions): Promise<Tr
|
||||
const red = results.filter(r => !r.ok);
|
||||
if (red.length) {
|
||||
const again = `${Q} train build ${prsArgs(t.slots, t.explicit_order)} --dry-run --stack-tests`;
|
||||
return outFailed({ code: 'QUEUE_TRAIN_STACK_RED', message: red.map(r => `#${r.pr}'s new tests fail on the integrated prefix T${r.prefix} (${r.files.join(', ')})`).join('; ') + '; they pass on the PR head alone only if nothing before it in the train changes what they read' },
|
||||
return outFailed({ code: 'QUEUE_TRAIN_STACK_RED', message: red.map(r => (r.files.length ? `#${r.pr}'s new tests fail on the integrated prefix T${r.prefix} (${r.files.join(', ')})` : `#${r.pr}: ${r.detail}`)).join('; ') + '; they pass on the PR head alone only if nothing before it in the train changes what they read' },
|
||||
[...dry, 'DRY-RUN: nothing written, pushed or dispatched'], `fix ${red.map(r => `#${r.pr}'s tests against T${r.prefix}`).join(' and ')}, or reorder with --order, then ${again}`, 'none');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user