From 36112ed603854f8d5df8b90edc092d0524359fbe Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Thu, 19 Nov 2026 19:31:18 +0000 Subject: [PATCH 1/3] aitools: test that deprecated experimental aliases mirror stable commands ## Changes Adds unit tests for the hidden `databricks experimental aitools` command group in `experimental/aitools/cmd/aitools_test.go`. Only tests change. - `TestExperimentalAitoolsSubcommands` checks that the group is hidden and has exactly these subcommands: `install`, `list`, `skills`, `tools`, `uninstall`, `update`, `version`. - `TestDeprecatedAliasesMirrorStableCommands` builds both `databricks aitools` and `databricks experimental aitools`. For each deprecated alias (`install`, `update`, `uninstall`, `list`, `version`) it checks that: - the alias is hidden and its deprecation notice reads `use "databricks aitools " instead.` - the stable command is visible and not deprecated - `Use`, `Short` and `Long` are the same on both - both have the same flags, compared by name, shorthand, type, default, hidden and deprecated state, and usage text ## Why The skills-management commands moved from `databricks experimental aitools ` to `databricks aitools `. The old paths still work as hidden, deprecated aliases. These tests fail if the two drift apart, for example when a flag is added to only one of them or the deprecation notice points to the wrong command. Without them, scripts that still use the old paths could break with no test catching it. ## Tests The new tests pass when run with `go test ./experimental/aitools/cmd/`. Co-authored-by: Isaac --- experimental/aitools/cmd/aitools_test.go | 73 ++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 experimental/aitools/cmd/aitools_test.go diff --git a/experimental/aitools/cmd/aitools_test.go b/experimental/aitools/cmd/aitools_test.go new file mode 100644 index 00000000000..71dc39d9604 --- /dev/null +++ b/experimental/aitools/cmd/aitools_test.go @@ -0,0 +1,73 @@ +package aitools + +import ( + "fmt" + "slices" + "testing" + + aitoolscmd "github.com/databricks/cli/cmd/aitools" + "github.com/databricks/cli/cmd/root" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func subcommand(t *testing.T, parent *cobra.Command, name string) *cobra.Command { + t.Helper() + for _, c := range parent.Commands() { + if c.Name() == name { + return c + } + } + require.FailNowf(t, "missing subcommand", "%q has no %q subcommand", parent.CommandPath(), name) + return nil +} + +// flagSummary lists a command's own flags with everything a user sees in --help. +func flagSummary(cmd *cobra.Command) []string { + var out []string + cmd.Flags().VisitAll(func(f *pflag.Flag) { + out = append(out, fmt.Sprintf("--%s -%s %s default=%q hidden=%t deprecated=%q: %s", + f.Name, f.Shorthand, f.Value.Type(), f.DefValue, f.Hidden, f.Deprecated, f.Usage)) + }) + slices.Sort(out) + return out +} + +func TestExperimentalAitoolsSubcommands(t *testing.T) { + cmd := NewAitoolsCmd() + assert.True(t, cmd.Hidden) + + var names []string + for _, c := range cmd.Commands() { + names = append(names, c.Name()) + } + slices.Sort(names) + assert.Equal(t, []string{"install", "list", "skills", "tools", "uninstall", "update", "version"}, names) +} + +// TestDeprecatedAliasesMirrorStableCommands checks that each deprecated +// `databricks experimental aitools ` alias stays a hidden copy of +// `databricks aitools ` with a notice that points to the new path. +func TestDeprecatedAliasesMirrorStableCommands(t *testing.T) { + stable := root.NewCommand(t.Context(), aitoolscmd.Spec) + experimental := NewAitoolsCmd() + + for _, name := range []string{"install", "update", "uninstall", "list", "version"} { + t.Run(name, func(t *testing.T) { + s := subcommand(t, stable, name) + a := subcommand(t, experimental, name) + + assert.True(t, a.Hidden) + assert.Equal(t, fmt.Sprintf(`use "databricks aitools %s" instead.`, name), a.Deprecated) + assert.False(t, s.Hidden) + assert.Empty(t, s.Deprecated) + + assert.Equal(t, s.Use, a.Use) + assert.Equal(t, s.Short, a.Short) + assert.Equal(t, s.Long, a.Long) + assert.Equal(t, flagSummary(s), flagSummary(a)) + }) + } +} From bb41534a3577d2a32053416845f69f299728dae8 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Thu, 19 Nov 2026 20:23:10 +0000 Subject: [PATCH 2/3] aitools: move alias tests to the aitools_test package Co-authored-by: Isaac --- experimental/aitools/cmd/aitools_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/experimental/aitools/cmd/aitools_test.go b/experimental/aitools/cmd/aitools_test.go index 71dc39d9604..66662c44c71 100644 --- a/experimental/aitools/cmd/aitools_test.go +++ b/experimental/aitools/cmd/aitools_test.go @@ -1,4 +1,4 @@ -package aitools +package aitools_test import ( "fmt" @@ -7,6 +7,7 @@ import ( aitoolscmd "github.com/databricks/cli/cmd/aitools" "github.com/databricks/cli/cmd/root" + aitools "github.com/databricks/cli/experimental/aitools/cmd" "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/stretchr/testify/assert" @@ -36,7 +37,7 @@ func flagSummary(cmd *cobra.Command) []string { } func TestExperimentalAitoolsSubcommands(t *testing.T) { - cmd := NewAitoolsCmd() + cmd := aitools.NewAitoolsCmd() assert.True(t, cmd.Hidden) var names []string @@ -52,7 +53,7 @@ func TestExperimentalAitoolsSubcommands(t *testing.T) { // `databricks aitools ` with a notice that points to the new path. func TestDeprecatedAliasesMirrorStableCommands(t *testing.T) { stable := root.NewCommand(t.Context(), aitoolscmd.Spec) - experimental := NewAitoolsCmd() + experimental := aitools.NewAitoolsCmd() for _, name := range []string{"install", "update", "uninstall", "list", "version"} { t.Run(name, func(t *testing.T) { From ef060273aa474ce1f6a593634480c434fea34d60 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:03:15 +0000 Subject: [PATCH 3/3] aitools: compare inherited flags and share alias names in alias tests Compare local and inherited flags (with NoOptDefVal) so a persistent flag added to only one parent is caught, keep the alias names in one list used by both tests, and build the experimental group under an experimental parent so failures name the tree that lacks a subcommand. Co-authored-by: Isaac --- experimental/aitools/cmd/aitools_test.go | 38 ++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/experimental/aitools/cmd/aitools_test.go b/experimental/aitools/cmd/aitools_test.go index 66662c44c71..a7700811c3e 100644 --- a/experimental/aitools/cmd/aitools_test.go +++ b/experimental/aitools/cmd/aitools_test.go @@ -25,19 +25,37 @@ func subcommand(t *testing.T, parent *cobra.Command, name string) *cobra.Command return nil } -// flagSummary lists a command's own flags with everything a user sees in --help. +// aliasNames lists the deprecated `databricks experimental aitools ` +// aliases of `databricks aitools `. +var aliasNames = []string{"install", "update", "uninstall", "list", "version"} + +// newExperimentalAitoolsCmd builds the experimental aitools group under an +// `experimental` parent, so command paths in failures read "experimental aitools". +func newExperimentalAitoolsCmd() *cobra.Command { + cmd := aitools.NewAitoolsCmd() + parent := &cobra.Command{Use: "experimental"} + parent.AddCommand(cmd) + return cmd +} + +// flagSummary lists the local and inherited flags of a command with their +// name, shorthand, type, defaults, visibility, deprecation and usage. func flagSummary(cmd *cobra.Command) []string { var out []string - cmd.Flags().VisitAll(func(f *pflag.Flag) { - out = append(out, fmt.Sprintf("--%s -%s %s default=%q hidden=%t deprecated=%q: %s", - f.Name, f.Shorthand, f.Value.Type(), f.DefValue, f.Hidden, f.Deprecated, f.Usage)) - }) + add := func(kind string) func(f *pflag.Flag) { + return func(f *pflag.Flag) { + out = append(out, fmt.Sprintf("%s --%s -%s %s default=%q noopt=%q hidden=%t deprecated=%q: %s", + kind, f.Name, f.Shorthand, f.Value.Type(), f.DefValue, f.NoOptDefVal, f.Hidden, f.Deprecated, f.Usage)) + } + } + cmd.LocalFlags().VisitAll(add("local")) + cmd.InheritedFlags().VisitAll(add("inherited")) slices.Sort(out) return out } func TestExperimentalAitoolsSubcommands(t *testing.T) { - cmd := aitools.NewAitoolsCmd() + cmd := newExperimentalAitoolsCmd() assert.True(t, cmd.Hidden) var names []string @@ -45,7 +63,9 @@ func TestExperimentalAitoolsSubcommands(t *testing.T) { names = append(names, c.Name()) } slices.Sort(names) - assert.Equal(t, []string{"install", "list", "skills", "tools", "uninstall", "update", "version"}, names) + expected := append(slices.Clone(aliasNames), "skills", "tools") + slices.Sort(expected) + assert.Equal(t, expected, names) } // TestDeprecatedAliasesMirrorStableCommands checks that each deprecated @@ -53,9 +73,9 @@ func TestExperimentalAitoolsSubcommands(t *testing.T) { // `databricks aitools ` with a notice that points to the new path. func TestDeprecatedAliasesMirrorStableCommands(t *testing.T) { stable := root.NewCommand(t.Context(), aitoolscmd.Spec) - experimental := aitools.NewAitoolsCmd() + experimental := newExperimentalAitoolsCmd() - for _, name := range []string{"install", "update", "uninstall", "list", "version"} { + for _, name := range aliasNames { t.Run(name, func(t *testing.T) { s := subcommand(t, stable, name) a := subcommand(t, experimental, name)