Repository navigation
feat(cli): compare saved plans with full-suite JUnit results - #74
Conversation
Signed-off-by: Emmanuel Mawulolo Tagbor <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
adityankale190895
left a comment
There was a problem hiding this comment.
Thanks for this, Emmanuel. The fixtures, provenance and strict-parsing limits are thorough, and the feature is one we want. Before merging, two things would make check-plan report false failures in common setups (pre-existing failures counted as missed, and runner-relative paths). Details are inline, roughly in order of importance. The rest are smaller.
One broader point: enforce-misses.ts already has a JUnit parser (parseJunit), path normalization (normalizeTestPath) and a missed/selected verdict that separates failures already present at base. With this PR the CLI would have two JUnit readers with different rules, so enforce-misses and check-plan could give different answers for the same report. We'd rather consolidate: either have both use your strict parser, or reuse the existing normalization and base-failure handling here. That would also make the case for the new saxes dependency (archived upstream) clearer.
| const attribution = attribute(failure, known); | ||
| if (!("file" in attribution)) { | ||
| unattributed.push({ ...details, ...attribution }); | ||
| } else if (plan.mode === "SELECTIVE" && plan.skipped.has(attribution.file)) { |
There was a problem hiding this comment.
Failures that already existed before the change are counted as missed. Any failure in a skipped file goes here, but a test that was already failing at base isn't something the selection missed.
With the example workflow (plan for HEAD^..HEAD nightly), one long-broken test in a file the last commit didn't touch is reported as missed and exits 1 every night. enforce-misses.ts already separates "failures the change introduced" from "ones already failing at base". Could check-plan take a base result, or at least label these as possibly pre-existing instead of missed?
| const slash = value.replace(/\\/g, "/"); | ||
| // Neither input supplies a trusted checkout root. A unique suffix is not proof of identity: | ||
| // /repo/packages/new/tests/a.test.js could otherwise be mistaken for selected tests/a.test.js. | ||
| if (slash.startsWith("/") || /^[a-z][a-z\d+.-]*:/i.test(slash)) return undefined; |
There was a problem hiding this comment.
Reporter paths are relative to the test runner's root, not the repository's. Vitest and Jest write classname/file relative to their own root directory, but plan paths are repo-relative and matched exactly.
In a monorepo where Vitest runs from packages/web, a failure in packages/web/tests/a.test.ts is reported as tests/a.test.ts. If the repo root also has tests/a.test.ts, it's attributed to the wrong file, so a real miss can come out as selected. Otherwise every failure is unattributed and the command exits 1. Absolute paths are always rejected here, while normalizeTestPath(path, repoRoot) in enforce-misses.ts already maps them into the repo.
A --root <dir> (the reporter's root relative to the repo) plus reuse of normalizeTestPath would fix both cases.
| const name = tag.name; | ||
| const parent = frames[frames.length - 1]; | ||
| if (tag.uri !== "") invalid("Namespaced JUnit elements are not supported."); | ||
| if (Object.values(tag.attributes).some((attribute) => attribute.uri !== "")) { |
There was a problem hiding this comment.
Rejecting every namespaced attribute also rejects the harmless xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="..." that several JUnit writers (Surefire among them) put on the root. That report gets exit 2 instead of a comparison. Rejecting namespaced elements seems enough; xmlns/xsi: attributes could be ignored.
| let unmatched = false; | ||
| for (const value of values) { | ||
| const path = reporterPath(value); | ||
| if (!path || !known.has(path)) unmatched = true; |
There was a problem hiding this comment.
One file value that doesn't match makes the whole failure unattributed, including inherited suite file attributes. If a suite has file="/abs/repo/tests/a.test.js" and the testcase has file="tests/a.test.js", the testcase's own (more specific) path matches but the failure is still unattributed and the command exits 1. Should the testcase file take precedence over inherited suite files when present?
| }; | ||
| result.testCases += 1; | ||
| } else if (name === "failure" || name === "error") { | ||
| if (!parent?.testCase) invalid("Failure evidence must be a direct testcase child."); |
There was a problem hiding this comment.
A suite-level <failure>/<error> (some reporters record beforeAll/setup crashes there) rejects the entire report with exit 2, so none of the ordinary testcase failures in the same report get classified. Reporting it as an unattributed suite-level failure would keep the rest of the evidence.
|
|
||
| - name: Retain comparison evidence | ||
| if: ${{ !cancelled() }} | ||
| uses: actions/upload-artifact@v4 |
There was a problem hiding this comment.
This uses the mutable tag actions/upload-artifact@v4; everything else in the repo is pinned by SHA (tests/action-metadata.test.ts asserts the pins for action.yml). main now uses:
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2and setup-node on line 31 is now actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0.
| const info = fstatSync(descriptor); | ||
| if (!info.isFile()) throw new Error(`Input must be a regular file: ${path}`); | ||
| if (info.size > CHECK_PLAN_MAX_INPUT_BYTES) throw new Error(`Input exceeds the 16 MiB limit: ${path}`); | ||
| const bytes = Buffer.allocUnsafe(CHECK_PLAN_MAX_INPUT_BYTES + 1); |
There was a problem hiding this comment.
Minor: this allocates 16 MiB + 1 for every input, even a 2 KB plan. Since info.size is known, Buffer.allocUnsafe(Math.min(info.size, CHECK_PLAN_MAX_INPUT_BYTES) + 1) still catches a file that grows after fstat, because a read past size is detected as growth.
| classname: attributes.classname, | ||
| file: attributes.file, | ||
| suite: testSuites[testSuites.length - 1]?.name, | ||
| suiteFiles: suites.flatMap((suite) => suite.file === undefined ? [] : [suite.file]), |
There was a problem hiding this comment.
Minor: every testcase (including passing ones) runs suites.filter and two flatMaps over the suite stack, but only failures use the result. Building suite/suiteFiles/suiteNames in the closetag handler when failed || errored would avoid those allocations on large reports.
| const files = new Map<string, string>(); | ||
| for (let index = 0; index < args.length; index += 2) { | ||
| const flag = args[index]!; | ||
| if (flag !== "--plan" && flag !== "--results") throw new Error(`Unsupported check-plan argument: ${flag}`); |
There was a problem hiding this comment.
Minor: because check-plan skips the shared parseArgs, diffci check-plan --help and --plan=plan.json both fail with exit 2, the same code as an invalid report. Supporting --help (exit 0 with usage) and the --flag=value form other commands accept would avoid confusing CI scripts.
Separate base failures and uncertain misses, map reporter roots explicitly, and share strict JUnit parsing with enforce-misses. Preserve suite errors, support help and equals arguments, bound reads, and pin example actions. Signed-off-by: Emmanuel Mawulolo Tagbor <[email protected]>
adityankale190895
left a comment
There was a problem hiding this comment.
Thanks, Emmanuel. This covers every point from the last round, and sharing the strict parser with enforce-misses is the direction we wanted. The new baseline split and the --root/--repo mapping read well.
Because enforce-misses now goes through readJunit/junitFile, its behavior changed in ways that can produce wrong openUnsafeMisses suggestions. The first three inline comments are about that, and they're the ones to fix before merging. After those come two about --base-results and the default exit code. The rest are smaller.
The branch also conflicts with main now.
| if (name === "failure") parent.testCase.failed = true; | ||
| else parent.testCase.errored = true; | ||
| } else if (parent?.suite) { | ||
| emit({ name: attributes.message ?? `(suite ${name})`, suiteLevel: true, ...inherited() }, true, false); |
There was a problem hiding this comment.
Suite-level failures become misses in enforce-misses. This emit also reaches enforce-misses' onCase, so a beforeAll crash on main becomes a failed TestOutcome with file: "". In classifyFailures, verdict(pr, "") returns "missed" for every PR with a selected receipt, because files.has("") is false. The crash is then classified as a miss, and unsafeMissEntries proposes entries against every selected PR in the window.
The id is built from the message attribute, which often contains paths or timings. That means the rerun id rarely matches, so the failure is never ruled flaky either. The old regex parser ignored suite-level failures. enforce-misses probably wants to skip suiteLevel cases, or classify them as unattributed rather than run them through verdict.
| if (!current) return; | ||
| const seen = byId.get(current.id); | ||
| readJunit(xml, (test, failed, skipped) => { | ||
| const file = junitFile(test, repoRoot); |
There was a problem hiding this comment.
Test ids change format, so stored baselines stop matching. The window baseline is record.deterministic_failures from the previous detector run (enforce-misses-collect.ts:116). Ids used to take their file part only from the testcase file attribute. junitFile also falls back to suite files and to a path-like classname or suite name, and it now posix.normalizes paths and turns paths containing .. into "".
For a reporter that gives a suite file or a path-like classname but no testcase file, the id goes from > suite > name to tests/a.test.js > suite > name. On the first run after upgrading, tests that were already failing won't match the baseline and get reported as new misses. Either keep the old id derivation for enforce-misses, or treat a baseline written by an older version as unusable and say so in the notes.
| const finish = () => { | ||
| if (!current) return; | ||
| const seen = byId.get(current.id); | ||
| readJunit(xml, (test, failed, skipped) => { |
There was a problem hiding this comment.
enforce-misses now crashes on reports it used to accept. parseJunit now applies every strict limit: 16 MiB, 100k tags, depth, DOCTYPE, structure, and declared counts higher than the observed testcases. runEnforceMisses calls it at cli.ts:902 without a try/catch.
A main-branch report over 16 MiB because of system-out, or a header with a higher tests= than the testcases actually emitted, used to be classified. Now it throws an unhandled stack trace and writes no report. The rerun parse in rerunFailingFiles (enforce-misses-collect.ts:200) also throws on a truncated file, when it should fall back to "not re-run". At a minimum, catch the error and exit 2 with the parser message, the way check-plan does.
| continue; | ||
| } | ||
| const key = identity(failure, file); | ||
| if (baseline.has(key) && baseCounts.get(key) === 1 && headCounts.get(key) === 1) { |
There was a problem hiding this comment.
A failure that never appears in the base report is classified as a definite missed. If count() never sees the identity in the base report, baseCounts.get(key) is undefined. uncertain is then false, so a failure in a skipped file goes into missed.
This is common when the base report comes from a separate checkout, such as $GITHUB_WORKSPACE/base, and uses absolute paths. Those paths are normalized against the head --repo, stay absolute, and match nothing in the plan. Every long-broken test then shows up as a confirmed miss, so passing a baseline gives a worse result than not passing one. Two fixes would cover it: treat (baseCounts.get(key) ?? 0) === 0 as uncertain, and add a --base-repo option for the base checkout.
| baseResults: basePath === undefined ? undefined : readCheckPlanInput(basePath), | ||
| }); | ||
| console.log(JSON.stringify(report)); | ||
| return report.summary.missed > 0 || report.summary.possibleMisses > 0 || report.summary.unattributed > 0 ? 1 : 0; |
There was a problem hiding this comment.
Without --base-results, possibleMisses still exits 1, and examples/github-actions-check-plan.yml doesn't pass a base report. In the nightly HEAD^..HEAD example, one long-broken test in a skipped file still fails the job every night, now labeled possibleMisses instead of missed.
There are two ways to settle this. The example could also produce base results. Or possibleMisses could be reported without a failing exit code when no baseline was given, perhaps behind a flag. Either is fine, but the current default doesn't solve the original problem.
| const root = options.root ?? "."; | ||
| if (root !== ".") planPaths([root], "reporter root"); | ||
| const repoRoot = options.repoRoot ?? process.cwd(); | ||
| const plan = readSelection(planInput); |
There was a problem hiding this comment.
Minor: planPaths rejects --root ./packages/web, --root packages/web/, and on Windows --root packages\web. Each one exits 2 with "Plan reporter root contains a noncanonical repository-relative path", which reads like a problem with the plan. Normalizing the root first, or giving it its own error message, would avoid that confusion.
|
|
||
| function emit(failure: JunitFailure, failed: boolean, skipped: boolean): void { | ||
| // Bound inherited metadata for both consumers, including passing cases in enforce-misses. | ||
| for (const value of [failure.name, failure.classname, failure.file, failure.suite, |
There was a problem hiding this comment.
Minor: when onCase is set (enforce-misses and --base-results), this budget also counts every passing testcase's inherited suite names and files. A large report with deep describe nesting and long absolute suite paths can now hit "Failure metadata exceeds the 16 MiB limit", even though the same report parses fine without a baseline. Either count only failures, or count each suite's metadata once when the suite is pushed.
| }; | ||
| const file = junitFile(failure, repoRoot, root); | ||
| if (!known.has(file)) { | ||
| unattributed.push({ ...details, reason: failure.suiteLevel ? "Suite-level failure has no testcase file identity" |
There was a problem hiding this comment.
Minor: the specific unattributed reasons from before (no file metadata, invalid path, multiple planned files) are now one generic message, and candidates is never set, although it's still in UnattributedPlanFailure. When suite and testcase paths disagree, the user can no longer tell whether --root or --repo is the fix. Either keep the distinct reasons and candidates, or remove the field from the type.
| if (failed) result.failures.push(failure); | ||
| onCase?.(failure, failed, skipped); | ||
| } | ||
| function inherited(): Pick<JunitFailure, "suite" | "suiteFiles" | "suiteNames"> { |
There was a problem hiding this comment.
Minor: with onCase, inherited() still copies and reverses the suite stack and runs two flatMaps for every testcase, including passing ones. Storing suiteFiles, suiteNames and the nearest testsuite on each Suite when it's pushed would make this O(1) per case.
| return result; | ||
| } | ||
|
|
||
| export function parseJunitFailures(xml: string): JunitFailures { |
There was a problem hiding this comment.
Nit: parseJunitFailures only forwards to readJunit. checkPlan could call readJunit(junitXml, onCase) in both cases, which would remove the branch and the second import.
Keep stored enforcement IDs, handle invalid reports conservatively, and compare separate base/head full-suite results. Signed-off-by: Emmanuel Mawulolo Tagbor <[email protected]>
…re-existing The reader now reports a missing testcase name as "", so the "(unnamed testcase)" comparisons in check-plan could never match. enforce-misses classified suite-level failures as unattributed before the window baseline check, so a long-standing setup crash was reported as unattributed on every run instead of pre-existing. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: adityankale190895 <[email protected]>
|
Merged. Thank you, @KingEmma7! This was a big piece of work, and you handled two rounds of review thoroughly: the strict reader shared by both commands, the base/head split, Before merging I pushed one small commit (c4ec22a) with two cleanups:
|
|
@KingEmma7 thank you for the Yarn work and for #74. Comparing saved plans with full-suite JUnit results is now how we measure misses on real repositories. If DiffCI has been useful to you, a ⭐ on the repo helps others find it. No pressure either way. |
|
Hi @KingEmma7, thank you for We have just added contributor tiers to DiffCI (CONTRIBUTING.md), and I would like to invite you as a regular contributor. You would be listed as one in the README, get first pick of new issues before they are labelled If you would like to go further, the Yarn area is open: #66 (Yarn Berry lockfile changes) would make you the natural area maintainer for Yarn support. The issue body has the full scope, including the You are also on our new contributors page, diffci.com/contributors. Tell me if you would rather not be listed there, or would like a different name or link. |
|
Thanks, Aditya! I appreciate the invitation and your offer to provide a recommendation. It’s great to hear that Before I decide, could you share what level of availability or ongoing participation you’d expect from a regular contributor? Thanks for pointing me to the Yarn Berry issue as well. |
|
Thanks @KingEmma7! There's no fixed availability expected. The regular tier recognises the work you've already done, and nothing about it obliges you to keep contributing on a schedule. Pick up issues when you have time, and if you get first pick on one, just say so if you can't get to it and we'll free it up. We'd occasionally tag you for input on design issues, mainly Yarn and |
|
Thanks, Aditya! I’d be happy to accept the regular contributor invitation. I appreciate the flexibility and look forward to contributing when I can. |
Accepted the invitation on #74 (2026-11-17). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: adityankale190895 <[email protected]>
|
Thank you @KingEmma7, and welcome! You're now listed as a regular contributor in the README and on diffci.com/contributors. |
Closes #69.
Adds
diffci check-plan --plan plan.json --results junit.xmlto compare a saved Core plan with full-suite JUnit results. With--base-results, a unique matching base failure ispreExisting; a skipped head failure ismissedonly when its matching base testcase passed. Missing, skipped or ambiguous base identities remainpossibleMisses. Missed, possible-miss and unattributed failures exit 1; invalid inputs exit 2. FULL fallback is explicit, and the full test runner remains the authority on suite success.--rootmaps a nested reporter root,--repoanchors head paths, and--base-reposupports a separate base checkout. Testcase file attributes take precedence over inherited metadata. Unknown paths and suite crashes stay unattributed. Vitest and Jest fixtures cover supported conventions; standard JUnit cannot establish completeness, provenance or causation. Go/Maven attribution and historical tracking remain outside this change.Both commands use one strict XML reader. Enforcement retains its existing v1 baseline IDs, keeps failures without a testcase file out of PR blame, returns exit 2 for invalid full reports, and treats invalid rerun reports as unavailable without discarding primary failures. The reader bounds input and expanded failure metadata and rejects malformed XML and DOCTYPE declarations. It uses pinned
[email protected], whose upstream repository is archived.The scheduled example runs the complete suite at both base and head, passes both reports and checkout roots to the comparison, and preserves head-suite failures. Actions are pinned by SHA. The branch integrates main through
dd7c405; CLI version 0.3.32 and Core dependencyd21cb932match upstream.Validation: 745 Core tests and 412 CLI tests passed, along with typechecks, builds, boundary and agent-package checks, benchmark, and installed-tarball smoke. Seven second-review regressions failed on the prior head and pass now. Actual CLI processes cover invalid full reports and truncated reruns. Executing the nightly example's shell steps against disposable Git repositories recognizes an existing skipped failure and detects a deliberately corrupted selection that misses a newly failing test. Linux/Windows hosted checks will validate this revision.