:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(ci): drop branch-only tests from the weekly flaky report (#82418)
Raúl Negrón-Oteroa90be76f0f6c
diff --git a/.github/scripts/weekly-flaky-report.mjs b/.github/scripts/weekly-flaky-report.mjsindex eefa6b49b40e..c51e778f8a92 100644--- a/.github/scripts/weekly-flaky-report.mjs+++ b/.github/scripts/weekly-flaky-report.mjs@@ -11,7 +11,8 @@//// Endpoint gaps inherited here (backend follow-ups): suites that don't ship junit// into the span pipeline are invisible, and rerun_passed_count only flows from-// retry-enabled lanes. Master-burst breakage is filtered out client-side.+// retry-enabled lanes. Master-burst breakage and branch-only tests are filtered+// out client-side.import { execFileSync } from 'node:child_process'import { pathToFileURL } from 'node:url'@@ -37,7 +38,6 @@ const CANDIDATE_POOL = 40const CLUSTER_MIN_TESTS = 5const REPORT_RUNNERS = ['pytest', 'jest']const RUNNER_LABELS = { pytest: 'pytest', jest: 'Jest' }-const PARKED_NAMES_SHOWN = 5// Two systems can suppress a failing test, and only one of them reaches the endpoint. The// quarantine file xfails the test, so the span records 'xfailed' and the item arrives already@@ -138,15 +138,35 @@ function isMasterBurst(item) {)}-function selectReportCandidates(items, runner) {- return items.filter((item) => item.runner === runner && !isMasterBurst(item)).slice(0, CANDIDATE_POOL)+// A test with no file on master runs only on the branch that added it, so only that branch can fix+// it. The span scan is branch-agnostic by design, so the checkout is what tells the two apart.+function selectReportCandidates(items, runner, toRepoPaths) {+ const qualifying = items.filter((item) => item.runner === runner && !isMasterBurst(item))+ const onMaster = []+ const branchOnly = []+ for (const item of qualifying) {+ if (toRepoPaths(item.selector.split('::')[0]).length > 0) {+ onMaster.push(item)+ } else {+ branchOnly.push(item)+ }+ }+ if (branchOnly.length > 0) {+ // Never drop silently: a resolver that stopped matching would read as a quiet week.+ console.info(+ `${runner}: dropped ${branchOnly.length} test(s) with no file on master: ${branchOnly+ .map((item) => item.selector)+ .join(', ')}`+ )+ }+ return onMaster.slice(0, CANDIDATE_POOL)}-async function fetchCandidatePools(runners, fetchTests = fetchFlakyTests) {+async function fetchCandidatePools(runners, toRepoPaths, fetchTests = fetchFlakyTests) {return Promise.all(runners.map(async (runner) => {const result = await fetchTests(runner)- return { runner, candidates: selectReportCandidates(result.items || [], runner) }+ return { runner, candidates: selectReportCandidates(result.items || [], runner, toRepoPaths) }}))}@@ -182,8 +202,7 @@ function repoPathResolver(trackedPaths = trackedTestPaths()) {}// Ambiguous suffix matches only count when every candidate agrees on the owner.-function resolveOwners(items) {- const toRepoPaths = repoPathResolver()+function resolveOwners(items, toRepoPaths = repoPathResolver()) {const candidates = new Map()for (const item of items) {const selectorPath = item.selector.split('::')[0]@@ -362,26 +381,23 @@ function testStatusFor(trunkFor, masksCi = TRUNK_MASKS_CI) {// decide: with any of them the test is still red and still work.const quarantineFile = item.classification === 'quarantined' || item.quarantined_failed_run_count > 0if (quarantineFile && !item.failed_run_count) {- return { parked: true, source: 'the quarantine file' }+ return { parked: true }}const trunk = trunkFor(item)if (!trunk) {return null}- return { parked: masksCi, source: 'Trunk', since: trunk.quarantinedAt }+ return { parked: masksCi }}}-// Parked tests leave the queue but stay listed below the table: a long-lived auto-quarantine-// covering a real breakage is the thing nobody notices otherwise.+// Parked tests leave the queue: a suppressed failure does not fail CI, so nobody has to act on it.//-// Partitioning has to precede clustering. A cluster's selector is a bare file path, which can+// Dropping them has to precede clustering. A cluster's selector is a bare file path, which can// never match a test id, so collapsing first buries parked tests in a row that then ranks as if// CI still failed on them.function buildQueue(candidates, statusFor) {- const parked = candidates.filter((item) => statusFor(item)?.parked)- const queue = candidates.filter((item) => !statusFor(item)?.parked)- return { queue: collapseClusters(queue), parked: parked.map((item) => ({ ...item, park: statusFor(item) })) }+ return collapseClusters(candidates.filter((item) => !statusFor(item)?.parked))}// 5+ co-failing tests in one file are one shared-fixture incident, not N flakes.@@ -434,9 +450,9 @@ async function buildRunnerReports(return Promise.all(candidatePools.map(async ({ runner, candidates }) => {const statusFor = testStatusFor(await getTrunk(runner))- const { queue, parked } = buildQueue(candidates, statusFor)+ const queue = buildQueue(candidates, statusFor)const extrasFor = await getEnrichment(runner, queue)- return { runner, candidates: rankReportCandidates(queue, extrasFor), extrasFor, statusFor, parked }+ return { runner, candidates: rankReportCandidates(queue, extrasFor), extrasFor, statusFor }}))}@@ -486,23 +502,8 @@ function tableRows(items, ownerFor, extrasFor, statusFor = () => null) {})}-function parkedSummary(parked) {- const shown = parked.slice(0, PARKED_NAMES_SHOWN).map((item) => shortName(item.selector))- const remaining = parked.length - shown.length- const names = remaining > 0 ? `${shown.join(', ')}, and ${remaining} more` : shown.join(', ')- const oldest = parked- .map((item) => item.park?.since)- .filter(Boolean)- .sort()[0]- const since = oldest ? ` Oldest parked ${oldest.slice(0, 10)}.` : ''- const count = parked.length === 1 ? '1 test is' : `${parked.length} tests are`- return `${count} quarantined, so CI no longer fails on them: ${names}.${since} Fix them or take them out of quarantine.`-}--function buildBlocks(now, rows, parked = []) {+function buildBlocks(now, rows) {const dateLabel = now.toISOString().slice(0, 10)- // Every candidate can be parked, which leaves the parked note as the whole report.- const heading = rows.length > 0 ? `Top ${rows.length} flaky tests` : 'Flaky tests'const blocks = [{type: 'section',@@ -511,38 +512,31 @@ function buildBlocks(now, rows, parked = []) {text: `*Weekly flaky tests - ${dateLabel}* _(CI, last 7 days, up to ${TOP_N} per runner)_`,},},+ {+ type: 'table',+ column_settings: [+ { align: 'left' },+ { align: 'left' },+ { align: 'left' },+ { align: 'right' },+ { align: 'right' },+ { align: 'left' },+ ],+ rows: [+ [cell('test'), cell('runner'), cell('owner'), cell('rescued'), cell('fails'), cell('logs')],+ ...rows,+ ],+ },+ {+ type: 'context',+ elements: [+ {+ type: 'mrkdwn',+ text: 'Fix: `/fixing-flaky-tests` · Park 14 days: `hogli test:quarantine add <test id>`',+ },+ ],+ },]- if (rows.length > 0) {- blocks.push(- {- type: 'table',- column_settings: [- { align: 'left' },- { align: 'left' },- { align: 'left' },- { align: 'right' },- { align: 'right' },- { align: 'left' },- ],- rows: [- [cell('test'), cell('runner'), cell('owner'), cell('rescued'), cell('fails'), cell('logs')],- ...rows,- ],- },- {- type: 'context',- elements: [- {- type: 'mrkdwn',- text: 'Fix: `/fixing-flaky-tests` · Park 14 days: `hogli test:quarantine add <test id>`',- },- ],- }- )- }- if (parked.length > 0) {- blocks.push({ type: 'context', elements: [{ type: 'mrkdwn', text: parkedSummary(parked) }] })- }const workflowPath = GITHUB_WORKFLOW_REF.split('@')[0].replace(`${GITHUB_REPOSITORY}/`, '')if (GITHUB_REPOSITORY && workflowPath) {const editUrl = `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/edit/${GITHUB_REF_NAME}/${workflowPath}`@@ -577,18 +571,19 @@ async function main() {return}const now = new Date()- const runnerReports = await buildRunnerReports(await fetchCandidatePools(REPORT_RUNNERS))+ // Built once so the filter and the owner resolution share one git ls-files.+ const toRepoPaths = repoPathResolver()+ const runnerReports = await buildRunnerReports(await fetchCandidatePools(REPORT_RUNNERS, toRepoPaths))const reportCandidates = runnerReports.flatMap(({ candidates }) => candidates)- const parked = runnerReports.flatMap((report) => report.parked)- if (reportCandidates.length === 0 && parked.length === 0) {+ if (reportCandidates.length === 0) {console.info('No qualifying flaky tests this week — nothing to post.')return}- const ownerFor = resolveOwners(reportCandidates)+ const ownerFor = resolveOwners(reportCandidates, toRepoPaths)const rows = runnerReports.flatMap(({ candidates, extrasFor, statusFor }) =>tableRows(candidates, ownerFor, extrasFor, statusFor))- const blocks = buildBlocks(now, rows, parked)+ const blocks = buildBlocks(now, rows)if (DRY_RUN) {console.info(JSON.stringify(blocks, null, 2))returndiff --git a/.github/scripts/weekly-flaky-report.test.mjs b/.github/scripts/weekly-flaky-report.test.mjsindex 0243b8834b85..a8ad7447e4cc 100644--- a/.github/scripts/weekly-flaky-report.test.mjs+++ b/.github/scripts/weekly-flaky-report.test.mjs@@ -19,6 +19,8 @@ import {trackedTestPaths,} from './weekly-flaky-report.mjs'+const onMasterResolver = (path) => [path]+describe('weekly flaky report', () => {it('builds runner-specific endpoint URLs before the endpoint limit', () => {const pytestUrl = flakyTestsUrl('pytest')@@ -120,18 +122,38 @@ describe('weekly flaky report', () => {]assert.deepEqual(- selectReportCandidates(items, 'pytest').map((candidate) => candidate.selector),+ selectReportCandidates(items, 'pytest', onMasterResolver).map((candidate) => candidate.selector),['test_proved.py::test_proved'])assert.deepEqual(- selectReportCandidates(items, 'jest').map((candidate) => candidate.selector),+ selectReportCandidates(items, 'jest', onMasterResolver).map((candidate) => candidate.selector),['test_report.ts'])})+ it('drops a test whose file only exists on the branch that added it', () => {+ const common = {+ classification: 'suspected_regression',+ failed_run_count: 6,+ failed_pr_count: 3,+ master_failed_run_count: 0,+ quarantined_failed_run_count: 0,+ }+ const items = [+ { ...common, runner: 'jest', selector: 'frontend/src/shared.test.tsx::shared flakes' },+ { ...common, runner: 'jest', selector: 'products/new/frontend/Unmerged.test.tsx::Unmerged explains itself' },+ ]+ const toRepoPaths = (path) => (path === 'frontend/src/shared.test.tsx' ? [path] : [])++ assert.deepEqual(+ selectReportCandidates(items, 'jest', toRepoPaths).map((candidate) => candidate.selector),+ ['frontend/src/shared.test.tsx::shared flakes']+ )+ })+it('fetches each runner into its own candidate pool', async () => {const requestedRunners = []- const pools = await fetchCandidatePools(['pytest', 'jest'], async (runner) => {+ const pools = await fetchCandidatePools(['pytest', 'jest'], onMasterResolver, async (runner) => {requestedRunners.push(runner)return {items: [@@ -291,7 +313,7 @@ describe('weekly flaky report', () => {assert.equal(trunkFor({ selector: 'backend/tests/test_migration.py::MigrationTest::test_other' }), null)})- it('treats both quarantine systems as parked, but keeps a Trunk flag that still fails CI', () => {+ it('drops both quarantine systems from the queue, but keeps a Trunk flag that still fails CI', () => {const quarantineFile = { runner: 'pytest', selector: 'file.py::test_file', classification: 'quarantined' }// Quarantined earlier in the window, un-quarantined since, and failing on its own now.const unparked = {@@ -311,11 +333,9 @@ describe('weekly flaky report', () => {const masked = buildQueue(items, testStatusFor(trunkFor, true))const unmasked = buildQueue(items, testStatusFor(trunkFor, false))- assert.deepEqual(selectors(masked.queue), [unparked.selector, plain.selector])- assert.deepEqual(selectors(masked.parked), [quarantineFile.selector, trunked.selector])+ assert.deepEqual(selectors(masked), [unparked.selector, plain.selector])// Masking off leaves Trunk's failure reddening CI, so only the quarantine file parks.- assert.deepEqual(selectors(unmasked.queue), [unparked.selector, trunked.selector, plain.selector])- assert.deepEqual(selectors(unmasked.parked), [quarantineFile.selector])+ assert.deepEqual(selectors(unmasked), [unparked.selector, trunked.selector, plain.selector])const [ownerCell] = tableRows([trunked],() => ({ owner: 'team-devex', repoPath: null }),@@ -333,13 +353,12 @@ describe('weekly flaky report', () => {failed_run_count: 2,}))- const { queue, parked } = buildQueue(+ const queue = buildQueue(items,testStatusFor(() => ({ quarantinedAt: '2026-07-13T17:12:22.000Z' }), true))assert.deepEqual(queue, [])- assert.equal(parked.length, CLUSTER_MIN_TESTS)})it('matches a Jest selector reported from the package root against Trunk', async () => {@@ -365,25 +384,4 @@ describe('weekly flaky report', () => {)})- it('keeps parked tests visible below the table instead of dropping them', () => {- const blocks = buildBlocks(- new Date('2026-07-27T00:00:00Z'),- [],- [{ selector: 'masked.py::test_masked', park: { since: '2026-07-13T17:12:22.000Z' } }]- )- // Actions always sets GITHUB_WORKFLOW_REF, which appends a block after the parked note,- // so find the note by content rather than by position.- const note = blocks- .filter((block) => block.type === 'context')- .map((block) => block.elements[0].text)- .find((text) => text.includes('quarantined'))-- assert.equal(- blocks.find((block) => block.type === 'table'),- undefined- )- assert.match(note, /1 test is quarantined/)- assert.match(note, /test_masked/)- assert.match(note, /Oldest parked 2026-07-13\./)- })})