Repository navigation
fix(discover): rewrite dotnet restore, not just build - #2142
Conversation
b67f390 to
c702065
Compare
|
Ran a fresh-context independent review (skeptical, diff + issue only). Verdict: no blockers. Two points addressed / noted:
Follow-up (intentionally out of scope here): the rule's flat |
|
Friendly ping on this one — #1830 is still open and picked up a +1 from a heavy user (reported |
`rtk dotnet test`, `rtk dotnet restore`, and `rtk dotnet format` proxies already exist and route to dedicated handlers, but the rewrite rule only matched `dotnet build`, so the Claude Code hook silently passed the other three through unfiltered. Extend the rule's subcommand set; the output filters already handle all four — this is purely a routing fix. Fixes rtk-ai#1830
…t comment Addresses a non-blocking review nitpick: the "(issue rtk-ai#1830 - only build was covered before)" parenthetical is history the comment does not need. Keep the part that explains why all four subcommands must route, drop the rest.
24ac995 to
e3a36cd
Compare
|
@KuSh since you've been folding the duplicates (#1207, #3654, #3300) into #1830 — this PR is the fix for it. It's a one-line change to the |
KuSh
left a comment
There was a problem hiding this comment.
Round 1 — CHANGES REQUESTED
Claim: the dotnet rewrite rule routes dotnet test, dotnet restore and dotnet format to their existing rtk dotnet handlers, not just build.
Scope: accept if narrowed to "the dotnet rewrite rule routes dotnet restore to rtk dotnet restore" (^dotnet\s+(build|restore)\b). test and format are cut: what each handler does differs from the native command an agent types, and fixing that is handler work, not routing. Filed as #4602 (format) and #4603 (test); the MTP part is #1289, evidence added.
Ran: native dotnet against rtk rewrite + the rewritten command, .NET SDK 10.0.400 in Docker, develop f16beca vs this PR merged onto it: 16 test rows (xunit VSTest: fail, pass via --filter, --logger console, --list-tests, -t, --no-build -v q, -v n, --collect, --blame, user --logger trx with and without --results-directory, a compile error after a green run; MSTest on MTP via global.json, with and without the TRX extension: run from the project and with --project, --list-tests), 13 restore rows (ok, explicit project, path target, --force, NU1903 warning, NU1101 failure, no project, bad --source, -v n, /v:n, user -bl:, --help, restore-x), 4 format rows, 36 rewrite spellings (pipes, chains, env/timeout prefixes, builder/testhost/test-x/format.sh boundaries); invariants: exit codes, files written and deleted, under the hook, every decision; restore savings 23–33% on small successful runs, 97% at -v n, failures passed through whole (20% floor, CONTRIBUTING.md)
Pins: 4 decisions (test, restore, format arms, \b on them), 4 mutated, 0 survived — test_rewrite_dotnet_subcommands kills each
Matrix: never — ran this round; pin check: never — ran this round
CI @e3a36cdc0: no run on this head (the fork workflow waited for approval and expired); I will approve the run on your next push. Locally on the merge with develop f16beca: fmt, clippy and 4955 tests green.
Blocks merge (3, frozen at round 1) — all three close by the narrowing above
src/discover/rules.rs:698—dotnet formatbecomes a check.rtk dotnet formatadds--verify-no-changesunless rtk's own--writeis passed. Evidence: on a file with whitespace violations, nativedotnet formatanddotnet format whitespaceexit 0 and reformat the file; through the rewrite both exit 2 and the file is unchanged. The output ends withRun `dotnet format` to apply fixes, and under the hook that hint runs the check again. #4602.src/discover/rules.rs:698— rtk's injected TRX reporting breaks MTP runs and--list-tests. Evidence: MSTest on MTP referencing onlyMSTest.TestAdapter+MSTest.TestFramework: nativedotnet testpasses, exit 0; through the rewrite exit 5,Unknown option '--report-trx',Zero tests ran. xunit--list-tests/-t: native prints both test names, exit 0; through the rewrite:ok dotnet test: completed (binlog-only mode, counts unavailable, 0 warnings) (unknown), exit 0. MSTest on MTP: native exit 0,Discovered 2 tests; through the rewrite exit 5 ('--report-trx' cannot be enabled when using '--list-tests'),Discovered 0 tests, and 4.6 KB of option help. #1289 (MTP without the extension), #4603 (--list-tests).src/discover/rules.rs:698— test artifacts are deleted. rtk adds--results-directory <temp>and deletes that directory afterwards. Evidence:--collect "XPlat Code Coverage": native writesTestResults/<guid>/coverage.cobertura.xmland prints its path underAttachments:; through the rewrite no coverage file is left and theAttachments:line is gone. Same for--logger "trx;LogFileName=r.trx": native keepsTestResults/r.trx, through the rewrite it is gone. Every failing xunit run through the rewrite also cites aResults File:under that deleted directory. #4603.
After narrowing, the test should also say what was cut: dotnet test and dotnet format rewrite to None. Re-adding test to the alternation has to turn it red.
Optional — will not hold merge
docs/guide/resources/what-rtk-covers.mdhas a .NET table withbuild,testandformat; adotnet restorerow would match what the rule now routes.
Filed as follow-ups
- #4602
rtk dotnet formatchecks by default, so a rewrittendotnet formatstops formatting — cut by the narrowed claim; filed - #4603
rtk dotnet testloses--list-testsoutput and deletes the test artifacts it redirects — cut by the narrowed claim; filed - #1289
rtk dotnet testfails on repositories that use the new testing infrastructure — cut by the narrowed claim; absorbed by existing #1289, comment added with the .NET 10 rows - #1830 stays open for
testandformatuntil those land.
Checked and correct — no need to re-verify
dotnet restorethrough the rewrite: exit code equal to native on all 13 rows; NU1101 and MSB1003 errors and the NU1903 warning kept; a user-bl:user.binlogis written where asked and rtk adds no second one;--helpforwarded unchanged; no temp binlog left in/tmp.dotnet restore-x,dotnet test-xanddotnet format.shdo rewrite (the\bboundary admits-and., as forbuildon develop), but rtk passes them through to dotnet: output and exit code are identical to native.dotnet builder,dotnet testhost,dotnet tests,dotnet publish,dotnet run,dotnet --info,sudo dotnet …,dotnet restore > log.txtare left alone, as on develop.dotnetis already inSUBCOMMAND_ROUTERS, so the tracking label keeps the subcommand.- The thread on the historical aside: fixed in e3a36cd; resolving it.
Your questions
- "Happy to file a separate PR adding
subcmd_savingsoverrides" → drop for now. Withtestandformatcut, onlyrestoreis new, and it measures 23% on a two-line success up to 97% at-v n; the 70% default is inside that range. - "Happy to rebase or reshape it if you'd prefer something different" → yes, the narrowing above. No rebase needed: it merges cleanly onto develop f16beca and the suite passes there.
Next
Narrow the pattern to ^dotnet\s+(build|restore)\b and turn the test/format rows of test_rewrite_dotnet_subcommands into negative assertions. After that push and a green CI run, this merges.
Rounds: 1. Threads: 0 open, 1 resolved this round.
`rtk dotnet test` and `rtk dotnet format` change what the native command does: format turns into a --verify-no-changes check, and test injects TRX reporting into a temp results directory it deletes afterwards (breaking MTP runs, --list-tests, and coverage/trx artifacts). Narrow the rule to `build|restore` until rtk-ai#4602 and rtk-ai#4603 land, and assert that `dotnet test` and `dotnet format` are not rewritten. Also list `dotnet restore` in the .NET table of what-rtk-covers.md.
…net-rewrite-subcommands # Conflicts: # docs/guide/resources/what-rtk-covers.md
|
Thanks @KuSh, that's a thorough round, and the
develop had moved since your round (the docs table lost its percentage column), so I merged |
The page lists what the hook intercepts. `cargo nextest`, `dotnet test`, `dotnet format` and `docker compose up` were listed, yet `rtk rewrite` leaves all four alone. `cargo nextest` and `docker compose up` have no rule yet (rtk-ai#2046, rtk-ai#1727); `dotnet test` and `dotnet format` stay out of the `dotnet` rule until their handlers match the native commands (rtk-ai#4603 and rtk-ai#1289, rtk-ai#4602). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KuSh
left a comment
There was a problem hiding this comment.
Round 2 — APPROVED
Claim: the dotnet rewrite rule routes dotnet restore to rtk dotnet restore, alongside build.
Scope: accept if narrowed to "the dotnet rewrite rule routes dotnet restore to rtk dotnet restore" (round 1, frozen). Narrowed in adf52a8.
Ran: rtk rewrite over 42 spellings, develop 5538d72 against this PR merged onto it (restore with and without args, -v n, /v:n, -bl:, --help, && chains, | pipes, cd … &&, env and timeout prefixes, restore-x, restorer, sudo, > log.txt; every round-1 test and format spelling); invariants: under the hook, every decision. The 13 rtk dotnet restore rows from round 1 (exit codes equal to native, errors and warnings kept, savings 23–97% vs the 20% floor in CONTRIBUTING.md) are reused: nothing the restore path calls has changed on develop since.
Pins: 4 decisions (restore arm, \b, test left out, format left out), 4 mutated, 0 survived — test_rewrite_dotnet_subcommands kills each
Matrix: executed round 1, rewrite rows rerun this round; pin check: executed this round
CI @4416e6f35 (with the fixup): all green; @dfae82640 before it: all green. Locally on the merge with develop 5538d72: fmt, clippy and 5011 tests green.
Blocks merge (0 of 3 frozen at round 1 still open)
All three closed by the narrowing: no spelling of dotnet test or dotnet format is rewritten any more, so the agent's command runs natively.
Filed as follow-ups
- #4602, #4603 and #1289 carry
formatandtest(filed at round 1). - #1830 stays open for them. Note: commit 6396c97 still says
Fixes #1830, and merge commits ondevelopkeep it, so merging will close #1830. I will reopen it after merge; no rebase needed for that. - #4695
what-rtk-covers.mddoes not match what the hook rewrites, and nothing checks it — pre-existing, rest of the page beyond the four rows the fixup drops; filed - #3770 shadow-warning guard misses the 21 clap commands outside both reserved lists — pre-existing: a trusted user filter for
dotnet testmakes the hook send it tortk dotnet test, on develop as here; absorbed by existing #3770, comment added
Checked and correct — no need to re-verify
dotnet restorein every spelling above rewrites tortk dotnet restore …with the arguments kept;dotnet restore && dotnet testrewrites only therestorehalf;dotnet build && dotnet formatonly thebuildhalf.dotnet restorer,dotnet builder,publish,run,--info,sudo dotnet restoreanddotnet restore > log.txtare left alone, as on develop.- The
what-rtk-covers.mdrow matches whatrtk dotnet restoreprints: the restore summary plus errors and warnings. - The three round-1 threads: fixed in adf52a8; resolving them.
Next
Fixup 4416e6f pushed, code-reviewed: what-rtk-covers.md no longer lists cargo nextest, dotnet test, dotnet format and docker compose up, none of which the hook rewrites (#2046, #1727; #4603 and #1289, #4602). Docs only. Approving once CI is green on it.
Rounds: 2. Threads: 0 open, 3 resolved this round.
Summary
rtk rewriteonly matcheddotnet build, so the hook passeddotnet restorethrough unfiltered even thoughrtk dotnet restoreexists. This routesrestoretoo. Part of [rewrite] dotnet test|restore|format should auto-rewrite to rtk dotnet #1830.dotnet testanddotnet formatare deliberately not routed: theirrtk dotnethandlers change what the native command does (formatbecomes a--verify-no-changescheck;testinjects TRX reporting into a temp results directory it deletes, which breaks MTP runs,--list-tests, and coverage/trx artifacts). Those are handler fixes, tracked inrtk dotnet formatchecks by default, so a rewrittendotnet formatstops formatting #4602 (format),rtk dotnet testloses--list-testsoutput and deletes the test artifacts it redirects #4603 (test) andrtk dotnet testfails on repositories that use the new testing infrastructure #1289 (MTP); [rewrite] dotnet test|restore|format should auto-rewrite to rtk dotnet #1830 stays open for them.Root cause
The
dotnetrewrite rule insrc/discover/rules.rsusedpattern: r"^dotnet\s+build\b", covering onlybuild, whileDotnetCommands::Restorealready dispatches to a real handler.Fix
Narrow change to the rule:
^dotnet\s+(build|restore)\b.Tests
test_rewrite_dotnet_subcommands:buildandrestorerewrite tortk dotnet <sub>(trailing args kept);dotnet testanddotnet formatrewrite toNone;dotnet publish/dotnet run/dotnet builderare left alone. Re-addingtestorformatto the alternation turns it red (checked both).7bff768c:cargo test discover683 passed,cargo fmt --checkclean.cargo clippy --all-targets -- -D warningsis clean on the touched files; locally it stops on aduplicated attributeinsrc/llm_proxy.rs, which this PR does not touch (develop as-is).Manual verification
Docs
Added a
dotnet restorerow to the .NET table indocs/guide/resources/what-rtk-covers.md(develop has since dropped the percentage column, so the row matches the new two-column format).