Repository navigation
fix(mvn): read goals through arg_tokenizer, not a dash scan - #4006
Merged
Merged
Conversation
📊 Automated PR Analysis
SummaryThis PR rewrites Maven goal detection in mvn_cmd.rs to use a proper argument tokenizer (arg_tokenizer with an Msbuild dialect) instead of a naive scan for the last non-dash token, fixing cases where option values (e.g. Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
KuSh
marked this pull request as draft
September 12, 2026 22:22
KuSh
force-pushed
the
feat/mvn-arg-tokenizer
branch
2 times, most recently
from
September 18, 2026 21:09
05b14e2 to
14db625
Compare
KuSh
marked this pull request as ready for review
September 18, 2026 21:10
KuSh
force-pushed
the
feat/mvn-arg-tokenizer
branch
from
October 6, 2026 22:18
14db625 to
4ec6756
Compare
KuSh
force-pushed
the
feat/mvn-arg-tokenizer
branch
from
October 6, 2026 22:23
4ec6756 to
14db625
Compare
KuSh
force-pushed
the
feat/tokenizer-dialect-axes
branch
from
October 6, 2026 22:35
a41cc10 to
cd9d7a6
Compare
KuSh
force-pushed
the
feat/mvn-arg-tokenizer
branch
2 times, most recently
from
October 6, 2026 22:49
7e58c55 to
1d3c809
Compare
`detect_phase` took the last argument not starting with `-` as the Maven goal, so any option whose value is a separate token hid the goal behind it: `mvn test -f pom.xml`, `mvn test -pl core`, `mvn verify -P prod` and `mvn install -l build.log` all resolved to Passthrough and ran unfiltered. Goal detection now comes from `tokenize_grammar` + `is_free_positional` under a `mvn_takes_value` predicate transcribed from `mvn --help` (3.9.16), read under `Dialect::CommonsCli`. Maven's CLI is Apache commons-cli, whose short options are whole multi-character words (`-pl`, `-gs`, `-amd`) that never cluster and whose names are case-sensitive, and which ends option parsing at `--` (verified: `mvn -- -X validate` reports `-X` as an unknown lifecycle phase), so the module states its grammar instead of correcting one. Routing moves into an `MvnRoute` enum so the verbose, quiet and phase decisions are one pure function over the args, testable without running Maven. `rtk mvnd` shares it, and is covered. Co-Authored-By: Claude Opus 5 <[email protected]>
KuSh
force-pushed
the
feat/mvn-arg-tokenizer
branch
from
October 6, 2026 22:54
1d3c809 to
6f7de39
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
detect_phasepicked the Maven goal as the last argument not starting with-:It has no notion of an option consuming the next token, so any option written with a separate value after the goal hid the goal behind its own value:
mvn test -f pom.xmlpom.xmlmvn test -pl corecoremvn verify -P prodprodmvn clean test -T 1C1Cmvn install -l build.logbuild.logmvn -D testtestVerified against Maven 3.9.16, not from memory:
runs Surefire and emits the standard
T E S T S/BUILD SUCCESSshape, so-f's value really is a separate token and the goal really istest. End to end through a shim,rtk mvn -B -o test -f pom.xmlwent from forwarding all 1845 raw bytes to ~370.Each of
-pl,-rf,-P,-s,-Tand-lwas checked the same way against the real binary: given a bogus value, Maven reports it as that option's value (Could not find the selected project in the reactor: nosuchmodule,The specified user settings file does not exist, …) and never as an unknown lifecycle phase.The fix
Goal detection is rebuilt on
tokenize_grammar+Token::is_free_positional, behind anmvn_takes_value(kind, name) -> Option<ValueSpec>predicate transcribed frommvn --help(3.9.16) — every option the table marks<arg>, in both its short and long spelling.Dialect:
Dialect::CommonsCli(new in #4008). Maven's CLI is Apache commons-cli —/usr/share/maven/lib/shipscommons-cli-1.11.0.jar— and the preset states that grammar directly: POSIX, exceptSingleDash::Atomic, because the library's short options are whole multi-character words (-pl,-gs,-amd,-ntp) that do not cluster. Case stays sensitive, so-b/-Band-t/-Tstay distinct, and--ends option parsing, measured:Because the preset says all three things, this module no longer compensates for any of them: flag lookups are plain
arg_tokenizer::has_flag, andgoals()is onefilter(is_free_positional)over the whole token vector, with nothing re-read past the--boundary.SingleDash::Atomictags-plasTokenKind::Long, notShort— Maven's own--helpcalls it a short option, and a predicate keyed onShortwould silently stop-plclaiming its value.mvn_takes_valuematches on the name alone and never reads the kind.The preset does not model commons-cli's Java-property options:
-DskipTests=truetokenizes as the flagDskipTests, sohas_flag(…, "D")is false for that spelling. Nothing here reads-D's value — goal detection only needs "this is not a positional", which holds — and the separate spellingmvn -D teststill matches theDentry in the table and swallowstest, which is why that entry stays.Routing moves into an
MvnRouteenum, so the verbose / quiet / phase decision is one pure function of the args and every regression test asserts on the resolved route rather than on a predicate.rtk mvndroutes through this same module and shares all of it; a test pins that, and that child argv is forwarded untouched for both binaries.Regression tests
Each was proven red against the previous logic and green after:
option_value_after_the_goal_is_not_the_goal— 7 invocations (-f,-pl,-P,-T,-l,-s,-rf)separate_define_value_is_not_a_goal—mvn -D testdefines a property, leaving no goalmulti_char_short_options_do_not_cluster—-pl core testyields the single goaltesteverything_after_double_dash_is_a_goalmvnd_shares_argument_handling_and_argvPlus
attached_option_values_do_not_swallow_the_goal,verbose_and_quiet_options_pick_their_routeandencrypt_options_are_not_the_errors_flagas guards.quiet_does_not_match_unrelated_flagsasserted!is_quiet(["-quiet", "test"]). That assertion was wrong:mvn -B -o -quiet validateruns quiet against a real Maven, because commons-cli accepts the single-dash spelling of a long option. It is nowquiet_detects_single_dash_long_flag, with--QUIETtaking its place as the negative case.Left out
mvn_cmddoes not callargs_utils::restore_double_dash, and this PR does not add it. Measured with amvnshim onPATH: clap consumes the user's--only when it is the first token of the trailing region, sortk mvn -- testreaches Maven as[test]andrtk mvn test -- fooas[test] [--] [foo]. For Maven the dropped leading--is inert — it has no forwarding convention, and post---arguments are just goals — except forrtk mvn -- -X, where dropping it turns a Maven "unknown lifecycle phase" error into a real debug run. That is a fidelity gap worth its own change, not this one; goal detection here already honours any--that does survive.