Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ parentPath = "/Workspace" + parentPath

**RULE: Do not add defensive `nil` checks for values the caller or framework is documented to always provide.** If a check exists "just in case", either remove it or attach a comment explaining why the invariant might be violated. Direct engine resource methods (`DoCreate`, `DoUpdate`, `RemapState`, etc.) never receive nil receivers or state from the framework, so extra nil-guards there are dead code.

**RULE: Use a non-resolving TLD reserved by [RFC 2606 §2](https://datatracker.ietf.org/doc/html/rfc2606#section-2) (`.test`, `.example`, `.invalid`, `.localhost`) for any test fixture host — `Config.Host`, `databricks.yml`'s `workspace.host`, `.databrickscfg`.** Real domains hit the SDK well-known endpoint resolver and can stall tests for ~5 minutes per call when the runner network can't fast-fail the lookup. The repo convention is `.test` (the TLD RFC 2606 specifically reserves "for use in testing"). See PR #5125 for prior history.

Where a panic is genuinely possible (e.g. `reflect.Type.Elem()` on a non-pointer, division by an empty slice's length), validate at the entry point and return an error.

# Error Handling
Expand Down
2 changes: 1 addition & 1 deletion bundle/config/validate/files_to_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func setupBundleForFilesToSyncTest(t *testing.T) *bundle.Bundle {

m := mocks.NewMockWorkspaceClient(t)
m.WorkspaceClient.Config = &sdkconfig.Config{
Host: "https://foo.com",
Host: "https://foo.test",
}

// The initialization logic in [sync.New] performs a check on the destination path.
Expand Down
2 changes: 1 addition & 1 deletion bundle/deploy/terraform/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestParseResourcesStateWithExistingStateFile(t *testing.T) {
"storage": "dbfs:/123456",
"target": "test_dev",
"timeouts": null,
"url": "https://test.com"
"url": "https://test.test"
},
"sensitive_attributes": []
}
Expand Down
2 changes: 1 addition & 1 deletion bundle/internal/schema/testdata/pass/job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bundle:
name: a job

workspace:
host: "https://myworkspace.com"
host: "https://myworkspace.test"
root_path: /abc

presets:
Expand Down
2 changes: 1 addition & 1 deletion bundle/internal/schema/testdata/pass/ml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bundle:
name: ML

workspace:
host: "https://myworkspace.com"
host: "https://myworkspace.test"
root_path: /abc

presets:
Expand Down
2 changes: 1 addition & 1 deletion bundle/internal/schema/testdata/pass/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bundle:
name: a pipeline

workspace:
host: "https://myworkspace.com"
host: "https://myworkspace.test"
root_path: /abc

presets:
Expand Down
2 changes: 1 addition & 1 deletion bundle/run/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestPipelineRunnerRestart(t *testing.T) {

m := mocks.NewMockWorkspaceClient(t)
m.WorkspaceClient.Config = &sdk_config.Config{
Host: "https://test.com",
Host: "https://test.test",
}
b.SetWorkpaceClient(m.WorkspaceClient)

Expand Down
14 changes: 7 additions & 7 deletions cmd/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@ func TestValidateProfileHostConflict(t *testing.T) {
// through Cobra's lifecycle (PreRunE on login) and that the root command's
// PersistentPreRunE is NOT shadowed (it initializes logging, IO, user agent).
func TestProfileHostConflictViaCobra(t *testing.T) {
// Point at a config file that has "profile-1" with host https://www.host1.com.
// Point at a config file that has "profile-1" with host https://www.host1.test.
t.Setenv("DATABRICKS_CONFIG_FILE", "./testdata/.databrickscfg")

ctx := cmdctx.GenerateExecId(t.Context())
cli := root.New(ctx)
cli.AddCommand(New())

// Set args: auth login --profile profile-1 --host https://other.host.com
// Set args: auth login --profile profile-1 --host https://other.host.test
cli.SetArgs([]string{
"auth", "login",
"--profile", "profile-1",
"--host", "https://other.host.com",
"--host", "https://other.host.test",
})

_, err := cli.ExecuteContextC(ctx)
require.Error(t, err)
assert.Contains(t, err.Error(), `--profile "profile-1" has host "https://www.host1.com", which conflicts with --host "https://other.host.com"`)
assert.Contains(t, err.Error(), `--profile "profile-1" has host "https://www.host1.test", which conflicts with --host "https://other.host.test"`)
assert.Contains(t, err.Error(), "Use --profile only to select a profile")
}

Expand All @@ -101,12 +101,12 @@ func TestProfileHostConflictTokenViaCobra(t *testing.T) {
cli.SetArgs([]string{
"auth", "token",
"--profile", "profile-1",
"--host", "https://other.host.com",
"--host", "https://other.host.test",
})

_, err := cli.ExecuteContextC(ctx)
require.Error(t, err)
assert.Contains(t, err.Error(), `--profile "profile-1" has host "https://www.host1.com", which conflicts with --host "https://other.host.com"`)
assert.Contains(t, err.Error(), `--profile "profile-1" has host "https://www.host1.test", which conflicts with --host "https://other.host.test"`)
}

// TestProfileHostCompatibleViaCobra verifies that matching --profile and --host
Expand All @@ -122,7 +122,7 @@ func TestProfileHostCompatibleViaCobra(t *testing.T) {
cli.SetArgs([]string{
"auth", "login",
"--profile", "profile-1",
"--host", "https://www.host1.com",
"--host", "https://www.host1.test",
})

_, err := cli.ExecuteContextC(ctx)
Expand Down
12 changes: 6 additions & 6 deletions cmd/auth/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestGetWorkspaceAuthStatus(t *testing.T) {

status, err := getAuthStatus(cmd, []string{}, showSensitive, func(cmd *cobra.Command, args []string) (*config.Config, bool, error) {
err := config.ConfigAttributes.ResolveFromStringMap(cfg, map[string]string{
"host": "https://test.com",
"host": "https://test.test",
"token": "test-token",
"auth_type": "azure-cli",
})
Expand All @@ -55,7 +55,7 @@ func TestGetWorkspaceAuthStatus(t *testing.T) {
require.NotNil(t, status)
require.Equal(t, "success", status.Status)
require.Equal(t, "test-user", status.Username)
require.Equal(t, "https://test.com", status.Details.Host)
require.Equal(t, "https://test.test", status.Details.Host)
require.Equal(t, "azure-cli", status.Details.AuthType)

require.Equal(t, "azure-cli", status.Details.Configuration["auth_type"].Value)
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestGetWorkspaceAuthStatusError(t *testing.T) {

status, err := getAuthStatus(cmd, []string{}, showSensitive, func(cmd *cobra.Command, args []string) (*config.Config, bool, error) {
err = config.ConfigAttributes.ResolveFromStringMap(cfg, map[string]string{
"host": "https://test.com",
"host": "https://test.test",
"token": "test-token",
"auth_type": "azure-cli",
})
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestGetWorkspaceAuthStatusSensitive(t *testing.T) {

status, err := getAuthStatus(cmd, []string{}, showSensitive, func(cmd *cobra.Command, args []string) (*config.Config, bool, error) {
err = config.ConfigAttributes.ResolveFromStringMap(cfg, map[string]string{
"host": "https://test.com",
"host": "https://test.test",
"token": "test-token",
"auth_type": "azure-cli",
})
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestGetAccountAuthStatus(t *testing.T) {
err = config.ConfigAttributes.ResolveFromStringMap(cfg, map[string]string{
"account_id": "test-account-id",
"username": "test-user",
"host": "https://test.com",
"host": "https://test.test",
"token": "test-token",
"auth_type": "azure-cli",
})
Expand All @@ -207,7 +207,7 @@ func TestGetAccountAuthStatus(t *testing.T) {
require.Equal(t, "success", status.Status)

require.Equal(t, "test-user", status.Username)
require.Equal(t, "https://test.com", status.Details.Host)
require.Equal(t, "https://test.test", status.Details.Host)
require.Equal(t, "azure-cli", status.Details.AuthType)
require.Equal(t, "test-account-id", status.AccountID)

Expand Down
16 changes: 8 additions & 8 deletions cmd/auth/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ func TestSetHost(t *testing.T) {
assert.Equal(t, "val from --host", authArguments.Host)

// Test setting host from flag with trailing slash is stripped
authArguments.Host = "https://www.host1.com/"
authArguments.Host = "https://www.host1.test/"
err = setHostAndAccountId(ctx, profile1, &authArguments, []string{})
assert.NoError(t, err)
assert.Equal(t, "https://www.host1.com", authArguments.Host)
assert.Equal(t, "https://www.host1.test", authArguments.Host)

// Test setting host from argument
authArguments.Host = ""
Expand All @@ -158,21 +158,21 @@ func TestSetHost(t *testing.T) {

// Test setting host from argument with trailing slash is stripped
authArguments.Host = ""
err = setHostAndAccountId(ctx, profile1, &authArguments, []string{"https://www.host1.com/"})
err = setHostAndAccountId(ctx, profile1, &authArguments, []string{"https://www.host1.test/"})
assert.NoError(t, err)
assert.Equal(t, "https://www.host1.com", authArguments.Host)
assert.Equal(t, "https://www.host1.test", authArguments.Host)

// Test setting host from profile
authArguments.Host = ""
err = setHostAndAccountId(ctx, profile1, &authArguments, []string{})
assert.NoError(t, err)
assert.Equal(t, "https://www.host1.com", authArguments.Host)
assert.Equal(t, "https://www.host1.test", authArguments.Host)

// Test setting host from profile
authArguments.Host = ""
err = setHostAndAccountId(ctx, profile2, &authArguments, []string{})
assert.NoError(t, err)
assert.Equal(t, "https://www.host2.com", authArguments.Host)
assert.Equal(t, "https://www.host2.test", authArguments.Host)

// Test host is not set. Should prompt.
authArguments.Host = ""
Expand Down Expand Up @@ -275,14 +275,14 @@ func TestLoadProfileByNameAndClusterID(t *testing.T) {
name: "cluster profile",
profile: "cluster-profile",
configFileEnv: "./testdata/.databrickscfg",
expectedHost: "https://www.host2.com",
expectedHost: "https://www.host2.test",
expectedClusterID: "cluster-from-config",
},
{
name: "profile from home directory (existing)",
profile: "cluster-profile",
homeDirOverride: "testdata",
expectedHost: "https://www.host2.com",
expectedHost: "https://www.host2.test",
expectedClusterID: "cluster-from-config",
},
{
Expand Down
6 changes: 3 additions & 3 deletions cmd/auth/testdata/.databrickscfg
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[profile-1]
host = https://www.host1.com
host = https://www.host1.test

[profile-2]
host = https://www.host2.com
host = https://www.host2.test

[account-profile]
host = https://accounts.cloud.databricks.com
account_id = id-from-profile

[cluster-profile]
host = https://www.host2.com
host = https://www.host2.test
cluster_id = cluster-from-config

[invalid-profile]
Expand Down
36 changes: 18 additions & 18 deletions cmd/root/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func setupDatabricksCfg(t *testing.T) {
homeEnvVar = "USERPROFILE"
}

cfg := []byte("[PROFILE-1]\nhost = https://a.com\ntoken = a\n[PROFILE-2]\nhost = https://a.com\ntoken = b\n")
cfg := []byte("[PROFILE-1]\nhost = https://a.test\ntoken = a\n[PROFILE-2]\nhost = https://a.test\ntoken = b\n")
err := os.WriteFile(filepath.Join(tempHomeDir, ".databrickscfg"), cfg, 0o644)
assert.NoError(t, err)

Expand Down Expand Up @@ -95,17 +95,17 @@ func TestBundleConfigureDefault(t *testing.T) {
}

cmd := emptyCommand(t)
diags := setupWithHost(t, cmd, "https://x.com")
diags := setupWithHost(t, cmd, "https://x.test")
require.Empty(t, diags)

assert.Equal(t, "https://x.com", cmdctx.ConfigUsed(cmd.Context()).Host)
assert.Equal(t, "https://x.test", cmdctx.ConfigUsed(cmd.Context()).Host)
}

func TestBundleConfigureWithMultipleMatches(t *testing.T) {
testutil.CleanupEnvironment(t)

cmd := emptyCommand(t)
diags := setupWithHost(t, cmd, "https://a.com")
diags := setupWithHost(t, cmd, "https://a.test")
require.Len(t, diags, 1)
assert.Contains(t, diags[0].Summary, "multiple profiles matched: PROFILE-1, PROFILE-2")
assert.Contains(t, diags[0].Summary, "Matching workspace profiles: PROFILE-1, PROFILE-2")
Expand All @@ -119,7 +119,7 @@ func TestBundleConfigureWithNonExistentProfileFlag(t *testing.T) {
err := cmd.Flag("profile").Value.Set("NOEXIST")
require.NoError(t, err)

diags := setupWithHost(t, cmd, "https://x.com")
diags := setupWithHost(t, cmd, "https://x.test")
require.Len(t, diags, 1)
assert.Contains(t, diags[0].Summary, "has no NOEXIST profile configured")
}
Expand All @@ -131,8 +131,8 @@ func TestBundleConfigureWithMismatchedProfile(t *testing.T) {
err := cmd.Flag("profile").Value.Set("PROFILE-1")
require.NoError(t, err)

diags := setupWithHost(t, cmd, "https://x.com")
assert.Equal(t, []diag.Diagnostic{{Summary: "cannot resolve bundle auth configuration: the host in the profile (https://a.com) doesn’t match the host configured in the bundle (https://x.com)"}}, diags)
diags := setupWithHost(t, cmd, "https://x.test")
assert.Equal(t, []diag.Diagnostic{{Summary: "cannot resolve bundle auth configuration: the host in the profile (https://a.test) doesn’t match the host configured in the bundle (https://x.test)"}}, diags)
}

func TestBundleConfigureWithCorrectProfile(t *testing.T) {
Expand All @@ -141,10 +141,10 @@ func TestBundleConfigureWithCorrectProfile(t *testing.T) {
cmd := emptyCommand(t)
err := cmd.Flag("profile").Value.Set("PROFILE-1")
require.NoError(t, err)
diags := setupWithHost(t, cmd, "https://a.com")
diags := setupWithHost(t, cmd, "https://a.test")

require.Empty(t, diags)
assert.Equal(t, "https://a.com", cmdctx.ConfigUsed(cmd.Context()).Host)
assert.Equal(t, "https://a.test", cmdctx.ConfigUsed(cmd.Context()).Host)
assert.Equal(t, "PROFILE-1", cmdctx.ConfigUsed(cmd.Context()).Profile)
}

Expand All @@ -154,8 +154,8 @@ func TestBundleConfigureWithMismatchedProfileEnvVariable(t *testing.T) {
t.Setenv("DATABRICKS_CONFIG_PROFILE", "PROFILE-1")
cmd := emptyCommand(t)

diags := setupWithHost(t, cmd, "https://x.com")
assert.Equal(t, []diag.Diagnostic{{Summary: "cannot resolve bundle auth configuration: the host in the profile (https://a.com) doesn’t match the host configured in the bundle (https://x.com)"}}, diags)
diags := setupWithHost(t, cmd, "https://x.test")
assert.Equal(t, []diag.Diagnostic{{Summary: "cannot resolve bundle auth configuration: the host in the profile (https://a.test) doesn’t match the host configured in the bundle (https://x.test)"}}, diags)
}

func TestBundleConfigureWithProfileFlagAndEnvVariable(t *testing.T) {
Expand All @@ -166,9 +166,9 @@ func TestBundleConfigureWithProfileFlagAndEnvVariable(t *testing.T) {
err := cmd.Flag("profile").Value.Set("PROFILE-1")
require.NoError(t, err)

diags := setupWithHost(t, cmd, "https://a.com")
diags := setupWithHost(t, cmd, "https://a.test")
require.Empty(t, diags)
assert.Equal(t, "https://a.com", cmdctx.ConfigUsed(cmd.Context()).Host)
assert.Equal(t, "https://a.test", cmdctx.ConfigUsed(cmd.Context()).Host)
assert.Equal(t, "PROFILE-1", cmdctx.ConfigUsed(cmd.Context()).Profile)
}

Expand All @@ -180,7 +180,7 @@ func TestBundleConfigureProfileDefault(t *testing.T) {

diags := setupWithProfile(t, cmd, "PROFILE-1")
require.Empty(t, diags)
assert.Equal(t, "https://a.com", cmdctx.ConfigUsed(cmd.Context()).Host)
assert.Equal(t, "https://a.test", cmdctx.ConfigUsed(cmd.Context()).Host)
assert.Equal(t, "a", cmdctx.ConfigUsed(cmd.Context()).Token)
assert.Equal(t, "PROFILE-1", cmdctx.ConfigUsed(cmd.Context()).Profile)
}
Expand All @@ -195,7 +195,7 @@ func TestBundleConfigureProfileFlag(t *testing.T) {

diags := setupWithProfile(t, cmd, "PROFILE-1")
require.Empty(t, diags)
assert.Equal(t, "https://a.com", cmdctx.ConfigUsed(cmd.Context()).Host)
assert.Equal(t, "https://a.test", cmdctx.ConfigUsed(cmd.Context()).Host)
assert.Equal(t, "b", cmdctx.ConfigUsed(cmd.Context()).Token)
assert.Equal(t, "PROFILE-2", cmdctx.ConfigUsed(cmd.Context()).Profile)
}
Expand All @@ -209,7 +209,7 @@ func TestBundleConfigureProfileEnvVariable(t *testing.T) {

diags := setupWithProfile(t, cmd, "PROFILE-1")
require.Empty(t, diags)
assert.Equal(t, "https://a.com", cmdctx.ConfigUsed(cmd.Context()).Host)
assert.Equal(t, "https://a.test", cmdctx.ConfigUsed(cmd.Context()).Host)
assert.Equal(t, "b", cmdctx.ConfigUsed(cmd.Context()).Token)
assert.Equal(t, "PROFILE-2", cmdctx.ConfigUsed(cmd.Context()).Profile)
}
Expand All @@ -225,7 +225,7 @@ func TestBundleConfigureProfileFlagAndEnvVariable(t *testing.T) {

diags := setupWithProfile(t, cmd, "PROFILE-1")
require.Empty(t, diags)
assert.Equal(t, "https://a.com", cmdctx.ConfigUsed(cmd.Context()).Host)
assert.Equal(t, "https://a.test", cmdctx.ConfigUsed(cmd.Context()).Host)
assert.Equal(t, "b", cmdctx.ConfigUsed(cmd.Context()).Token)
assert.Equal(t, "PROFILE-2", cmdctx.ConfigUsed(cmd.Context()).Profile)
}
Expand All @@ -240,7 +240,7 @@ func TestBundleConfigureMultiMatchInteractivePromptFires(t *testing.T) {

contents := `
workspace:
host: "https://a.com"
host: "https://a.test"
`
err := os.WriteFile(filepath.Join(rootPath, "databricks.yml"), []byte(contents), 0o644)
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions libs/auth/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ func TestAuthArgumentsFromConfig(t *testing.T) {
{
name: "all fields",
cfg: &config.Config{
Host: "https://myhost.com",
Host: "https://myhost.test",
AccountID: "acc-123",
WorkspaceID: "ws-456",
Profile: "my-profile",
DiscoveryURL: "https://myhost.com/oidc/accounts/acc-123/.well-known/oauth-authorization-server",
DiscoveryURL: "https://myhost.test/oidc/accounts/acc-123/.well-known/oauth-authorization-server",
},
want: AuthArguments{
Host: "https://myhost.com",
Host: "https://myhost.test",
AccountID: "acc-123",
WorkspaceID: "ws-456",
Profile: "my-profile",
DiscoveryURL: "https://myhost.com/oidc/accounts/acc-123/.well-known/oauth-authorization-server",
DiscoveryURL: "https://myhost.test/oidc/accounts/acc-123/.well-known/oauth-authorization-server",
},
},
}
Expand Down
Loading
Loading