Skip to content

Commit 2cee048

Browse files
pieternclaude
andcommitted
Prevent SDK from invoking az during cmd/root tests
The SDK upgrade to v0.117.0 changed credential resolution such that Azure CLI auth is attempted even for non-Azure hosts. This causes `az account show` to be invoked during tests that go through auth resolution, adding ~0.5-2.5s per test and writing `.azure/` cache files into the source tree. Clear PATH in auth tests to prevent the SDK from finding `az`. For the bundle loader test, restrict PATH to system directories instead since the bundle loader currently requires a shell to be available (fixing that separately). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent b50013c commit 2cee048

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

cmd/root/auth_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ func TestAccountClientOrPrompt(t *testing.T) {
8888
0o755)
8989
require.NoError(t, err)
9090
t.Setenv("DATABRICKS_CONFIG_FILE", configFile)
91-
t.Setenv("PATH", "/nothing")
91+
// Clear PATH to prevent the SDK from invoking external tools (e.g. az) during auth resolution.
92+
t.Setenv("PATH", "")
9293

9394
t.Run("Prompt if nothing is specified", func(t *testing.T) {
9495
expectPrompts(t, accountPromptFn, &config.Config{})
@@ -157,7 +158,8 @@ func TestWorkspaceClientOrPrompt(t *testing.T) {
157158
0o755)
158159
require.NoError(t, err)
159160
t.Setenv("DATABRICKS_CONFIG_FILE", configFile)
160-
t.Setenv("PATH", "/nothing")
161+
// Clear PATH to prevent the SDK from invoking external tools (e.g. az) during auth resolution.
162+
t.Setenv("PATH", "")
161163

162164
t.Run("Prompt if nothing is specified", func(t *testing.T) {
163165
expectPrompts(t, workspacePromptFn, &config.Config{})
@@ -248,6 +250,8 @@ func TestMustAccountClientErrorsWithNoDatabricksCfg(t *testing.T) {
248250

249251
func TestMustAnyClientCanCreateWorkspaceClient(t *testing.T) {
250252
testutil.CleanupEnvironment(t)
253+
// Clear PATH to prevent the SDK from invoking external tools (e.g. az) during auth resolution.
254+
t.Setenv("PATH", "")
251255

252256
dir := t.TempDir()
253257
configFile := filepath.Join(dir, ".databrickscfg")
@@ -276,6 +280,8 @@ func TestMustAnyClientCanCreateWorkspaceClient(t *testing.T) {
276280

277281
func TestMustAnyClientCanCreateAccountClient(t *testing.T) {
278282
testutil.CleanupEnvironment(t)
283+
// Clear PATH to prevent the SDK from invoking external tools (e.g. az) during auth resolution.
284+
t.Setenv("PATH", "")
279285

280286
dir := t.TempDir()
281287
configFile := filepath.Join(dir, ".databrickscfg")
@@ -305,6 +311,8 @@ func TestMustAnyClientCanCreateAccountClient(t *testing.T) {
305311

306312
func TestMustAnyClientWithEmptyDatabricksCfg(t *testing.T) {
307313
testutil.CleanupEnvironment(t)
314+
// Clear PATH to prevent the SDK from invoking external tools (e.g. az) during auth resolution.
315+
t.Setenv("PATH", "")
308316

309317
dir := t.TempDir()
310318
configFile := filepath.Join(dir, ".databrickscfg")

cmd/root/bundle_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ workspace:
8585

8686
func TestBundleConfigureDefault(t *testing.T) {
8787
testutil.CleanupEnvironment(t)
88+
// Restrict PATH to system directories to prevent the SDK from invoking
89+
// external tools (e.g. az) during auth resolution.
90+
// Bundle loading requires a shell so PATH cannot be fully cleared.
91+
if runtime.GOOS == "windows" {
92+
t.Setenv("PATH", `C:\Windows\System32`)
93+
} else {
94+
t.Setenv("PATH", "/usr/bin:/bin")
95+
}
8896

8997
cmd := emptyCommand(t)
9098
diags := setupWithHost(t, cmd, "https://x.com")

0 commit comments

Comments
 (0)