Skip to content

Commit 3d4eede

Browse files
pieternclaude
andauthored
Prevent SDK from invoking az during cmd/root tests (#4710)
## Summary - Clear `PATH` in `cmd/root` auth tests to prevent the Go SDK (v0.117.0+) from shelling out to `az account show` during credential resolution - For `TestBundleConfigureDefault`, restrict `PATH` to system directories instead of clearing it fully — the bundle loader's script hook mutator currently requires a shell to be present even when no scripts are configured (fixing that separately) - Normalize existing `PATH="/nothing"` in prompt tests to `PATH=""` The SDK upgrade to v0.117.0 (databricks/databricks-sdk-go#1505, bumped in #4631) removed per-strategy cloud guards from Azure CLI credentials, causing `az` to be probed on all platforms regardless of the configured host. This added ~0.5–2.5s per affected test and wrote `.azure/` cache files into the source tree. Verified on macOS and Windows. ## Test plan - [x] `go test -count=1 ./cmd/root` passes on macOS (1.2s, down from 5.2s) - [x] `go test -count=1 ./cmd/root` passes on Windows (0.19s) - [x] No `.azure/` or `Library/` directories created in `cmd/root/` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cb3c326 commit 3d4eede

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)