Skip to content

: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.

feat(ci): add Jest to flaky report (#74349)

Raúl Negrón-Otero5082b8ea70a4
diff --git a/.github/scripts/weekly-flaky-report.mjs b/.github/scripts/weekly-flaky-report.mjs
index 1d0e4127d3de..eefa6b49b40e 100644
--- a/.github/scripts/weekly-flaky-report.mjs
+++ b/.github/scripts/weekly-flaky-report.mjs
@@ -1,11 +1,11 @@
// Weekly flaky-test report, posted to #flakey-tests on Monday.
//
// PULL model, sibling of eng-analytics-weekly-digest.mjs: reads the
-// engineering_analytics flaky_tests endpoint for candidates, then one HogQL read
-// of the product's ci_failures view joined to the synced runs table for the
-// rerun-rescue counts and failing-job evidence links the endpoint does not carry
-// yet. The product owns the flake signal; this owns cadence, owner attribution,
-// and the relay.
+// engineering_analytics flaky_tests endpoint for candidates, then one pytest-only
+// HogQL read of the product's ci_failures view joined to the synced runs table for
+// the rerun-rescue counts and failing-job evidence links the endpoint does not
+// carry yet. The product owns the flake signal; this owns cadence, owner
+// attribution, and the relay.
//
// GHA cron ──> flaky_tests endpoint + one HogQL query ──> Slack
//
@@ -35,12 +35,14 @@ const GITHUB_REF_NAME = process.env.GITHUB_REF_NAME || 'master'
const TOP_N = 10
const CANDIDATE_POOL = 40
const CLUSTER_MIN_TESTS = 5
-const REPORT_RUNNERS = ['pytest']
+const REPORT_RUNNERS = ['pytest', 'jest']
+const RUNNER_LABELS = { pytest: 'pytest', jest: 'Jest' }
const PARKED_NAMES_SHOWN = 5
-// The endpoint's quarantine signal only covers `.test_quarantine.json`, where the pytest adapter
-// xfails the test and the span records 'xfailed'. Trunk masks the job verdict instead, leaving a
-// hard failure in the junit, so its quarantines reach the spans as plain failures.
+// 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
+// marked. Trunk instead masks the job verdict and leaves a hard failure in the junit, so its
+// quarantines arrive as ordinary failures and have to be read separately.
// Same two variables the CI uploaders read: uploads decide whether the synced Trunk state is
// current, masking decides whether a quarantine actually keeps a failure from failing CI.
const TRUNK_UPLOADS_ON = process.env.TRUNK_UPLOAD_ENABLED === 'true'
@@ -151,14 +153,20 @@ async function fetchCandidatePools(runners, fetchTests = fetchFlakyTests) {
// Product suites run from their product dir, so a selector path may be repo- or
// product-relative — suffix-match the tracked index (full even under sparse checkout).
-function repoPathResolver() {
+function trackedTestPaths(runGit = execFileSync) {
// The tracked-file list is a few MB; the 1MB execFileSync default truncates it.
- const tracked = execFileSync('git', ['ls-files', '*.py'], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 })
+ return runGit('git', ['ls-files', '*.py', '*.js', '*.jsx', '*.ts', '*.tsx'], {
+ encoding: 'utf8',
+ maxBuffer: 64 * 1024 * 1024,
+ })
.split('\n')
.filter(Boolean)
- const trackedSet = new Set(tracked)
+}
+
+function repoPathResolver(trackedPaths = trackedTestPaths()) {
+ const trackedSet = new Set(trackedPaths)
const bySuffix = new Map()
- for (const path of tracked) {
+ for (const path of trackedPaths) {
const base = path.split('/').pop()
if (!bySuffix.has(base)) {
bySuffix.set(base, [])
@@ -207,15 +215,20 @@ function resolveOwners(items) {
}
}
-// The logs view records test ids as pytest printed them, so a product suite appears
-// product-relative there while the endpoint selector may be repo-relative.
+// One test carries different leading path segments depending on who named it: a product suite
+// runs from its product dir, jest reports from its package root, and the endpoint reports
+// repo-relative. Matching on every path suffix lets either side hold the longer prefix, which a
+// fixed list of known prefixes cannot do as packages come and go. Stops above the bare filename,
+// where two packages' same-named files would collide.
function selectorVariants(selector) {
- const variants = [selector]
- const productRelative = selector.replace(/^products\/[^/]+\//, '')
- if (productRelative !== selector) {
- variants.push(productRelative)
+ const [path, ...rest] = selector.split('::')
+ const tail = rest.length > 0 ? `::${rest.join('::')}` : ''
+ const segments = path.split('/')
+ const variants = []
+ for (let start = 0; start <= segments.length - 2; start++) {
+ variants.push(segments.slice(start).join('/') + tail)
}
- return variants
+ return variants.length > 0 ? variants : [selector]
}
// Rescue counts (failed at attempt N, run green at a later attempt) and the two most
@@ -275,24 +288,36 @@ async function enrich(items, runHogql = hogql) {
return (item) => enriched.get(item.selector) || empty
}
-// Trunk keys a test by (file, classname, name), with the class inside `classname` rather than
-// between file and name where a node id has it. `classname` is the file's module plus the class,
-// so trimming the module prefix off it recovers the class and rebuilds the node id.
+async function enrichRunnerCandidates(runner, candidates, runHogql = hogql) {
+ if (runner === 'pytest') {
+ return enrich(
+ candidates.filter((item) => !item.cluster_size),
+ runHogql
+ )
+ }
+ const empty = { runsRescued: null, evidence: [] }
+ return () => empty
+}
+
+// Trunk keys a test by (file, classname, name) rather than by one id, and the two runners split
+// the name differently: pytest hides the class inside `classname` (the file's module plus the
+// class), while jest puts the whole title in `name`. Trimming the module prefix recovers the
+// pytest class; jest needs no reassembly, so file and name concatenate directly.
//
-// The table carries no repository column, so this cannot be repo-scoped. It doesn't need to be:
-// a row only annotates a selector the repo-scoped endpoint already returned, so another repo's
-// rows would have to carry an identical node id to collide.
+// `parent` carries the runner for pytest and the file path for jest, which is what separates the
+// two sets. The table has no repository column, so this cannot be repo-scoped. It does not need
+// to be: a row only annotates a selector the repo-scoped endpoint already returned.
const TRUNK_QUARANTINED_QUERY = `
SELECT concat(file, '::', if(cls = '', '', concat(cls, '::')), name) AS nodeid,
quarantined_at
FROM (
SELECT file, name, quarantined_at,
replaceAll(substring(file, 1, length(file) - 3), '/', '.') AS module,
- if(startsWith(classname, concat(module, '.')),
+ if({runner} = 'pytest' AND startsWith(classname, concat(module, '.')),
replaceAll(substring(classname, length(module) + 2, length(classname)), '.', '::'),
'') AS cls
FROM __TRUNK_TABLE__
- WHERE parent = {runner}
+ WHERE if({runner} = 'pytest', parent = 'pytest', parent != 'pytest')
)`
// Uploads off, a missing table, or a query error all degrade to a report without Trunk state,
@@ -314,8 +339,6 @@ async function fetchTrunkQuarantined(runner, runHogql = hogql, enabled = TRUNK_U
}
const byVariant = new Map()
for (const [nodeid, quarantinedAt] of rows) {
- // Trunk reports repo-relative paths while a product suite's selector is product-relative,
- // so index both forms and look the selector up under both.
for (const variant of selectorVariants(nodeid)) {
byVariant.set(variant, { quarantinedAt })
}
@@ -326,25 +349,39 @@ async function fetchTrunkQuarantined(runner, runHogql = hogql, enabled = TRUNK_U
.find(Boolean) || null
}
-// Masking already stops these failures from failing CI, so they don't belong in a queue whose
-// call to action is "park it". They stay listed below the table rather than dropped, so a
-// long-lived auto-quarantine covering a real breakage still shows up somewhere.
-function partitionParked(items, trunkFor, masksCi = TRUNK_MASKS_CI) {
- if (!masksCi) {
- return { queue: items, parked: [] }
- }
- return {
- queue: items.filter((item) => !trunkFor(item)),
- parked: items.filter((item) => trunkFor(item)).map((item) => ({ ...item, trunk: trunkFor(item) })),
+// One question for both systems: is this failure already suppressed, so the queue should not ask
+// anyone to act on it? Returns null while the test still fails CI.
+//
+// Trunk with masking off is the one case that is marked but not suppressed: Trunk called the test
+// flaky, CI still goes red on it, so it stays in the queue carrying a label.
+function testStatusFor(trunkFor, masksCi = TRUNK_MASKS_CI) {
+ return (item) => {
+ // Both counts are seven-day aggregates and the endpoint counts a quarantined run
+ // separately from a failed one, so a park that ended inside the window leaves the
+ // quarantined count set while CI fails on the test again. The unquarantined failures
+ // decide: with any of them the test is still red and still work.
+ const quarantineFile = item.classification === 'quarantined' || item.quarantined_failed_run_count > 0
+ if (quarantineFile && !item.failed_run_count) {
+ return { parked: true, source: 'the quarantine file' }
+ }
+ const trunk = trunkFor(item)
+ if (!trunk) {
+ return null
+ }
+ return { parked: masksCi, source: 'Trunk', since: trunk.quarantinedAt }
}
}
-// Parking has to happen before clustering: a cluster's selector is a bare file path, which can
-// never match a Trunk node id, so collapsing first buries quarantined tests in a row that then
-// ranks as if CI still failed on them.
-function buildQueue(candidates, trunkFor, masksCi = TRUNK_MASKS_CI) {
- const { queue, parked } = partitionParked(candidates, trunkFor, masksCi)
- return { queue: collapseClusters(queue), parked }
+// 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.
+//
+// Partitioning 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) })) }
}
// 5+ co-failing tests in one file are one shared-fixture incident, not N flakes.
@@ -361,6 +398,7 @@ function collapseClusters(items) {
for (const [file, group] of byFile) {
if (group.length >= CLUSTER_MIN_TESTS) {
collapsed.push({
+ runner: group[0].runner,
selector: file,
cluster_size: group.length,
failed_run_count: group.reduce((sum, item) => sum + item.failed_run_count, 0),
@@ -374,6 +412,35 @@ function collapseClusters(items) {
return collapsed
}
+// Rescued runs first (the strongest per-test signal), clusters and the rest by volume.
+function rankReportCandidates(items, extrasFor) {
+ return items
+ .map((item, index) => ({ item, index }))
+ .sort(
+ (left, right) =>
+ (extrasFor(right.item).runsRescued ?? 0) - (extrasFor(left.item).runsRescued ?? 0) ||
+ right.item.failed_run_count - left.item.failed_run_count ||
+ left.index - right.index
+ )
+ .slice(0, TOP_N)
+ .map(({ item }) => item)
+}
+
+async function buildRunnerReports(
+ candidatePools,
+ getEnrichment = enrichRunnerCandidates,
+ getTrunk = fetchTrunkQuarantined
+) {
+ return Promise.all(
+ candidatePools.map(async ({ runner, candidates }) => {
+ const statusFor = testStatusFor(await getTrunk(runner))
+ const { queue, parked } = buildQueue(candidates, statusFor)
+ const extrasFor = await getEnrichment(runner, queue)
+ return { runner, candidates: rankReportCandidates(queue, extrasFor), extrasFor, statusFor, parked }
+ })
+ )
+}
+
function cell(text) {
return { type: 'raw_text', text }
}
@@ -391,7 +458,7 @@ function shortName(selector) {
return name.length > 36 ? `${name.slice(0, 35)}…` : name
}
-function tableRows(items, ownerFor, extrasFor, trunkFor = () => null) {
+function tableRows(items, ownerFor, extrasFor, statusFor = () => null) {
return items.map((item) => {
const { owner, repoPath } = ownerFor(item)
const { runsRescued, evidence } = extrasFor(item)
@@ -401,18 +468,17 @@ function tableRows(items, ownerFor, extrasFor, trunkFor = () => null) {
const testCell = repoPath
? linkedCell([{ url: `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/blob/master/${repoPath}`, text: name }])
: cell(name)
- const quarantined =
- item.classification === 'quarantined' || item.quarantined_failed_run_count > 0 ? ' (quarantined)' : ''
- // Only reachable with masking off: masking on moves these rows out of the table entirely.
- // Trunk marked the test, but CI still fails on it, so it stays ranked.
- const trunkFlagged = trunkFor(item) ? ' (Trunk flagged)' : ''
+ // Anything parked has already left the table, so the only status a row can carry is
+ // Trunk having flagged a test that still fails CI.
+ const flagged = statusFor(item) ? ' (Trunk flagged)' : ''
const logLinks = evidence.map(({ runId, jobId }, index) => ({
url: `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${runId}${jobId ? `/job/${jobId}` : ''}`,
text: String(index + 1),
}))
return [
testCell,
- cell(owner.replace(/^team-/, '') + quarantined + trunkFlagged),
+ cell(RUNNER_LABELS[item.runner] || item.runner),
+ cell(owner.replace(/^team-/, '') + flagged),
cell(runsRescued == null ? '-' : String(runsRescued)),
cell(String(item.failed_run_count)),
logLinks.length > 0 ? linkedCell(logLinks) : cell('-'),
@@ -425,12 +491,12 @@ function parkedSummary(parked) {
const remaining = parked.length - shown.length
const names = remaining > 0 ? `${shown.join(', ')}, and ${remaining} more` : shown.join(', ')
const oldest = parked
- .map((item) => item.trunk?.quarantinedAt)
+ .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 in Trunk, so CI no longer fails on them: ${names}.${since} Fix them or take them out of quarantine.`
+ 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 = []) {
@@ -442,7 +508,7 @@ function buildBlocks(now, rows, parked = []) {
type: 'section',
text: {
type: 'mrkdwn',
- text: `*${heading} — ${dateLabel}* _(backend CI, last 7 days)_`,
+ text: `*Weekly flaky tests - ${dateLabel}* _(CI, last 7 days, up to ${TOP_N} per runner)_`,
},
},
]
@@ -451,13 +517,17 @@ function buildBlocks(now, rows, parked = []) {
{
type: 'table',
column_settings: [
+ { align: 'left' },
{ align: 'left' },
{ align: 'left' },
{ align: 'right' },
{ align: 'right' },
{ align: 'left' },
],
- rows: [[cell('test'), cell('owner'), cell('rescued'), cell('fails'), cell('logs')], ...rows],
+ rows: [
+ [cell('test'), cell('runner'), cell('owner'), cell('rescued'), cell('fails'), cell('logs')],
+ ...rows,
+ ],
},
{
type: 'context',
@@ -507,24 +577,18 @@ async function main() {
return
}
const now = new Date()
- const [{ runner, candidates }] = await fetchCandidatePools(REPORT_RUNNERS)
- const trunkFor = await fetchTrunkQuarantined(runner)
- const { queue, parked } = buildQueue(candidates, trunkFor)
- const extrasFor = await enrich(queue.filter((item) => !item.cluster_size))
- // Rescued runs first (the strongest per-test signal), clusters and the rest by volume.
- const flaky = queue
- .sort(
- (a, b) =>
- (extrasFor(b).runsRescued ?? 0) - (extrasFor(a).runsRescued ?? 0) ||
- b.failed_run_count - a.failed_run_count
- )
- .slice(0, TOP_N)
- if (flaky.length === 0 && parked.length === 0) {
+ const runnerReports = await buildRunnerReports(await fetchCandidatePools(REPORT_RUNNERS))
+ const reportCandidates = runnerReports.flatMap(({ candidates }) => candidates)
+ const parked = runnerReports.flatMap((report) => report.parked)
+ if (reportCandidates.length === 0 && parked.length === 0) {
console.info('No qualifying flaky tests this week — nothing to post.')
return
}
- const ownerFor = resolveOwners(flaky)
- const blocks = buildBlocks(now, tableRows(flaky, ownerFor, extrasFor, trunkFor), parked)
+ const ownerFor = resolveOwners(reportCandidates)
+ const rows = runnerReports.flatMap(({ candidates, extrasFor, statusFor }) =>
+ tableRows(candidates, ownerFor, extrasFor, statusFor)
+ )
+ const blocks = buildBlocks(now, rows, parked)
if (DRY_RUN) {
console.info(JSON.stringify(blocks, null, 2))
return
@@ -546,12 +610,17 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
export {
buildBlocks,
buildQueue,
+ buildRunnerReports,
CLUSTER_MIN_TESTS,
enrich,
+ enrichRunnerCandidates,
fetchCandidatePools,
fetchTrunkQuarantined,
flakyTestsUrl,
REPORT_RUNNERS,
+ repoPathResolver,
selectReportCandidates,
tableRows,
+ testStatusFor,
+ trackedTestPaths,
}
diff --git a/.github/scripts/weekly-flaky-report.test.mjs b/.github/scripts/weekly-flaky-report.test.mjs
index 4b53f6ce6bde..0243b8834b85 100644
--- a/.github/scripts/weekly-flaky-report.test.mjs
+++ b/.github/scripts/weekly-flaky-report.test.mjs
@@ -4,14 +4,19 @@ import { describe, it } from 'node:test'
import {
buildBlocks,
buildQueue,
+ buildRunnerReports,
CLUSTER_MIN_TESTS,
enrich,
+ enrichRunnerCandidates,
fetchCandidatePools,
fetchTrunkQuarantined,
flakyTestsUrl,
REPORT_RUNNERS,
+ repoPathResolver,
selectReportCandidates,
tableRows,
+ testStatusFor,
+ trackedTestPaths,
} from './weekly-flaky-report.mjs'
describe('weekly flaky report', () => {
@@ -19,7 +24,7 @@ describe('weekly flaky report', () => {
const pytestUrl = flakyTestsUrl('pytest')
const jestUrl = flakyTestsUrl('jest')
- assert.deepEqual(REPORT_RUNNERS, ['pytest'])
+ assert.deepEqual(REPORT_RUNNERS, ['pytest', 'jest'])
assert.equal(pytestUrl.searchParams.get('runner'), 'pytest')
assert.equal(jestUrl.searchParams.get('runner'), 'jest')
assert.equal(jestUrl.searchParams.get('repo'), 'PostHog/posthog')
@@ -30,6 +35,7 @@ describe('weekly flaky report', () => {
const rows = tableRows(
[
{
+ runner: 'pytest',
selector: 'posthog/test/test_example.py::TestExample::test_report',
classification: 'confirmed_flake',
quarantined_failed_run_count: 0,
@@ -49,6 +55,10 @@ describe('weekly flaky report', () => {
const table = blocks.find((block) => block.type === 'table')
assert.ok(table)
+ assert.deepEqual(
+ table.rows[0].map((tableCell) => tableCell.text),
+ ['test', 'runner', 'owner', 'rescued', 'fails', 'logs']
+ )
for (const tableCell of table.rows.flat()) {
assert.ok(['raw_text', 'raw_number', 'rich_text'].includes(tableCell.type))
}
@@ -67,7 +77,8 @@ describe('weekly flaky report', () => {
},
],
})
- assert.deepEqual(rows[0][4], {
+ assert.deepEqual(rows[0][1], { type: 'raw_text', text: 'pytest' })
+ assert.deepEqual(rows[0][5], {
type: 'rich_text',
elements: [
{
@@ -140,6 +151,83 @@ describe('weekly flaky report', () => {
)
})
+ it('ranks and limits each runner independently', async () => {
+ const candidatePools = ['pytest', 'jest'].map((runner) => ({
+ runner,
+ candidates: Array.from({ length: 12 }, (_, index) => ({
+ runner,
+ selector: `${runner}-${index}`,
+ failed_run_count: index === 10 ? 20 : 5,
+ })),
+ }))
+ const runnerReports = await buildRunnerReports(candidatePools, async () => (item) => ({
+ runsRescued: item.selector.endsWith('-11') ? 1 : 0,
+ evidence: [],
+ }))
+
+ for (const { runner, candidates } of runnerReports) {
+ assert.equal(candidates.length, 10)
+ assert.deepEqual(
+ candidates.map((candidate) => candidate.selector),
+ [`${runner}-11`, `${runner}-10`, ...Array.from({ length: 8 }, (_, index) => `${runner}-${index}`)]
+ )
+ }
+ assert.deepEqual(
+ runnerReports.flatMap(({ candidates }) => candidates.map((candidate) => candidate.runner)),
+ [...Array(10).fill('pytest'), ...Array(10).fill('jest')]
+ )
+ })
+
+ it('resolves tracked Python and JavaScript-family test paths', () => {
+ let gitArguments
+ const expectedPaths = [
+ 'posthog/test/test_report.py',
+ 'frontend/src/report.test.js',
+ 'frontend/src/report.test.jsx',
+ 'frontend/src/report.test.ts',
+ 'frontend/src/report.test.tsx',
+ ]
+ const trackedPaths = trackedTestPaths((command, args) => {
+ gitArguments = { command, args }
+ return expectedPaths.join('\n')
+ })
+ const toRepoPaths = repoPathResolver(trackedPaths)
+
+ assert.deepEqual(gitArguments, {
+ command: 'git',
+ args: ['ls-files', '*.py', '*.js', '*.jsx', '*.ts', '*.tsx'],
+ })
+ for (const path of expectedPaths) {
+ assert.deepEqual(toRepoPaths(path), [path])
+ }
+ assert.deepEqual(toRepoPaths('src/report.test.tsx'), ['frontend/src/report.test.tsx'])
+ })
+
+ it('omits unsupported Jest enrichment and renders fallback cells', async () => {
+ let enrichmentRequested = false
+ const item = {
+ runner: 'jest',
+ selector: 'frontend/src/report.test.ts::renders the report',
+ classification: 'confirmed_flake',
+ quarantined_failed_run_count: 0,
+ failed_run_count: 3,
+ }
+ const extrasFor = await enrichRunnerCandidates('jest', [item], async () => {
+ enrichmentRequested = true
+ return { results: [] }
+ })
+ const [row] = tableRows(
+ [item],
+ () => ({ owner: 'team-devex', repoPath: 'frontend/src/report.test.ts' }),
+ extrasFor
+ )
+
+ assert.equal(enrichmentRequested, false)
+ assert.deepEqual(row[1], { type: 'raw_text', text: 'Jest' })
+ assert.deepEqual(row[3], { type: 'raw_text', text: '-' })
+ assert.deepEqual(row[5], { type: 'raw_text', text: '-' })
+ })
+
it('scopes enrichment to the current repository', async () => {
let request
await enrich([{ selector: 'products/example/backend/test_report.py::test_report' }], async (query, values) => {
@@ -149,8 +237,10 @@ describe('weekly flaky report', () => {
assert.match(request.query, /lower\(f\.repo\) = lower\(\{repository\}\)/)
assert.equal(request.values.repository, 'PostHog/posthog')
+ // Every path suffix, so either side of the join can carry the longer prefix.
assert.deepEqual(request.values.selectors, [
'products/example/backend/test_report.py::test_report',
+ 'example/backend/test_report.py::test_report',
'backend/test_report.py::test_report',
])
})
@@ -201,65 +291,98 @@ describe('weekly flaky report', () => {
assert.equal(trunkFor({ selector: 'backend/tests/test_migration.py::MigrationTest::test_other' }), null)
})
- it('parks Trunk-quarantined tests only while masking is on, and labels them otherwise', () => {
- const items = [
- { runner: 'pytest', selector: 'masked.py::test_masked', failed_run_count: 9, failed_pr_count: 9 },
- { runner: 'pytest', selector: 'plain.py::test_plain', failed_run_count: 1, failed_pr_count: 1 },
- ]
+ it('treats both quarantine systems as parked, 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 = {
+ runner: 'pytest',
+ selector: 'expired.py::test_expired',
+ classification: 'quarantined',
+ quarantined_failed_run_count: 3,
+ failed_run_count: 4,
+ }
+ const trunked = { runner: 'pytest', selector: 'masked.py::test_masked', failed_run_count: 9 }
+ const plain = { runner: 'pytest', selector: 'plain.py::test_plain', failed_run_count: 1 }
+ const items = [quarantineFile, unparked, trunked, plain]
const trunkFor = (item) =>
- item.selector === 'masked.py::test_masked' ? { quarantinedAt: '2026-07-13T17:12:22.000Z' } : null
+ item.selector === trunked.selector ? { quarantinedAt: '2026-07-13T17:12:22.000Z' } : null
const selectors = (list) => list.map((item) => item.selector)
- const masked = buildQueue(items, trunkFor, true)
- const unmasked = buildQueue(items, trunkFor, false)
+ const masked = buildQueue(items, testStatusFor(trunkFor, true))
+ const unmasked = buildQueue(items, testStatusFor(trunkFor, false))
- assert.deepEqual(selectors(masked.queue), ['plain.py::test_plain'])
- assert.deepEqual(selectors(masked.parked), ['masked.py::test_masked'])
- // Masking off leaves the failure reddening CI, so it stays ranked and carries a label.
- assert.deepEqual(selectors(unmasked.queue), selectors(items))
- assert.deepEqual(unmasked.parked, [])
+ assert.deepEqual(selectors(masked.queue), [unparked.selector, plain.selector])
+ assert.deepEqual(selectors(masked.parked), [quarantineFile.selector, trunked.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])
const [ownerCell] = tableRows(
- [items[0]],
+ [trunked],
() => ({ owner: 'team-devex', repoPath: null }),
() => ({ runsRescued: null, evidence: [] }),
- trunkFor
- ).map((row) => row[1])
+ testStatusFor(trunkFor, false)
+ ).map((row) => row[2])
assert.equal(ownerCell.text, 'devex (Trunk flagged)')
})
it('parks a quarantined test that would otherwise be buried in a collapsed cluster', () => {
- // A cluster's selector is a bare file path, so it can never match a Trunk node id.
+ // A cluster's selector is a bare file path, so it can never match a test id.
const items = Array.from({ length: CLUSTER_MIN_TESTS }, (_, index) => ({
runner: 'pytest',
selector: `shared.py::test_${index}`,
failed_run_count: 2,
- failed_pr_count: 2,
}))
- const { queue, parked } = buildQueue(items, () => ({ quarantinedAt: '2026-07-13T17:12:22.000Z' }), true)
+ const { queue, parked } = 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 () => {
+ const trunkFor = await fetchTrunkQuarantined(
+ 'jest',
+ async () => ({
+ results: [
+ [
+ 'src/lib/components/ActivityLog/activityLogLogic.person.test.tsx::the activity log logic humanizing persons can handle addition of a property',
+ '2026-07-11T16:45:09.000Z',
+ ],
+ ],
+ }),
+ true
+ )
+
+ assert.equal(
+ trunkFor({
+ selector:
+ 'frontend/src/lib/components/ActivityLog/activityLogLogic.person.test.tsx::the activity log logic humanizing persons can handle addition of a property',
+ }).quarantinedAt,
+ '2026-07-11T16:45:09.000Z'
+ )
+ })
+
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', trunk: { quarantinedAt: '2026-07-13T17:12:22.000Z' } }]
+ [{ 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 in Trunk'))
+ .find((text) => text.includes('quarantined'))
assert.equal(
blocks.find((block) => block.type === 'table'),
undefined
)
- assert.match(note, /1 test is quarantined in Trunk/)
+ assert.match(note, /1 test is quarantined/)
assert.match(note, /test_masked/)
assert.match(note, /Oldest parked 2026-07-13\./)
})
diff --git a/products/engineering_analytics/README.md b/products/engineering_analytics/README.md
index 4d86cb16f9d9..ad809283ee62 100644
--- a/products/engineering_analytics/README.md
+++ b/products/engineering_analytics/README.md
@@ -82,7 +82,7 @@ graph LR
- Job-level CI: per-job duration, queue time, runner tier, and dollar cost ride `workflow_jobs` (webhook stream plus bounded backfill).
- One write surface: test quarantine. The UI files a tracking issue plus a PR against the repo's checked-in `.test_quarantine.json` through the team's GitHub App. Everything else is read-only.
-- The test-health view is an active work queue, not a failure-rate leaderboard: the main pytest and Jest suites emit failures and same-job re-run recovery evidence. Jest writes a small marker beside JUnit when quarantine tolerates a failure, so masking it does not erase the signal. Evidence is counted per CI run, a test is called flaky only where one commit was seen both failing and passing it, and every other failure ranks as an honest suspected regression by blast radius. Callers can filter by `runner` before ranking and limiting when they need a runner-specific queue.
+- The test-health view is an active work queue, not a failure-rate leaderboard: the main pytest and Jest suites emit failures and same-job re-run recovery evidence. Jest writes a small marker beside JUnit when quarantine tolerates a failure, so masking it does not erase the signal. Evidence is counted per CI run, a test is called flaky only where one commit was seen both failing and passing it, and every other failure ranks as an honest suspected regression by blast radius. Callers can filter by `runner` before ranking and limiting when they need a runner-specific queue. The weekly Slack report requests each runner separately and shows up to 10 pytest tests followed by up to 10 Jest tests. Logs-based rescue counts and links remain pytest-only.
- Access control: per-user warehouse RBAC at the source resolver, `engineering_analytics:read` scopes on tools, feature-flag gated.
## The goal: CI Signals for PostHog Desktop