Repository navigation
Test sync option builders without a root command - #7485
Conversation
✅ Integration test reportCommit: e5f2afa
Top 4 slowest tests (at least 2 minutes):
|
a93d90a to
083a314
Compare
simonfaltum
left a comment
There was a problem hiding this comment.
🤖 Automated review from simonfaltum's review agent (pr-review skill) at 083a314. Each finding was verified against the code; simonfaltum may follow up.
No blocking issues found, approving. 3 non-blocking comment(s) and 1 question(s) below.
This PR changes the sync and bundle sync option builders to take the context, output type and stdout instead of a *cobra.Command, so their tests no longer need root.New(). It also moves the two-argument check for sync into RunE without changing the CLI's error. The refactor preserves behavior and CI is green. One non-blocking gap: the one-argument databricks sync ./dir case lost its only test, and the commit message says it moved to an acceptance test, but it didn't. There are also two small nits (a shadowed err in RunE, and the new tests' doc comments) and a question about the unused syncOptionsFromBundle in cmd/sync.
Questions
syncOptionsFromBundleincmd/sync/sync.gohas no production caller:RunEonly callssyncOptionsFromArgsand the command setsSkipLoadBundle, so onlyTestSyncOptionsFromBundlereaches it. Since this PR already changes its signature, would you rather delete it and its test here, or leave that for a follow-up? (non-blocking)
Accepted answers
- Why check ExactArgs(2) in RunE rather than Args?
Comments outside the changed lines
- [nit]
cmd/sync/sync.go:203:var err erroris declared at line 193, and the newif err := root.ExactArgs(2)(cmd, args)at line 195 declares a seconderrthat hides it.ctx := cmd.Context()is then declared aftercmd.Context()was already passed to the builder. Considerctx := cmd.Context(), then the args check, thenopts, err := f.syncOptionsFromArgs(ctx, root.OutputType(cmd), cmd.OutOrStdout(), args), and drop thevardeclarations.
| var err error | ||
|
|
||
| opts, err = f.syncOptionsFromArgs(cmd, args) | ||
| if err := root.ExactArgs(2)(cmd, args); err != nil { |
There was a problem hiding this comment.
[nice to have] The commit message says the argument-count cases "move to the sync-without-args acceptance test", but the PR changes no acceptance files, and acceptance/cmd/sync-without-args only runs databricks sync with no arguments. The deleted TestSyncOptionsFromArgsRequiredTwoArgs was the only test of the one-argument case (databricks sync ./dir, which should fail with "accepts 2 arg(s), received 1"). If this ExactArgs(2) check were dropped from RunE, syncOptionsFromArgs would panic on args[1] and no test would fail. Add a one-argument invocation to acceptance/cmd/sync-without-args/script (e.g. trace musterr $CLI sync .), or reword the commit message.
| // Flags that sync defines with the names or shorthands of the root's | ||
| // --output and --profile flags would shadow them. |
There was a problem hiding this comment.
[nit] .agents/rules/comments.md asks Go doc comments to start with the function name. This one and the one on TestBundleSyncDoesNotShadowRootFlags (cmd/bundle/sync_test.go:15-16) start with "Flags that ...". Both also say a conflicting shorthand "would shadow" the root flag. A local flag with the same name does shadow it (the #5493 bug), but a different flag using -o or -p makes pflag panic when cobra merges the root's flags. Suggest something like: // TestSyncDoesNotShadowRootFlags checks that sync defines no local --output or --profile, which would hide the root's flags, and no -o or -p shorthand, which would conflict with them.
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>
083a314 to
e5f2afa
Compare
Changes
databricks syncanddatabricks bundle syncbuild their options from a*cobra.Command, so their tests created a full root command withroot.New()to get there. The builders now take only what they use: the context, output type, stdout, and args or bundle. The tests call them directly.The two-argument check for
syncmoves from the builder intoRunE, so the CLI's error is unchanged.This reduces usage of
root.New()ahead of making it private later in this stack.Tests
Existing unit and acceptance tests. The shorthand tests now check that neither command defines flags that shadow the root's
--outputand--profile.This pull request and its description were written by Isaac.