Skip to content

Remove import-time side effects from bundle/config and databrickscfg#5526

Open
simonfaltum wants to merge 2 commits into
mainfrom
simonfaltum/b52-import-side-effects
Open

Remove import-time side effects from bundle/config and databrickscfg#5526
simonfaltum wants to merge 2 commits into
mainfrom
simonfaltum/b52-import-side-effects

Conversation

@simonfaltum

Copy link
Copy Markdown
Member

Why

Found during a full-repo review of the CLI. Two packages mutate process-global state at import time:

  • bundle/config has an init() that exports DATABRICKS_CLI_PATH into the process environment. This runs in every importer, including test binaries and code generators, where os.Args[0] is not the CLI and the resulting value is wrong.
  • libs/databrickscfg has an init() that flips the process-global ini.DefaultHeader option, affecting every user of the ini package in the process even when no databrickscfg file is ever written.

Changes

Before, importing these packages was enough to trigger the side effects; now they only happen when the CLI binary starts or when a config file is actually written.

  • The DATABRICKS_CLI_PATH export moves from bundle/config/workspace.go to main.go, with the original condition and comment preserved. It runs before command execution, so it is still set before any SDK auth resolution and before any child process is spawned.
  • libs/databrickscfg/ops.go enables ini.DefaultHeader lazily via sync.OnceFunc from writeConfigFile, the single function through which all profile writes (SaveToProfile, DeleteProfile) go.

Behavior is unchanged for the CLI binary itself. Existing tests lock both behaviors: TestSaveToProfile_NewFileWithoutDefault asserts the [DEFAULT] header in written files, and the no-auth and multi-profile acceptance tests assert DATABRICKS_CLI_PATH shows up in SDK auth error output. A new test in main_test.go guards against reintroducing the env export in a package init.

Test plan

  • go test . ./bundle/config ./libs/databrickscfg ./cmd/configure ./cmd/auth
  • go test ./acceptance -run 'TestAccept/bundle/run/scripts/no-auth|TestAccept/bundle/multi_profile|TestAccept/cmd/configure' (outputs unchanged, so the binary still exports the variable before SDK config resolution and still writes the [DEFAULT] header)
  • go test ./acceptance -run 'TestAccept/bundle/run/inline-script/no-auth|TestAccept/auth'
  • New unit test TestImportDoesNotSetCliPathEnv in main_test.go
  • ./task fmt-q, lint on touched packages, ./task checks

This pull request and its description were written by Isaac.

bundle/config's init() exported DATABRICKS_CLI_PATH into the process
environment of every importer, including test binaries and generators.
Move the export to main so only the CLI binary itself sets it.

libs/databrickscfg's init() flipped the process-global ini.DefaultHeader
option at import time. Enable it lazily on first config file write
instead, via sync.OnceFunc.

Behavior is unchanged for the CLI binary.

Co-authored-by: Isaac
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Approval status: pending

/bundle/ - needs approval

Files: bundle/config/workspace.go
Suggested: @denik
Also eligible: @pietern, @janniklasrose, @anton-107, @andrewnester, @shreyas-goenka, @lennartkats-db

/libs/databrickscfg/ - needs approval

Files: libs/databrickscfg/ops.go
Suggested: @tanmay-db
Also eligible: @mihaimitrea-db, @renaudhartert-db, @hectorcast-db, @parthban-db, @Divyansh-db, @tejaskochar-db, @chrisst, @rauchy

General files (require maintainer)

Files: main.go, main_test.go
Based on git history:

  • @denik -- recent work in bundle/config/, libs/databrickscfg/

Any maintainer (@andrewnester, @anton-107, @denik, @pietern, @shreyas-goenka, @renaudhartert-db) can approve all areas.
See OWNERS for ownership rules.

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Commit: bdbfcbf

Run: 27255528594

Env 💚​RECOVERED 🙈​SKIP ✅​pass 🙈​skip Time
💚​ aws linux 7 15 261 928 7:34
💚​ aws windows 7 15 263 926 10:08
💚​ aws-ucws linux 7 15 357 842 7:09
💚​ aws-ucws windows 7 15 359 840 12:06
💚​ azure linux 1 17 264 926 6:08
💚​ azure windows 1 17 266 924 10:49
💚​ azure-ucws linux 1 17 362 838 7:57
💚​ azure-ucws windows 1 17 364 836 11:51
💚​ gcp linux 1 17 260 929 7:20
22 interesting tests: 15 SKIP, 7 RECOVERED
Test Name aws linux aws windows aws-ucws linux aws-ucws windows azure linux azure windows azure-ucws linux azure-ucws windows gcp linux
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
🙈​ TestAccept/bundle/invariant/no_drift 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/permissions 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
💚​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions 💚​R 💚​R 💚​R 💚​R 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
💚​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions/DATABRICKS_BUNDLE_ENGINE=direct 💚​R 💚​R 💚​R 💚​R
💚​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions/DATABRICKS_BUNDLE_ENGINE=terraform 💚​R 💚​R 💚​R 💚​R
💚​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/without_permissions 💚​R 💚​R 💚​R 💚​R 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
💚​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/without_permissions/DATABRICKS_BUNDLE_ENGINE=direct 💚​R 💚​R 💚​R 💚​R
💚​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/without_permissions/DATABRICKS_BUNDLE_ENGINE=terraform 💚​R 💚​R 💚​R 💚​R
🙈​ TestAccept/bundle/resources/postgres_branches/basic 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_branches/recreate 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_branches/replace_existing 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_branches/update_protected 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_branches/without_branch_id 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_endpoints/basic 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_endpoints/recreate 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_projects/update_display_name 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/synced_database_tables/basic 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_endpoints/drift/recreated_same_name 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_indexes/basic 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_indexes/grants/select 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/ssh/connection 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
Top 27 slowest tests (at least 2 minutes):
duration env testname
6:13 azure windows TestAccept
6:10 azure-ucws windows TestAccept
5:57 aws-ucws windows TestAccept
5:52 aws windows TestAccept
4:26 gcp linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
3:59 gcp linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
3:20 aws linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
3:06 aws-ucws linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:59 aws-ucws windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:54 azure linux TestAccept
2:53 aws linux TestAccept
2:51 azure-ucws windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:50 azure windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:49 azure-ucws linux TestAccept
2:49 gcp linux TestAccept
2:49 aws windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:47 azure linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:46 aws-ucws linux TestAccept
2:43 aws linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:43 azure-ucws windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:41 aws windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:37 aws-ucws linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:35 azure linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:34 azure-ucws linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:29 aws-ucws windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:24 azure windows TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:22 azure-ucws linux TestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct

Co-authored-by: Isaac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants