Skip to content

acceptance: use templates for bundle_default_profile scenarios#5270

Open
janniklasrose wants to merge 6 commits into
mainfrom
janniklasrose/default-profile-test-templates
Open

acceptance: use templates for bundle_default_profile scenarios#5270
janniklasrose wants to merge 6 commits into
mainfrom
janniklasrose/default-profile-test-templates

Conversation

@janniklasrose
Copy link
Copy Markdown
Contributor

Summary

Follow-up to #5214 (per pietern's review comment).

Replace the inline heredocs in acceptance/auth/bundle_default_profile/script with three committed templates:

  • databricks.yml.no-host.tmpl — bundle with neither workspace.host nor workspace.profile. Used for the "default_profile is honored" and "--profile overrides" phases.
  • databricks.yml.with-host.tmpl — pins workspace.host: $DATABRICKS_HOST. envsubst fills in the test server URL before each invocation.
  • databricks.yml.with-profile.tmpl — pins workspace.profile: other.

Before each phase the script overwrites the active databricks.yml from the relevant template. The per-scenario subdirectories (./bundle-with-host, ./bundle-with-profile) and the cd calls are gone — the active bundle is always at the test root.

Stacked on #5266 (sethome-absolute fix). The base will auto-retarget to main once #5266 merges.

output.txt is unchanged across the refactor: both engine variants (terraform and direct) produce byte-identical output to the pre-refactor run.

Test plan

  • go test ./acceptance -run TestAccept/auth/bundle_default_profile -v passes for both DATABRICKS_BUNDLE_ENGINE=terraform and =direct.
  • ./task fmt-q and ./task lint-q clean.

This pull request and its description were written by Isaac.

sethome exported HOME (and USERPROFILE) as the relative path the caller
passed in (typically "./home"). The SDK expands `~/.databrickscfg`
against $HOME at lookup time, so the moment a test cd's into a child
directory, the cfg "disappears": helpers like
databrickscfg.GetConfiguredDefaultProfile silently return "" because
the relative path no longer points at a real file. That made it easy
to write tests that look like they exercise default_profile resolution
but actually only succeed because the cfg lookup short-circuits.

Resolve $1 to an absolute path with `cd && pwd` (portable on
macOS/Linux/Windows-MSYS) before exporting. With this fix, the
acceptance/auth/bundle_default_profile "workspace.profile pinned"
sub-case correctly fails when the Workspace.Profile == "" guard in
cmd/root/bundle.go configureProfile is removed; previously it passed
either way.

Output for the same directory's "Bundle with workspace.host" sub-case
also changes: with the cfg now reachable from the bundle subdir, the
SDK's host-based lookup finds the matching profile and validate
succeeds instead of failing with "default auth: cannot configure
default credentials".

Co-authored-by: Isaac
81d9297 changed sethome to export an absolute HOME so the SDK can
locate ~/.databrickscfg after a test cd's. The SDK now reports paths
relative to the absolute HOME, which surfaces in user-visible output as
[TEST_TMP_DIR]/home/.databrickscfg (or [HOME]/.zshrc where the test
registers a HOME replacement). The four committed outputs predated the
fix and still expected the relative ./home form; regenerated with
./task test-update.

Co-authored-by: Isaac
The previous fix resolved $home with `cd && pwd` to give HOME and
USERPROFILE an absolute path. On Git Bash (MSYS), plain `pwd` returns
Unix-style /c/... paths that the native Windows Go binary can't open,
so the SDK silently fails to load ~/.databrickscfg and tests like
cmd/api/default-profile (no auth resolves) and cmd/api/workspace-id-none
(profile not read; SDK back-fills WorkspaceID from host metadata) fail
on Windows only.

Use `pwd -W` for USERPROFILE on MSYS/Cygwin to emit the mixed C:/...
form Windows file APIs accept. HOME keeps the Unix-style path bash
itself wants.

Co-authored-by: Isaac
The absolute-path resolution (cd && pwd) introduced in 81d9297 works
on macOS/Linux but emits Unix-style /c/... paths on Git Bash, which the
native Windows Go binary can't open; the follow-up adb452f fixed the
CLI path with `pwd -W` but broke tests like cmd/completion that compare
the bash $HOME placeholder against the CLI's USERPROFILE-derived output.

Revert sethome to the original simple form and restore the four
outputs regenerated in f893006 to their pre-fix relative-./home
forms. bundle_default_profile keeps its sub-cases but the cd'ing
variants short-circuit on a missing cfg again (same expected output as
before 81d9297). A separate PR will revisit the test setup to make
absolute HOME work cleanly across platforms.

Co-authored-by: Isaac
sethome exported HOME (and USERPROFILE) as the relative path the caller
passed in (typically "./home"). The SDK expands `~/.databrickscfg`
against $HOME at lookup time, so the moment a test cd's into a child
directory the cfg "disappears": helpers like
databrickscfg.GetConfiguredDefaultProfile silently return "" because
the relative path no longer points at a real file. That made it easy
to write tests that look like they exercise default_profile resolution
but actually only succeed because the cfg lookup short-circuits.

Resolve $1 to an absolute path with `cd && pwd` before exporting. On
Git Bash (MSYS) plain `pwd` returns Unix-style /c/... paths that the
native Windows Go binary can't open, so use `pwd -W` to get the mixed
C:/... form. Use the same form for both HOME and USERPROFILE so tests
like cmd/completion (which registers `$HOME` as the `[HOME]`
replacement) match the CLI's USERPROFILE-derived output on Windows.

Regenerate the four affected outputs.

Co-authored-by: Isaac
Replace inline heredocs and per-scenario subdirectories
(./bundle-with-host, ./bundle-with-profile) with three committed
template files: databricks.yml.{no-host,with-host,with-profile}.tmpl.
The script copies (or envsubsts, for the host-pinned template) the
active template into databricks.yml before each phase, so the active
bundle is always at the test root.

Follows pietern's suggestion in #5214.

Co-authored-by: Isaac
@github-actions
Copy link
Copy Markdown
Contributor

Waiting for approval

Could not determine reviewers from git history.
Round-robin suggestion: @Divyansh-db

Eligible reviewers: @Divyansh-db, @chrisst, @hectorcast-db, @mihaimitrea-db, @parthban-db, @rauchy, @renaudhartert-db, @simonfaltum, @tanmay-db, @tejaskochar-db

Suggestions based on git history. See OWNERS for ownership rules.

Base automatically changed from janniklasrose/sethome-absolute to main May 19, 2026 13:22
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.

1 participant