Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

ci(e2e): classify full E2E shards from their job annotations, not cancelled()

garrytanf22f00c27a05
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
index 70908b5728..8aedfa9de2 100644
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -863,6 +863,11 @@ jobs:
needs: [coverage-full-unit, coverage-full-serial, coverage-full-slow, coverage-full-e2e]
if: always() && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.full_corpus))
runs-on: ubicloud-standard-4-ubuntu-2404
+ # actions + checks: the shard classifier reads this run's jobs and their annotations.
+ permissions:
+ contents: read
+ actions: read
+ checks: read
timeout-minutes: 15
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
@@ -880,36 +885,15 @@ jobs:
# A run cancelled by a newer run in its concurrency group or by a user
# reports its cancelled shards as cancelled (no coverage, not a test
# failure). A shard that failed or hit timeout-minutes in a run nobody
- # cancelled stays a failure. docs/TESTING.md#full-corpus-report-states
- # Status functions are only valid in `if:`, so cancellation reaches the
- # classifier through GITHUB_ENV.
- - name: Note run cancellation
- if: cancelled()
- run: echo "RUN_CANCELLED=true" >> "$GITHUB_ENV"
+ # cancelled stays a failure. cancelled() cannot tell (it is false in an
+ # always() job started after the cancel), so the script reads the shard
+ # jobs' annotations. docs/TESTING.md#full-corpus-report-states
- name: Classify full E2E shards
id: shards
- if: always()
env:
FULL_E2E_RESULT: ${{ needs.coverage-full-e2e.result }}
- RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- RUN_ID: ${{ github.run_id }}
- DOCS: docs/TESTING.md#full-corpus-report-states
- run: |
- if [ "$FULL_E2E_RESULT" = success ]; then
- echo "state=complete" >> "$GITHUB_OUTPUT"
- exit 0
- fi
- if [ "$FULL_E2E_RESULT" = cancelled ] && [ "$RUN_CANCELLED" = true ]; then
- msg="Full E2E shards cancelled: this run ($RUN_URL) was cancelled by a newer run in its concurrency group or by a user before the four shards finished, so no full-corpus coverage report exists for it. This is not a test failure. Next: gh workflow run e2e.yml --ref master -f full_corpus=true (or wait for the next schedule). Docs: $DOCS"
- echo "::warning title=Full E2E shards cancelled::$msg"
- { echo "### Full-corpus coverage: cancelled"; echo; echo "$msg"; } >> "$GITHUB_STEP_SUMMARY"
- echo "state=cancelled" >> "$GITHUB_OUTPUT"
- exit 0
- fi
- msg="Full E2E did not succeed (result: ${FULL_E2E_RESULT:-none}) and nobody cancelled this run, so a shard failed or hit its timeout-minutes; refusing a complete report from prior-attempt artifacts. Next: gh run view $RUN_ID --log-failed, fix the failing shard, then gh run rerun $RUN_ID --failed. Docs: $DOCS"
- echo "::error title=Full E2E shards failed::$msg"
- { echo "### Full-corpus coverage: failed"; echo; echo "$msg"; } >> "$GITHUB_STEP_SUMMARY"
- exit 1
+ GH_TOKEN: ${{ github.token }}
+ run: bun scripts/classify-full-e2e-shards.ts
- name: Merge full corpus
if: steps.shards.outputs.state == 'complete'
env:
diff --git a/docs/TESTING.md b/docs/TESTING.md
index 222621acfb..85da3e122c 100644
--- a/docs/TESTING.md
+++ b/docs/TESTING.md
@@ -1279,7 +1279,11 @@ optional assertion within a file.
#### Full-corpus report states
`coverage-full-report` classifies the four full E2E shards before merging
-anything. All shards succeeded: it merges, renders and gates the full corpus.
+anything (`scripts/classify-full-e2e-shards.ts`, reading this run attempt's
+shard jobs and their check-run annotations; `cancelled()` cannot tell, since it
+reads false in an `always()` job that starts after the cancel, and a timed-out
+shard also reports `cancelled` through `needs`). All shards succeeded: it
+merges, renders and gates the full corpus.
The run was cancelled (by a newer run in its concurrency group or by a user)
before the shards finished: it reports `Full E2E shards cancelled` as a
warning and a step-summary section, publishes no coverage and does not fail,
@@ -1287,7 +1291,8 @@ because nothing was measured; re-run with
`gh workflow run e2e.yml --ref master -f full_corpus=true` or wait for the next
schedule. Any other non-success (a shard failed, or hit its `timeout-minutes`
in a run nobody cancelled) is a failure: read `gh run view <run-id> --log-failed`,
-fix the shard, then `gh run rerun <run-id> --failed`. Scheduled runs use their
+fix the shard, then `gh run rerun <run-id> --failed`. Shard evidence that
+cannot be read is a failure, never a cancellation on a guess. Scheduled runs use their
own `-nightly` concurrency group, so a push to master no longer cancels the
nightly full corpus (#6040).
diff --git a/scripts/classify-full-e2e-shards.ts b/scripts/classify-full-e2e-shards.ts
new file mode 100644
index 0000000000..6e332bc5e0
--- /dev/null
+++ b/scripts/classify-full-e2e-shards.ts
@@ -0,0 +1,105 @@
+#!/usr/bin/env bun
+/**
+ * First step of e2e.yml's coverage-full-report (#6040): decide whether the
+ * four full E2E shards are complete, were cancelled with their run, or failed.
+ *
+ * A run cancelled by a newer run in its concurrency group or by a user is
+ * reported as cancelled (no coverage, not a test failure). Any other
+ * non-success, including a shard that hit its timeout-minutes in a run nobody
+ * cancelled, is a failure. The workflow cannot decide this from expressions:
+ * cancelled() is false in an always() job that starts after the run was
+ * cancelled (dispatch run 37371914954), and needs.<job>.result reads
+ * `cancelled` for a timed-out shard too. GitHub stamps each job of a cancelled
+ * run with a check-run annotation ("Canceling since a higher priority waiting
+ * request for <group> exists" or "The run was canceled by @<user>.") and a
+ * timed-out job with "The job running on runner <name> has exceeded the
+ * maximum execution time of <n> minutes.", so the shard jobs of this run
+ * attempt and their annotations decide it. Evidence that cannot be read is a
+ * failure, never a cancellation on a guess.
+ *
+ * Usage (Actions): FULL_E2E_RESULT=<needs result> GH_TOKEN=<token>
+ * bun scripts/classify-full-e2e-shards.ts
+ * Writes state=complete|cancelled to $GITHUB_OUTPUT; exits 0 for complete or
+ * cancelled, 1 for failed. Docs: docs/TESTING.md#full-corpus-report-states
+ */
+import { appendFileSync } from 'node:fs';
+import { type GitHubClient, inert, restClient } from './lib/gh-issue.ts';
+
+export const DOCS = 'docs/TESTING.md#full-corpus-report-states';
+const SHARD_JOB = /^coverage-full-e2e \(\d+\)$/;
+const RUN_CANCELLED = [/^Canceling since a higher priority waiting request for .+ exists/, /^The run was canceled by /];
+const TIMED_OUT = /has exceeded the maximum execution time/;
+
+export interface ShardJob { name: string; conclusion: string | null; annotations: string[] }
+export type ShardState = 'complete' | 'cancelled' | 'failed';
+export interface Classification { state: ShardState; title: string; message: string }
+
+export interface RunRef { repo: string; runId: string; attempt: string; serverUrl: string }
+
+export function classifyShards(result: string, shards: ShardJob[] | Error, run: RunRef): Classification {
+ const url = `${run.serverUrl}/${run.repo}/actions/runs/${run.runId}`;
+ const rerun = `Next: gh run view ${run.runId} --log-failed, fix the failing shard, then gh run rerun ${run.runId} --failed. Docs: ${DOCS}`;
+ if (result === 'success') return { state: 'complete', title: 'Full E2E shards complete', message: 'All four full E2E shards succeeded.' };
+ if (shards instanceof Error) {
+ return {
+ state: 'failed',
+ title: 'Full E2E shard evidence unreadable',
+ message: `Full E2E did not succeed (result: ${result || 'none'}) and the shard jobs of ${url} could not be read (${inert(shards.message, 300)}), so a cancellation cannot be told apart from a failure; refusing a report. ${rerun}`,
+ };
+ }
+ const notOk = shards.filter(s => s.conclusion !== 'success');
+ const withRun = (s: ShardJob) => s.conclusion === 'cancelled'
+ && !s.annotations.some(a => TIMED_OUT.test(a))
+ && s.annotations.some(a => RUN_CANCELLED.some(re => re.test(a)));
+ if (shards.length > 0 && notOk.length > 0 && notOk.every(withRun)) {
+ return {
+ state: 'cancelled',
+ title: 'Full E2E shards cancelled',
+ message: `Full E2E shards cancelled: ${url} was cancelled by a newer run in its concurrency group or by a user before ${notOk.map(s => s.name).join(', ')} finished, so no full-corpus coverage report exists for it. This is not a test failure. Next: gh workflow run e2e.yml --ref master -f full_corpus=true (or wait for the next schedule). Docs: ${DOCS}`,
+ };
+ }
+ const detail = shards.length === 0
+ ? 'no coverage-full-e2e shard jobs were found in this run attempt'
+ : notOk.map(s => `${s.name}: ${s.conclusion ?? 'no conclusion'}${s.annotations.some(a => TIMED_OUT.test(a)) ? ' (hit timeout-minutes)' : ''}`).join('; ');
+ return {
+ state: 'failed',
+ title: 'Full E2E shards failed',
+ message: `Full E2E did not succeed (result: ${result || 'none'}) and the run was not cancelled: ${inert(detail, 600)}. A failed or timed-out shard is a failure; refusing a complete report from prior-attempt artifacts. ${rerun}`,
+ };
+}
+
+interface JobInfo { id: number; name: string; conclusion: string | null }
+interface Annotation { message: string }
+
+export async function readShards(client: GitHubClient, run: RunRef): Promise<ShardJob[] | Error> {
+ try {
+ const { jobs } = await client.request<{ jobs: JobInfo[] }>('GET', `repos/{repo}/actions/runs/${run.runId}/attempts/${run.attempt}/jobs?per_page=100`);
+ const shards = jobs.filter(j => SHARD_JOB.test(j.name));
+ return await Promise.all(shards.map(async j => ({
+ name: j.name,
+ conclusion: j.conclusion,
+ annotations: (await client.request<Annotation[]>('GET', `repos/{repo}/check-runs/${j.id}/annotations?per_page=50`)).map(a => a.message.trim()),
+ })));
+ } catch (e) {
+ return e instanceof Error ? e : new Error(String(e));
+ }
+}
+
+export async function main(env: Record<string, string | undefined>, client?: GitHubClient): Promise<number> {
+ const run: RunRef = {
+ repo: env.GITHUB_REPOSITORY ?? '',
+ runId: env.GITHUB_RUN_ID ?? '',
+ attempt: env.GITHUB_RUN_ATTEMPT ?? '1',
+ serverUrl: env.GITHUB_SERVER_URL ?? 'https://github.com',
+ };
+ const result = env.FULL_E2E_RESULT ?? '';
+ const shards = result === 'success' ? [] : await readShards(client ?? restClient(run.repo), run);
+ const c = classifyShards(result, shards, run);
+ const level = c.state === 'failed' ? 'error' : c.state === 'cancelled' ? 'warning' : 'notice';
+ console.log(`::${level} title=${c.title}::${c.message}`);
+ if (env.GITHUB_STEP_SUMMARY && c.state !== 'complete') appendFileSync(env.GITHUB_STEP_SUMMARY, `### Full-corpus coverage: ${c.state}\n\n${c.message}\n`);
+ if (env.GITHUB_OUTPUT && c.state !== 'failed') appendFileSync(env.GITHUB_OUTPUT, `state=${c.state}\n`);
+ return c.state === 'failed' ? 1 : 0;
+}
+
+if (import.meta.main) process.exit(await main(process.env));
diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsv
index 1a57e0704f..79bd320951 100644
--- a/scripts/structural-suites.tsv
+++ b/scripts/structural-suites.tsv
@@ -276,6 +276,7 @@ test/scripts/e2e-wiring.test.ts (file-level) 12 readFileSync
test/scripts/fix-wave-gate.test.ts fix-wave gate workflow 3 readFileSync
test/scripts/heavy-door-workflow.test.ts heavy door supply chain and coverage gates 8 readFileSync
test/scripts/native-lock-prebuilds.test.ts native lock distribution integrity 2 readFileSync
+test/scripts/nightly-e2e.test.ts full E2E shard classification (#6040) 2 readFileSync
test/scripts/nightly-e2e.test.ts nightly E2E scheduling 4 readFileSync
test/scripts/nightly-issue.test.ts .github/nightly-known-red.tsv 2 readFileSync
test/scripts/nightly-issue.test.ts nightly-watch incidents 9 readFileSync
diff --git a/test/scripts/nightly-e2e.test.ts b/test/scripts/nightly-e2e.test.ts
index 0624d106c0..8bbd1cde21 100644
--- a/test/scripts/nightly-e2e.test.ts
+++ b/test/scripts/nightly-e2e.test.ts
@@ -5,6 +5,7 @@ import { join } from 'node:path';
import { spawnSync } from 'node:child_process';
import { safeLoad } from 'js-yaml';
import { verifyNightlyE2E } from '../../scripts/verify-nightly-e2e.ts';
+import { classifyShards, main as classifyMain, DOCS as CLASSIFY_DOCS, type ShardJob } from '../../scripts/classify-full-e2e-shards.ts';
const repo = join(import.meta.dir, '../..');
const fullProfile = "github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.full_corpus)";
@@ -137,52 +138,17 @@ describe('nightly E2E scheduling', () => {
const classify = report.steps.find((step: any) => step.name === 'Classify full E2E shards');
expect(report.steps.indexOf(classify)).toBeLessThan(report.steps.indexOf(mergeStep));
expect(classify.id).toBe('shards');
- expect(classify.env.FULL_E2E_RESULT).toBe('${{ needs.coverage-full-e2e.result }}');
- expect(classify.if).toBe('always()');
- expect(classify.env.RUN_CANCELLED).toBeUndefined();
- const note = report.steps.find((step: any) => step.name === 'Note run cancellation');
- expect(report.steps.indexOf(note)).toBe(report.steps.indexOf(classify) - 1);
- expect(note.if).toBe('cancelled()');
- expect(note.run).toBe('echo "RUN_CANCELLED=true" >> "$GITHUB_ENV"');
+ expect(classify.run).toBe('bun scripts/classify-full-e2e-shards.ts');
+ expect(classify.env).toEqual({ FULL_E2E_RESULT: '${{ needs.coverage-full-e2e.result }}', GH_TOKEN: '${{ github.token }}' });
+ expect(report.permissions).toEqual({ contents: 'read', actions: 'read', checks: 'read' });
// Status functions such as cancelled() are refused outside `if:` (HTTP 422
- // at dispatch), so no step may carry one in env or run.
- for (const step of report.steps) expect(JSON.stringify({ env: step.env, run: step.run })).not.toMatch(/\b(cancelled|always|success|failure)\(\)/);
+ // at dispatch), and inside an always() job started after a cancel they
+ // read false (run 37371914954), so no step may lean on one.
+ for (const step of report.steps) expect(JSON.stringify(step)).not.toMatch(/\bcancelled\(\)/);
for (const name of ['Merge full corpus', 'Coverage summary → step summary', 'Baseline gate (fullCorpus, like-for-like)']) {
expect(report.steps.find((step: any) => step.name === name).if).toBe("steps.shards.outputs.state == 'complete'");
}
expect(readFileSync(join(repo, 'docs/TESTING.md'), 'utf8')).toMatch(/^#+ Full-corpus report states$/m);
- fixture(root => {
- // A timed-out shard in a run nobody cancelled reports `cancelled` from
- // needs but RUN_CANCELLED=false: it must stay a failure.
- for (const [result, runCancelled, status, state] of [
- ['success', 'false', 0, 'complete'], ['success', 'true', 0, 'complete'],
- ['failure', 'false', 1, ''], ['failure', 'true', 1, ''],
- ['cancelled', 'false', 1, ''], ['cancelled', 'true', 0, 'cancelled'],
- ['skipped', 'false', 1, ''], ['', 'false', 1, ''],
- ] as const) {
- const out = join(root, `out-${result || 'none'}-${runCancelled}`);
- const summary = `${out}.summary`;
- writeFileSync(out, '');
- writeFileSync(summary, '');
- const run = spawnSync('bash', ['-e', '-c', classify.run], {
- encoding: 'utf8',
- env: { ...process.env, FULL_E2E_RESULT: result, RUN_CANCELLED: runCancelled, RUN_ID: '42', RUN_URL: 'https://example.test/runs/42', DOCS: classify.env.DOCS, GITHUB_OUTPUT: out, GITHUB_STEP_SUMMARY: summary },
- });
- expect(run.status, `${result}/${runCancelled}: ${run.stdout}${run.stderr}`).toBe(status);
- expect(readFileSync(out, 'utf8')).toBe(state ? `state=${state}\n` : '');
- if (state === 'cancelled') {
- expect(run.stdout).toContain('::warning title=Full E2E shards cancelled::');
- expect(readFileSync(summary, 'utf8')).toContain('Full-corpus coverage: cancelled');
- expect(run.stdout).toContain('gh workflow run e2e.yml --ref master -f full_corpus=true');
- }
- if (status === 1) {
- expect(run.stdout).toContain('::error title=Full E2E shards failed::');
- expect(run.stdout).toContain('gh run view 42 --log-failed');
- expect(readFileSync(summary, 'utf8')).toContain('Full-corpus coverage: failed');
- }
- if (status !== 0 || state === 'cancelled') expect(run.stdout).toContain('docs/TESTING.md#full-corpus-report-states');
- }
- });
const status = workflow.jobs['e2e-status'];
expect(status.if).toBe('always()');
expect(status.needs).toContain('coverage-full-e2e');
@@ -227,3 +193,66 @@ esac
}
});
});
+
+describe('full E2E shard classification (#6040)', () => {
+ const run = { repo: 'acme-example/brain', runId: '42', attempt: '1', serverUrl: 'https://example.test' };
+ // Annotation texts recorded from real runs: 37273083933 (cancelled by a
+ // newer push, concurrency) and 37371914954 (cancelled by a user).
+ const CONCURRENCY = 'Canceling since a higher priority waiting request for E2E Tests-refs/heads/master exists';
+ const USER = 'The run was canceled by @capy-ai[bot].';
+ const TIMEOUT = 'The job running on runner ubicloud-runner-1 has exceeded the maximum execution time of 60 minutes.';
+ const OP = 'The operation was canceled.';
+ const shard = (n: number, conclusion: string | null, annotations: string[] = []): ShardJob => ({ name: `coverage-full-e2e (${n})`, conclusion, annotations });
+ const all = (conclusion: string, annotations: string[]) => [1, 2, 3, 4].map(n => shard(n, conclusion, annotations));
+
+ test.each([
+ ['all shards succeeded', 'success', all('success', []), 'complete'],
+ ['cancelled by a newer run in the concurrency group', 'cancelled', all('cancelled', [CONCURRENCY, OP]), 'cancelled'],
+ ['cancelled by a user', 'cancelled', all('cancelled', [USER, OP]), 'cancelled'],
+ ['some shards finished before the run was cancelled', 'cancelled', [shard(1, 'success'), shard(2, 'cancelled', [USER, OP]), shard(3, 'success'), shard(4, 'cancelled', [USER])], 'cancelled'],
+ ['a shard hit timeout-minutes in a run nobody cancelled', 'cancelled', [shard(1, 'success'), shard(2, 'cancelled', [TIMEOUT, OP]), shard(3, 'success'), shard(4, 'success')], 'failed'],
+ ['a timed-out shard in a run later cancelled stays a failure', 'cancelled', [shard(1, 'cancelled', [USER]), shard(2, 'cancelled', [TIMEOUT, USER]), shard(3, 'success'), shard(4, 'success')], 'failed'],
+ ['a shard failed before the run was cancelled', 'failure', [shard(1, 'failure', ['Process completed with exit code 1.']), shard(2, 'cancelled', [USER]), shard(3, 'success'), shard(4, 'success')], 'failed'],
+ ['cancelled with no annotation saying why', 'cancelled', all('cancelled', [OP]), 'failed'],
+ ['no shard jobs found', 'cancelled', [], 'failed'],
+ ['skipped', 'skipped', all('skipped', []), 'failed'],
+ ] as const)('%s → %s', (_name, result, shards, state) => {
+ const c = classifyShards(result, [...shards], run);
+ expect(c.state).toBe(state);
+ if (state !== 'complete') expect(c.message).toContain(CLASSIFY_DOCS);
+ if (state === 'cancelled') expect(c.message).toContain('gh workflow run e2e.yml --ref master -f full_corpus=true');
+ if (state === 'failed') expect(c.message).toContain('gh run view 42 --log-failed');
+ });
+
+ test('unreadable evidence is a failure, never a cancellation on a guess', () => {
+ const c = classifyShards('cancelled', new Error('GitHub API GET ... -> 403'), run);
+ expect(c.state).toBe('failed');
+ expect(c.title).toBe('Full E2E shard evidence unreadable');
+ });
+
+ test('the CLI reads this attempt\'s shard jobs and annotations, writes state and the summary', async () => {
+ const root = mkdtempSync(join(tmpdir(), 'gbrain-classify-shards-'));
+ try {
+ const calls: string[] = [];
+ const client = {
+ async request<T>(_method: string, path: string): Promise<T> {
+ calls.push(path);
+ if (path.includes('/jobs')) return { jobs: [{ id: 7, name: 'coverage-full-e2e (1)', conclusion: 'cancelled' }, { id: 8, name: 'coverage-full-unit (1)', conclusion: 'success' }] } as T;
+ return [{ message: USER }, { message: OP }] as T;
+ },
+ };
+ const env = { FULL_E2E_RESULT: 'cancelled', GITHUB_REPOSITORY: run.repo, GITHUB_RUN_ID: '42', GITHUB_RUN_ATTEMPT: '2', GITHUB_OUTPUT: join(root, 'out'), GITHUB_STEP_SUMMARY: join(root, 'summary') };
+ expect(await classifyMain(env, client)).toBe(0);
+ expect(calls).toEqual(['repos/{repo}/actions/runs/42/attempts/2/jobs?per_page=100', 'repos/{repo}/check-runs/7/annotations?per_page=50']);
+ expect(readFileSync(join(root, 'out'), 'utf8')).toBe('state=cancelled\n');
+ expect(readFileSync(join(root, 'summary'), 'utf8')).toContain('### Full-corpus coverage: cancelled');
+ const failing = { ...client, async request<T>(_m: string, path: string): Promise<T> { if (path.includes('/jobs')) throw Object.assign(new Error('403'), { status: 403 }); return [] as T; } };
+ const env2 = { ...env, GITHUB_OUTPUT: join(root, 'out2'), GITHUB_STEP_SUMMARY: join(root, 'summary2') };
+ writeFileSync(env2.GITHUB_OUTPUT, '');
+ expect(await classifyMain(env2, failing)).toBe(1);
+ expect(readFileSync(env2.GITHUB_OUTPUT, 'utf8')).toBe('');
+ expect(await classifyMain({ ...env, FULL_E2E_RESULT: 'success', GITHUB_OUTPUT: join(root, 'out3') }, failing)).toBe(0);
+ expect(readFileSync(join(root, 'out3'), 'utf8')).toBe('state=complete\n');
+ } finally { rmSync(root, { recursive: true, force: true }); }
+ });
+});