|
1 | 1 | package version |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
| 5 | + "os" |
| 6 | + "path/filepath" |
4 | 7 | "testing" |
5 | 8 |
|
| 9 | + "github.com/databricks/cli/internal/testutil" |
| 10 | + "github.com/databricks/cli/libs/aitools/agents" |
| 11 | + "github.com/databricks/cli/libs/aitools/installer" |
6 | 12 | "github.com/databricks/cli/libs/cmdio" |
| 13 | + "github.com/databricks/cli/libs/dbr" |
| 14 | + "github.com/databricks/cli/libs/flags" |
7 | 15 | "github.com/databricks/cli/libs/versioncheck" |
8 | 16 | "github.com/stretchr/testify/assert" |
9 | 17 | "github.com/stretchr/testify/require" |
@@ -85,3 +93,73 @@ Could not reach GitHub to check for a newer version. See https://github.com/data |
85 | 93 | }) |
86 | 94 | } |
87 | 95 | } |
| 96 | + |
| 97 | +func TestRenderUpdateCheckAIToolsTip(t *testing.T) { |
| 98 | + upToDate := &versioncheck.Result{CurrentVersion: "0.245.0", LatestVersion: "0.245.0"} |
| 99 | + devBuild := &versioncheck.Result{CurrentVersion: "0.0.0-dev+abc123", DevelopmentBuild: true} |
| 100 | + upToDateText := "Databricks CLI v0.245.0\nYou're on the latest version.\n" |
| 101 | + tip := "Tip: coding agents detected without Databricks skills. Run 'databricks aitools install' to install them.\n" |
| 102 | + |
| 103 | + tests := []struct { |
| 104 | + name string |
| 105 | + result *versioncheck.Result |
| 106 | + output flags.Output |
| 107 | + recordedCodexPlugin bool |
| 108 | + wantStdout string |
| 109 | + wantStderr string |
| 110 | + }{ |
| 111 | + { |
| 112 | + name: "text output prints the tip on stderr", |
| 113 | + result: upToDate, |
| 114 | + output: flags.OutputText, |
| 115 | + wantStdout: upToDateText, |
| 116 | + wantStderr: tip, |
| 117 | + }, |
| 118 | + { |
| 119 | + name: "codex plugin recorded in the install state", |
| 120 | + result: upToDate, |
| 121 | + output: flags.OutputText, |
| 122 | + recordedCodexPlugin: true, |
| 123 | + wantStdout: upToDateText, |
| 124 | + }, |
| 125 | + { |
| 126 | + name: "development build", |
| 127 | + result: devBuild, |
| 128 | + output: flags.OutputText, |
| 129 | + wantStdout: "Databricks CLI v0.0.0-dev+abc123\nThis is a development build; skipping the update check.\n", |
| 130 | + }, |
| 131 | + { |
| 132 | + name: "json output", |
| 133 | + result: upToDate, |
| 134 | + output: flags.OutputJSON, |
| 135 | + wantStdout: "{\n \"current_version\": \"0.245.0\",\n \"latest_version\": \"0.245.0\",\n \"update_available\": false\n}\n", |
| 136 | + }, |
| 137 | + } |
| 138 | + |
| 139 | + for _, tt := range tests { |
| 140 | + t.Run(tt.name, func(t *testing.T) { |
| 141 | + home := t.TempDir() |
| 142 | + testutil.SetAgentEnv(t, "HOME", home, "USERPROFILE", home) |
| 143 | + t.Chdir(t.TempDir()) |
| 144 | + // Codex CLI is detected by its config dir; a plugin install through |
| 145 | + // `databricks aitools install` is recorded only in the install state. |
| 146 | + require.NoError(t, os.MkdirAll(filepath.Join(home, ".codex"), 0o755)) |
| 147 | + if tt.recordedCodexPlugin { |
| 148 | + state := &installer.InstallState{ |
| 149 | + Plugins: map[string]installer.PluginRecord{ |
| 150 | + "codex": {Plugin: "databricks", Version: "0.2.6"}, |
| 151 | + }, |
| 152 | + } |
| 153 | + require.NoError(t, installer.SaveState(filepath.Join(home, agents.CanonicalSkillsDir), state)) |
| 154 | + } |
| 155 | + |
| 156 | + var stdout, stderr bytes.Buffer |
| 157 | + ctx := dbr.MockRuntime(t.Context(), dbr.Environment{}) |
| 158 | + ctx = cmdio.InContext(ctx, cmdio.NewIO(ctx, tt.output, nil, &stdout, &stderr, "", "")) |
| 159 | + err := renderUpdateCheck(ctx, tt.result, tt.output) |
| 160 | + require.NoError(t, err) |
| 161 | + assert.Equal(t, tt.wantStdout, stdout.String()) |
| 162 | + assert.Equal(t, tt.wantStderr, stderr.String()) |
| 163 | + }) |
| 164 | + } |
| 165 | +} |
0 commit comments