From 1b7f80c014df45ad12dd6eea7145e460dedea800 Mon Sep 17 00:00:00 2001 From: "ben.hansen" Date: Fri, 20 Nov 2026 18:50:00 +0000 Subject: [PATCH 1/2] Guard AIR bundle conversion against existing bundle root aliases --- .../air/convert-to-dabs-existing-root.md | 1 + cmd/air/convert_to_dabs.go | 12 +++++--- cmd/air/convert_to_dabs_test.go | 28 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 .nextchanges/air/convert-to-dabs-existing-root.md diff --git a/.nextchanges/air/convert-to-dabs-existing-root.md b/.nextchanges/air/convert-to-dabs-existing-root.md new file mode 100644 index 00000000000..e0e4de27944 --- /dev/null +++ b/.nextchanges/air/convert-to-dabs-existing-root.md @@ -0,0 +1 @@ +* Reject an existing bundle configuration under any supported filename when running `databricks air convert-to-dabs` without `--force`. diff --git a/cmd/air/convert_to_dabs.go b/cmd/air/convert_to_dabs.go index fdb7ad51f76..6d8e882a5d8 100644 --- a/cmd/air/convert_to_dabs.go +++ b/cmd/air/convert_to_dabs.go @@ -631,10 +631,14 @@ func writeBundle(ctx context.Context, cfg *runConfig, configPath, dir string, fo return os.WriteFile(target, data, 0o600) } - bundlePath := filepath.Join(dir, "databricks.yml") + const bundleFileName = "databricks.yml" + bundlePath := filepath.Join(dir, bundleFileName) if !force { - if _, err := os.Stat(bundlePath); err == nil { - return nil, fmt.Errorf("databricks.yml already exists in %s; pass --force to overwrite or remove it", dir) + if name := bundleFileIn(dir); name != "" { + if name == bundleFileName { + return nil, fmt.Errorf("%s already exists in %s; pass --force to overwrite or remove it", name, dir) + } + return nil, fmt.Errorf("%s already exists in %s; move or remove it before converting", name, dir) } } // SaveAsYAML's force arg is passed true unconditionally: the collision check @@ -645,7 +649,7 @@ func writeBundle(ctx context.Context, cfg *runConfig, configPath, dir string, fo if err := quoteJobKey(bundlePath, bundleResourceKey(cfg.ExperimentName)); err != nil { return nil, err } - written := []string{"databricks.yml"} + written := []string{bundleFileName} // Launch artifacts (command.sh + sidecars) under generated_artifacts/. for _, item := range artifacts { diff --git a/cmd/air/convert_to_dabs_test.go b/cmd/air/convert_to_dabs_test.go index 01f348b163b..acfc2493db3 100644 --- a/cmd/air/convert_to_dabs_test.go +++ b/cmd/air/convert_to_dabs_test.go @@ -52,6 +52,34 @@ func TestConvertToDabsForceOverwrite(t *testing.T) { assert.Contains(t, string(regenerated), "ai_runtime_task") } +func TestConvertToDabsExistingBundleRoot(t *testing.T) { + for _, name := range config.FileNames { + t.Run(name, func(t *testing.T) { + path := writeConfigFile(t, "run.yaml", minimalConfig+"code_source:\n root_path: ./src\n") + dir := filepath.Dir(path) + require.NoError(t, os.Mkdir(filepath.Join(dir, "src"), 0o700)) + loaded, err := loadRunConfig(path) + require.NoError(t, err) + existing := filepath.Join(dir, name) + edited := []byte("# hand-edited\n") + require.NoError(t, os.WriteFile(existing, edited, 0o600)) + + _, err = writeBundle(t.Context(), loaded, path, dir, false) + want := fmt.Sprintf("%s already exists in %s; move or remove it before converting", name, dir) + if name == "databricks.yml" { + want = fmt.Sprintf("databricks.yml already exists in %s; pass --force to overwrite or remove it", dir) + } + require.EqualError(t, err, want) + found, err := config.FileNames.FindInPath(dir) + require.NoError(t, err) + assert.Equal(t, existing, found) + kept, err := os.ReadFile(existing) + require.NoError(t, err) + assert.Equal(t, edited, kept) + }) + } +} + // command.sh is the user's command copied verbatim — convert injects no cd. The // launcher exports $CODE_SOURCE_PATH and runs the command in the launch dir without // cd-ing, so (as under air run) the command owns its own cd; convert must not add one, From 232b0c7fedd5637899ad47dc0a1481082515cc85 Mon Sep 17 00:00:00 2001 From: "ben.hansen" Date: Fri, 20 Nov 2026 18:51:07 +0000 Subject: [PATCH 2/2] Link AIR changelog entry to its introducing PR --- .nextchanges/air/convert-to-dabs-existing-root.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/air/convert-to-dabs-existing-root.md b/.nextchanges/air/convert-to-dabs-existing-root.md index e0e4de27944..eb8079eb80d 100644 --- a/.nextchanges/air/convert-to-dabs-existing-root.md +++ b/.nextchanges/air/convert-to-dabs-existing-root.md @@ -1 +1 @@ -* Reject an existing bundle configuration under any supported filename when running `databricks air convert-to-dabs` without `--force`. +* Reject an existing bundle configuration under any supported filename when running `databricks air convert-to-dabs` without `--force`. ([#7853](https://github.com/databricks/cli/pull/7853))