Skip to content
Open
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
5 changes: 3 additions & 2 deletions bundle/config/mutator/prepend_workspace_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions bundle/config/mutator/prepend_workspace_prefix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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{
Expand Down
Loading