Repository navigation
feat(ci): report advisory cross-repository check co-occurrences #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -241,6 +241,58 @@ async function getEvidence(repo, pr, getJson) { | |
| return diagnoseChecks(checkRuns.check_runs, statuses.statuses); | ||
| } | ||
|
|
||
| const CORRELATABLE_OUTCOMES = new Set(['failure', 'error', 'timed_out', 'startup_failure', 'action_required']); | ||
|
|
||
| // Pure advisory co-occurrence across inspected repositories; matching check names | ||
| // and outcomes cannot establish a shared runner or infrastructure root cause. | ||
| export function correlateObservedFailures(reports, { limit = 10 } = {}) { | ||
| if (!Array.isArray(reports) || !Number.isSafeInteger(limit) || limit < 1 || limit > 50) { | ||
| throw new Error('Invalid portfolio correlation input'); | ||
| } | ||
| const grouped = new Map(); | ||
| for (const report of reports) { | ||
| if (typeof report?.repo !== 'string' || !Array.isArray(report.priority)) { | ||
| throw new Error('Malformed repository report for CI correlation'); | ||
| } | ||
| for (const pr of report.priority) { | ||
| const diagnosis = pr?.ciDiagnosis; | ||
| if (diagnosis?.evidenceComplete !== true || !Array.isArray(diagnosis.attentionChecks)) continue; | ||
| for (const check of diagnosis.attentionChecks) { | ||
| if (!['check-run', 'commit-status'].includes(check?.source) | ||
| || typeof check.name !== 'string' || !check.name.trim() | ||
| || !CORRELATABLE_OUTCOMES.has(check.outcome)) continue; | ||
| const key = JSON.stringify([check.source, check.name, check.outcome]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Group by the original check name, not the display name.
Preserve the original name as the grouping identity. Keep the bounded name for display. Identical original names must still correlate.
|
||
| if (!grouped.has(key)) { | ||
| grouped.set(key, { | ||
| source: check.source, name: check.name, outcome: check.outcome, | ||
| repositories: new Set(), pullRequests: new Set(), | ||
| }); | ||
| } | ||
| const group = grouped.get(key); | ||
| group.repositories.add(report.repo); | ||
| if (Number.isSafeInteger(pr.number) && pr.number > 0) { | ||
| group.pullRequests.add(report.repo + '#' + pr.number); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| const all = [...grouped.values()].filter(group => group.repositories.size >= 2) | ||
| .map(group => ({ | ||
| source: group.source, | ||
| name: group.name, | ||
| outcome: group.outcome, | ||
| repositoryCount: group.repositories.size, | ||
| repositories: [...group.repositories].sort(), | ||
| affectedPRs: group.pullRequests.size, | ||
| confidence: 'unverified', | ||
| })) | ||
| .sort((a, b) => b.repositoryCount - a.repositoryCount | ||
| || a.name.localeCompare(b.name) | ||
| || a.outcome.localeCompare(b.outcome) | ||
| || a.source.localeCompare(b.source)); | ||
| return { signals: all.slice(0, limit), total: all.length }; | ||
| } | ||
|
|
||
| export async function collectPortfolio(repos, getJson, { now = new Date(), days = 7, staleDays = 3, maxPages = 20, inspect = 5 } = {}) { | ||
| const since = new Date(now.getTime() - days * DAY_MS); | ||
| const reports = []; | ||
|
|
@@ -258,7 +310,7 @@ export async function collectPortfolio(repos, getJson, { now = new Date(), days | |
| } | ||
| return { generatedAt: now.toISOString(), since: since.toISOString(), | ||
| caveat: 'Read-only snapshot, checks are advisory. Passing observed checks do not certify required contexts, reviews, merged state, or deployment.', | ||
| reports }; | ||
| sharedFailureSignals: correlateObservedFailures(reports), reports }; | ||
| } | ||
|
|
||
| export function formatMarkdown(data, { show = 10 } = {}) { | ||
|
|
@@ -270,6 +322,21 @@ export function formatMarkdown(data, { show = 10 } = {}) { | |
| '| Repository | Created in cohort | Merged | Open in cohort | Closed unmerged | All open | Draft open | Stale open |', | ||
| '|---|---:|---:|---:|---:|---:|---:|---:|', | ||
| ]; | ||
| lines.push('', '## Cross-repository check co-occurrences', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Place the new section after the portfolio table rows. The table header is already in Append the complete co-occurrence section after the table rows and a blank line.
|
||
| 'Advisory only: matching observed check source, name, and outcome in multiple inspected repositories is not evidence of a common root cause.', ''); | ||
|
Comment on lines
+325
to
+326
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Every Markdown report now inserts the co-occurrence section between the repository table header and its data rows. The blank line and heading terminate the table, so repository counts render as standalone pipe-delimited text beneath the advisory section rather than as the inventory table. Emit this section either before the table header or after the loop that appends repository rows. Useful? React with 👍 / 👎. |
||
| const correlation = data.sharedFailureSignals ?? correlateObservedFailures(data.reports); | ||
| if (correlation.signals.length === 0) { | ||
| lines.push('No cross-repository check co-occurrences observed in the inspected subset.'); | ||
| } else { | ||
| for (const signal of correlation.signals) { | ||
| lines.push('- ' + escapeEvidenceLabel(signal.name) + ' (' + signal.source + ', ' + signal.outcome + '): ' | ||
| + signal.repositoryCount + ' repositories; ' + signal.affectedPRs + ' PRs; ' | ||
| + signal.repositories.map(escapeEvidenceLabel).join(', ') + '. Shared cause unverified.'); | ||
| } | ||
| if (correlation.total > correlation.signals.length) { | ||
| lines.push('- ' + (correlation.total - correlation.signals.length) + ' additional co-occurrence groups omitted by report limit.'); | ||
| } | ||
| } | ||
| for (const r of data.reports) { | ||
| lines.push(`| ${r.repo} | ${r.counts.created} | ${r.counts.merged} | ${r.counts.open} | ${r.counts.closedUnmerged} | ${r.inventory.open} | ${r.inventory.draft} | ${r.inventory.stale} |`); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ import assert from 'node:assert/strict'; | |||||
| import test from 'node:test'; | ||||||
| import { | ||||||
| classifyChecks, | ||||||
| correlateObservedFailures, | ||||||
| diagnoseChecks, | ||||||
| collectPortfolio, | ||||||
| formatMarkdown, | ||||||
|
|
@@ -269,3 +270,103 @@ test('incomplete evidence guidance identifies commit-status pagination, check-ru | |||||
| assert.match(bothTruncated.nextAction, /check.run/i); | ||||||
| assert.match(bothTruncated.nextAction, /commit.status/i); | ||||||
| }); | ||||||
|
|
||||||
| test('correlates only observed failed check outcomes across distinct repositories', () => { | ||||||
| const failed = (number, head, outcomes) => ({ | ||||||
| number, head, ciDiagnosis: { evidenceComplete: true, attentionChecks: outcomes, attentionTotal: outcomes.length }, | ||||||
| }); | ||||||
| const build = { source: 'check-run', name: 'build', outcome: 'startup_failure', url: 'https://ci.example/build' }; | ||||||
| const reports = [ | ||||||
| { repo: 'acme/api', priority: [failed(1, 'aaaa', [build]), failed(2, 'bbbb', [build])] }, | ||||||
| { repo: 'acme/web', priority: [failed(7, 'cccc', [build])] }, | ||||||
| { repo: 'acme/ops', priority: [failed(4, 'dddd', [{ ...build, outcome: 'failure' }])] }, | ||||||
| ]; | ||||||
| const result = correlateObservedFailures(reports); | ||||||
| assert.equal(result.total, 1); | ||||||
| assert.equal(result.signals.length, 1); | ||||||
| const signal = result.signals[0]; | ||||||
| assert.equal(signal.source, 'check-run'); | ||||||
| assert.equal(signal.name, 'build'); | ||||||
| assert.equal(signal.outcome, 'startup_failure'); | ||||||
| assert.equal(signal.repositoryCount, 2); | ||||||
| assert.equal(signal.confidence, 'unverified'); | ||||||
| assert.deepEqual(signal.repositories, ['acme/api', 'acme/web']); | ||||||
| assert.equal(signal.affectedPRs, 3); | ||||||
| }); | ||||||
|
|
||||||
| test('avoids false correlation from missing, truncated, pending, and canceled evidence', () => { | ||||||
| const complete = (outcome, evidenceComplete = true) => ({ | ||||||
| number: 1, head: 'sha', ciDiagnosis: { | ||||||
| evidenceComplete, attentionChecks: [{ source: 'commit-status', name: 'Woodpecker', outcome }], | ||||||
| attentionTotal: 1, | ||||||
| }, | ||||||
| }); | ||||||
| const reports = [ | ||||||
| { repo: 'acme/api', priority: [complete('failure')] }, | ||||||
| { repo: 'acme/web', priority: [complete('failure', false)] }, | ||||||
| { repo: 'acme/pending', priority: [complete('pending')] }, | ||||||
| { repo: 'acme/canceled', priority: [complete('cancelled')] }, | ||||||
| { repo: 'acme/success', priority: [{ number: 2, ciDiagnosis: { evidenceComplete: true, attentionChecks: [] } }] }, | ||||||
| ]; | ||||||
| assert.deepEqual(correlateObservedFailures(reports), { signals: [], total: 0 }); | ||||||
| }); | ||||||
|
|
||||||
| test('cross-repository signal summaries are bounded, escaped and explicitly advisory', () => { | ||||||
| const check = { source: 'check-run', name: 'build [a] | b', outcome: 'failure' }; | ||||||
| const reports = ['acme/a', 'acme/b'].map(repo => ({ | ||||||
| repo, priority: [{ | ||||||
| number: 1, head: 'abcdef123456789', ciDiagnosis: { | ||||||
| evidenceComplete: true, attentionTotal: 1, attentionChecks: [check], | ||||||
| }, | ||||||
| }], | ||||||
| })); | ||||||
| const signals = correlateObservedFailures(reports); | ||||||
| const markdown = formatMarkdown({ | ||||||
| generatedAt: now.toISOString(), since: now.toISOString(), caveat: 'observed only', | ||||||
| reports: reports.map(r => ({ | ||||||
| ...r, priority: [], counts: { created: 0, merged: 0, open: 0, closedUnmerged: 0 }, | ||||||
| inventory: { open: 0, draft: 0, stale: 0 }, | ||||||
| })), | ||||||
| sharedFailureSignals: signals, | ||||||
| }); | ||||||
| assert.match(markdown, /Cross-repository check co-occurrences/); | ||||||
| assert.match(markdown, /not evidence of a common root cause/i); | ||||||
| assert.match(markdown, /build \\[a\\] \\| b/); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the escaping assertion reject unescaped output. The unescaped Use a literal substring assertion: Proposed fix
This accepts the required escaped text and rejects the unescaped text. Committable suggestion
|
||||||
| assert.match(markdown, /acme\/a/); | ||||||
| assert.match(markdown, /acme\/b/); | ||||||
| }); | ||||||
|
|
||||||
|
|
||||||
| test('portfolio collection adds only bounded cross-repository co-occurrences from inspected PRs', async () => { | ||||||
| const getJson = async path => { | ||||||
| if (path.includes('/pulls?')) { | ||||||
| return [PR(1, 'open', false, '2026-10-17T12:00:00Z')]; | ||||||
| } | ||||||
| if (path.includes('/check-runs')) return { | ||||||
| total_count: 1, | ||||||
| check_runs: [{ name: 'bootstrap', status: 'completed', conclusion: 'startup_failure' }], | ||||||
| }; | ||||||
| if (path.includes('/status')) return { total_count: 0, statuses: [] }; | ||||||
| throw new Error('Unexpected route: ' + path); | ||||||
| }; | ||||||
| const result = await collectPortfolio(['acme/a', 'acme/b'], getJson, { now, inspect: 1 }); | ||||||
| assert.equal(result.sharedFailureSignals.total, 1); | ||||||
| assert.equal(result.sharedFailureSignals.signals[0].repositoryCount, 2); | ||||||
| assert.equal(result.sharedFailureSignals.signals[0].outcome, 'startup_failure'); | ||||||
| assert.equal(result.sharedFailureSignals.signals[0].confidence, 'unverified'); | ||||||
| assert.equal((await collectPortfolio(['acme/a', 'acme/b'], getJson, { now, inspect: 0 })).sharedFailureSignals.total, 0); | ||||||
| }); | ||||||
|
|
||||||
| test('cross-repository correlation respects its output limit without hiding total groups', () => { | ||||||
| const checks = Array.from({ length: 4 }, (_, i) => | ||||||
| ({ name: 'check-' + i, source: 'check-run', outcome: 'failure' })); | ||||||
| const reports = ['acme/a', 'acme/b'].map(repo => ({ | ||||||
| repo, priority: [{ number: 1, ciDiagnosis: { | ||||||
| evidenceComplete: true, attentionChecks: checks, attentionTotal: checks.length, | ||||||
| } }], | ||||||
| })); | ||||||
| const result = correlateObservedFailures(reports, { limit: 2 }); | ||||||
| assert.equal(result.total, 4); | ||||||
| assert.equal(result.signals.length, 2); | ||||||
| assert.throws(() => correlateObservedFailures(reports, { limit: 0 }), /Invalid/); | ||||||
| }); | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When distinct failing check names share their first 120 characters, this key incorrectly groups them as an exact-name cross-repository co-occurrence. The production collector supplies
diagnoseChecks()output, whoseattentionEvidence()trims, sanitizes, and truncates names to 120 characters before this function sees them; for example, two matrix job names differing only after that prefix produce a positive signal. Preserve the original name as a separate correlation identity and restrict shortening to presentation so unrelated failures do not manufacture shared signals.Useful? React with 👍 / 👎.