From 6cd5c2a1ba5c7e3fd18fd19a17ba7f95278d5c1d Mon Sep 17 00:00:00 2001 From: "ben.hansen" Date: Fri, 20 Nov 2026 02:49:57 +0000 Subject: [PATCH 1/3] Suggest regenerating a matching workload bundle --- cmd/air/convert_to_dabs.go | 18 +++++++++++++++-- cmd/air/convert_to_dabs_test.go | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/cmd/air/convert_to_dabs.go b/cmd/air/convert_to_dabs.go index fdb7ad51f76..8422b38ab67 100644 --- a/cmd/air/convert_to_dabs.go +++ b/cmd/air/convert_to_dabs.go @@ -267,7 +267,7 @@ func bundleCodeSourcePath(ctx context.Context, cfg *runConfig, configPath, bundl } rel, err := filepath.Rel(bundleAbs, root) if err != nil || !filepath.IsLocal(rel) { - return "", codeOutsideBundleError(snap, root, bundleDir) + return "", codeOutsideBundleError(snap, root, bundleDir, cfg.ExperimentName) } return localBundlePath(filepath.ToSlash(rel)), nil } @@ -278,12 +278,15 @@ func bundleCodeSourcePath(ctx context.Context, cfg *runConfig, configPath, bundl // 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 { +func codeOutsideBundleError(snap *snapshotSourceConfig, root, bundleDir, experimentName string) error { remedy := "move the code inside the bundle directory" if snap.Git == nil { parent := filepath.Dir(root) if name := bundleFileIn(parent); name != "" { remedy = fmt.Sprintf("%s already holds a bundle (%s), and converting there would replace it; pass --output-dir with another directory that contains the code directory, or %s", quotedPath(parent), name, remedy) + if quoted, ok := shellquote.Arg(runtime.GOOS, parent); ok && isWorkloadBundle(parent, experimentName) { + remedy = fmt.Sprintf("pass --output-dir %s --force to replace this workload's bundle, or move the code inside the bundle directory", quoted) + } } 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 { @@ -293,6 +296,17 @@ func codeOutsideBundleError(snap *snapshotSourceConfig, root, bundleDir string) return fmt.Errorf("code_source root_path %q (%s) is not inside the bundle directory %q, and convert-to-dabs can package only code inside the bundle directory; %s", snap.RootPath, quotedPath(root), bundleDir, remedy) } +// writeBundle replaces databricks.yml only. An alternate or ambiguous root +// cannot be safely regenerated even if one configuration names the workload. +func isWorkloadBundle(dir, experimentName string) bool { + path, err := config.FileNames.FindInPath(dir) + if err != nil || filepath.Base(path) != "databricks.yml" || experimentName == "" { + return false + } + existing, diags := config.Load(path) + return !diags.HasError() && existing.Bundle.Name == experimentName +} + // quotedPath quotes a local path the way the --output-dir suggestion does, so a // Windows path keeps single backslashes instead of the doubled ones %q prints. It // falls back to %q for a path the user's shell can't quote, such as one with diff --git a/cmd/air/convert_to_dabs_test.go b/cmd/air/convert_to_dabs_test.go index 01f348b163b..a85b00dab4d 100644 --- a/cmd/air/convert_to_dabs_test.go +++ b/cmd/air/convert_to_dabs_test.go @@ -834,3 +834,38 @@ func TestConvertToDabsGitPinOutsideBundleDoesNotSuggestOutputDir(t *testing.T) { assert.Contains(t, err.Error(), "; move the code inside the bundle directory") assert.NotContains(t, err.Error(), "--output-dir") } + +func TestConvertToDabsReconvertSharedCode(t *testing.T) { + dir := t.TempDir() + _, path := rayLayoutConfig(t, dir, "core") + run := func(flags ...string) error { + cmd := newConvertToDabsCommand() + ctx, _ := cmdio.NewTestContextWithStderr(t.Context()) + cmd.SetContext(ctx) + cmd.SetArgs(append(flags, path)) + return cmd.Execute() + } + require.NoError(t, run("--output-dir", dir)) + quoted, ok := shellquote.Arg(runtime.GOOS, dir) + require.True(t, ok) + require.ErrorContains(t, run(), "--output-dir "+quoted+" --force") + require.NoError(t, run("--output-dir", dir, "--force")) + for _, content := range []string{"bundle: {name: ray-data}", "bundle: {}", "bundle: ["} { + require.NoError(t, os.WriteFile(filepath.Join(dir, "databricks.yml"), []byte(content), 0o600)) + err := run() + require.ErrorContains(t, err, "already holds a bundle") + assert.NotContains(t, err.Error(), "--force") + } + require.NoError(t, os.WriteFile(filepath.Join(dir, "databricks.yaml"), []byte("bundle: {name: ray-core}"), 0o600)) + for _, duplicate := range []bool{true, false} { + yml := filepath.Join(dir, "databricks.yml") + if duplicate { + require.NoError(t, os.WriteFile(yml, []byte("bundle: {name: ray-core}"), 0o600)) + } else { + require.NoError(t, os.Remove(yml)) + } + err := run() + require.ErrorContains(t, err, "already holds a bundle") + assert.NotContains(t, err.Error(), "--force") + } +} From d676c37de3fc0371c71807f58dc5ab705e7e3be6 Mon Sep 17 00:00:00 2001 From: "ben.hansen" Date: Fri, 20 Nov 2026 03:15:14 +0000 Subject: [PATCH 2/3] Clarify the workload bundle check and its command test --- .../air/convert-replace-workload-bundle.md | 1 + cmd/air/convert_to_dabs.go | 3 +- cmd/air/convert_to_dabs_test.go | 28 +++++++++++-------- 3 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 .nextchanges/air/convert-replace-workload-bundle.md diff --git a/.nextchanges/air/convert-replace-workload-bundle.md b/.nextchanges/air/convert-replace-workload-bundle.md new file mode 100644 index 00000000000..a14ff7735e7 --- /dev/null +++ b/.nextchanges/air/convert-replace-workload-bundle.md @@ -0,0 +1 @@ +* Fix the guidance from `air convert-to-dabs` when the suggested output directory already contains the workload’s bundle. diff --git a/cmd/air/convert_to_dabs.go b/cmd/air/convert_to_dabs.go index 8422b38ab67..f5f96122eec 100644 --- a/cmd/air/convert_to_dabs.go +++ b/cmd/air/convert_to_dabs.go @@ -296,8 +296,7 @@ func codeOutsideBundleError(snap *snapshotSourceConfig, root, bundleDir, experim return fmt.Errorf("code_source root_path %q (%s) is not inside the bundle directory %q, and convert-to-dabs can package only code inside the bundle directory; %s", snap.RootPath, quotedPath(root), bundleDir, remedy) } -// writeBundle replaces databricks.yml only. An alternate or ambiguous root -// cannot be safely regenerated even if one configuration names the workload. +// isWorkloadBundle requires a single databricks.yml because writeBundle replaces only that file. func isWorkloadBundle(dir, experimentName string) bool { path, err := config.FileNames.FindInPath(dir) if err != nil || filepath.Base(path) != "databricks.yml" || experimentName == "" { diff --git a/cmd/air/convert_to_dabs_test.go b/cmd/air/convert_to_dabs_test.go index a85b00dab4d..738efc582a4 100644 --- a/cmd/air/convert_to_dabs_test.go +++ b/cmd/air/convert_to_dabs_test.go @@ -835,24 +835,28 @@ func TestConvertToDabsGitPinOutsideBundleDoesNotSuggestOutputDir(t *testing.T) { assert.NotContains(t, err.Error(), "--output-dir") } +// reconvertSharedCode runs the conversion with the same arguments as a workload author. +func reconvertSharedCode(t *testing.T, path string, flags ...string) error { + t.Helper() + cmd := newConvertToDabsCommand() + ctx, _ := cmdio.NewTestContextWithStderr(t.Context()) + cmd.SetContext(ctx) + cmd.SetArgs(append(flags, path)) + return cmd.Execute() +} + func TestConvertToDabsReconvertSharedCode(t *testing.T) { dir := t.TempDir() _, path := rayLayoutConfig(t, dir, "core") - run := func(flags ...string) error { - cmd := newConvertToDabsCommand() - ctx, _ := cmdio.NewTestContextWithStderr(t.Context()) - cmd.SetContext(ctx) - cmd.SetArgs(append(flags, path)) - return cmd.Execute() - } - require.NoError(t, run("--output-dir", dir)) + + require.NoError(t, reconvertSharedCode(t, path, "--output-dir", dir)) quoted, ok := shellquote.Arg(runtime.GOOS, dir) require.True(t, ok) - require.ErrorContains(t, run(), "--output-dir "+quoted+" --force") - require.NoError(t, run("--output-dir", dir, "--force")) + require.ErrorContains(t, reconvertSharedCode(t, path), "--output-dir "+quoted+" --force") + require.NoError(t, reconvertSharedCode(t, path, "--output-dir", dir, "--force")) for _, content := range []string{"bundle: {name: ray-data}", "bundle: {}", "bundle: ["} { require.NoError(t, os.WriteFile(filepath.Join(dir, "databricks.yml"), []byte(content), 0o600)) - err := run() + err := reconvertSharedCode(t, path) require.ErrorContains(t, err, "already holds a bundle") assert.NotContains(t, err.Error(), "--force") } @@ -864,7 +868,7 @@ func TestConvertToDabsReconvertSharedCode(t *testing.T) { } else { require.NoError(t, os.Remove(yml)) } - err := run() + err := reconvertSharedCode(t, path) require.ErrorContains(t, err, "already holds a bundle") assert.NotContains(t, err.Error(), "--force") } From b3b2312304e36eadc43b4f3473bb2b6f07eac3f9 Mon Sep 17 00:00:00 2001 From: "ben.hansen" Date: Fri, 20 Nov 2026 03:49:40 +0000 Subject: [PATCH 3/3] Link the AIR changelog entry to its introducing PR --- .nextchanges/air/convert-replace-workload-bundle.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/air/convert-replace-workload-bundle.md b/.nextchanges/air/convert-replace-workload-bundle.md index a14ff7735e7..885b9da4218 100644 --- a/.nextchanges/air/convert-replace-workload-bundle.md +++ b/.nextchanges/air/convert-replace-workload-bundle.md @@ -1 +1 @@ -* Fix the guidance from `air convert-to-dabs` when the suggested output directory already contains the workload’s bundle. +* Fix the guidance from `air convert-to-dabs` when the suggested output directory already contains the workload’s bundle. ([#7835](https://github.com/databricks/cli/pull/7835))