Skip to content
Merged
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
1 change: 1 addition & 0 deletions .nextchanges/cli/aitools-install-telemetry-auth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fix `databricks aitools install` waiting a long time on an unreachable or slow workspace while it resolves authentication for telemetry; that wait is now limited to a few seconds. ([#7468](https://github.com/databricks/cli/pull/7468))
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = false
10 changes: 10 additions & 0 deletions acceptance/cmd/aitools/install-host-metadata/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

=== workspace unreachable: the background auth resolution prints nothing

>>> [CLI] aitools install --skills-only --scope=global --agents=claude-code
Installing Databricks skills for Claude Code...
Using skills version test-ref
Fetching skills manifest...
Installed 1 skill.

=== --debug still shows the hostmetadata line, at debug level
17 changes: 17 additions & 0 deletions acceptance/cmd/aitools/install-host-metadata/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Isolate HOME so the real machine's agents and skills are not seen. The
# committed home/.claude is what agent detection finds.
sethome home

# The workspace host does not resolve, so the background telemetry auth
# resolution fails to fetch host metadata and logs hostmetadata's warning.
# The skills still come from the mock server (DATABRICKS_SKILLS_BASE_URL).
export DATABRICKS_HOST=https://unreachable.test

title "workspace unreachable: the background auth resolution prints nothing"
trace $CLI aitools install --skills-only --scope=global --agents=claude-code

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[nice to have] The success path, where the real MustAnyClient runs on the shadow command and the copied config reaches root's Upload, is covered only by a unit test with a fake resolver. If the shadow stopped seeing --profile, or root uploaded from a different context, aitools install would silently stop uploading its event and no test would fail. Please add a case under acceptance/cmd/aitools/telemetry/, which already records /telemetry-ext and has print_telemetry. It would run aitools install --skills-only --scope=global --agents=claude-code against the mock server, with this test's manifest stubs, and print the uploaded aitools_install_event.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added acceptance/cmd/aitools/telemetry/install in e503a62. It runs aitools install --skills-only --scope=global --agents=claude-code against the mock server and prints the uploaded aitools_install_event for PAT auth and for a databricks-cli profile passed with --profile and a valid cached token. A third case uses an expired cached token and checks that nothing is refreshed or uploaded.

While there: the new base includes #7003 (title adds its own trailing newline), so I dropped the \n from this script's titles, which had made the test fail on the restacked head.


title "--debug still shows the hostmetadata line, at debug level"
# A fresh cache, so the first run's negative-cache entry does not skip the fetch.
export DATABRICKS_CACHE_DIR="$PWD/debug-cache"
trace $CLI aitools install --skills-only --scope=global --agents=claude-code --debug &> LOG.debug
contains.py 'Debug: [hostmetadata] failed to fetch host metadata for https://unreachable.test' '!Warn: [hostmetadata]' < LOG.debug > /dev/null
36 changes: 36 additions & 0 deletions acceptance/cmd/aitools/install-host-metadata/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Mock server replaces raw.githubusercontent.com for the skills manifest and files.
Env.DATABRICKS_SKILLS_BASE_URL = "$DATABRICKS_HOST"
Env.DATABRICKS_SKILLS_REF = "test-ref"
# The case needs the telemetry auth resolution to run, whatever the shell sets.
Env.DATABRICKS_CLI_DISABLE_TELEMETRY = ""

Ignore = [
"home",
"debug-cache",
]

[[Server]]
Pattern = "GET /test-ref/manifest.json"
Response.Body = '''
{
"version": "2",
"updated_at": "2026-01-01T00:00:00Z",
"skills": {
"test-stable": {
"version": "1.0.0",
"description": "Stable test skill",
"files": ["SKILL.md"],
"repo_dir": "skills"
}
}
}
'''

[[Server]]
Pattern = "GET /test-ref/skills/test-stable/SKILL.md"
Response.Body = '''---
name: test-stable
---

# Test stable skill
'''
Empty file.
1 change: 1 addition & 0 deletions acceptance/cmd/aitools/telemetry/install/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = false
35 changes: 35 additions & 0 deletions acceptance/cmd/aitools/telemetry/install/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

=== install resolves auth in the background: its install event is uploaded

>>> [CLI] aitools install --skills-only --scope=global --agents=claude-code
Installing Databricks skills for Claude Code...
Using skills version test-ref
Fetching skills manifest...
Installed 1 skill.

>>> print_telemetry
{"command":"aitools_install","exit_code":0,"aitools_install_event":{"agents":["CLAUDE_CODE"],"scope":"GLOBAL","error_category":"TYPE_UNSPECIFIED"}}

=== databricks-cli auth with a valid cached token: the event is uploaded

>>> [CLI] aitools install --skills-only --scope=global --agents=claude-code --profile test-profile
Installing Databricks skills for Claude Code...
Using skills version test-ref
Fetching skills manifest...
Installed 1 skill.

>>> print_telemetry
{"command":"aitools_install","exit_code":0,"aitools_install_event":{"agents":["CLAUDE_CODE"],"scope":"GLOBAL","error_category":"TYPE_UNSPECIFIED"}}

=== databricks-cli auth with an expired cached token: no refresh, nothing is uploaded

>>> [CLI] aitools install --skills-only --scope=global --agents=claude-code --profile test-profile
Installing Databricks skills for Claude Code...
Using skills version test-ref
Fetching skills manifest...
Installed 1 skill.

>>> print_requests.py //oidc/v1/token //telemetry-ext

>>> gron.py [TEST_TMP_DIR]/home/.databricks/token-cache.json
json.tokens.test-profile.access_token = "expired-access-token";
42 changes: 42 additions & 0 deletions acceptance/cmd/aitools/telemetry/install/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Isolate HOME so the real machine's agents and skills are not seen. The
# committed home/.claude is what agent detection finds.
sethome home

title "install resolves auth in the background: its install event is uploaded"
trace $CLI aitools install --skills-only --scope=global --agents=claude-code
trace print_telemetry

# A databricks-cli profile whose token comes from the CLI's token cache.
cat > "$HOME/.databrickscfg" <<ENDCFG
[test-profile]
host = $DATABRICKS_HOST
auth_type = databricks-cli
ENDCFG
unset DATABRICKS_HOST DATABRICKS_TOKEN
write_token_cache() {
mkdir -p "$HOME/.databricks"
cat > "$HOME/.databricks/token-cache.json" <<ENDCACHE
{
"version": 1,
"tokens": {
"test-profile": {
"access_token": "$1",
"token_type": "Bearer",
"refresh_token": "test-refresh-token",
"expiry": "$2"
}
}
}
ENDCACHE
}

title "databricks-cli auth with a valid cached token: the event is uploaded"
write_token_cache valid-access-token 2099-01-01T00:00:00Z
trace $CLI aitools install --skills-only --scope=global --agents=claude-code --profile test-profile
trace print_telemetry

title "databricks-cli auth with an expired cached token: no refresh, nothing is uploaded"
write_token_cache expired-access-token 2000-01-01T00:00:00Z
trace $CLI aitools install --skills-only --scope=global --agents=claude-code --profile test-profile
trace print_requests.py //oidc/v1/token //telemetry-ext
trace gron.py "$HOME/.databricks/token-cache.json" | grep access_token
29 changes: 29 additions & 0 deletions acceptance/cmd/aitools/telemetry/install/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Mock server replaces raw.githubusercontent.com for the skills manifest and files.
Env.DATABRICKS_SKILLS_BASE_URL = "$DATABRICKS_HOST"
Env.DATABRICKS_SKILLS_REF = "test-ref"

[[Server]]
Pattern = "GET /test-ref/manifest.json"
Response.Body = '''
{
"version": "2",
"updated_at": "2026-01-01T00:00:00Z",
"skills": {
"test-stable": {
"version": "1.0.0",
"description": "Stable test skill",
"files": ["SKILL.md"],
"repo_dir": "skills"
}
}
}
'''

[[Server]]
Pattern = "GET /test-ref/skills/test-stable/SKILL.md"
Response.Body = '''---
name: test-stable
---

# Test stable skill
'''
8 changes: 4 additions & 4 deletions cmd/aitools/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ func NewInstallCmd() *cobra.Command {
var projectFlag, globalFlag bool

cmd := &cobra.Command{
Use: "install",
// Resolve auth best-effort so telemetry can upload; see tryConfigureAuth.
PreRunE: tryConfigureAuth,
Short: "Install Databricks skills and plugins for coding agents",
Use: "install",
Short: "Install Databricks skills and plugins for coding agents",
Long: `Install Databricks skills and plugins for detected coding agents.

By default this installs the databricks plugin through each agent's own CLI
Expand Down Expand Up @@ -252,6 +250,8 @@ Supported agents: ` + strings.Join(agents.SupportedNames(), ", "),
cmd.Flags().BoolVar(&projectFlag, "project", false, "Install to project directory (cwd)")
cmd.Flags().BoolVar(&globalFlag, "global", false, "Install globally (default)")
markScopeBoolsDeprecated(cmd)
// Resolve auth best-effort and time-bounded so telemetry can upload.
withTelemetryAuth(cmd)
return cmd
}

Expand Down
6 changes: 5 additions & 1 deletion cmd/aitools/legacy_skills.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func newLegacySkillsInstallCmd() *cobra.Command {
delegateArgs = append(delegateArgs, "--experimental")
}
installCmd.SetArgs(delegateArgs)
return installCmd.Execute()
err := installCmd.Execute()
// Root uploads telemetry from this command's context, so carry over
// the auth config the install resolved on its own context.
cmd.SetContext(installCmd.Context())
return err
},
}

Expand Down
25 changes: 25 additions & 0 deletions cmd/aitools/legacy_skills_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package aitools

import (
"testing"
"time"

"github.com/databricks/cli/libs/cmdctx"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/env"
"github.com/databricks/cli/libs/telemetry"
"github.com/databricks/databricks-sdk-go/config"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -120,3 +124,24 @@ func TestLegacySkillsListDelegatesToListFn(t *testing.T) {
require.NoError(t, err)
assert.True(t, called)
}

// Root uploads telemetry from the alias command's context, so the config the
// delegated install resolves for its telemetry must end up there.
func TestLegacySkillsInstallKeepsTelemetryAuthConfig(t *testing.T) {
setupTestAgents(t)
setupInstallMock(t)
setTelemetryAuth(t, time.Second, func(cmd *cobra.Command, args []string) error {
cmd.SetContext(cmdctx.SetConfigUsed(cmd.Context(), &config.Config{Host: "https://ws.test"}))
return nil
})

ctx := telemetry.WithNewLogger(cmdio.MockDiscard(t.Context()))
ctx = env.Set(ctx, "DATABRICKS_CLI_DISABLE_TELEMETRY", "")
cmd := newLegacySkillsInstallCmd()
cmd.SetContext(ctx)
cmd.SetArgs([]string{})

require.NoError(t, cmd.Execute())
require.True(t, cmdctx.HasConfigUsed(cmd.Context()))
assert.Equal(t, "https://ws.test", cmdctx.ConfigUsed(cmd.Context()).Host)
}
Loading
Loading