From 28787b5ed56e7176c29816547ebc92a5bddcf958 Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Sat, 14 Nov 2026 23:49:25 +0000 Subject: [PATCH 1/6] air: suggest a working --output-dir when convert-to-dabs code is outside the bundle When code_source.root_path resolved outside the bundle directory, for example the getting-started Ray recipes that snapshot their parent directory with root_path: .., convert-to-dabs suggested setting sync.paths in a databricks.yml that it had not written. The error now names the resolved code directory and, for working-tree snapshots, the --output-dir value that converts the workload. Co-authored-by: Isaac --- cmd/air/convert_to_dabs.go | 8 +++++- cmd/air/convert_to_dabs_test.go | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/cmd/air/convert_to_dabs.go b/cmd/air/convert_to_dabs.go index 363bc07e4d7..48e114a24d4 100644 --- a/cmd/air/convert_to_dabs.go +++ b/cmd/air/convert_to_dabs.go @@ -264,7 +264,13 @@ func bundleCodeSourcePath(ctx context.Context, cfg *runConfig, configPath, bundl } rel, err := filepath.Rel(bundleAbs, root) if err != nil || !filepath.IsLocal(rel) { - return "", fmt.Errorf("code_source root_path %q is not inside the bundle directory %q; bundle deploy can only upload files under the bundle's sync root. Move the code inside the bundle, or set sync.paths in databricks.yml to a directory that contains both (note that widens what gets synced)", snap.RootPath, bundleDir) + remedy := "move the code inside the bundle directory" + // As in codeArtifactFor, only a working-tree snapshot can be bundled from a + // parent directory of the code. + if snap.Git == nil { + remedy = fmt.Sprintf("pass --output-dir %s to write the bundle to the code directory's parent, or %s", filepath.Dir(root), remedy) + } + return "", fmt.Errorf("code_source root_path %q (%s) is not inside the bundle directory %q, and bundle deploy only packages code inside the bundle; %s", snap.RootPath, root, bundleDir, remedy) } return localBundlePath(filepath.ToSlash(rel)), nil } diff --git a/cmd/air/convert_to_dabs_test.go b/cmd/air/convert_to_dabs_test.go index 1ac0a4f8c3c..a0d27393979 100644 --- a/cmd/air/convert_to_dabs_test.go +++ b/cmd/air/convert_to_dabs_test.go @@ -729,3 +729,49 @@ func TestConvertToDabsRejectsUnsupported(t *testing.T) { require.ErrorContains(t, err, "usage_policy_name is not yet supported") }) } + +// The getting-started Ray layout: the workload in ray/core snapshots its parent so it +// can include the shared ray/ray_bootstrap.sh. The error names an --output-dir that +// converts, and does not suggest editing a databricks.yml that was never written. +func TestConvertToDabsCodeOutsideBundleSuggestsOutputDir(t *testing.T) { + dir := t.TempDir() + recipe := filepath.Join(dir, "ray", "core") + require.NoError(t, os.MkdirAll(recipe, 0o700)) + require.NoError(t, os.WriteFile(filepath.Join(dir, "ray", "ray_bootstrap.sh"), []byte("#!/bin/bash\n"), 0o600)) + cfg := "experiment_name: ray-core\ncommand: bash ray_bootstrap.sh\n" + + "compute: {accelerator_type: GPU_1xA10, num_accelerators: 2}\n" + + "code_source:\n root_path: ..\n include_paths: [ray_bootstrap.sh, core]\n" + path := filepath.Join(recipe, "workload.yaml") + require.NoError(t, os.WriteFile(path, []byte(cfg), 0o600)) + loaded, err := loadRunConfig(path) + require.NoError(t, err) + + _, _, err = convertToDabs(t.Context(), loaded, path, recipe) + require.ErrorContains(t, err, "not inside the bundle") + assert.Contains(t, err.Error(), "--output-dir "+dir+" ") + assert.NotContains(t, err.Error(), "sync.paths") + + root, _, err := convertToDabs(t.Context(), loaded, path, dir) + require.NoError(t, err) + inc := get(t, root, "artifacts."+codeSourceArtifactKey+".include").MustSequence() + require.Len(t, inc, 2) + assert.Equal(t, "ray/ray_bootstrap.sh", inc[0].MustString()) + assert.Equal(t, "ray/core", inc[1].MustString()) +} + +// A git-pinned snapshot is archived from the bundle root, so a parent directory is +// not offered as the bundle root. +func TestConvertToDabsGitPinOutsideBundleDoesNotSuggestOutputDir(t *testing.T) { + outside := t.TempDir() + require.NoError(t, os.MkdirAll(filepath.Join(outside, "src"), 0o700)) + cfg := "experiment_name: outside\ncommand: python train.py\n" + + "compute: {accelerator_type: GPU_1xH100, num_accelerators: 1}\n" + + "code_source:\n root_path: " + filepath.Join(outside, "src") + "\n git:\n commit: abc123\n" + path := writeConfigFile(t, "run.yaml", cfg) + loaded, err := loadRunConfig(path) + require.NoError(t, err) + + _, _, err = convertToDabs(t.Context(), loaded, path, filepath.Dir(path)) + require.ErrorContains(t, err, "not inside the bundle") + assert.NotContains(t, err.Error(), "--output-dir") +} From 54a6caddabc2ac1e7459b924b200c262632366ba Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Sun, 15 Nov 2026 00:03:56 +0000 Subject: [PATCH 2/6] Add changelog entry Co-authored-by: Isaac --- .nextchanges/air/7640.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nextchanges/air/7640.md diff --git a/.nextchanges/air/7640.md b/.nextchanges/air/7640.md new file mode 100644 index 00000000000..b75ce0ec8e5 --- /dev/null +++ b/.nextchanges/air/7640.md @@ -0,0 +1 @@ +* `air convert-to-dabs` now suggests the `--output-dir` that converts a workload whose `code_source.root_path` is outside the bundle directory, instead of suggesting `sync.paths`. ([#7640](https://github.com/databricks/cli/pull/7640)) From 9c63d4700611880f5a8314e715c1c0b5373f08a4 Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Sun, 15 Nov 2026 06:20:13 +0000 Subject: [PATCH 3/6] air: do not suggest an --output-dir that already holds a bundle Sibling workloads that snapshot the same parent directory were all sent to it, so converting a second one there replaced the first bundle once the user passed --force. The hint now says when that directory already holds a databricks.yml instead of offering it, quotes the suggested path for the shell, and states the actual limit: the bundle convert-to-dabs writes packages only code inside its directory. The tests assert the full remedy text. Co-authored-by: Isaac --- cmd/air/convert_to_dabs.go | 28 ++++++++++++----- cmd/air/convert_to_dabs_test.go | 56 ++++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 21 deletions(-) diff --git a/cmd/air/convert_to_dabs.go b/cmd/air/convert_to_dabs.go index 48e114a24d4..e7acdb9b5bb 100644 --- a/cmd/air/convert_to_dabs.go +++ b/cmd/air/convert_to_dabs.go @@ -16,6 +16,7 @@ import ( "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/yamlsaver" + "github.com/databricks/cli/libs/shellquote" "github.com/spf13/cobra" ) @@ -264,17 +265,30 @@ func bundleCodeSourcePath(ctx context.Context, cfg *runConfig, configPath, bundl } rel, err := filepath.Rel(bundleAbs, root) if err != nil || !filepath.IsLocal(rel) { - remedy := "move the code inside the bundle directory" - // As in codeArtifactFor, only a working-tree snapshot can be bundled from a - // parent directory of the code. - if snap.Git == nil { - remedy = fmt.Sprintf("pass --output-dir %s to write the bundle to the code directory's parent, or %s", filepath.Dir(root), remedy) - } - return "", fmt.Errorf("code_source root_path %q (%s) is not inside the bundle directory %q, and bundle deploy only packages code inside the bundle; %s", snap.RootPath, root, bundleDir, remedy) + return "", codeOutsideBundleError(snap, root, bundleDir) } return localBundlePath(filepath.ToSlash(rel)), nil } +// codeOutsideBundleError explains a code directory outside the bundle directory. For +// a working-tree snapshot it names the code directory's parent as an --output-dir, +// unless that parent already holds a bundle: sibling workloads that share a code +// directory would each be sent there and replace one another's bundle. As in +// codeArtifactFor, a git snapshot is not offered a parent, which may be outside the +// repository. +func codeOutsideBundleError(snap *snapshotSourceConfig, root, bundleDir string) error { + remedy := "move the code inside the bundle directory" + if snap.Git == nil { + parent := filepath.Dir(root) + if _, err := os.Stat(filepath.Join(parent, "databricks.yml")); err == nil { + remedy = fmt.Sprintf("%q already holds a databricks.yml, and converting there would replace that bundle; pass --output-dir with another directory that contains the code directory, or %s", parent, remedy) + } else { + remedy = fmt.Sprintf("pass --output-dir %s to write the bundle to the code directory's parent, or %s", shellquote.BashArg(parent), remedy) + } + } + return fmt.Errorf("code_source root_path %q (%q) is not inside the bundle directory %q, and the bundle convert-to-dabs writes packages only code inside its directory; %s", snap.RootPath, root, bundleDir, remedy) +} + // nv builds a dyn.Value at "position" n: yamlsaver orders a map's keys by their // Location line, so assigning ascending n values fixes the emitted key order. // It routes through dyn.V so nested Go maps/slices are converted recursively, diff --git a/cmd/air/convert_to_dabs_test.go b/cmd/air/convert_to_dabs_test.go index a0d27393979..57548d25ee6 100644 --- a/cmd/air/convert_to_dabs_test.go +++ b/cmd/air/convert_to_dabs_test.go @@ -1,6 +1,7 @@ package aircmd import ( + "fmt" "os" "path/filepath" "strings" @@ -8,6 +9,7 @@ import ( "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/dyn" + "github.com/databricks/cli/libs/shellquote" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.yaml.in/yaml/v3" @@ -730,37 +732,62 @@ func TestConvertToDabsRejectsUnsupported(t *testing.T) { }) } -// The getting-started Ray layout: the workload in ray/core snapshots its parent so it -// can include the shared ray/ray_bootstrap.sh. The error names an --output-dir that -// converts, and does not suggest editing a databricks.yml that was never written. -func TestConvertToDabsCodeOutsideBundleSuggestsOutputDir(t *testing.T) { - dir := t.TempDir() - recipe := filepath.Join(dir, "ray", "core") - require.NoError(t, os.MkdirAll(recipe, 0o700)) +// rayLayoutConfig writes ray//workload.yaml under dir, snapshotting its parent +// (root_path: ..) to include the shared ray/ray_bootstrap.sh, and loads it. +func rayLayoutConfig(t *testing.T, dir, recipe string) (*runConfig, string) { + t.Helper() + recipeDir := filepath.Join(dir, "ray", recipe) + require.NoError(t, os.MkdirAll(recipeDir, 0o700)) require.NoError(t, os.WriteFile(filepath.Join(dir, "ray", "ray_bootstrap.sh"), []byte("#!/bin/bash\n"), 0o600)) - cfg := "experiment_name: ray-core\ncommand: bash ray_bootstrap.sh\n" + + cfg := "experiment_name: ray-" + recipe + "\ncommand: bash ray_bootstrap.sh\n" + "compute: {accelerator_type: GPU_1xA10, num_accelerators: 2}\n" + - "code_source:\n root_path: ..\n include_paths: [ray_bootstrap.sh, core]\n" - path := filepath.Join(recipe, "workload.yaml") + "code_source:\n root_path: ..\n include_paths: [ray_bootstrap.sh, " + recipe + "]\n" + path := filepath.Join(recipeDir, "workload.yaml") require.NoError(t, os.WriteFile(path, []byte(cfg), 0o600)) loaded, err := loadRunConfig(path) require.NoError(t, err) + return loaded, path +} + +// A workload whose root_path is its parent directory gets an --output-dir that +// converts it, not advice to edit a databricks.yml that was never written. +func TestConvertToDabsCodeOutsideBundleSuggestsOutputDir(t *testing.T) { + dir := t.TempDir() + loaded, path := rayLayoutConfig(t, dir, "core") - _, _, err = convertToDabs(t.Context(), loaded, path, recipe) + _, _, err := convertToDabs(t.Context(), loaded, path, filepath.Dir(path)) require.ErrorContains(t, err, "not inside the bundle") - assert.Contains(t, err.Error(), "--output-dir "+dir+" ") + assert.Contains(t, err.Error(), fmt.Sprintf("(%q)", filepath.Join(dir, "ray"))) + assert.Contains(t, err.Error(), "--output-dir "+shellquote.BashArg(dir)+" ") + assert.Contains(t, err.Error(), "or move the code inside the bundle directory") assert.NotContains(t, err.Error(), "sync.paths") root, _, err := convertToDabs(t.Context(), loaded, path, dir) require.NoError(t, err) + assert.Equal(t, ".", get(t, root, "artifacts."+codeSourceArtifactKey+".path").MustString()) inc := get(t, root, "artifacts."+codeSourceArtifactKey+".include").MustSequence() require.Len(t, inc, 2) assert.Equal(t, "ray/ray_bootstrap.sh", inc[0].MustString()) assert.Equal(t, "ray/core", inc[1].MustString()) } -// A git-pinned snapshot is archived from the bundle root, so a parent directory is -// not offered as the bundle root. +// Sibling workloads that share a code directory would all be sent to its parent, and +// converting a second one there would replace the first bundle. Once the parent holds +// a databricks.yml, it is not suggested. +func TestConvertToDabsCodeOutsideBundleSkipsParentWithBundle(t *testing.T) { + dir := t.TempDir() + rayLayoutConfig(t, dir, "core") + require.NoError(t, os.WriteFile(filepath.Join(dir, "databricks.yml"), []byte("bundle:\n name: ray-core\n"), 0o600)) + loaded, path := rayLayoutConfig(t, dir, "data") + + _, _, err := convertToDabs(t.Context(), loaded, path, filepath.Dir(path)) + require.ErrorContains(t, err, "not inside the bundle") + assert.Contains(t, err.Error(), fmt.Sprintf("%q already holds a databricks.yml", dir)) + assert.NotContains(t, err.Error(), "--output-dir "+shellquote.BashArg(dir)+" ") +} + +// A git-pinned snapshot is archived from the bundle root, and a parent of the code +// directory may be outside the repository, so no parent is offered. func TestConvertToDabsGitPinOutsideBundleDoesNotSuggestOutputDir(t *testing.T) { outside := t.TempDir() require.NoError(t, os.MkdirAll(filepath.Join(outside, "src"), 0o700)) @@ -773,5 +800,6 @@ func TestConvertToDabsGitPinOutsideBundleDoesNotSuggestOutputDir(t *testing.T) { _, _, err = convertToDabs(t.Context(), loaded, path, filepath.Dir(path)) require.ErrorContains(t, err, "not inside the bundle") + assert.Contains(t, err.Error(), "; move the code inside the bundle directory") assert.NotContains(t, err.Error(), "--output-dir") } From 86667834d3d1070b7748c2bd77a41bc6f5903623 Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Sun, 15 Nov 2026 06:22:21 +0000 Subject: [PATCH 4/6] Point the changelog entry at #7644 Co-authored-by: Isaac --- .nextchanges/air/7640.md | 1 - .nextchanges/air/7644.md | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 .nextchanges/air/7640.md create mode 100644 .nextchanges/air/7644.md diff --git a/.nextchanges/air/7640.md b/.nextchanges/air/7640.md deleted file mode 100644 index b75ce0ec8e5..00000000000 --- a/.nextchanges/air/7640.md +++ /dev/null @@ -1 +0,0 @@ -* `air convert-to-dabs` now suggests the `--output-dir` that converts a workload whose `code_source.root_path` is outside the bundle directory, instead of suggesting `sync.paths`. ([#7640](https://github.com/databricks/cli/pull/7640)) diff --git a/.nextchanges/air/7644.md b/.nextchanges/air/7644.md new file mode 100644 index 00000000000..b3eaf02d050 --- /dev/null +++ b/.nextchanges/air/7644.md @@ -0,0 +1 @@ +* `air convert-to-dabs` now suggests the `--output-dir` that converts a working-tree workload whose `code_source.root_path` is outside the bundle directory, instead of suggesting `sync.paths`. ([#7644](https://github.com/databricks/cli/pull/7644)) From 025d2abbccec5e71b70feb752504526d20df1c7c Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Sun, 15 Nov 2026 07:19:50 +0000 Subject: [PATCH 5/6] air: quote the suggested --output-dir for the user's shell, check every bundle file name - Move quoteArg from cmd/aitools to libs/shellquote as Arg, unchanged apart from the name, and use it for the suggested --output-dir. Bash quoting broke a pasted cmd.exe command on Windows; a path that no quoting keeps literal, such as one with a control character, gets generic wording. - Treat a parent holding any bundle file DABs accepts (databricks.yml, databricks.yaml, bundle.yml, bundle.yaml) as already holding a bundle. - Test a parent whose path has a space, and each bundle file name. Co-authored-by: Isaac --- cmd/air/convert_to_dabs.go | 21 +++++++++++++++--- cmd/air/convert_to_dabs_test.go | 38 ++++++++++++++++++++++++++------- cmd/aitools/recovery.go | 22 +++---------------- libs/shellquote/quote.go | 15 +++++++++++++ libs/shellquote/quote_test.go | 13 +++++++++++ 5 files changed, 79 insertions(+), 30 deletions(-) diff --git a/cmd/air/convert_to_dabs.go b/cmd/air/convert_to_dabs.go index e7acdb9b5bb..7c9af269462 100644 --- a/cmd/air/convert_to_dabs.go +++ b/cmd/air/convert_to_dabs.go @@ -8,9 +8,11 @@ import ( "os" "path" "path/filepath" + "runtime" "strconv" "strings" + "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/diag" @@ -280,15 +282,28 @@ func codeOutsideBundleError(snap *snapshotSourceConfig, root, bundleDir string) remedy := "move the code inside the bundle directory" if snap.Git == nil { parent := filepath.Dir(root) - if _, err := os.Stat(filepath.Join(parent, "databricks.yml")); err == nil { - remedy = fmt.Sprintf("%q already holds a databricks.yml, and converting there would replace that bundle; pass --output-dir with another directory that contains the code directory, or %s", parent, remedy) + if name := bundleFileIn(parent); name != "" { + remedy = fmt.Sprintf("%q already holds a bundle (%s), and converting there would replace it; pass --output-dir with another directory that contains the code directory, or %s", parent, name, remedy) + } else if quoted, ok := shellquote.Arg(runtime.GOOS, parent); ok { + remedy = fmt.Sprintf("pass --output-dir %s to write the bundle to the code directory's parent, or %s", quoted, remedy) } else { - remedy = fmt.Sprintf("pass --output-dir %s to write the bundle to the code directory's parent, or %s", shellquote.BashArg(parent), remedy) + remedy = "pass --output-dir with the code directory's parent, or " + remedy } } return fmt.Errorf("code_source root_path %q (%q) is not inside the bundle directory %q, and the bundle convert-to-dabs writes packages only code inside its directory; %s", snap.RootPath, root, bundleDir, remedy) } +// bundleFileIn returns the name of the bundle configuration file in dir, or "" when +// it has none. +func bundleFileIn(dir string) string { + for _, name := range config.FileNames { + if _, err := os.Stat(filepath.Join(dir, name)); err == nil { + return name + } + } + return "" +} + // nv builds a dyn.Value at "position" n: yamlsaver orders a map's keys by their // Location line, so assigning ascending n values fixes the emitted key order. // It routes through dyn.V so nested Go maps/slices are converted recursively, diff --git a/cmd/air/convert_to_dabs_test.go b/cmd/air/convert_to_dabs_test.go index 57548d25ee6..bc0d9d5e18c 100644 --- a/cmd/air/convert_to_dabs_test.go +++ b/cmd/air/convert_to_dabs_test.go @@ -4,9 +4,11 @@ import ( "fmt" "os" "path/filepath" + "runtime" "strings" "testing" + "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/shellquote" @@ -758,7 +760,9 @@ func TestConvertToDabsCodeOutsideBundleSuggestsOutputDir(t *testing.T) { _, _, err := convertToDabs(t.Context(), loaded, path, filepath.Dir(path)) require.ErrorContains(t, err, "not inside the bundle") assert.Contains(t, err.Error(), fmt.Sprintf("(%q)", filepath.Join(dir, "ray"))) - assert.Contains(t, err.Error(), "--output-dir "+shellquote.BashArg(dir)+" ") + quoted, ok := shellquote.Arg(runtime.GOOS, dir) + require.True(t, ok) + assert.Contains(t, err.Error(), "--output-dir "+quoted+" ") assert.Contains(t, err.Error(), "or move the code inside the bundle directory") assert.NotContains(t, err.Error(), "sync.paths") @@ -773,17 +777,35 @@ func TestConvertToDabsCodeOutsideBundleSuggestsOutputDir(t *testing.T) { // Sibling workloads that share a code directory would all be sent to its parent, and // converting a second one there would replace the first bundle. Once the parent holds -// a databricks.yml, it is not suggested. +// a bundle, under any of the names DABs accepts, it is not suggested. func TestConvertToDabsCodeOutsideBundleSkipsParentWithBundle(t *testing.T) { - dir := t.TempDir() - rayLayoutConfig(t, dir, "core") - require.NoError(t, os.WriteFile(filepath.Join(dir, "databricks.yml"), []byte("bundle:\n name: ray-core\n"), 0o600)) - loaded, path := rayLayoutConfig(t, dir, "data") + for _, name := range config.FileNames { + t.Run(name, func(t *testing.T) { + dir := t.TempDir() + rayLayoutConfig(t, dir, "core") + require.NoError(t, os.WriteFile(filepath.Join(dir, name), []byte("bundle:\n name: ray-core\n"), 0o600)) + loaded, path := rayLayoutConfig(t, dir, "data") + + _, _, err := convertToDabs(t.Context(), loaded, path, filepath.Dir(path)) + require.ErrorContains(t, err, "not inside the bundle") + assert.Contains(t, err.Error(), fmt.Sprintf("%q already holds a bundle (%s)", dir, name)) + assert.NotContains(t, err.Error(), "to write the bundle to the code directory's parent") + }) + } +} + +// The suggested directory is quoted for the user's shell, so a parent whose path +// has a space pastes as one argument. +func TestConvertToDabsCodeOutsideBundleQuotesOutputDir(t *testing.T) { + dir := filepath.Join(t.TempDir(), "my recipes") + loaded, path := rayLayoutConfig(t, dir, "core") _, _, err := convertToDabs(t.Context(), loaded, path, filepath.Dir(path)) require.ErrorContains(t, err, "not inside the bundle") - assert.Contains(t, err.Error(), fmt.Sprintf("%q already holds a databricks.yml", dir)) - assert.NotContains(t, err.Error(), "--output-dir "+shellquote.BashArg(dir)+" ") + quoted, ok := shellquote.Arg(runtime.GOOS, dir) + require.True(t, ok) + require.NotEqual(t, dir, quoted) + assert.Contains(t, err.Error(), "--output-dir "+quoted+" ") } // A git-pinned snapshot is archived from the bundle root, and a parent of the code diff --git a/cmd/aitools/recovery.go b/cmd/aitools/recovery.go index ebb02260ca3..ec52afb727a 100644 --- a/cmd/aitools/recovery.go +++ b/cmd/aitools/recovery.go @@ -13,7 +13,6 @@ import ( "slices" "strconv" "strings" - "unicode" "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/aitools/installer" @@ -53,7 +52,7 @@ func renderInstallCommand(goos string, inv installInvocation) (string, bool) { // the backslashes. filepath.ToSlash follows the host OS, not goos. path = strings.ReplaceAll(path, `\`, "/") } - path, ok := quoteArg(goos, path) + path, ok := shellquote.Arg(goos, path) if !ok { return "", false } @@ -65,7 +64,7 @@ func renderInstallCommand(goos string, inv installInvocation) (string, bool) { if inv.agents != "" { // Quoted like --skills: PowerShell reads a bare comma as the array // operator and would split the list into two arguments. - names, ok := quoteArg(goos, inv.agents) + names, ok := shellquote.Arg(goos, inv.agents) if !ok { return "", false } @@ -76,7 +75,7 @@ func renderInstallCommand(goos string, inv installInvocation) (string, bool) { } if inv.skills != "" { // Normalized as install parses it, so "a, b" pastes as one value. - skills, ok := quoteArg(goos, strings.Join(splitAndTrim(inv.skills), ",")) + skills, ok := shellquote.Arg(goos, strings.Join(splitAndTrim(inv.skills), ",")) if !ok { return "", false } @@ -91,21 +90,6 @@ func renderInstallCommand(goos string, inv installInvocation) (string, bool) { return strings.Join(args, " "), true } -// quoteArg quotes a flag value for the shell a user on goos pastes the printed -// command into, only when it needs it, so the common case stays readable: -// cmd.exe or PowerShell on Windows, a POSIX shell elsewhere. It reports false -// for a value no quoting keeps literal there, and for any value with a control -// character: a line break in a pasted command runs what follows it. -func quoteArg(goos, value string) (string, bool) { - if goos == "windows" { - return shellquote.WindowsArg(value) - } - if strings.ContainsFunc(value, unicode.IsControl) { - return "", false - } - return shellquote.BashArg(value), true -} - // commandText renders inv followed by extra flags, for printing after a colon. // When a value cannot be printed so that it pastes literally, it returns false // and a phrase asking for the user's own command with the flags in changed diff --git a/libs/shellquote/quote.go b/libs/shellquote/quote.go index fdc4a8bd5ef..434b9f97a45 100644 --- a/libs/shellquote/quote.go +++ b/libs/shellquote/quote.go @@ -77,3 +77,18 @@ func WindowsArg(s string) (string, bool) { trailing := len(s) - len(strings.TrimRight(s, `\`)) return `"` + s + strings.Repeat(`\`, trailing) + `"`, true } + +// Arg quotes a flag value for the shell a user on goos pastes a printed command +// into, only when it needs it, so the common case stays readable: cmd.exe or +// PowerShell on Windows, a POSIX shell elsewhere. It reports false for a value no +// quoting keeps literal there, and for any value with a control character: a line +// break in a pasted command runs what follows it. +func Arg(goos, value string) (string, bool) { + if goos == "windows" { + return WindowsArg(value) + } + if strings.ContainsFunc(value, unicode.IsControl) { + return "", false + } + return BashArg(value), true +} diff --git a/libs/shellquote/quote_test.go b/libs/shellquote/quote_test.go index 4ed53d3f508..0cfbfd12e6c 100644 --- a/libs/shellquote/quote_test.go +++ b/libs/shellquote/quote_test.go @@ -132,3 +132,16 @@ func TestWindowsArgRejectsWhatNoQuotingKeepsLiteral(t *testing.T) { }) } } + +func TestArg(t *testing.T) { + quoted, ok := Arg("linux", "/tmp/my dir") + assert.True(t, ok) + assert.Equal(t, "'/tmp/my dir'", quoted) + + quoted, ok = Arg("windows", `C:\my dir`) + assert.True(t, ok) + assert.Equal(t, `"C:\my dir"`, quoted) + + _, ok = Arg("linux", "/tmp/a\nb") + assert.False(t, ok) +} From 0ef8a37a61017ab0e37d83ecba3019befc640b1b Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Sun, 15 Nov 2026 23:49:50 +0000 Subject: [PATCH 6/6] air: add acceptance tests for the convert-to-dabs --output-dir suggestion Extend the convert-to-dabs script with a workload whose code_source is outside its directory (workloads/eval.yaml, root_path ../src). Converted before the in-place bundle exists, the error suggests --output-dir with the code directory's parent; converted after it, the error says that the parent already holds databricks.yml. A Repl keeps the quoted code directory path identical on Windows. Co-authored-by: Isaac --- acceptance/air/convert-to-dabs/output.txt | 10 ++++++++++ acceptance/air/convert-to-dabs/script | 7 +++++++ acceptance/air/convert-to-dabs/test.toml | 5 +++++ acceptance/air/convert-to-dabs/workloads/eval.yaml | 9 +++++++++ 4 files changed, 31 insertions(+) create mode 100644 acceptance/air/convert-to-dabs/workloads/eval.yaml diff --git a/acceptance/air/convert-to-dabs/output.txt b/acceptance/air/convert-to-dabs/output.txt index 707b03a2eec..72037334a3d 100644 --- a/acceptance/air/convert-to-dabs/output.txt +++ b/acceptance/air/convert-to-dabs/output.txt @@ -1,4 +1,9 @@ +=== code_source outside the bundle directory: the error suggests the code directory's parent as --output-dir + +>>> [CLI] air convert-to-dabs workloads/eval.yaml +Error: code_source root_path "../src" ("[TEST_TMP_DIR]/src") is not inside the bundle directory "workloads", and the bundle convert-to-dabs writes packages only code inside its directory; pass --output-dir [TEST_TMP_DIR] to write the bundle to the code directory's parent, or move the code inside the bundle directory + === convert an AIR run YAML into a DABs bundle (in place, next to the source) >>> [CLI] air convert-to-dabs train.yaml @@ -223,3 +228,8 @@ Workspace: Path: /Workspace/Users/[USERNAME]/.bundle/databricks-ai-v5-smoke-test/dev Validation OK! + +=== a parent that already holds a bundle is not suggested: converting there would replace it + +>>> [CLI] air convert-to-dabs workloads/eval.yaml +Error: code_source root_path "../src" ("[TEST_TMP_DIR]/src") is not inside the bundle directory "workloads", and the bundle convert-to-dabs writes packages only code inside its directory; "[TEST_TMP_DIR]" already holds a bundle (databricks.yml), and converting there would replace it; pass --output-dir with another directory that contains the code directory, or move the code inside the bundle directory diff --git a/acceptance/air/convert-to-dabs/script b/acceptance/air/convert-to-dabs/script index 5dea9e8ae3b..b0ae1894cd5 100644 --- a/acceptance/air/convert-to-dabs/script +++ b/acceptance/air/convert-to-dabs/script @@ -1,3 +1,7 @@ +title "code_source outside the bundle directory: the error suggests the code directory's parent as --output-dir" +# Runs first: the in-place conversion below writes databricks.yml into src's parent. +musterr trace $CLI air convert-to-dabs workloads/eval.yaml + title "convert an AIR run YAML into a DABs bundle (in place, next to the source)" trace $CLI air convert-to-dabs train.yaml @@ -31,3 +35,6 @@ trace grep -E 'environment_version|base_environment' databricks.yml title "the Databricks AI bundle validates" trace $CLI bundle validate + +title "a parent that already holds a bundle is not suggested: converting there would replace it" +musterr trace $CLI air convert-to-dabs workloads/eval.yaml diff --git a/acceptance/air/convert-to-dabs/test.toml b/acceptance/air/convert-to-dabs/test.toml index 956c8efc16e..bf2c71951f8 100644 --- a/acceptance/air/convert-to-dabs/test.toml +++ b/acceptance/air/convert-to-dabs/test.toml @@ -1,3 +1,8 @@ # convert-to-dabs writes the bundle in place (next to train.yaml + src/). These are # generated artifacts, not committed inputs, so exclude them from the repo-diff check. Ignore = ["databricks.yml", "generated_artifacts", "generated-b300", "generated-docker"] + +[[Repls]] +# Fix the quoted code directory path for Windows, where %q doubles its backslashes. +Old = 'TEST_TMP_DIR]\\\\src' +New = 'TEST_TMP_DIR]/src' diff --git a/acceptance/air/convert-to-dabs/workloads/eval.yaml b/acceptance/air/convert-to-dabs/workloads/eval.yaml new file mode 100644 index 00000000000..c7eabae7a93 --- /dev/null +++ b/acceptance/air/convert-to-dabs/workloads/eval.yaml @@ -0,0 +1,9 @@ +experiment_name: eval-smoke-test +command: python train.py --eval +compute: + accelerator_type: GPU_1xA10 + num_accelerators: 1 +code_source: + type: snapshot + snapshot: + root_path: ../src