Repository navigation
Pass args to root.Execute explicitly - #7486
Conversation
✅ Integration test reportCommit: cc0e151
Top 3 slowest tests (at least 2 minutes):
|
d67cf1d to
2fa82f1
Compare
simonfaltum
left a comment
There was a problem hiding this comment.
🤖 Automated review from simonfaltum's review agent (pr-review skill) at 2fa82f1. Each finding was verified against the code; simonfaltum may follow up.
No blocking issues found, approving. 3 non-blocking comment(s) below.
This PR makes root.Execute take its args explicitly and turns nil into an empty slice, so cobra can no longer fall back to the process arguments. main passes os.Args[1:], so the binary behaves exactly as before. Every caller is updated, the new test pins the nil contract, and all CI checks pass. I found nothing blocking, only three nits: the new test's assertion also passes if RunE never runs, the start log still reads os.Args (pre-existing), and the description drops the template's ## Why section.
Comments outside the changed lines
- [nit]
cmd/root/root.go:77: Not introduced by this PR, and fine as a follow-up.PersistentPreRunEstill logsos.Args, so in-process runs (internal/testcli.Runner, the configure tests) log the test binary's path and-test.*flags rather than e.g.configure --token --host .... Production is unaffected becausemainpassesos.Args[1:]. Now thatExecuteowns the args, you could put them on the context and log those instead. - [nit]
.github/PULL_REQUEST_TEMPLATE.md:.agents/skills/pr-checklist/SKILL.mdasks for all three template headings (## Changes,## Why,## Tests) and says not to drop any. The motivation ("The next PR needs this: it has to see the args before cobra runs") sits under Changes and doesn't link #7487. Consider moving it under## Whyand linking #7487. The commit message explains it better: lazily added subcommands need Execute to resolve the target command before cobra runs.
| }, | ||
| } | ||
| require.NoError(t, Execute(t.Context(), cmd, nil)) | ||
| assert.Empty(t, got) |
There was a problem hiding this comment.
[nit] got starts as nil and assert.Empty(t, got) accepts nil, so this test also passes if Execute returns nil without running RunE. That could happen after an early return or a help/version short-circuit. It does catch the regression it targets: without the nil guard, got is ["process-arg"]. Consider setting a ran flag in RunE and asserting it with assert.True(t, ran), or asserting NotNil on got. Cobra passes a non-nil empty slice when the command runs.
The sync and bundle sync option builders took the command only to read its context, output type, and stdout. Pass those instead, so their tests no longer attach the command to root.New() to resolve the root flags. The argument count check for sync moves from the builder into RunE. Co-authored-by: Isaac <no-reply@databricks.com>
Lets Execute resolve the target command before running cobra, which lazily added subcommands need. nil args now mean no arguments instead of falling back to the process arguments. Co-authored-by: Isaac <no-reply@databricks.com>
2fa82f1 to
cc0e151
Compare
Changes
root.Executenow takes the args to run instead of reading them from the command, where cobra falls back toos.Argsif they were never set.nilmeans no arguments.mainpassesos.Args[1:], and tests pass their args directly instead of callingSetArgsfirst.Why
#7487 builds top-level commands lazily, so it has to resolve the command from the args before cobra runs. That requires
Executeto receive the args.Tests
New unit test
TestExecuteWithNilArgsRunsWithoutArgschecks that nil means no arguments; existing unit and acceptance tests cover the callers.This pull request and its description were written by Isaac.