Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ func testAccept(t *testing.T, inprocessMode bool, selectedTests []string, skipTo
// so a host value would add skill/ pairs to recorded user agents.
os.Unsetenv("DATABRICKS_SKILLS_INVOKED") //nolint:usetesting // t.Setenv cannot unset

// DATABRICKS_AGENT_FEATURES_DISABLED turns off the skills and aitools
// hints, so a host value would hide the output the goldens expect.
os.Unsetenv("DATABRICKS_AGENT_FEATURES_DISABLED") //nolint:usetesting // t.Setenv cannot unset

if !requirePrerequisites(t) {
// Don't run the suite against a stale toolchain; the failed subtest
// has already marked the parent test as failed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

>>> [CLI] aitools auto-install enable
Automatic installation of Databricks AI tools is enabled.

=== disabled: no install notice, no install or skills hint, nothing installed

>>> DATABRICKS_AGENT_FEATURES_DISABLED=1 CLAUDECODE=1 [CLI] jobs list

>>> print_telemetry

>>> cursor_skills
(no skills)

>>> auto_install_state
{
"consented": true,
"id": "treatment-machine"
}

=== unset: the first run of this version installs, and no hint is printed

>>> env -u DATABRICKS_AGENT_FEATURES_DISABLED CLAUDECODE=1 [CLI] jobs list
Installed Databricks AI tools for Claude Code, Cursor. Turn off: databricks aitools auto-install disable. Remove: databricks aitools uninstall

>>> print_telemetry
{"command":"jobs_list","exit_code":0,"aitools_install_event":{"agents":["CLAUDE_CODE","CURSOR"],"scope":"GLOBAL","error_category":"TYPE_UNSPECIFIED","agent_results":[{"agent":"CLAUDE_CODE","error_category":"CLI_NOT_ON_PATH"}],"trigger":"AUTO_FIRST_RUN"}}
{"command":"jobs_list","exit_code":0,"aitools_auto_install_event":{"outcome":"INSTALLED","holdout_arm":"TREATMENT","interactive":false}}

>>> cursor_skills
databricks-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# DATABRICKS_AGENT_FEATURES_DISABLED turns off the aitools hint and auto-install,
# with the skills preview and hints on. The user agreed to auto-install, so the
# unset run after it installs for the same agent, and the quiet run is not
# quiet for lack of a gate or consent.
unset AGENT CLAUDE_CODE_SESSION_ID CLAUDE_CODE_CHILD_SESSION
use_home home
"$mkdir_bin" -p "${USERPROFILE:-$HOME}/.claude"
gate true
trace $CLI aitools auto-install enable
export DATABRICKS_SKILLS_PREVIEW=1
export DATABRICKS_SKILLS_HINTS=1

title "disabled: no install notice, no install or skills hint, nothing installed"
trace DATABRICKS_AGENT_FEATURES_DISABLED=1 CLAUDECODE=1 $CLI jobs list
trace print_telemetry
trace cursor_skills
trace auto_install_state

title "unset: the first run of this version installs, and no hint is printed"
trace env -u DATABRICKS_AGENT_FEATURES_DISABLED CLAUDECODE=1 $CLI jobs list
trace print_telemetry
trace cursor_skills
12 changes: 12 additions & 0 deletions acceptance/cmd/aitools/auto-install/enable-disable/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ Automatic installation of Databricks AI tools is enabled.
Automatic installation of Databricks AI tools is enabled.
DATABRICKS_AITOOLS_AUTO_INSTALL still disables it in this environment; unset it to let it run.

=== enable names the agent features switch when it still turns it off

>>> DATABRICKS_AGENT_FEATURES_DISABLED=1 [CLI] aitools auto-install enable
Automatic installation of Databricks AI tools is enabled.
DATABRICKS_AGENT_FEATURES_DISABLED still disables it in this environment; unset it to let it run.

=== enable names both variables, and says to unset both

>>> DATABRICKS_AITOOLS_AUTO_INSTALL=false DATABRICKS_AGENT_FEATURES_DISABLED=1 [CLI] aitools auto-install enable
Automatic installation of Databricks AI tools is enabled.
DATABRICKS_AITOOLS_AUTO_INSTALL and DATABRICKS_AGENT_FEATURES_DISABLED still disable it in this environment; unset both to let it run.

=== disable replaces a state file it cannot read

>>> [CLI] aitools auto-install disable
Expand Down
6 changes: 6 additions & 0 deletions acceptance/cmd/aitools/auto-install/enable-disable/script
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ trace auto_install_state
title "enable says when the environment still turns it off"
trace DATABRICKS_AITOOLS_AUTO_INSTALL=false $CLI aitools auto-install enable

title "enable names the agent features switch when it still turns it off"
trace DATABRICKS_AGENT_FEATURES_DISABLED=1 $CLI aitools auto-install enable

title "enable names both variables, and says to unset both"
trace DATABRICKS_AITOOLS_AUTO_INSTALL=false DATABRICKS_AGENT_FEATURES_DISABLED=1 $CLI aitools auto-install enable

title "disable replaces a state file it cannot read"
echo "not json" > "${USERPROFILE:-$HOME}/.databricks/aitools/auto-install.json"
trace $CLI aitools auto-install disable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = false
15 changes: 15 additions & 0 deletions acceptance/cmd/skills/agent-features-disabled/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

>>> DATABRICKS_AGENT_FEATURES_DISABLED=1 CLAUDECODE=1 [CLI] skills list
Error: unknown command "skills" for "databricks"

>>> DATABRICKS_AGENT_FEATURES_DISABLED=1 CLAUDECODE=1 [CLI] --help

>>> DATABRICKS_AGENT_FEATURES_DISABLED=1 CLAUDECODE=1 [CLI] fs --help

>>> env -u DATABRICKS_AGENT_FEATURES_DISABLED [CLI] --help

>>> env -u DATABRICKS_AGENT_FEATURES_DISABLED [CLI] fs --help

>>> DATABRICKS_AGENT_FEATURES_DISABLED=1 CLAUDECODE=1 [CLI] quickstart

>>> env -u DATABRICKS_AGENT_FEATURES_DISABLED -u DATABRICKS_SKILLS_PREVIEW [CLI] quickstart
19 changes: 19 additions & 0 deletions acceptance/cmd/skills/agent-features-disabled/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export DATABRICKS_SKILLS_DIR="$TESTDIR/../../../cmd/skills/release"

# DATABRICKS_AGENT_FEATURES_DISABLED is set, with the preview and the hints on
# and a coding agent calling: the skills group is not registered, so it is an
# unknown command.
musterr trace DATABRICKS_AGENT_FEATURES_DISABLED=1 CLAUDECODE=1 $CLI skills list

# Help shows no skills footer, on the root or on a group the fixture skill covers.
trace DATABRICKS_AGENT_FEATURES_DISABLED=1 CLAUDECODE=1 $CLI --help | contains.py "!databricks skills" > LOG.help

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] The root --help check has no control run without the variable. If a later change removes the skills footer from root help, this check still passes and tests nothing. Add a run of root --help with env -u DATABRICKS_AGENT_FEATURES_DISABLED that contains databricks skills, as line 13 does for fs --help.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in b130330. Root --help with DATABRICKS_AGENT_FEATURES_DISABLED unset now runs in the script and must contain "databricks skills", the control for the root footer check. It sits beside the fs --help control and writes to LOG.help-unset. The golden shows the run, and the acceptance test passes, so the root footer is checked with the variable set and unset.

trace DATABRICKS_AGENT_FEATURES_DISABLED=1 CLAUDECODE=1 $CLI fs --help | contains.py "!databricks skills" > LOG.fs-help

# With the variable unset, the root and the same group get their footer, so the checks above can fail.
trace env -u DATABRICKS_AGENT_FEATURES_DISABLED $CLI --help | contains.py "databricks skills" > LOG.help-unset
trace env -u DATABRICKS_AGENT_FEATURES_DISABLED $CLI fs --help | contains.py "databricks skills read" > LOG.fs-help-unset

# The agent text drops its aitools block too, so it names no aitools install and keeps the shared text.
trace DATABRICKS_AGENT_FEATURES_DISABLED=1 CLAUDECODE=1 $CLI quickstart | contains.py "# Databricks Quickstart" "!aitools install" "!install the matching skill" "!databricks skills" > LOG.quickstart
# With the variable unset and the skills preview off, the agent text names the aitools install, so the check above can fail.
trace env -u DATABRICKS_AGENT_FEATURES_DISABLED -u DATABRICKS_SKILLS_PREVIEW $CLI quickstart | contains.py "databricks aitools install" > LOG.quickstart-unset
1 change: 1 addition & 0 deletions acceptance/cmd/skills/agent-features-disabled/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Env.DATABRICKS_SKILLS_HINTS = "1"
1 change: 1 addition & 0 deletions cmd/air/air_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func TestHelpSkillsFooterForNestedGroup(t *testing.T) {
require.NoError(t, os.WriteFile(filepath.Join(dir, "manifest.json"), []byte(manifest), 0o644))
ctx := env.Set(t.Context(), "DATABRICKS_SKILLS_PREVIEW", "1")
ctx = env.Set(ctx, "DATABRICKS_SKILLS_HINTS", "1")
ctx = env.Set(ctx, "DATABRICKS_AGENT_FEATURES_DISABLED", "")
ctx = env.Set(ctx, "DATABRICKS_SKILLS_DIR", dir)

// Under a databricks root, the group key is "air pools", as in the CLI.
Expand Down
21 changes: 19 additions & 2 deletions cmd/aitools/autoinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package aitools
import (
"context"
"fmt"
"strings"

"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/aitools/autoinstall"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/skills"
"github.com/spf13/cobra"
)

Expand All @@ -30,7 +32,9 @@ It stays off after 'databricks aitools auto-install disable', a global-scope
'databricks aitools uninstall', or a "no" to the skills prompt of 'databricks
apps init', until 'databricks aitools auto-install enable'. Setting
` + autoinstall.EnvVar + ` to anything but a true value (true, 1, yes, on) turns
it off in that environment.`,
it off in that environment. Setting ` + skills.AgentFeaturesDisabledEnv + `
to a true value (true, 1, yes, on) also turns it off, along with the skills and
the aitools hints.`,
RunE: root.ReportUnknownSubcommand,
}
cmd.AddCommand(newAutoInstallToggleCmd(true))
Expand Down Expand Up @@ -71,7 +75,20 @@ func printAutoInstallSetting(ctx context.Context, enabled bool) {
return
}
cmdio.LogString(ctx, "Automatic installation of Databricks AI tools is enabled.")
// Both variables can be set. They share one warning, so unsetting only one
// is not mistaken for a fix.
var overrides []string
if autoinstall.EnvOptedOut(ctx) {
cmdio.LogString(ctx, cmdio.Yellow(ctx, autoinstall.EnvVar+" still disables it in this environment; unset it to let it run."))
overrides = append(overrides, autoinstall.EnvVar)
}
if skills.AgentFeaturesDisabled(ctx) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] enable now warns that DATABRICKS_AGENT_FEATURES_DISABLED still turns auto-install off. The Long help of auto-install (lines 27-31) still names DATABRICKS_AITOOLS_AUTO_INSTALL as the only environment switch. Can you add the new variable there so databricks aitools auto-install --help matches the warning? Also, with both variables set, enable prints two warnings that each say "unset it to let it run", but unsetting just one of them isn't enough.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ee9742b. The auto-install help now names DATABRICKS_AGENT_FEATURES_DISABLED and says a true value turns auto-install off, along with the skills and the aitools hints. When both auto-install variables are set, enable now prints one warning that names both and says to unset both. With only one set, the message is the same as before. TestPrintAutoInstallSettingBothOverrides covers the two-variable case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] The new enable warnings, for this variable alone and for both variables, have only unit tests in cmd/aitools/autoinstall_test.go. .agents/rules/testing.md asks for acceptance tests for user-visible CLI output. A text change in these warnings does not show in a golden file. Add the two cases as trace lines to acceptance/cmd/aitools/auto-install/enable-disable/script, next to the DATABRICKS_AITOOLS_AUTO_INSTALL=false case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b130330. The enable-disable acceptance script has two new cases next to the DATABRICKS_AITOOLS_AUTO_INSTALL=false one: DATABRICKS_AGENT_FEATURES_DISABLED=1 alone, which names that variable, and both variables together, which get the shared warning that says to unset both. Their lines are in the regenerated output.txt, and cmd/aitools acceptance passes.

overrides = append(overrides, skills.AgentFeaturesDisabledEnv)
}
switch len(overrides) {
case 0:
case 1:
cmdio.LogString(ctx, cmdio.Yellow(ctx, overrides[0]+" still disables it in this environment; unset it to let it run."))
default:
cmdio.LogString(ctx, cmdio.Yellow(ctx, strings.Join(overrides, " and ")+" still disable it in this environment; unset both to let it run."))
}
}
7 changes: 6 additions & 1 deletion cmd/aitools/autoinstall_hint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/databricks/cli/libs/aitools/agents"
"github.com/databricks/cli/libs/aitools/autoinstall"
"github.com/databricks/cli/libs/skills"
"github.com/spf13/cobra"
)

Expand All @@ -19,9 +20,13 @@ import (
// install gives tools to the agents its plan names; an update gives skills to
// every agent with a config directory when a skill changed, which is only
// known after the manifest is fetched, so it counts as installing for each of
// them.
// them. With DATABRICKS_AGENT_FEATURES_DISABLED set, nothing is installed, so
// it reports false, as AutoInstall does.
func AutoInstallsFor(cmd *cobra.Command, agentName string) bool {
ctx := cmd.Context()
if skills.AgentFeaturesDisabled(ctx) {
return false
}
in := autoInstallInputs(ctx, skipsAutoInstall(cmd))
if slices.Contains(stateFreeSkips, autoinstall.Decide(in)) {
return false
Expand Down
1 change: 1 addition & 0 deletions cmd/aitools/autoinstall_hint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestAutoInstallsFor(t *testing.T) {
{name: "a version whose retries ran out installs nothing", state: `{"id": "treatment-machine", "last_version": "1.30.0", "attempts": 10}`},
{name: "an opt-out installs nothing", state: `{"id": "treatment-machine", "opted_out": true}`},
{name: "the env opt-out installs nothing", env: map[string]string{"DATABRICKS_AITOOLS_AUTO_INSTALL": "false"}},
{name: "the agent features switch installs nothing", env: map[string]string{"DATABRICKS_AGENT_FEATURES_DISABLED": "1"}},
{name: "CI installs nothing", env: map[string]string{"CI": "true"}},
{name: "a development build installs nothing", env: map[string]string{"DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION": ""}},
{name: "a command that skips auto-install installs nothing", command: "aitools list"},
Expand Down
4 changes: 4 additions & 0 deletions cmd/aitools/autoinstall_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/databricks/cli/libs/log"
"github.com/databricks/cli/libs/log/handler"
"github.com/databricks/cli/libs/process"
"github.com/databricks/cli/libs/skills"
"github.com/databricks/cli/libs/telemetry"
"github.com/databricks/cli/libs/telemetry/protos"
"github.com/databricks/cli/libs/versioncheck"
Expand Down Expand Up @@ -109,6 +110,9 @@ const autoInstallNoticeCommands = "Turn off: databricks aitools auto-install dis
// would have without auto-install.
func AutoInstall(cmd *cobra.Command) os.Signal {
ctx := cmd.Context()
if skills.AgentFeaturesDisabled(ctx) {
return nil
}
defer func() {
if r := recover(); r != nil {
log.Debugf(ctx, "auto-install: panic: %v", r)
Expand Down
39 changes: 39 additions & 0 deletions cmd/aitools/autoinstall_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,45 @@ func TestAutoInstallSkipsTheGateLookup(t *testing.T) {
assert.Equal(t, autoinstall.State{Consented: true, ID: "treatment-machine"}, state, "the version is not settled")
}

// DATABRICKS_AGENT_FEATURES_DISABLED turns auto-install off: the run neither
// looks the gate up nor installs, though the same coding agent's call installs
// without it.
func TestAutoInstallOffWithAgentFeaturesDisabled(t *testing.T) {
for _, tc := range []struct {
name string
disabled []string
install bool
}{
{name: "unset", install: true},
{name: "true", disabled: []string{"DATABRICKS_AGENT_FEATURES_DISABLED", "1"}},
} {
t.Run(tc.name, func(t *testing.T) {
agentEnv := append([]string{"CLAUDECODE", "1"}, tc.disabled...)
home := setupAutoInstallHome(t, "", agentEnv...)
lookups := 0
t.Cleanup(func() { gateOn = autoinstall.GateOn })
gateOn = func(context.Context, string) (bool, error) {
lookups++
return true, nil
}
ctx := cmdio.MockDiscard(t.Context())
ctx = telemetry.WithNewLogger(ctx)
runAutoInstallHook(ctx)
if tc.install {
assert.Equal(t, 1, lookups)
assert.FileExists(t, filepath.Join(home, ".cursor", "skills", "databricks-test", "SKILL.md"))
return
}
assert.Zero(t, lookups)
assert.NoDirExists(t, filepath.Join(home, ".cursor", "skills"))
assert.Empty(t, telemetry.BufferedEvents(ctx))
state, err := autoinstall.Load(ctx)
require.NoError(t, err)
assert.Equal(t, autoinstall.State{Consented: true, ID: "treatment-machine"}, state, "the seeded state is left as it was")
})
}
}

// Root running in a user's home (sudo with HOME kept) leaves the home alone:
// it takes no lock, reads and writes no state, looks no gate up and installs
// nothing, so the user's own runs can still write there. The same run as the
Expand Down
47 changes: 47 additions & 0 deletions cmd/aitools/autoinstall_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package aitools

import (
"testing"

"github.com/databricks/cli/libs/aitools/autoinstall"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/env"
"github.com/databricks/cli/libs/skills"
"github.com/stretchr/testify/assert"
)

// enable says when DATABRICKS_AGENT_FEATURES_DISABLED still turns auto-install
// off, as it does for DATABRICKS_AITOOLS_AUTO_INSTALL; unset, it says nothing
// about it.
func TestPrintAutoInstallSettingAgentFeaturesDisabled(t *testing.T) {
const warning = "DATABRICKS_AGENT_FEATURES_DISABLED still disables it in this environment; unset it to let it run."

ctx, stderr := cmdio.NewTestContextWithStderr(t.Context())
ctx = env.Set(ctx, skills.AgentFeaturesDisabledEnv, "")
printAutoInstallSetting(ctx, true)
assert.NotContains(t, stderr.String(), skills.AgentFeaturesDisabledEnv)

ctx, stderr = cmdio.NewTestContextWithStderr(t.Context())
ctx = env.Set(ctx, skills.AgentFeaturesDisabledEnv, "1")
printAutoInstallSetting(ctx, true)
assert.Contains(t, stderr.String(), "Automatic installation of Databricks AI tools is enabled.")
assert.Contains(t, stderr.String(), warning)

// A disable says nothing about the environment.
ctx, stderr = cmdio.NewTestContextWithStderr(t.Context())
ctx = env.Set(ctx, skills.AgentFeaturesDisabledEnv, "1")
printAutoInstallSetting(ctx, false)
assert.NotContains(t, stderr.String(), skills.AgentFeaturesDisabledEnv)
}

// With both variables set, one warning names both, so unsetting only one of
// them is not taken for a fix.
func TestPrintAutoInstallSettingBothOverrides(t *testing.T) {
ctx, stderr := cmdio.NewTestContextWithStderr(t.Context())
ctx = env.Set(ctx, autoinstall.EnvVar, "false")
ctx = env.Set(ctx, skills.AgentFeaturesDisabledEnv, "1")
printAutoInstallSetting(ctx, true)
assert.Contains(t, stderr.String(), autoinstall.EnvVar+" and "+skills.AgentFeaturesDisabledEnv+
" still disable it in this environment; unset both to let it run.")
assert.NotContains(t, stderr.String(), "unset it to let it run")
}
Loading
Loading