Repository navigation
fix(hooks): rewrite go -C DIR <subcommand> - #4971
LetMeSleep8h wants to merge 2 commits into
Conversation
The go rule only matched subcommand-first text, so — the form agents use to work across clones without moving the shell's cwd — reached the agent uncompressed while was filtered. The rule pattern now accepts the chdir flag between and the subcommand in all four spellings go accepts (-C DIR, -C=DIR, --C DIR, --C=DIR), first flag only, and a strip_go_chdir_opt normalization aligns classify with the rewrite so discover accounting does not report a saving the hook cannot deliver. The rewrite re-emits the original command, so the flag reaches rtk go untouched. Closes rtk-ai#4970
|
|
📊 Automated PR Analysis
SummaryFixes the rtk Review Checklist
Linked issues: #4970 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
Kernel-Hunter
left a comment
There was a problem hiding this comment.
Ran this branch on macOS with a stub go on PATH that logs its argv and prints go test -json events when it gets -json, plain go test text otherwise.
The rewrite works: all four spellings now give rtk go -C ./sub test ./... where develop gives nothing, and both go_chdir_* tests pass.
What runs after the rewrite isn't filtered, though. rtk go -C ./sub test ./... lands in GoCommands::Other (run_other, src/cmds/go/go_cmd.rs:144), so go gets -C ./sub test ./... with no -json and the output comes back raw:
$ rtk go test ./...
Go test: 1 passed in 1 packages # go got: test -json ./...
$ rtk go -C ./sub test ./... # go got: -C ./sub test ./...
=== RUN TestA
--- PASS: TestA (0.00s)
PASS
ok ex/sub 0.100s
So these calls still reach the agent uncompressed, which is what #4970 is about, while classify_command now reports them as supported (src/discover/registry.rs:224) and rtk discover stops listing them as missed. The issue asks for -C DIR kept first with -json injected, i.e. go -C DIR test -json ARGS. I think that needs the go dispatch to recognise a leading chdir flag followed by test/build/vet and call run_test/run_build/run_vet with the flag placed before the subcommand. Rewriting to rtk go test -C DIR would run into the ordering problem #3520 is still fixing.
Smaller: the comment at src/discover/rules.rs:564 says "(also -C=DIR, -C=DIR single-arg)", and the pattern itself doesn't match --C, so the --C cases in the test presumably pass through strip_go_chdir_opt rather than the regex.
|
Hey @LetMeSleep8h, thanks for handling |
Closes #4970
What
The go rule's pattern only matched subcommand-first text, so
go -C ./sub test ./...was never rewritten whilecd ./sub && go testwas — the exact inversion an agent working across clones hits (the issue'srtk discovershows 4,155 unhandledgocalls in 30 days, most in the-Cform).goandtest|build|vetin all four spellings go itself accepts (-C DIR,-C=DIR,--C DIR,--C=DIR), as the first flag only — one optional group, mirroringhandleChdirFlagin cmd/go/main.go.strip_go_chdir_optnormalizes the same flag inclassify_command, sortk discoveraccounting stays aligned with what the hook can actually rewrite (the same classify/rewrite-alignment discipline as the pnpm and golangci strippers, per fix(pnpm): rewrite pnpm commands with global flags before the subcommand #3275).go -C ./sub test ./...→rtk go -C ./sub test ./.... With the flag first, clap routes it through theOtherpassthrough, which runs the command as typed — verified end-to-end below.Testing
Two new unit tests: the four chdir spellings all rewrite (plus
go test -C DIRstill working, barego -C DIRandgo -C DIR envstaying put), and the helper's alignment cases. End-to-end on a real two-module tree: