@cleocode/core 2026.11.21 → 2026.11.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1147,13 +1147,76 @@ export function untestedFailureCause(log) {
1147
1147
  const UNTESTED_CAUSE_TEXT = {
1148
1148
  'runner-cancel': 'the runner was cancelled',
1149
1149
  'worker-crash': 'a test worker crashed',
1150
+ 'runner-lost': 'the runner lost communication with GitHub',
1151
+ 'job-timeout': 'the job exceeded its maximum execution time',
1152
+ 'runner-shutdown': 'the runner shut down',
1150
1153
  };
1154
+ /** GitHub's own annotations for a job the infrastructure ended (T14693). */
1155
+ const INFRA_ANNOTATIONS = [
1156
+ ['runner-lost', /^The (?:self-)?hosted runner\b.*\blost communication with the server\b/],
1157
+ ['job-timeout', /^The job\b.*\bhas exceeded the maximum execution time of\b/],
1158
+ ['runner-shutdown', /^The runner has received a shutdown signal\b/],
1159
+ ];
1160
+ /** The {@link UntestedFailureCause}s the CI infrastructure produced (T14693). */
1161
+ const INFRA_CAUSES = new Set([
1162
+ 'runner-lost',
1163
+ 'job-timeout',
1164
+ 'runner-shutdown',
1165
+ ]);
1166
+ /**
1167
+ * The names of the jobs the CI infrastructure ended (T14693): a stand-in must
1168
+ * have run each of them to success itself.
1169
+ *
1170
+ * @param untested - The merge commit's untested job failures.
1171
+ * @returns Their job names, deduplicated.
1172
+ * @task T14693
1173
+ */
1174
+ export function infraClearedJobs(untested) {
1175
+ return [...new Set((untested ?? []).filter((j) => INFRA_CAUSES.has(j.cause)).map((j) => j.name))];
1176
+ }
1177
+ /** The cancellation GitHub annotates beside an infrastructure stop (T14693). */
1178
+ const GITHUB_CANCEL_ANNOTATION = /^The operation was canceled\.\s*$/;
1179
+ /**
1180
+ * Why the CI infrastructure, not the change, failed a job (T14693), or `null`
1181
+ * when the job may have failed on the change. Every failure-level annotation
1182
+ * must be GitHub's own: a lost runner, a job past its maximum execution time,
1183
+ * or a runner shutdown (the cancellation notice beside one is allowed), and
1184
+ * at least one must name the cause. A `timed_out` conclusion names a timeout
1185
+ * by itself. A readable log must name no failed test; a timeout needs a
1186
+ * readable log, since only its log shows that no test failed before the
1187
+ * limit. A lost or shut-down runner usually uploads no log, and decided
1188
+ * nothing, as a cancelled run did not.
1189
+ *
1190
+ * @param input - The job's conclusion, failure-level annotation messages (null: unreadable) and log (null: none).
1191
+ * @returns The infrastructure cause, or `null`.
1192
+ * @task T14693
1193
+ */
1194
+ export function infraFailureCause(input) {
1195
+ const notes = (input.annotations ?? []).map((n) => n.trim());
1196
+ let cause = null;
1197
+ for (const note of notes) {
1198
+ const found = INFRA_ANNOTATIONS.find(([, re]) => re.test(note))?.[0];
1199
+ if (found)
1200
+ cause ??= found;
1201
+ else if (!GITHUB_CANCEL_ANNOTATION.test(note))
1202
+ return null;
1203
+ }
1204
+ if (cause === null && input.conclusion === 'timed_out')
1205
+ cause = 'job-timeout';
1206
+ if (cause === null)
1207
+ return null;
1208
+ if (input.log === null)
1209
+ return cause === 'job-timeout' ? null : cause;
1210
+ return noTestFailedLog(input.log) ? cause : null;
1211
+ }
1151
1212
  /**
1152
1213
  * The failing jobs of a pinned workflow on `sha` (the required aggregate and
1153
1214
  * workflow runs excluded) that failed without a failed test: a runner
1154
1215
  * cancellation (T14049) or a worker crash (T14074), by
1155
- * {@link untestedFailureCause}. A pending job or an unreadable log is never
1156
- * one, so `all` is then false.
1216
+ * {@link untestedFailureCause}, or the CI infrastructure ending it (T14693),
1217
+ * by {@link infraFailureCause} from its annotations. A pending job, or one
1218
+ * neither its log nor its annotations clear, is never one, so `all` is then
1219
+ * false.
1157
1220
  *
1158
1221
  * @param checks - Checks fetched for `sha`.
1159
1222
  * @param sha - The commit judged.
@@ -1161,11 +1224,13 @@ const UNTESTED_CAUSE_TEXT = {
1161
1224
  * @param pins - Required-name to app/workflow pin.
1162
1225
  * @param fetchJobLog - Plain-text log of one job.
1163
1226
  * @param cwd - Repository work tree for `gh`.
1227
+ * @param fetchJobAnnotations - Failure-level annotations of one job (T14693); omitted, none are read.
1164
1228
  * @returns Those jobs, and whether they are every failure.
1165
1229
  * @task T14049
1166
1230
  * @task T14074
1231
+ * @task T14693
1167
1232
  */
1168
- export async function untestedJobFailures(checks, sha, required, pins, fetchJobLog, cwd) {
1233
+ export async function untestedJobFailures(checks, sha, required, pins, fetchJobLog, cwd, fetchJobAnnotations) {
1169
1234
  const jobs = [];
1170
1235
  let all = true;
1171
1236
  for (const c of latestRuns(checks, sha, pinnedScope(required, pins))) {
@@ -1177,8 +1242,16 @@ export async function untestedJobFailures(checks, sha, required, pins, fetchJobL
1177
1242
  }
1178
1243
  if (HARMLESS_CONCLUSIONS.has(c.conclusion ?? ''))
1179
1244
  continue;
1180
- const log = c.conclusion === 'failure' ? await fetchJobLog(c.id, cwd) : null;
1181
- const cause = log === null ? null : untestedFailureCause(log);
1245
+ const failed = c.conclusion === 'failure' || c.conclusion === 'timed_out';
1246
+ const log = failed ? await fetchJobLog(c.id, cwd) : null;
1247
+ let cause = log === null ? null : untestedFailureCause(log);
1248
+ if (cause === null && failed && fetchJobAnnotations) {
1249
+ // T14693: a lost runner or a timeout is recorded in annotations, often with no log.
1250
+ const annotations = await fetchJobAnnotations(c.id, cwd);
1251
+ if (annotations !== null) {
1252
+ cause = infraFailureCause({ conclusion: c.conclusion ?? null, annotations, log });
1253
+ }
1254
+ }
1182
1255
  if (cause)
1183
1256
  jobs.push({ name: c.name, mergeRunId: c.id, cause });
1184
1257
  else
@@ -1343,7 +1416,7 @@ export async function findGreenDescendant(input) {
1343
1416
  // cancellation, or a vitest worker crash) decided nothing, though GitHub
1344
1417
  // reports it and the aggregate as `failure`: it is superseded, as a
1345
1418
  // cancelled run is. A job with any failed test never is.
1346
- const found = await untestedJobFailures(input.checks, merge, required, pins, input.fetchJobLog, cwd);
1419
+ const found = await untestedJobFailures(input.checks, merge, required, pins, input.fetchJobLog, cwd, input.fetchJobAnnotations);
1347
1420
  untestedIds = found.ids;
1348
1421
  if (found.all) {
1349
1422
  untested = found.jobs;
@@ -1491,7 +1564,7 @@ export async function findGreenDescendant(input) {
1491
1564
  // T14176: a run whose every failing job tested nothing (its runner was
1492
1565
  // cancelled, or a test worker crashed with no test failed) cannot show
1493
1566
  // the PR failing either; look on, recording it. A failed test still refuses.
1494
- const untestedHere = await untestedJobFailures(fetched.checks, sha, required, pins, input.fetchJobLog, cwd);
1567
+ const untestedHere = await untestedJobFailures(fetched.checks, sha, required, pins, input.fetchJobLog, cwd, input.fetchJobAnnotations);
1495
1568
  if (untestedHere.all) {
1496
1569
  passedOver.push({
1497
1570
  sha,
@@ -1506,7 +1579,7 @@ export async function findGreenDescendant(input) {
1506
1579
  if (failedJob) {
1507
1580
  return refuse(`${failedJob.name}: ${failedJob.conclusion} on later ${input.ref} commit ${sha.slice(0, 12)}`);
1508
1581
  }
1509
- const verdict = judgeStandIn(fetched.checks, sha, supersededNames, pins, input.jobs, input.ref);
1582
+ const verdict = judgeStandIn(fetched.checks, sha, supersededNames, pins, input.jobs, input.ref, infraClearedJobs(untested));
1510
1583
  if ('undecided' in verdict) {
1511
1584
  lastUndecided ??= `${sha.slice(0, 12)}: ${verdict.undecided}`;
1512
1585
  continue;
@@ -1552,7 +1625,7 @@ function notGreenOnPrHead(names, headChecks, head, pins) {
1552
1625
  * the caller looks at the next candidate; the undecided verdict says why, and
1553
1626
  * whether CI's own change filter skipped the gates' jobs (T14177).
1554
1627
  */
1555
- function judgeStandIn(checks, sha, names, pins, jobs, ref) {
1628
+ function judgeStandIn(checks, sha, names, pins, jobs, ref, rerun = []) {
1556
1629
  for (const name of names) {
1557
1630
  const pinned = checks.filter((c) => c.name === name && pinMatches(c, pins[name]));
1558
1631
  const verdict = judgeOnSha(pinned, sha, 'push');
@@ -1594,6 +1667,27 @@ function judgeStandIn(checks, sha, names, pins, jobs, ref) {
1594
1667
  return { ok: false, reason: `${decisive} (later ${ref} commit)` };
1595
1668
  notRun.push(...onSha.reasons);
1596
1669
  }
1670
+ // T14693: a job the infrastructure ended on the merge commit decided
1671
+ // nothing, so the stand-in must have run that same job to success itself; a
1672
+ // filter-skipped job there never re-ran what may have hung on the PR.
1673
+ const scope = pinnedScope(names, pins);
1674
+ for (const name of rerun) {
1675
+ const runs = latestRuns(checks, sha, scope).filter((c) => c.name === name && c.source !== 'workflow-run' && (c.event ?? 'push') === 'push');
1676
+ if (runs.some((c) => c.status !== 'completed')) {
1677
+ return {
1678
+ ok: false,
1679
+ reason: `${name}: pending on later ${ref} commit ${sha.slice(0, 12)} — wait for ${sha.slice(0, 12)} to finish, then verify again`,
1680
+ };
1681
+ }
1682
+ if (runs.length === 0 || !runs.every((c) => c.conclusion === 'success')) {
1683
+ const seen = runs.find((c) => c.conclusion !== 'success')?.conclusion ?? 'no push run';
1684
+ return {
1685
+ undecided: `${name}, which the infrastructure ended on the merge commit, did not run to success (${seen} on ${sha.slice(0, 12)})`,
1686
+ filterSkipped: false,
1687
+ neverRan: false,
1688
+ };
1689
+ }
1690
+ }
1597
1691
  if (notRun.length === 0)
1598
1692
  return { ok: true };
1599
1693
  return {
@@ -1681,7 +1775,7 @@ export async function findGreenCurrentHead(input) {
1681
1775
  const fetched = await input.fetchChecks(sha, cwd);
1682
1776
  if (!fetched.ok)
1683
1777
  return { ok: false, reason: fetched.reason };
1684
- const verdict = judgeStandIn(fetched.checks, sha, input.required, input.pins, input.jobs, ref);
1778
+ const verdict = judgeStandIn(fetched.checks, sha, input.required, input.pins, input.jobs, ref, input.rerunJobs);
1685
1779
  if (!('undecided' in verdict)) {
1686
1780
  if (!verdict.ok)
1687
1781
  return verdict;
@@ -2073,6 +2167,33 @@ export async function defaultFetchJobLog(jobId, cwd) {
2073
2167
  return null;
2074
2168
  }
2075
2169
  }
2170
+ /**
2171
+ * Default {@link ResolveCiEvidenceOptions.fetchJobAnnotations}: the messages
2172
+ * of a job's failure-level check-run annotations via `gh` (T14693), or null
2173
+ * when they cannot be read.
2174
+ *
2175
+ * @param jobId - The job's check-run id.
2176
+ * @param cwd - Repository work tree for `gh`.
2177
+ * @returns The failure-level annotation messages, or null.
2178
+ * @task T14693
2179
+ */
2180
+ export async function defaultFetchJobAnnotations(jobId, cwd) {
2181
+ if (!isGitWorkTree(cwd) || !isGhCliAvailable())
2182
+ return null;
2183
+ const rows = ghApi(`repos/{owner}/{repo}/check-runs/${jobId}/annotations?per_page=100`, cwd);
2184
+ // A full page may hide more annotations; fail closed rather than miss one.
2185
+ if (!Array.isArray(rows) || rows.length >= 100)
2186
+ return null;
2187
+ const messages = [];
2188
+ for (const row of rows) {
2189
+ if (row.annotation_level !== 'failure')
2190
+ continue;
2191
+ if (typeof row.message !== 'string')
2192
+ return null;
2193
+ messages.push(row.message);
2194
+ }
2195
+ return messages;
2196
+ }
2076
2197
  /**
2077
2198
  * Fetch once more when a required check's run came back without the identity
2078
2199
  * its pin names (T13017): GitHub lists a job before its workflow run, and a
@@ -2627,6 +2748,7 @@ export async function resolveCiEvidenceAtom(prNumber, roots, opts = {}) {
2627
2748
  isAncestor: opts.isAncestor ?? defaultIsAncestor,
2628
2749
  firstParentOf: opts.firstParentOf ?? defaultFirstParentOf,
2629
2750
  fetchJobLog: opts.fetchJobLog ?? defaultFetchJobLog,
2751
+ fetchJobAnnotations: opts.fetchJobAnnotations ?? defaultFetchJobAnnotations,
2630
2752
  nextMainCommitAt: opts.nextMainCommitAt ?? defaultNextMainCommitAt,
2631
2753
  });
2632
2754
  if (found.ok) {
@@ -2698,6 +2820,7 @@ export async function resolveCiEvidenceAtom(prNumber, roots, opts = {}) {
2698
2820
  const found = await findGreenCurrentHead({
2699
2821
  ...(jobSpecs.length > 0 ? { jobs: jobSpecs } : {}),
2700
2822
  required: pushRequired,
2823
+ ...(cleared?.untested ? { rerunJobs: infraClearedJobs(cleared.untested) } : {}),
2701
2824
  mergeCommitSha: pr.mergeCommitSha,
2702
2825
  pins,
2703
2826
  ref: onDefault.ref,