Skip to content

Pass args to root.Execute explicitly - #7486

Merged
pietern merged 2 commits into
mainfrom
execute-args
Nov 16, 2026
Merged

pietern merged 2 commits into
mainfrom
execute-args

Conversation

@pietern

@pietern pietern commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Changes

root.Execute now takes the args to run instead of reading them from the command, where cobra falls back to os.Args if they were never set. nil means no arguments. main passes os.Args[1:], and tests pass their args directly instead of calling SetArgs first.

Why

#7487 builds top-level commands lazily, so it has to resolve the command from the args before cobra runs. That requires Execute to receive the args.

Tests

New unit test TestExecuteWithNilArgsRunsWithoutArgs checks that nil means no arguments; existing unit and acceptance tests cover the callers.

This pull request and its description were written by Isaac.

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: cc0e151

Run: 43895632459

Env 🔄​flaky 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 270 15 11:16
💚​ aws-windows-latest-4core-16gb 1 272 13 7:15
🔄​ azure linux-2core-8gb 3 1 266 15 13:09
💚​ azure-windows-latest-4core-16gb 1 271 13 7:40
💚​ gcp linux-2core-8gb 1 270 15 10:44
💚​ gcp-windows-latest-4core-16gb 1 272 13 10:18
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
🔄​ TestFsCpFileToDirWithOverwriteFlag/dbfs_to_dbfs ✅​p ✅​p 🔄​f ✅​p ✅​p ✅​p
🔄​ TestFsCpFileToDirWithOverwriteFlag/dbfs_to_local ✅​p ✅​p 🔄​f ✅​p ✅​p ✅​p
🔄​ TestFsCpFileToDirWithOverwriteFlag/dbfs_to_uc-volumes ✅​p ✅​p 🔄​f ✅​p ✅​p ✅​p
Top 3 slowest tests (at least 2 minutes):
duration env testname
4:39 gcp-windows-latest-4core-16gb TestAccept
3:07 azure-windows-latest-4core-16gb TestAccept
2:39 aws-windows-latest-4core-16gb TestAccept

@pietern
pietern force-pushed the execute-args branch 6 times, most recently from d67cf1d to 2fa82f1 Compare November 16, 2026 08:00
@pietern pietern added the aitools AI tools (databricks aitools) related changes label Nov 16, 2026
@pietern
pietern requested a review from simonfaltum November 16, 2026 14:30

@simonfaltum simonfaltum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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. PersistentPreRunE still logs os.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 because main passes os.Args[1:]. Now that Execute owns the args, you could put them on the context and log those instead.
  • [nit] .github/PULL_REQUEST_TEMPLATE.md: .agents/skills/pr-checklist/SKILL.md asks 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 ## Why and linking #7487. The commit message explains it better: lazily added subcommands need Execute to resolve the target command before cobra runs.

Comment thread cmd/root/root_test.go
},
}
require.NoError(t, Execute(t.Context(), cmd, nil))
assert.Empty(t, got)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

pietern and others added 2 commits November 16, 2026 15:08
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>
@pietern
pietern added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit 155fe6d Nov 16, 2026
28 checks passed
Base automatically changed from sync-options-values to main November 16, 2026 19:43
@pietern
pietern requested a review from a team as a code owner November 16, 2026 19:43
@pietern
pietern deleted the execute-args branch November 16, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aitools AI tools (databricks aitools) related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants