diff --git a/bundle/config/mutator/prepend_workspace_prefix.go b/bundle/config/mutator/prepend_workspace_prefix.go index 616759ee4f..3124244c85 100644 --- a/bundle/config/mutator/prepend_workspace_prefix.go +++ b/bundle/config/mutator/prepend_workspace_prefix.go @@ -41,7 +41,7 @@ func (m *prependWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) di v, err = dyn.MapByPattern(v, pattern, func(p dyn.Path, pv dyn.Value) (dyn.Value, error) { path, ok := pv.AsString() if !ok { - return dyn.InvalidValue, fmt.Errorf("expected string, got %s", v.Kind()) + return dyn.InvalidValue, fmt.Errorf("expected string, got %s", pv.Kind()) } // Skip prefixing if the path does not start with /, it might be variable reference or smth else. @@ -55,7 +55,8 @@ func (m *prependWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) di } } - return dyn.NewValue("/Workspace"+path, v.Locations()), nil + // Use pv's locations, not the root v's, so diagnostics point at the original config line. + return dyn.NewValue("/Workspace"+path, pv.Locations()), nil }) if err != nil { return dyn.InvalidValue, err diff --git a/bundle/config/mutator/prepend_workspace_prefix_test.go b/bundle/config/mutator/prepend_workspace_prefix_test.go index b4c3f4ddaa..93b3acde92 100644 --- a/bundle/config/mutator/prepend_workspace_prefix_test.go +++ b/bundle/config/mutator/prepend_workspace_prefix_test.go @@ -5,6 +5,8 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/config" + "github.com/databricks/cli/bundle/internal/bundletest" + "github.com/databricks/cli/libs/dyn" "github.com/databricks/databricks-sdk-go/service/iam" "github.com/stretchr/testify/require" ) @@ -63,6 +65,23 @@ func TestPrependWorkspacePrefix(t *testing.T) { } } +func TestPrependWorkspacePrefixPreservesLocations(t *testing.T) { + b := &bundle.Bundle{ + Config: config.Root{ + Workspace: config.Workspace{ + RootPath: "/Users/test", + }, + }, + } + locations := []dyn.Location{{File: "databricks.yml", Line: 42, Column: 5}} + bundletest.SetLocation(b, "workspace.root_path", locations) + + diags := bundle.Apply(t.Context(), b, PrependWorkspacePrefix()) + require.Empty(t, diags) + require.Equal(t, "/Workspace/Users/test", b.Config.Workspace.RootPath) + require.Equal(t, locations, b.Config.GetLocations("workspace.root_path")) +} + func TestPrependWorkspaceForDefaultConfig(t *testing.T) { b := &bundle.Bundle{ Config: config.Root{