mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-30 20:04:15 +01:00
gstack-pr-wait ignores cancelled checks a newer pass replaced, and the npm git-dependency hint names allow-git (#4832)
`gstack-pr-wait` no longer blocks on a cancelled check that a newer run of the same check replaced, and the `DEPS_MISSING` stop names npm 12's `allow-git` setting when the lockfile installs a package from git. The docs audit that /gstack-ship launches also starts after a reviewer's install, and a refused launch no longer uses up its one retry. Nothing for you to do. Fixes #4807 and #4815; thanks to exGeni for both reports and the repro. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/red-team#1 reader=red-team
This commit is contained in:
1 parent
959df8ccc4
commit
8aafd408e2
16 files changed
+175
-23
No files matched your search
+10
-4
@@ -148,13 +148,19 @@ export function verdictProblem(skill: string, gstackRoot: string, env: Env, bunP
|
||||
/**
|
||||
* The verdict file that admits `skill`: `file` itself, else the workflow's own record
|
||||
* <verdict>.for/<skill>.json that every install also writes, so a later install for another
|
||||
* workflow never drops this one (GST-1233), except after a failed ./setup, which changed the
|
||||
* checkout every record certified. When neither admits, `file` with its problem.
|
||||
* workflow never drops this one (GST-1233), and when an install profile (a reviewer's
|
||||
* review-voice install) wrote `file`, /ship's own record, which a workflow /ship launches
|
||||
* (document-release) runs under (CAPY-1); each record is checked for `skill` in full. Never after a failed ./setup, which changed the
|
||||
* checkout every record certified. When none admits, `file` with its problem.
|
||||
*/
|
||||
export function admittedVerdict(skill: string, src: string, file: string, project: string | null, bunPath: string, bunVersion: string): { file: string; problem: VerdictProblem | null } {
|
||||
const problem = verdictFileProblem(file, skill, src, project, bunPath, bunVersion);
|
||||
const own = file.replace(/\.json$/, `.for/${skill}.json`);
|
||||
if (problem && /^[A-Za-z0-9._-]+$/.test(skill) && !readInstallVerdict(file)?.trailer?.startsWith('gstack: fail setup') && fs.existsSync(own) && !verdictFileProblem(own, skill, src, project, bunPath, bunVersion)) return { file: own, problem: null };
|
||||
if (!problem || !/^[A-Za-z0-9._-]+$/.test(skill) || readInstallVerdict(file)?.trailer?.startsWith('gstack: fail setup')) return { file, problem };
|
||||
const records = INSTALL_PROFILES.includes(readInstallVerdict(file)?.for ?? '') ? new Set([skill, 'ship']) : [skill];
|
||||
for (const name of records) {
|
||||
const own = file.replace(/\.json$/, `.for/${name}.json`);
|
||||
if (fs.existsSync(own) && !verdictFileProblem(own, skill, src, project, bunPath, bunVersion)) return { file: own, problem: null };
|
||||
}
|
||||
return { file, problem };
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
import type { GhResult, GhRunner } from './ci-gate';
|
||||
import { headCheckRows } from './ci-head-checks';
|
||||
import { parseHeadChecks, parsePullState, rateLimitKind, type PullState } from './gh-poll';
|
||||
import { replacedCancels } from './ship-queue';
|
||||
|
||||
export class GhError extends Error {
|
||||
constructor(message: string, readonly transient: boolean) {
|
||||
@@ -183,12 +184,16 @@ function restList(env: GhEnv, path: string, key: string): unknown[] {
|
||||
* statuses (the same rows `gh pr checks` reads through GraphQL) plus CI at the
|
||||
* head as gstack-ship-queue ready reads it (lib/ci-head-checks.ts: a failed
|
||||
* check whose rerun attempt created no jobs, a workflow run that failed with
|
||||
* no jobs), duplicates collapsed to the worst bucket. An unknown read is a
|
||||
* no jobs), duplicates collapsed to the worst bucket. A cancelled run that a
|
||||
* newer passing or still-running run of the same app and check name replaced is left out first,
|
||||
* as that reader leaves it out (replacedCancels, #4807). An unknown read is a
|
||||
* transient GhError, so the poll loop tries again.
|
||||
*/
|
||||
export function fetchChecks(env: GhEnv, repo: string, head: string): Map<string, Check> {
|
||||
const runs = restList(env, `repos/${repo}/commits/${head}/check-runs?per_page=100`, 'check_runs') as Array<Record<string, unknown>>;
|
||||
const replaced = replacedCancels(runs);
|
||||
const listed = parseHeadChecks(
|
||||
restList(env, `repos/${repo}/commits/${head}/check-runs?per_page=100`, 'check_runs'),
|
||||
runs.filter(r => !replaced.has(r)),
|
||||
restList(env, `repos/${repo}/commits/${head}/status?per_page=100`, 'statuses'),
|
||||
);
|
||||
const ci = headCheckRows(args => runGh(env, args), repo, head);
|
||||
|
||||
@@ -221,7 +221,15 @@ function depsInstall(root: string): string | null {
|
||||
try { pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')); } catch { return null; }
|
||||
const has = (f: string) => fs.existsSync(path.join(root, f));
|
||||
if (!Object.keys({ ...pkg.dependencies, ...pkg.devDependencies }).length || has('node_modules') || has('.pnp.cjs') || has('.pnp.loader.mjs') || has('.pnp.js')) return null;
|
||||
return has('bun.lock') || has('bun.lockb') ? 'bun install --frozen-lockfile' : has('pnpm-lock.yaml') ? 'pnpm install --frozen-lockfile' : has('yarn.lock') ? 'yarn install --frozen-lockfile' : has('package-lock.json') || has('npm-shrinkwrap.json') ? 'npm ci' : 'bun install';
|
||||
return has('bun.lock') || has('bun.lockb') ? 'bun install --frozen-lockfile' : has('pnpm-lock.yaml') ? 'pnpm install --frozen-lockfile' : has('yarn.lock') ? 'yarn install --frozen-lockfile' : has('npm-shrinkwrap.json') ? npmCi(root, 'npm-shrinkwrap.json') : has('package-lock.json') ? npmCi(root, 'package-lock.json') : 'bun install';
|
||||
}
|
||||
|
||||
/** npm ci, with a note naming npm's allow-git setting when the lockfile resolves a package from git, which npm 12 refuses by default (#4815). */
|
||||
function npmCi(root: string, lock: string): string {
|
||||
let text = '';
|
||||
try { text = fs.readFileSync(path.join(root, lock), 'utf8'); } catch { /* plain npm ci */ }
|
||||
if (!/"(?:resolved|version)"\s*:\s*"(?:git\+|git:\/\/|github:)/.test(text)) return 'npm ci';
|
||||
return `npm ci (${lock} resolves a package from git, which npm 12 and later install only when npm's allow-git setting permits it: add --allow-git=all if you trust that source)`;
|
||||
}
|
||||
|
||||
async function tests(cwd: string, base: string, list: { label: string; command: string }[], policyFrom: string, timeout: string | undefined, step: { seconds: number; source: string }, run: { concurrency: number; line: string; hold: boolean; testsOnly: boolean }, r: Report): Promise<void> {
|
||||
|
||||
@@ -160,6 +160,21 @@ export function latestRunPerName<T extends CheckRun>(runs: T[]): T[] {
|
||||
const suiteOf = (r: Record<string, unknown>) => String((r.check_suite as { id?: unknown } | null | undefined)?.id ?? '');
|
||||
const PASSING = ['success', 'skipped', 'neutral'];
|
||||
|
||||
/**
|
||||
* The cancelled runs latestRunPerName judges by a newer run of the same app and check name that passed or is still
|
||||
* running, such as a pull_request run that concurrency: cancel-in-progress cancelled when the next run on the same head
|
||||
* started (#4807). gstack-pr-wait leaves these out before keeping the worst bucket per name, so the check reads as that
|
||||
* newer run (pass or pending), as ready reads it; every other older run still gates there.
|
||||
*/
|
||||
export function replacedCancels<T extends CheckRun & { conclusion?: unknown }>(runs: T[]): Set<T> {
|
||||
const winners = new Map(latestRunPerName(runs).map(r => [checkKey(r), r] as const).filter(([k]) => k !== null));
|
||||
return new Set(runs.filter(r => {
|
||||
const key = checkKey(r);
|
||||
const by = key === null ? undefined : winners.get(key);
|
||||
return r.status === 'completed' && r.conclusion === 'cancelled' && !!by && by !== r && (by.status !== 'completed' || PASSING.includes(String(by.conclusion)));
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* A CI_SUPERSEDED line for each red run whose check counts by a passing newer run from another check suite, such as a
|
||||
* branch-only dispatch that replaced a red pull_request run, which tested the merge with the base (reports/GSTA-461.md
|
||||
|
||||
Reference in new issue
Block a user