From 85d587ba8fd3764bcdb0b2314d086888a1343e70 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:27:30 +0000 Subject: [PATCH 1/4] aitools: stop auto-install from downgrading newer skills ## Changes Automatic installation no longer downgrades skills. If the installed skills come from a newer release than the one auto-install would install, it leaves them as they are. - `libs/aitools/installer`: new `UpdateOptions.NoDowngrade`. When it is set and the target ref is a release tag older than the installed release, `UpdateSkills` returns the usual `RefusedError` from the downgrade check. It does this even when the ref is pinned, whether by `DATABRICKS_SKILLS_REF` or by the compatibility manifest. A branch or commit SHA has no release order to compare against, so a pinned branch or SHA is still installed. - `cmd/aitools/update.go`: the auto-install path, which sets `keepModified`, now also sets `NoDowngrade`. A `databricks aitools update` that you run yourself works as before and still installs the pinned release. - Auto-install already treats a `RefusedError` as `KEPT`. So in this case it prints nothing, reports the `KEPT` outcome and records the version, which means the next command doesn't retry. - Changelog fragment under `.nextchanges/cli/`. ## Why The compatibility manifest pins each released CLI to a skills release, and the update code counts that pin as an explicit ref. An explicit ref skipped the downgrade check. Say a user installed a newer skills release themselves, for example with `DATABRICKS_SKILLS_REF=v0.4.0`. When they upgraded the CLI, auto-install replaced those skills with the older release pinned for that CLI and reported it as "Updated". Auto-install runs without being asked, so it should never undo a newer install the user chose. Rolling back is still possible with an explicit `databricks aitools update`. ## Tests - `TestUpdateNoDowngradeRefusesAnOlderPinnedRelease`: with `NoDowngrade`, a pinned older release is refused and the installed release stays the same. Without it, the same pinned release is installed. - `TestUpdateNoDowngradeInstallsAPinnedBranch`: with `NoDowngrade`, a pinned branch (`main`) is still installed. - Acceptance test `acceptance/cmd/aitools/auto-install/upgrade`: new scenario that installs skills `v0.4.0` explicitly, then upgrades to a CLI version that the compatibility manifest pins to `0.3.0`. It checks that nothing is printed, the outcome is `KEPT`, the installed skills are unchanged and the new version is recorded. Co-authored-by: Isaac --- ...aitools-auto-install-keeps-newer-skills.md | 1 + .../aitools/auto-install/upgrade/output.txt | 26 ++++++++++ .../cmd/aitools/auto-install/upgrade/script | 15 ++++++ .../aitools/auto-install/upgrade/test.toml | 2 + cmd/aitools/update.go | 4 +- libs/aitools/installer/update.go | 11 ++++- libs/aitools/installer/update_test.go | 48 +++++++++++++++++++ 7 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 .nextchanges/cli/aitools-auto-install-keeps-newer-skills.md diff --git a/.nextchanges/cli/aitools-auto-install-keeps-newer-skills.md b/.nextchanges/cli/aitools-auto-install-keeps-newer-skills.md new file mode 100644 index 00000000000..eff6081b4d2 --- /dev/null +++ b/.nextchanges/cli/aitools-auto-install-keeps-newer-skills.md @@ -0,0 +1 @@ +* Automatic installation of Databricks AI tools no longer moves skills you installed from a newer release (for example with `DATABRICKS_SKILLS_REF`) back to the older release this CLI version is pinned to, and no longer reports that as "Updated"; it leaves them alone. `databricks aitools update` still installs the pinned release when you run it. diff --git a/acceptance/cmd/aitools/auto-install/upgrade/output.txt b/acceptance/cmd/aitools/auto-install/upgrade/output.txt index f608694937f..e7e2668e911 100644 --- a/acceptance/cmd/aitools/auto-install/upgrade/output.txt +++ b/acceptance/cmd/aitools/auto-install/upgrade/output.txt @@ -64,3 +64,29 @@ kept 2.0.0 "last_version": "1.32.0", "id": "treatment-machine" } + +>>> DATABRICKS_SKILLS_REF=v0.4.0 [CLI] aitools install --skills-only --scope=global --agents=cursor +Installing Databricks skills for Cursor... +Using skills version 0.4.0 +Fetching skills manifest... +Installed 2 skills in [TEST_TMP_DIR]/pinned-home/.databricks/aitools/skills. + +=== upgrade to 1.33.0 pinned to 0.3.0 over an explicit 0.4.0 install: no downgrade, nothing printed, not retried + +>>> DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION=1.33.0 [CLI] jobs list + +>>> print_telemetry +{"command":"jobs_list","exit_code":0,"aitools_auto_install_event":{"outcome":"KEPT","holdout_arm":"TREATMENT","interactive":false}} + +>>> cursor_skills +databricks-edited +databricks-kept + +>>> skill_file databricks-kept +kept 2.0.0 + +>>> auto_install_state +{ + "last_version": "1.33.0", + "id": "treatment-machine" +} diff --git a/acceptance/cmd/aitools/auto-install/upgrade/script b/acceptance/cmd/aitools/auto-install/upgrade/script index 98b3705fab5..d28f95384a2 100644 --- a/acceptance/cmd/aitools/auto-install/upgrade/script +++ b/acceptance/cmd/aitools/auto-install/upgrade/script @@ -36,3 +36,18 @@ title "an older CLI on the same machine (e.g. one an IDE ships) does nothing" trace DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION=1.31.0 $CLI jobs list trace print_telemetry trace auto_install_state + +# The user pinned release 0.4.0 with an explicit install. The compatibility +# manifest pins this CLI to the older 0.3.0, as it pins released CLIs. +use_home pinned-home +skills_dir="${USERPROFILE:-$HOME}/.databricks/aitools/skills" +trace DATABRICKS_SKILLS_REF=v0.4.0 $CLI aitools install --skills-only --scope=global --agents=cursor +print_telemetry > /dev/null +echo '{"0.0.0": {"appkit": "0.84.0", "skills": "0.3.0", "auto_install": true}}' > "$DATABRICKS_CACHE_DIR/compat-manifest.json" + +title "upgrade to 1.33.0 pinned to 0.3.0 over an explicit 0.4.0 install: no downgrade, nothing printed, not retried" +trace DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION=1.33.0 $CLI jobs list +trace print_telemetry +trace cursor_skills +trace skill_file databricks-kept +trace auto_install_state diff --git a/acceptance/cmd/aitools/auto-install/upgrade/test.toml b/acceptance/cmd/aitools/auto-install/upgrade/test.toml index 1511d4aaad2..cd0ef11212d 100644 --- a/acceptance/cmd/aitools/auto-install/upgrade/test.toml +++ b/acceptance/cmd/aitools/auto-install/upgrade/test.toml @@ -1,3 +1,5 @@ +Ignore = ["pinned-home"] + # Skills releases: the latest release is v0.3.0, under /newer it is v0.4.0 and # under /older it is v0.2.0 (DATABRICKS_CLI_GITHUB_API_URL picks one). diff --git a/cmd/aitools/update.go b/cmd/aitools/update.go index b4865afa570..673b00e981f 100644 --- a/cmd/aitools/update.go +++ b/cmd/aitools/update.go @@ -79,7 +79,8 @@ type updateFlags struct { project, global bool // keepModified is not a flag: auto-install sets it (see // installer.UpdateOptions.KeepModified). It also keeps the raw skills of - // agents that have, or could get, the plugin. + // agents that have, or could get, the plugin, and refuses a downgrade + // (installer.UpdateOptions.NoDowngrade). keepModified bool } @@ -219,6 +220,7 @@ func runUpdate(ctx context.Context, f updateFlags) error { Scope: scope, KeepModified: f.keepModified, + NoDowngrade: f.keepModified, } opts.Skills = skills diff --git a/libs/aitools/installer/update.go b/libs/aitools/installer/update.go index cbd3a48bd89..683e0aeccd9 100644 --- a/libs/aitools/installer/update.go +++ b/libs/aitools/installer/update.go @@ -36,6 +36,12 @@ type UpdateOptions struct { // no record to check against), instead of replacing it. Automatic updates // set it: they must never overwrite what the user changed. KeepModified bool + + // NoDowngrade refuses a release older than the installed one even when + // the ref is pinned (by DATABRICKS_SKILLS_REF or the compatibility + // manifest). A pinned branch or commit SHA is still installed. Automatic updates set it: a newer release the user installed + // is theirs to roll back. + NoDowngrade bool } // UpdateResult describes what UpdateSkills did (or would do in check mode). @@ -117,7 +123,10 @@ func UpdateSkills(ctx context.Context, src ManifestSource, targetAgents []*agent } return nil, err } - if err := checkSkillsDowngrade(installedRef, latestTag, explicit); err != nil { + // A branch or commit SHA has no release order to compare, so NoDowngrade + // applies only to a release tag; the explicit ref is honored otherwise. + noDowngrade := opts.NoDowngrade && semver.IsValid(latestTag) + if err := checkSkillsDowngrade(installedRef, latestTag, explicit && !noDowngrade); err != nil { return nil, err } diff --git a/libs/aitools/installer/update_test.go b/libs/aitools/installer/update_test.go index 0c582d0bb8b..70741123e40 100644 --- a/libs/aitools/installer/update_test.go +++ b/libs/aitools/installer/update_test.go @@ -3,6 +3,7 @@ package installer import ( "bytes" "context" + "errors" "io/fs" "log/slog" "os" @@ -163,6 +164,53 @@ func TestUpdateKeepModifiedKeepsEditedSkill(t *testing.T) { assert.Equal(t, "0.2.0", state.Skills["databricks-jobs"]) } +func TestUpdateNoDowngradeRefusesAnOlderPinnedRelease(t *testing.T) { + tmp := setupTestHome(t) + ctx := cmdio.MockDiscard(t.Context()) + setupFetchMock(t) + t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.0") + + src := &mockManifestSource{manifest: testManifest()} + agent := testAgent(tmp) + require.NoError(t, InstallSkillsForAgents(ctx, src, []*agents.Agent{agent}, InstallOptions{})) + + // A pinned older release, as the compatibility manifest pins one. + t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef) + _, err := UpdateSkills(ctx, src, []*agents.Agent{agent}, UpdateOptions{NoDowngrade: true}) + _, refused := errors.AsType[*RefusedError](err) + assert.True(t, refused, "got %v", err) + globalDir := filepath.Join(tmp, ".databricks", "aitools", "skills") + state, err := LoadState(globalDir) + require.NoError(t, err) + assert.Equal(t, "v0.2.0", state.Release) + + // Without it, the pinned ref is the user's choice. + _, err = UpdateSkills(ctx, src, []*agents.Agent{agent}, UpdateOptions{}) + require.NoError(t, err) + state, err = LoadState(globalDir) + require.NoError(t, err) + assert.Equal(t, testSkillsRef, state.Release) +} + +func TestUpdateNoDowngradeInstallsAPinnedBranch(t *testing.T) { + tmp := setupTestHome(t) + ctx := cmdio.MockDiscard(t.Context()) + setupFetchMock(t) + t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.0") + + src := &mockManifestSource{manifest: testManifest()} + agent := testAgent(tmp) + require.NoError(t, InstallSkillsForAgents(ctx, src, []*agents.Agent{agent}, InstallOptions{})) + + // A branch has no release order, so it is not a downgrade. + t.Setenv("DATABRICKS_SKILLS_REF", "main") + _, err := UpdateSkills(ctx, src, []*agents.Agent{agent}, UpdateOptions{NoDowngrade: true}) + require.NoError(t, err) + state, err := LoadState(filepath.Join(tmp, ".databricks", "aitools", "skills")) + require.NoError(t, err) + assert.Equal(t, "main", state.Release) +} + func TestUpdateCheckDryRun(t *testing.T) { tmp := setupTestHome(t) ctx := cmdio.MockDiscard(t.Context()) From 046dac180770c23ff597a21fab67dc1173ce6531 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:39:10 +0000 Subject: [PATCH 2/4] Add PR link to changelog fragment Co-authored-by: Isaac --- .nextchanges/cli/aitools-auto-install-keeps-newer-skills.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/cli/aitools-auto-install-keeps-newer-skills.md b/.nextchanges/cli/aitools-auto-install-keeps-newer-skills.md index eff6081b4d2..74b64d683ff 100644 --- a/.nextchanges/cli/aitools-auto-install-keeps-newer-skills.md +++ b/.nextchanges/cli/aitools-auto-install-keeps-newer-skills.md @@ -1 +1 @@ -* Automatic installation of Databricks AI tools no longer moves skills you installed from a newer release (for example with `DATABRICKS_SKILLS_REF`) back to the older release this CLI version is pinned to, and no longer reports that as "Updated"; it leaves them alone. `databricks aitools update` still installs the pinned release when you run it. +* Automatic installation of Databricks AI tools no longer moves skills you installed from a newer release (for example with `DATABRICKS_SKILLS_REF`) back to the older release this CLI version is pinned to, and no longer reports that as "Updated"; it leaves them alone. `databricks aitools update` still installs the pinned release when you run it. ([#7888](https://github.com/databricks/cli/pull/7888)) From 22c79c5b71e61d5f35d4bd973a833f130849efe5 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:19:33 +0000 Subject: [PATCH 3/4] aitools: address review of the auto-install downgrade guard Refuse an older pinned release before fetching its manifest, with a message that names the kept release and how to install the pinned one. Report the plugins an update changed even when it then keeps the raw skills. Give the acceptance gate helper a skills argument, and document the guard in internal/build/README.md and planTools. Co-authored-by: Isaac --- .../cmd/aitools/auto-install/script.prepare | 7 +-- .../cmd/aitools/auto-install/upgrade/script | 2 +- cmd/aitools/autoinstall_plan_test.go | 46 +++++++++++++++++++ cmd/aitools/autoinstall_run.go | 22 ++++++--- internal/build/README.md | 2 +- libs/aitools/installer/update.go | 16 ++++--- libs/aitools/installer/update_test.go | 10 ++-- 7 files changed, 84 insertions(+), 21 deletions(-) diff --git a/acceptance/cmd/aitools/auto-install/script.prepare b/acceptance/cmd/aitools/auto-install/script.prepare index ad4bd0fd397..ebc99b77818 100644 --- a/acceptance/cmd/aitools/auto-install/script.prepare +++ b/acceptance/cmd/aitools/auto-install/script.prepare @@ -57,11 +57,12 @@ use_home() { echo "{\"id\": \"${2:-treatment-machine}\"}" > "${USERPROFILE:-$HOME}/.databricks/aitools/auto-install.json" } -# gate true|false writes a compatibility manifest into the CLI cache with that -# auto_install flag. A fresh cache file replaces the remote manifest. +# gate true|false [SKILLS] writes a compatibility manifest into the CLI cache +# with that auto_install flag and skills version SKILLS (default: latest). A +# fresh cache file replaces the remote manifest. gate() { "$mkdir_bin" -p "$DATABRICKS_CACHE_DIR" - echo "{\"0.0.0\": {\"appkit\": \"0.84.0\", \"skills\": \"latest\", \"auto_install\": $1}}" > "$DATABRICKS_CACHE_DIR/compat-manifest.json" + echo "{\"0.0.0\": {\"appkit\": \"0.84.0\", \"skills\": \"${2:-latest}\", \"auto_install\": $1}}" > "$DATABRICKS_CACHE_DIR/compat-manifest.json" } # cursor_skills lists the skills installed for Cursor. diff --git a/acceptance/cmd/aitools/auto-install/upgrade/script b/acceptance/cmd/aitools/auto-install/upgrade/script index d28f95384a2..0cd0338817d 100644 --- a/acceptance/cmd/aitools/auto-install/upgrade/script +++ b/acceptance/cmd/aitools/auto-install/upgrade/script @@ -43,7 +43,7 @@ use_home pinned-home skills_dir="${USERPROFILE:-$HOME}/.databricks/aitools/skills" trace DATABRICKS_SKILLS_REF=v0.4.0 $CLI aitools install --skills-only --scope=global --agents=cursor print_telemetry > /dev/null -echo '{"0.0.0": {"appkit": "0.84.0", "skills": "0.3.0", "auto_install": true}}' > "$DATABRICKS_CACHE_DIR/compat-manifest.json" +gate true 0.3.0 title "upgrade to 1.33.0 pinned to 0.3.0 over an explicit 0.4.0 install: no downgrade, nothing printed, not retried" trace DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION=1.33.0 $CLI jobs list diff --git a/cmd/aitools/autoinstall_plan_test.go b/cmd/aitools/autoinstall_plan_test.go index 14dc7ef3411..e6f780ce6ce 100644 --- a/cmd/aitools/autoinstall_plan_test.go +++ b/cmd/aitools/autoinstall_plan_test.go @@ -1,6 +1,8 @@ package aitools import ( + "context" + "errors" "maps" "os" "path/filepath" @@ -9,6 +11,7 @@ import ( "github.com/databricks/cli/libs/aitools/agents" "github.com/databricks/cli/libs/aitools/autoinstall" "github.com/databricks/cli/libs/aitools/installer" + "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/telemetry/protos" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" @@ -161,3 +164,46 @@ func TestSkipsAutoInstall(t *testing.T) { assert.False(t, skipsAutoInstall(cmd), cmd.CommandPath()) } } + +// The update runs the plugin updates before it refuses the raw skills, so a +// refusal still reports the plugins it updated. +func TestUpdateToolsReportsPluginsUpdatedBeforeARefusal(t *testing.T) { + autoInstallHome(t) + noTelemetryAuth(t) + t.Setenv("DATABRICKS_SKILLS_REF", "v0.3.0") + resetUpdatePluginSeams(t) + dir := saveGlobalState(t, map[string]string{"databricks-sql": "0.1.0"}) + before, err := installer.LoadState(dir) + require.NoError(t, err) + + origUpdateSkills := updateSkillsFn + t.Cleanup(func() { updateSkillsFn = origUpdateSkills }) + updateSkillsFn = func(context.Context, installer.ManifestSource, []*agents.Agent, installer.UpdateOptions) (*installer.UpdateResult, error) { + return nil, &installer.RefusedError{Err: errors.New("keeping the installed skills")} + } + pluginUpdated := false + updatePluginsFn = func(context.Context, string, string) ([]installer.PluginUpdate, error) { + if !pluginUpdated { + return nil, nil + } + state, err := installer.LoadState(dir) + require.NoError(t, err) + rec := state.Plugins[agents.NameClaudeCode] + rec.Version = "0.3.0" + state.Plugins[agents.NameClaudeCode] = rec + require.NoError(t, installer.SaveState(dir, state)) + return []installer.PluginUpdate{{Agent: "Claude Code", Version: "0.3.0"}}, nil + } + ctx := cmdio.MockDiscard(t.Context()) + + // Nothing changed: the refusal is returned, which auto-install reports + // as kept. + _, err = updateTools(ctx, dir, before) + assert.ErrorAs(t, err, new(*installer.RefusedError)) + + pluginUpdated = true + result, err := updateTools(ctx, dir, before) + require.NoError(t, err) + assert.Equal(t, protos.AitoolsAutoInstallOutcomeInstalled, result.outcome) + assert.Equal(t, []string{"Claude Code"}, result.agents) +} diff --git a/cmd/aitools/autoinstall_run.go b/cmd/aitools/autoinstall_run.go index 6802ef4d9f3..e92a80fe646 100644 --- a/cmd/aitools/autoinstall_run.go +++ b/cmd/aitools/autoinstall_run.go @@ -488,8 +488,9 @@ func (t toolsPlan) fresh() bool { // planTools plans what `databricks aitools install --scope=global` runs // without prompts, for the agents whose config directory exists. An existing // global installation is updated as `databricks aitools update --scope=global` -// does instead, which keeps its downgrade guard, keeps the skills whose files -// the user modified at their version, and does not migrate skills to plugins. +// does instead, which keeps its downgrade guard, also keeps an installed +// release newer than a pinned one, keeps the skills whose files the user +// modified at their version, and does not migrate skills to plugins. // Planning reads only local state; prior is the auto-install state. func planTools(ctx context.Context, prior autoinstall.State) (toolsPlan, error) { globalDir, err := installer.GlobalSkillsDir(ctx) @@ -583,8 +584,12 @@ func updateTools(ctx context.Context, globalDir string, before *installer.Instal uctx := telemetry.WithNewLogger(ctx) uctx = context.WithValue(uctx, funnelKey{}, &commandFunnel{command: protos.AitoolsCommandUpdate}) uctx = context.WithValue(uctx, telemetryAuthKey{}, &telemetryAuth{}) - if err := runUpdate(uctx, updateFlags{scope: installer.ScopeGlobal, keepModified: true}); err != nil { - return installResult{}, err + updateErr := runUpdate(uctx, updateFlags{scope: installer.ScopeGlobal, keepModified: true}) + // The update refuses the raw skills after it updated the plugins, so a + // refusal still reports the plugins it changed. + _, refused := errors.AsType[*installer.RefusedError](updateErr) + if updateErr != nil && !refused { + return installResult{}, updateErr } after, err := installer.LoadState(globalDir) if err != nil { @@ -594,9 +599,14 @@ func updateTools(ctx context.Context, globalDir string, before *installer.Instal if after != nil { result.agents = changedAgents(ctx, before, after) } - if len(result.agents) > 0 { - result.outcome = protos.AitoolsAutoInstallOutcomeInstalled + if len(result.agents) == 0 { + // Nothing changed: the caller reports a refusal as kept. + return result, updateErr + } + if refused { + log.Debugf(ctx, "auto-install: kept the installed skills: %v", updateErr) } + result.outcome = protos.AitoolsAutoInstallOutcomeInstalled return result, nil } diff --git a/internal/build/README.md b/internal/build/README.md index d82afac3751..2f60d423f81 100644 --- a/internal/build/README.md +++ b/internal/build/README.md @@ -23,7 +23,7 @@ An entry can also set `"auto_install": true` to turn on the automatic installati This skills fallback only applies to raw-file delivery. Version checks omit update availability when latest is unknown, and plugin operations don't substitute the fallback version. -Raw-skills updates and reinstalls reject automatic downgrades, including with `--force`: the fallback must be at least as new as the installed release. Existing installs without a comparable release require a successful latest-release fetch. Explicit `DATABRICKS_SKILLS_REF` overrides and compatibility pins can still select an older release. +Raw-skills updates and reinstalls reject automatic downgrades, including with `--force`: the fallback must be at least as new as the installed release. Existing installs without a comparable release require a successful latest-release fetch. Explicit `DATABRICKS_SKILLS_REF` overrides and compatibility pins can still select an older release, except in automatic installation: it keeps an installed release newer than the pinned one, which `databricks aitools update` still installs. CLIs before `1.6.0` reject the whole remote manifest when any entry uses `"latest"`, even an entry they never resolve to. They use a valid cached manifest or their embedded manifest without returning a parse error. These CLIs stop receiving remote compatibility updates for both AppKit and skills. diff --git a/libs/aitools/installer/update.go b/libs/aitools/installer/update.go index 683e0aeccd9..7bf0df4a128 100644 --- a/libs/aitools/installer/update.go +++ b/libs/aitools/installer/update.go @@ -39,8 +39,9 @@ type UpdateOptions struct { // NoDowngrade refuses a release older than the installed one even when // the ref is pinned (by DATABRICKS_SKILLS_REF or the compatibility - // manifest). A pinned branch or commit SHA is still installed. Automatic updates set it: a newer release the user installed - // is theirs to roll back. + // manifest). A pinned branch or commit SHA is still installed. Automatic + // updates set it: a newer release the user installed is theirs to roll + // back. NoDowngrade bool } @@ -115,6 +116,12 @@ func UpdateSkills(ctx context.Context, src ManifestSource, targetAgents []*agent return &UpdateResult{Unchanged: slices.Sorted(maps.Keys(state.Skills))}, nil } + // A pinned ref is the ref installed, so it is compared before fetching its + // manifest. A branch or commit SHA has no release order to compare. + if explicit && opts.NoDowngrade && semver.IsValid(latestTag) && semver.Compare(latestTag, installedRef) < 0 { + return nil, &RefusedError{Err: fmt.Errorf("keeping the installed skills %s, which are newer than the pinned %s; run 'databricks aitools update' to install %s", DisplaySkillsVersion(installedRef), DisplaySkillsVersion(latestTag), DisplaySkillsVersion(latestTag))} + } + manifest, latestTag, err := FetchSkillsManifestWithFallback(ctx, src, latestTag, allowFallback && !explicit) if err != nil { if opts.Check { @@ -123,10 +130,7 @@ func UpdateSkills(ctx context.Context, src ManifestSource, targetAgents []*agent } return nil, err } - // A branch or commit SHA has no release order to compare, so NoDowngrade - // applies only to a release tag; the explicit ref is honored otherwise. - noDowngrade := opts.NoDowngrade && semver.IsValid(latestTag) - if err := checkSkillsDowngrade(installedRef, latestTag, explicit && !noDowngrade); err != nil { + if err := checkSkillsDowngrade(installedRef, latestTag, explicit); err != nil { return nil, err } diff --git a/libs/aitools/installer/update_test.go b/libs/aitools/installer/update_test.go index 70741123e40..bd89e225919 100644 --- a/libs/aitools/installer/update_test.go +++ b/libs/aitools/installer/update_test.go @@ -174,11 +174,13 @@ func TestUpdateNoDowngradeRefusesAnOlderPinnedRelease(t *testing.T) { agent := testAgent(tmp) require.NoError(t, InstallSkillsForAgents(ctx, src, []*agents.Agent{agent}, InstallOptions{})) - // A pinned older release, as the compatibility manifest pins one. + // A pinned older release, as the compatibility manifest pins one. It is + // refused before its manifest is fetched. t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef) - _, err := UpdateSkills(ctx, src, []*agents.Agent{agent}, UpdateOptions{NoDowngrade: true}) - _, refused := errors.AsType[*RefusedError](err) - assert.True(t, refused, "got %v", err) + unfetchable := &mockManifestSource{fetchErr: errors.New("the manifest was fetched")} + _, err := UpdateSkills(ctx, unfetchable, []*agents.Agent{agent}, UpdateOptions{NoDowngrade: true}) + assert.ErrorAs(t, err, new(*RefusedError)) + assert.ErrorContains(t, err, "keeping the installed skills 0.2.0, which are newer than the pinned 0.1.5; run 'databricks aitools update' to install 0.1.5") globalDir := filepath.Join(tmp, ".databricks", "aitools", "skills") state, err := LoadState(globalDir) require.NoError(t, err) From 644d2c9dd481e1d269353125ed18b6b3f28ea336 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Mon, 23 Nov 2026 22:38:46 +0000 Subject: [PATCH 4/4] aitools: test that NoDowngrade installs a newer pinned release Co-authored-by: Isaac --- libs/aitools/installer/update_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libs/aitools/installer/update_test.go b/libs/aitools/installer/update_test.go index bd89e225919..6f13f2df026 100644 --- a/libs/aitools/installer/update_test.go +++ b/libs/aitools/installer/update_test.go @@ -194,6 +194,24 @@ func TestUpdateNoDowngradeRefusesAnOlderPinnedRelease(t *testing.T) { assert.Equal(t, testSkillsRef, state.Release) } +func TestUpdateNoDowngradeInstallsANewerPinnedRelease(t *testing.T) { + tmp := setupTestHome(t) + ctx := cmdio.MockDiscard(t.Context()) + setupFetchMock(t) + t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef) + + src := &mockManifestSource{manifest: testManifest()} + agent := testAgent(tmp) + require.NoError(t, InstallSkillsForAgents(ctx, src, []*agents.Agent{agent}, InstallOptions{})) + + t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.0") + _, err := UpdateSkills(ctx, src, []*agents.Agent{agent}, UpdateOptions{NoDowngrade: true}) + require.NoError(t, err) + state, err := LoadState(filepath.Join(tmp, ".databricks", "aitools", "skills")) + require.NoError(t, err) + assert.Equal(t, "v0.2.0", state.Release) +} + func TestUpdateNoDowngradeInstallsAPinnedBranch(t *testing.T) { tmp := setupTestHome(t) ctx := cmdio.MockDiscard(t.Context())