From c6a2a950b545d7d15227cad65cdcba72c427efd9 Mon Sep 17 00:00:00 2001 From: Factory Local Trial Date: Mon, 2 Nov 2026 02:56:04 +0000 Subject: [PATCH] [factory] Fix qualified DABs behavior --- .../prepend-workspace-var/output.txt | 75 +++---------------- .../variables/prepend-workspace-var/script | 5 +- .../mutator/prepend_workspace_prefix.go | 4 + .../mutator/prepend_workspace_prefix_test.go | 35 +++++++++ bundle/phases/initialize.go | 2 + 5 files changed, 54 insertions(+), 67 deletions(-) diff --git a/acceptance/bundle/variables/prepend-workspace-var/output.txt b/acceptance/bundle/variables/prepend-workspace-var/output.txt index 81a62f511ea..322f3d3f389 100644 --- a/acceptance/bundle/variables/prepend-workspace-var/output.txt +++ b/acceptance/bundle/variables/prepend-workspace-var/output.txt @@ -1,67 +1,12 @@ -/Workspace should be prepended on all paths, but it is not the case: -Warning: required field "entry_point" is not set - at resources.jobs.my_job.tasks[0].python_wheel_task - in databricks.yml:26:13 - -Warning: required field "package_name" is not set - at resources.jobs.my_job.tasks[0].python_wheel_task - in databricks.yml:26:13 - { - "bundle": { - "environment": "dev", - "git": { - "bundle_root_path": "." - }, - "name": "test-bundle", - "target": "dev" - }, - "resources": { - "jobs": { - "my_job": { - "deployment": { - "kind": "BUNDLE", - "metadata_file_path": "/Users/[USERNAME]/path/to/root/state/metadata.json" - }, - "edit_mode": "UI_LOCKED", - "format": "MULTI_TASK", - "max_concurrent_runs": 1, - "name": "Untitled", - "queue": { - "enabled": true - }, - "tasks": [ - { - "existing_cluster_id": "500", - "python_wheel_task": { - "named_parameters": { - "conf-file": "/Users/[USERNAME]/path/to/root/files/path/to/config.yaml" - } - }, - "task_key": "" - } - ] - } - } - }, - "sync": { - "paths": [ - "." - ] - }, - "variables": { - "workspace_root": { - "default": "/Users/[USERNAME]", - "description": "root directory in the Databricks workspace to store the Declarative Automation Bundle and associated artifacts", - "value": "/Users/[USERNAME]" - } - }, - "workspace": { - "artifact_path": "/Users/[USERNAME]/path/to/root/artifacts", - "file_path": "/Users/[USERNAME]/path/to/root/files", - "profile": "profile_name", - "resource_path": "/Users/[USERNAME]/path/to/root/resources", - "root_path": "/Users/[USERNAME]/path/to/root", - "state_path": "/Users/[USERNAME]/path/to/root/state" - } + "target": "dev", + "root_path": "/Workspace/Users/[USERNAME]/path/to/root", + "file_path": "/Workspace/Users/[USERNAME]/path/to/root/files", + "conf_file": "/Workspace/Users/[USERNAME]/path/to/root/files/path/to/config.yaml" +} +{ + "target": "prod", + "root_path": "/Workspace/Shared/path/to/root", + "file_path": "/Workspace/Shared/path/to/root/files", + "conf_file": "/Workspace/Shared/path/to/root/files/path/to/config.yaml" } diff --git a/acceptance/bundle/variables/prepend-workspace-var/script b/acceptance/bundle/variables/prepend-workspace-var/script index e30ffb9c4f3..42dc66ae301 100644 --- a/acceptance/bundle/variables/prepend-workspace-var/script +++ b/acceptance/bundle/variables/prepend-workspace-var/script @@ -1,2 +1,3 @@ -echo /Workspace should be prepended on all paths, but it is not the case: #2181 -$CLI bundle validate -o json | jq 'del(.workspace.current_user)' +for target in dev prod; do + $CLI bundle validate -t "$target" -o json 2>/dev/null | jq '{target: .bundle.target, root_path: .workspace.root_path, file_path: .workspace.file_path, conf_file: .resources.jobs.my_job.tasks[0].python_wheel_task.named_parameters["conf-file"]}' +done diff --git a/bundle/config/mutator/prepend_workspace_prefix.go b/bundle/config/mutator/prepend_workspace_prefix.go index 45af605c5f9..deed1425b3a 100644 --- a/bundle/config/mutator/prepend_workspace_prefix.go +++ b/bundle/config/mutator/prepend_workspace_prefix.go @@ -45,6 +45,10 @@ func prependWorkspacePrefixTo(path string) string { return path } + if path == "/Workspace" || path == "/Volumes" { + return path + } + for _, prefix := range skipPrefixes { if strings.HasPrefix(path, prefix) { return path diff --git a/bundle/config/mutator/prepend_workspace_prefix_test.go b/bundle/config/mutator/prepend_workspace_prefix_test.go index 6c439247051..82e7a957531 100644 --- a/bundle/config/mutator/prepend_workspace_prefix_test.go +++ b/bundle/config/mutator/prepend_workspace_prefix_test.go @@ -106,3 +106,38 @@ func TestPrependWorkspaceForDefaultConfig(t *testing.T) { require.Equal(t, "/Workspace/Users/jane@doe.com/.bundle/test/dev/state", b.Config.Workspace.StatePath) require.Equal(t, "/Workspace/Users/jane@doe.com/.bundle/test/dev/resources", b.Config.Workspace.ResourcePath) } + +func TestFactory96162B875C12(t *testing.T) { + for _, root := range []string{"/Users/jane@doe.com", "/Shared"} { + t.Run(root, func(t *testing.T) { + b := &bundle.Bundle{ + Config: config.Root{ + Bundle: config.Bundle{Name: root}, + Workspace: config.Workspace{ + RootPath: "${bundle.name}/path/to/root", + }, + }, + } + + diags := bundle.ApplySeq(t.Context(), b, + DefineDefaultWorkspacePaths(), + PrependWorkspacePrefix(), + ResolveVariableReferencesWithoutResources(), + ) + require.NoError(t, diags.Error()) + require.Equal(t, root+"/path/to/root", b.Config.Workspace.RootPath) + + diags = bundle.Apply(t.Context(), b, PrependWorkspacePrefix()) + require.NoError(t, diags.Error()) + require.Equal(t, "/Workspace"+root+"/path/to/root", b.Config.Workspace.RootPath) + require.Equal(t, "/Workspace"+root+"/path/to/root/files", b.Config.Workspace.FilePath) + require.Equal(t, "/Workspace"+root+"/path/to/root/artifacts", b.Config.Workspace.ArtifactPath) + require.Equal(t, "/Workspace"+root+"/path/to/root/state", b.Config.Workspace.StatePath) + require.Equal(t, "/Workspace"+root+"/path/to/root/resources", b.Config.Workspace.ResourcePath) + }) + } + + for _, path := range []string{"/Workspace", "/Volumes"} { + require.Equal(t, path, prependWorkspacePrefixTo(path)) + } +} diff --git a/bundle/phases/initialize.go b/bundle/phases/initialize.go index ef74a786ca1..de19c3f3ff5 100644 --- a/bundle/phases/initialize.go +++ b/bundle/phases/initialize.go @@ -130,6 +130,8 @@ func Initialize(ctx context.Context, b *bundle.Bundle) { // Resolves variable references in configuration (except resources) using bundle, workspace, // and variables prefixes mutator.ResolveVariableReferencesWithoutResources(), + // Variable-based workspace paths can become absolute only after resolution. + mutator.PrependWorkspacePrefix(), // Check for invalid use of /Volumes in workspace paths validate.ValidateVolumePath(),