diff --git a/bundle/config/mutator/apply_presets.go b/bundle/config/mutator/apply_presets.go index a376e303..9cec704e 100644 --- a/bundle/config/mutator/apply_presets.go +++ b/bundle/config/mutator/apply_presets.go @@ -223,11 +223,8 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos } if config.IsExplicitlyEnabled((b.Config.Presets.SourceLinkedDeployment)) { - root := b.SyncRootPath - isInWorkspace := strings.HasPrefix(root, "/Workspace/") - if isInWorkspace && dbr.RunsOnRuntime(ctx) { - b.Config.Workspace.FilePath = root - } else { + isDatabricksWorkspace := dbr.RunsOnRuntime(ctx) && strings.HasPrefix(b.SyncRootPath, "/Workspace/") + if !isDatabricksWorkspace { disabled := false b.Config.Presets.SourceLinkedDeployment = &disabled diags = diags.Extend(diag.Warningf("source-linked deployment is available only in the Databricks Workspace")) diff --git a/bundle/config/mutator/apply_presets_test.go b/bundle/config/mutator/apply_presets_test.go index 8aa2addd..dc56c27f 100644 --- a/bundle/config/mutator/apply_presets_test.go +++ b/bundle/config/mutator/apply_presets_test.go @@ -377,75 +377,63 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) { testContext := context.Background() enabled := true disabled := false - remotePath := "/Users/files" workspacePath := "/Workspace/user.name@company.com" tests := []struct { - bundlePath string - ctx context.Context - name string - initialValue *bool - expectedValue *bool - expectedFilePath string - expectedWarning string + bundlePath string + ctx context.Context + name string + initialValue *bool + expectedValue *bool + expectedWarning string }{ { - name: "preset enabled, bundle in Workspace, databricks runtime", - bundlePath: workspacePath, - ctx: dbr.MockRuntime(testContext, true), - initialValue: &enabled, - expectedValue: &enabled, - expectedFilePath: workspacePath, - expectedWarning: "", + name: "preset enabled, bundle in Workspace, databricks runtime", + bundlePath: workspacePath, + ctx: dbr.MockRuntime(testContext, true), + initialValue: &enabled, + expectedValue: &enabled, }, { - name: "preset enabled, bundle not in Workspace, databricks runtime", - bundlePath: "/Users/user.name@company.com", - ctx: dbr.MockRuntime(testContext, true), - initialValue: &enabled, - expectedValue: &disabled, - expectedFilePath: remotePath, - expectedWarning: "source-linked deployment is available only in the Databricks Workspace", + name: "preset enabled, bundle not in Workspace, databricks runtime", + bundlePath: "/Users/user.name@company.com", + ctx: dbr.MockRuntime(testContext, true), + initialValue: &enabled, + expectedValue: &disabled, + expectedWarning: "source-linked deployment is available only in the Databricks Workspace", }, { - name: "preset enabled, bundle in Workspace, not databricks runtime", - bundlePath: workspacePath, - ctx: dbr.MockRuntime(testContext, false), - initialValue: &enabled, - expectedValue: &disabled, - expectedFilePath: remotePath, - expectedWarning: "source-linked deployment is available only in the Databricks Workspace", + name: "preset enabled, bundle in Workspace, not databricks runtime", + bundlePath: workspacePath, + ctx: dbr.MockRuntime(testContext, false), + initialValue: &enabled, + expectedValue: &disabled, + expectedWarning: "source-linked deployment is available only in the Databricks Workspace", }, { - name: "preset disabled, bundle in Workspace, databricks runtime", - bundlePath: workspacePath, - ctx: dbr.MockRuntime(testContext, true), - initialValue: &disabled, - expectedValue: &disabled, - expectedFilePath: remotePath, + name: "preset disabled, bundle in Workspace, databricks runtime", + bundlePath: workspacePath, + ctx: dbr.MockRuntime(testContext, true), + initialValue: &disabled, + expectedValue: &disabled, }, { - name: "preset nil, bundle in Workspace, databricks runtime", - bundlePath: workspacePath, - ctx: dbr.MockRuntime(testContext, true), - initialValue: nil, - expectedValue: nil, - expectedFilePath: remotePath, + name: "preset nil, bundle in Workspace, databricks runtime", + bundlePath: workspacePath, + ctx: dbr.MockRuntime(testContext, true), + initialValue: nil, + expectedValue: nil, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { b := &bundle.Bundle{ - SyncRoot: vfs.MustNew(tt.bundlePath), SyncRootPath: tt.bundlePath, Config: config.Root{ Presets: config.Presets{ SourceLinkedDeployment: tt.initialValue, }, - Workspace: config.Workspace{ - FilePath: remotePath, - }, }, } @@ -458,7 +446,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) { require.Equal(t, tt.expectedWarning, diags[0].Summary) } - require.Equal(t, tt.expectedFilePath, b.Config.Workspace.FilePath) require.Equal(t, tt.expectedValue, b.Config.Presets.SourceLinkedDeployment) }) } diff --git a/bundle/config/mutator/process_target_mode_test.go b/bundle/config/mutator/process_target_mode_test.go index d6985bda..bf2129f9 100644 --- a/bundle/config/mutator/process_target_mode_test.go +++ b/bundle/config/mutator/process_target_mode_test.go @@ -524,14 +524,12 @@ func TestSourceLinkedDeploymentEnabled(t *testing.T) { b, diags := processSourceLinkedBundle(t, true) require.NoError(t, diags.Error()) assert.True(t, *b.Config.Presets.SourceLinkedDeployment) - assert.Equal(t, b.Config.Workspace.FilePath, b.SyncRootPath) } func TestSourceLinkedDeploymentDisabled(t *testing.T) { b, diags := processSourceLinkedBundle(t, false) require.NoError(t, diags.Error()) assert.False(t, *b.Config.Presets.SourceLinkedDeployment) - assert.NotEqual(t, b.Config.Workspace.FilePath, b.SyncRootPath) } func processSourceLinkedBundle(t *testing.T, presetEnabled bool) (*bundle.Bundle, diag.Diagnostics) { @@ -542,7 +540,6 @@ func processSourceLinkedBundle(t *testing.T, presetEnabled bool) (*bundle.Bundle b := mockBundle(config.Development) workspacePath := "/Workspace/lennart@company.com/" - b.SyncRoot = vfs.MustNew(workspacePath) b.SyncRootPath = workspacePath b.Config.Presets.SourceLinkedDeployment = &presetEnabled diff --git a/bundle/config/mutator/translate_paths.go b/bundle/config/mutator/translate_paths.go index 321fa5b3..1e2484c7 100644 --- a/bundle/config/mutator/translate_paths.go +++ b/bundle/config/mutator/translate_paths.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/databricks/cli/bundle" + "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/notebook" @@ -103,8 +104,13 @@ func (t *translateContext) rewritePath( return fmt.Errorf("path %s is not contained in sync root path", localPath) } - // Prefix remote path with its remote root path. - remotePath := path.Join(t.b.Config.Workspace.FilePath, filepath.ToSlash(localRelPath)) + var workspacePath string + if config.IsExplicitlyEnabled(t.b.Config.Presets.SourceLinkedDeployment) { + workspacePath = t.b.SyncRootPath + } else { + workspacePath = t.b.Config.Workspace.FilePath + } + remotePath := path.Join(workspacePath, filepath.ToSlash(localRelPath)) // Convert local path into workspace path via specified function. interp, err := fn(*p, localPath, localRelPath, remotePath)