Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: remote-gate reuse sees same-tree heads whose only full run failed

garrytan3009d584f3cb
diff --git a/scripts/ci-reuse.ts b/scripts/ci-reuse.ts
index 9dd63dbd00..4ff05b82b3 100644
--- a/scripts/ci-reuse.ts
+++ b/scripts/ci-reuse.ts
@@ -151,6 +151,8 @@ function accept(run: FullRun, tree: string, rejected: Rejection[], where: string
export type GateState = 'reuse' | 'pending' | 'failed' | 'none';
export interface GateDecision { state: GateState; detail: string; tests?: number; failed?: number; url?: string }
export interface GateDeps extends ReuseDeps {
+ /** The newest workflow_dispatch and push runs of `file`, whatever their status (a failed run counts against its tree too). */
+ recentRuns(file: string): Promise<FullRun[]>;
/** Executed (pass, fail) test identities in the run's executed-identities artifact, or why they cannot be read. */
executed(runId: number): Promise<{ tests: number; failed: number } | { reason: string }>;
}
@@ -163,7 +165,7 @@ export async function decideGate(deps: GateDeps, p: Profile, head: string, tree:
const own = await headGate(deps, p, head, tree, repo, rejected);
if (own) return own;
const heads = new Map<string, string>();
- for (const run of (await deps.recentSuccessfulRuns(p.file)).sort((a, b) => b.id - a.id)) {
+ for (const run of (await deps.recentRuns(p.file)).sort((a, b) => b.id - a.id)) {
if (!isCandidate(run) || run.head_sha === head || run.head_repository?.full_name !== repo || heads.has(run.head_sha)) continue;
if (heads.size >= MAX_FALLBACK_HEADS) break;
heads.set(run.head_sha, (await deps.commit(run.head_sha)).tree);
@@ -281,6 +283,10 @@ export function apiDeps(client: GitHubClient): ReuseDeps {
export function gateDeps(client: GitHubClient): GateDeps {
return {
...apiDeps(client),
+ async recentRuns(file) {
+ const pages = await Promise.all(CANDIDATE_EVENTS.map(event => client.request<{ workflow_runs: FullRun[] }>('GET', `repos/{repo}/actions/workflows/${file}/runs?event=${event}&per_page=100`)));
+ return pages.flatMap(p => p.workflow_runs);
+ },
async executed(runId) {
const got = await fetchArtifactJson(client, runId, 'executed-identities', 'executed-identities.json');
if (got.reason) return { reason: got.reason };
diff --git a/test/scripts/ci-reuse.test.ts b/test/scripts/ci-reuse.test.ts
index 41cab32b48..f81435a3e4 100644
--- a/test/scripts/ci-reuse.test.ts
+++ b/test/scripts/ci-reuse.test.ts
@@ -324,6 +324,7 @@ describe('ci-reuse remote-gate decision', () => {
async commit(sha) { if (!commits[sha]) throw new Error(`GitHub API GET git/commits/${sha} -> 404`); return commits[sha]!; },
async runsForHead(file, sha) { return o.runs.filter(r => r.file === file && r.head_sha === sha); },
async recentSuccessfulRuns(file) { return o.runs.filter(r => r.file === file && r.conclusion === 'success'); },
+ async recentRuns(file) { return o.runs.filter(r => r.file === file); },
async jobs(runId, attempt) {
const r = o.runs.find(x => x.id === runId)!;
return o.jobs?.[`${runId}/${attempt}`] ?? [{ name: files[r.file].job, status: 'completed', conclusion: 'success' }];
@@ -457,6 +458,10 @@ describe('ci-reuse remote-gate decision', () => {
expect((await go(deps, C2)).code).toBe(3);
const busy = gate({ commits, runs: [run('test.yml', { id: 610, status: 'in_progress', conclusion: null }), run('test.yml'), run('e2e.yml')] });
expect(await decideGate(busy, PROFILES.test, C2, T, REPO)).toMatchObject({ state: 'pending' });
+ // A same-tree commit whose only full run failed is seen too, though it has no passed run to be listed by.
+ const C3 = '9'.repeat(40);
+ const failedElsewhere = gate({ commits: { ...commits, [C3]: { tree: T, parents: [C2] } }, runs: [run('test.yml', { id: 640, head_sha: C2, conclusion: 'failure' }), run('test.yml'), run('e2e.yml')] });
+ expect(await decideGate(failedElsewhere, PROFILES.test, C3, T, REPO)).toMatchObject({ state: 'failed' });
});
test('a cancelled newest run looks further back; a passed run of the same tree on another head (a merge commit) reuses', async () => {