Repository navigation
refactor(xtask): extract the 47k-line test module out of main.rs (#2119) - #2184
Conversation
First behavior-preserving decomposition slice of the 120k-line xtask monolith: the single mod tests block (46.8k lines) moves verbatim to xtask/src/tests.rs, declared as mod tests from the crate root, so every test name and the module path (crate::tests) are unchanged. main.rs drops to ~74k lines. rustfmt did the reindentation so raw-string fixtures are byte-identical (a scripted de-indent corrupted them the first attempt; rustfmt is string-literal-safe). Allowlist paths that pinned findings in the test module were repointed: 20 semantic entries in policy/no-panic-allowlist.toml and the devtools entry in .ripr/static-language-allowlist.toml (new entry naming the moved regression tests). Zero behavior change: 1213 xtask tests pass, and precommit, goldens check, fixtures, dogfood, clippy, and fmt are all clean.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
Summary by CodeRabbit
WalkthroughAllowlist configuration now recognizes ChangesAllowlist relocation
Estimated code review effort: 1 (Trivial) | ~3 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.44.1)xtask/src/main.rsast-grep timed out on this file Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- PR body says 1213/1213 tests pass and CI is green; the lane-level public-route check is whether the new
mod testsdeclaration in main.rs and any required[[test]]entry in Cargo.toml still letcargo test --locked --package xtask --test testsresolve the same fixture surface. Run that one focused command before approving the public split; no semantic change is implied.
Verification questions
- Confirm splitting tests.rs into a sibling module keeps
crate::testspaths, and the only behavior-shaped file in the change ispolicy/no-panic-allowlist.toml(20 path renames + 1 new entry). - Confirm xtask::tests is a self-contained submodule that imports only via
super::*(dispatch, gates, helpers) and extern crates (serde_json, etc.); the test bodies reference symbols that must still resolve throughcrate::testsafter the split. - Confirm the 51+ tests in this file mostly stub inputs and assert structural keys/values or simple counts. They are deterministic on the input shape but do not exercise the production code paths through the actual function arguments; risk of tautological pass if inputs are themselves wrong.
- Confirm module-level test-name slugs (badge_basics_summary_markdown_omits_forbidden_terms, ci_full_evidence_gate_runner_names_failing_gate, etc.) already pin module::test ordering invariants; moving them wholesale to xtask::tests preserves the gate contract — but no test inside tests.rs asserts that
super::SomeTypeispub used before being referenced, so if a refactor downstream turns a sibling-in-fixture helper pub-private the test still compiles while the production helper stops being reachable. Verifying the new tests.rs is wired up viamod tests;(not just#[cfg(test)] mod tests;) is the bare minimum. - Confirm public API surface in tests.rs mirrors the public API of the file it split from: any
super::dispatch,super::Type,super::XtaskCommandthe tests need is only reachable ifsuper::is still pub at the call site. Since the tests body was originally inline inmod tests, the gate was: if main.rs compiles forcargo test --workspace --test, it compiles. After the split,mod tests;declarations in main.rs must compile against thepub useboundary of the newtests.rsfile (its own private items are not reachable to siblings), so the same suite that previously was 'just inside the same file' now has to satisfy crate's pub export list. The PR diff does not showpub usechanges for thesuper::dispatch/super::Type/super::XtaskCommandlines that the test body was calling. - Confirm main.rs
mod tests;now reads onlytests;after the move; siblingtestsblock is the only othermod tests;in the tree. - Confirm pR moves a 47,094-line mod tests block out of main.rs to xtask/src/tests.rs verbatim. main.rs drops to ~74,072 lines (~73,000 lines of non-test code). Net: removes 47k lines from main.rs; adds 47k lines to tests.rs.
- Confirm new tests.rs imports 333 items from super (super::regress, super::test_efficiency_entry, super::fetched_lsp_cockpit_json_value, etc.). This is a single-file super::import surface duplication of every private item the old mod tests used. Adding a new internal helper anywhere in main.rs requires it to be visible to tests.rs (private(crate), or duplicated, or pub use-re-exported.
- Confirm the 1213+ test names are preserved verbatim across the move; we only confirmed the move is byte-for-byte at the function-name level via grep, not via a green test run. Need a locked cargo test to prove parity.
- Confirm extracting 47k lines into xtask::tests is a high-risk refactor by line volume. The lane cannot statically prove that no symbol resolution or path-handling code moved between the two files. Central should run the lane1 CI test command + the project's precommit gate to confirm the module compiles, the runtime tests pass, and that downstream crates consuming
crate::tests::*symbols see no observable change.
Refuted
Test proof
Parked follow-ups
[review body truncated; see review artifacts]
[review body truncated; see review artifacts]
…main.rs (#2119) (#2283) Behavior-preserving module extraction, following the #2184/#2221 protocol. The evidence-promotion-honesty gate cluster (honesty options parsing, corpus validation, typed semantic assertions, pinned external checkout machinery, external run report, corpus summary report, and the report-local evidence_promotion_* helpers) moves from main.rs (37943 -> 33694 lines) into the new flat module xtask/src/evidence_promotion.rs (4276 lines): 95 top-level fns, 7 structs, 2 enums, and 12 consts, including parse_json_rejecting_duplicate_keys (#2279). Moved blocks are byte-identical except visibility widening for the items main.rs and tests.rs reach through the crate root (pub(crate) on 10 fns, 5 types, 3 consts, and the fields of the four structs tests.rs constructs literally). main.rs additions are exactly the mod declaration plus two re-export blocks (one #[cfg(test)]); dispatch.rs and tests.rs compile unchanged. No no-panic, process, or static-language allowlist repoints were needed: the cluster contains no panic-family calls, no Command::new, and no prohibited vocabulary, and none of the 17 main.rs-pinned no-panic containers live in this cluster. Verified: cargo test -p xtask -- --list count 1262 == base 1262 (sorted lists byte-identical), cargo test -p xtask exit 0 (1260 passed, 0 failed); check-evidence-promotion-honesty and module-health stdout plus evidence-promotion-honesty.md and corpus-summary.{json,md} byte-identical to the base build; fmt --check, precommit, and goldens check (pass, 186 fixtures, zero drift) all exit 0.
Summary
First behavior-preserving decomposition slice of #2119: the 120,652-line
xtask/src/main.rsmonolith was roughly 74k lines of production code + one 47k-linemod testsblock. That single test module moves verbatim toxtask/src/tests.rs, still declaredmod tests;from the crate root — every test name and thecrate::testsmodule path are unchanged.main.rsdrops to ~74k lines; further decomposition (production areas, test areas) is follow-up work.Zero behavior change is the proof, per the AGENTS.md monolith doctrine:
policy/no-panic-allowlist.toml(xtask/src/main.rs→xtask/src/tests.rs, exactly the entries the checker reported stale after the move).devtoolsentry in.ripr/static-language-allowlist.tomlforxtask/src/tests.rs(the regression tests that intentionally contain prohibited terms, moved verbatim).Validation
cargo test -p xtask— 1213 passed, 0 failedcargo clippy -p xtask --all-targets -- -D warnings— cleancargo fmt --check— cleancargo xtask precommit/goldens check/fixtures/dogfood— all exit 0Follow-ups (not in this PR)
main.rs's 74k production lines by area (policy checks, reports, repo-ops).tests.rsby area when the next test module hits the module-health threshold.