Skip to content

feat(jvm): add rtk mvn with Surefire/Failsafe XML test summarization - #1974

Closed
bkirosangma wants to merge 2 commits into
rtk-ai:developfrom
bkirosangma:feature/mvn-test-coverage
Closed

bkirosangma wants to merge 2 commits into
rtk-ai:developfrom
bkirosangma:feature/mvn-test-coverage

Conversation

@bkirosangma

Copy link
Copy Markdown

Summary

Adds rtk mvn test and rtk mvn verify coverage for Maven projects, mirroring the existing rtk gradlew design. The command runs mvn unchanged, then walks target/{surefire,failsafe}-reports/TEST-*.xml across all modules and emits a compact, failure-focused summary instead of the raw 10–25 KB Surefire log.

  • New src/cmds/jvm/mvn_cmd.rs (~600 LOC, 10 unit tests) auto-discovered via automod::dir!.
  • src/discover/rules.rs regex extended so the Bash hook rewrites mvn (test|verify|integration-test|failsafe:integration-test) to rtk mvn … (5 new dispatch tests).
  • Build-mode line filter (strips [INFO], Downloading/Downloaded, progress) is used for non-test goals; [ERROR], [WARNING], BUILD, Total time, Finished are always preserved.
  • -X, --debug, --verbose trigger passthrough per the "Never Block" / "Correctness vs Token Savings" principles in CONTRIBUTING.md.

Why

mvn test is the most common Maven workflow and produces a large amount of noise the LLM doesn't need: per-module Surefire headers, Tests run: … lines, build banners. On green runs the totals are the only signal; on red runs only the failure rows matter. Parsing the Surefire XML and emitting a short summary fits the same niche rtk cargo test / rtk pytest / rtk go test already occupy for their ecosystems.

Token reduction

Measured end-to-end against a synthetic noisy mvn shim that emits a realistic Surefire log + two TEST-*.xml reports (5 tests, 1 failure):

Stream Raw bytes rtk bytes Ratio
Combined stdout + surefire reports 5,412 219 0.0405

i.e. ~95.95% reduction on this fixture. rtk's output is the four lines:

TESTS: 5 OK=4 FAIL=1 ERR=0 SKIP=0
FAIL: com.example.FailingTest.test_fails — expected:<42> but was:<41>
BUILD FAILURE
Total time: 1.234 s

The token-savings unit test in mvn_cmd.rs (test_build_filter_savings) asserts the build-mode filter alone hits ≥ 60% on a representative noisy build log fixture.

Production-module verification against workout-management-service (87 tests, multi-module Maven build) is queued on the contributor's regular dev machine; it was blocked in the sandbox by AWS CodeArtifact 401. Synthetic E2E figure above is the binding empirical measurement.

Implementation

  • src/cmds/jvm/mvn_cmd.rs: new module, parses TEST-*.xml with quick-xml (already in Cargo.lock).
    • Task family detection: Test | Build | Other from the args list.
    • Multi-module aware: recursively walks every target/surefire-reports/ and target/failsafe-reports/.
    • Failure/error messages truncated to 80 chars with a … suffix; up to N rows printed and the rest summarised.
  • src/main.rs: adds a Commands::Mvn variant routed to cmds::jvm::mvn_cmd::run.
  • src/discover/rules.rs: extends the JVM dispatch regex to include test|verify|integration-test|failsafe:integration-test.
  • src/discover/registry.rs: 5 new classify/rewrite tests for mvn test, mvn verify, mvn failsafe:integration-test.
  • tests/fixtures/mvn_build_noisy_raw.txt: representative noisy mvn package log used by the build-mode filter savings test.

Compatibility

  • mvn -X / mvn --debug / mvn --verbose → passthrough (no compression).
  • RTK_DISABLED=1 honoured via the existing dispatch path.
  • Multi-module builds: walks every target/{surefire,failsafe}-reports/ recursively from the working directory.
  • Falls back to raw output if XML parsing fails for any module (filter never blocks).
  • Exit code of the underlying mvn invocation is propagated.

Test plan

  • cargo fmt --all --check && cargo clippy --all-targets && cargo test — 1916 passed; 0 failed; 6 ignored (locally on macOS aarch64).
  • New unit tests in src/cmds/jvm/mvn_cmd.rs (10): task detection w/ debug flags, all-pass / one-failure / one-error / skipped / failsafe fixtures, summary formatting, build-mode line filter, build-mode token savings (≥60%), detect-task.
  • New classify/rewrite tests in src/discover/registry.rs (5): mvn test, mvn verify, mvn failsafe:integration-test.
  • Manual end-to-end: rewrote mvn test to rtk mvn test via the Bash hook against a synthetic mvn shim producing the noisy fixture above → ratio = 0.0405.
  • Production-module verification on a real Spring Boot multi-module build — follow-up on contributor's dev machine where CodeArtifact creds are available (sandbox blocked by 401).

Notes for reviewers

  • Module is placed under src/cmds/jvm/ next to gradlew_cmd.rs — symmetric with the existing Gradle filter.
  • No new dependencies; quick-xml is already present.
  • CHANGELOG.md intentionally untouched — release-please will pick up the feat(jvm): prefix.
  • Happy to split the commit into per-file atomic commits if the maintainers prefer (kept it as one logical change for review clarity).

bsangma-sportstech and others added 2 commits May 20, 2026 01:38
- Extend dispatch regex in src/discover/rules.rs to include
  test|verify|integration-test|failsafe:integration-test, so the Claude
  Code Bash hook now rewrites `mvn test` etc. to `rtk mvn test`.
- Add Commands::Mvn variant in main.rs routing to a new cmds::jvm::mvn_cmd
  module (auto-discovered via automod::dir!).
- New mvn_cmd.rs:
    * Detects task family (Test | Build | Other) from args; honors -X /
      --debug / --verbose passthrough per CONTRIBUTING.md "Never Block".
    * Test mode: runs mvn, then walks target/{surefire,failsafe}-reports/
      for TEST-*.xml files (multi-module aware), parses with quick-xml,
      and emits a compact summary:
          TESTS: N OK=O FAIL=F ERR=E SKIP=S
          FAIL: <classname>.<name> — <80 chars>
          ERR:  <classname>.<name> — <80 chars>
          BUILD SUCCESS/FAILURE + Total time
    * Build mode: line filter that strips Maven [INFO] chatter,
      Downloading/Downloaded noise, and progress lines, while always
      keeping [ERROR], [WARNING], and BUILD/Total/Finished lines.
- New tests/fixtures/mvn_build_noisy_raw.txt — representative noisy mvn
  build log for the token-savings assertion (≥60% target).
- 10 new unit tests in mvn_cmd covering: task detection w/ flags, all-pass,
  one-failure, one-error, skipped, failsafe, summary formatting, build
  filter behavior, token savings ratio.
- 5 new classify/rewrite tests in discover::registry for `mvn test`,
  `mvn verify`, `mvn failsafe:integration-test`.

cargo fmt --all && cargo clippy --all-targets && cargo test --bin rtk all pass
(1916 tests, 0 failures).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds the new Maven Surefire/Failsafe entries to the Test Runners section
of the top-level README, per CONTRIBUTING.md doc-update map for new
Rust filter modules.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@rtk-release-bot rtk-release-bot Bot added the stale label Sep 3, 2026
@KuSh

KuSh commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this. The Rust mvn module landed as #1956 on 2026-06-08 and was extended by #3199 on 2026-08-30. The file is now built around a log driven filter with per module lanes, caps and mvnd daemon support, so the version proposed here cannot be applied on top of it. One idea from this PR has no equivalent on develop: reading totals and failures from target/surefire-reports and target/failsafe-reports TEST-*.xml as a fallback when the build log cannot be parsed. That would be worth an issue, or a narrow PR adding the fallback inside the current filter. If I missed something, please comment or reopen.

@KuSh KuSh closed this Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants