Skip to content

Commit 6da414b

Browse files
authored
Fix labs installer to work in non-interactive mode with env var auth (#3735)
## Changes When authentication is configured via environment variables, `askWorkspaceProfile()` was failing because it checked for a profile name instead of checking if auth is actually configured. This made labs installers fail when running from non-interactive terminals (Cursor, specifically). The fix makes `askWorkspaceProfile()` consistent with `askCluster()` and `askWarehouse()`, which both check if their values are already set before prompting. ## Why When running tests from Cursor, I saw the following failures after #3709: Failing Tests: * TestInstallerWorksForReleases * TestInstallerWorksForDevelopment Both tests fail with the error: ``` login: ask for workspace: profile: not in an interactive terminal ``` ## Tests The tests that previously failed on a non-interactive terminal now pass.
1 parent 739a132 commit 6da414b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cmd/labs/project/installer_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,13 @@ func TestInstallerWorksForDevelopment(t *testing.T) {
371371

372372
// development installer assumes it's in the active virtualenv
373373
ctx = env.Set(ctx, "PYTHON_BIN", py)
374+
375+
// Set up authentication via environment variables to avoid prompting in non-interactive mode
376+
ctx = env.Set(ctx, "DATABRICKS_HOST", server.URL)
377+
ctx = env.Set(ctx, "DATABRICKS_TOKEN", "...")
378+
ctx = env.Set(ctx, "DATABRICKS_CLUSTER_ID", "abc-id")
379+
ctx = env.Set(ctx, "DATABRICKS_WAREHOUSE_ID", "efg-id")
380+
374381
home, _ := env.UserHomeDir(ctx)
375382
err = os.WriteFile(filepath.Join(home, ".databrickscfg"), []byte(fmt.Sprintf(`
376383
[profile-one]

cmd/labs/project/login.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ func (lc *loginConfig) askWorkspaceProfile(ctx context.Context, cfg *config.Conf
5050
lc.WorkspaceProfile = cfg.Profile
5151
return err
5252
}
53+
// Check if authentication is already configured (e.g., via environment variables).
54+
// This is consistent with askCluster() and askWarehouse() which check if their
55+
// values are already set before prompting.
56+
if lc.isAuthConfigured(cfg) {
57+
return err
58+
}
5359
if !cmdio.IsPromptSupported(ctx) {
5460
return ErrNotInTTY
5561
}

0 commit comments

Comments
 (0)