Skip to content

Test sync option builders without a root command - #7485

Merged
pietern merged 1 commit into
mainfrom
sync-options-values
Nov 16, 2026
Merged

pietern merged 1 commit into
mainfrom
sync-options-values

Conversation

@pietern

@pietern pietern commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Changes

databricks sync and databricks bundle sync build their options from a *cobra.Command, so their tests created a full root command with root.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 sync moves from the builder into RunE, 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 --output and --profile.

This pull request and its description were written by Isaac.

@pietern
pietern requested review from a team as code owners November 11, 2026 16:37
@pietern
pietern added this pull request to stack #7488 November 11, 2026 16:37
@github-actions github-actions Bot added the DABs DABs related issues label Nov 11, 2026
@eng-dev-ecosystem-bot

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

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: e5f2afa

Run: 43895944082

Env 🔄​flaky 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 270 15 8:36
💚​ aws-windows-latest-4core-16gb 1 272 13 7:40
💚​ azure linux-2core-8gb 1 269 15 10:32
💚​ azure-windows-latest-4core-16gb 1 271 13 8:05
🔄​ gcp linux-2core-8gb 2 1 268 15 12:14
💚​ gcp-windows-latest-4core-16gb 1 272 13 9:13
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
🔄​ TestFsCpDirToDirFileNotOverwritten ✅​p ✅​p ✅​p ✅​p 🔄​f ✅​p
🔄​ TestFsCpDirToDirFileNotOverwritten/uc-volumes_to_uc-volumes ✅​p ✅​p ✅​p ✅​p 🔄​f ✅​p
Top 4 slowest tests (at least 2 minutes):
duration env testname
4:26 azure-windows-latest-4core-16gb TestAccept
3:20 gcp-windows-latest-4core-16gb TestAccept
3:11 aws-windows-latest-4core-16gb TestAccept
2:08 azure linux-2core-8gb TestFilerWorkspaceFilesExtensionsReadDir

@pietern
pietern force-pushed the sync-options-values branch 5 times, most recently from a93d90a to 083a314 Compare November 16, 2026 08:00
@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 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

  1. syncOptionsFromBundle in cmd/sync/sync.go has no production caller: RunE only calls syncOptionsFromArgs and the command sets SkipLoadBundle, so only TestSyncOptionsFromBundle reaches 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 error is declared at line 193, and the new if err := root.ExactArgs(2)(cmd, args) at line 195 declares a second err that hides it. ctx := cmd.Context() is then declared after cmd.Context() was already passed to the builder. Consider ctx := cmd.Context(), then the args check, then opts, err := f.syncOptionsFromArgs(ctx, root.OutputType(cmd), cmd.OutOrStdout(), args), and drop the var declarations.

Comment thread cmd/sync/sync.go
var err error

opts, err = f.syncOptionsFromArgs(cmd, args)
if err := root.ExactArgs(2)(cmd, args); err != nil {

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.

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

Comment thread cmd/sync/sync_test.go Outdated
Comment on lines +58 to +59
// Flags that sync defines with the names or shorthands of the root's
// --output and --profile flags would shadow them.

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] .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>
@pietern
pietern force-pushed the sync-options-values branch from 083a314 to e5f2afa Compare November 16, 2026 15:20
@pietern
pietern added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit eef814f Nov 16, 2026
27 checks passed
@pietern
pietern deleted the sync-options-values 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

DABs DABs related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants