diff --git a/.nextchanges/cli/aitools-install-telemetry-auth.md b/.nextchanges/cli/aitools-install-telemetry-auth.md new file mode 100644 index 00000000000..6917342d9f7 --- /dev/null +++ b/.nextchanges/cli/aitools-install-telemetry-auth.md @@ -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)) diff --git a/acceptance/cmd/aitools/install-host-metadata/home/.claude/.gitkeep b/acceptance/cmd/aitools/install-host-metadata/home/.claude/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/acceptance/cmd/aitools/install-host-metadata/out.test.toml b/acceptance/cmd/aitools/install-host-metadata/out.test.toml new file mode 100644 index 00000000000..18b1a88417e --- /dev/null +++ b/acceptance/cmd/aitools/install-host-metadata/out.test.toml @@ -0,0 +1 @@ +Cloud = false diff --git a/acceptance/cmd/aitools/install-host-metadata/output.txt b/acceptance/cmd/aitools/install-host-metadata/output.txt new file mode 100644 index 00000000000..6bf0804fd1e --- /dev/null +++ b/acceptance/cmd/aitools/install-host-metadata/output.txt @@ -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 diff --git a/acceptance/cmd/aitools/install-host-metadata/script b/acceptance/cmd/aitools/install-host-metadata/script new file mode 100644 index 00000000000..55a631f1722 --- /dev/null +++ b/acceptance/cmd/aitools/install-host-metadata/script @@ -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 + +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 diff --git a/acceptance/cmd/aitools/install-host-metadata/test.toml b/acceptance/cmd/aitools/install-host-metadata/test.toml new file mode 100644 index 00000000000..ddb4180d056 --- /dev/null +++ b/acceptance/cmd/aitools/install-host-metadata/test.toml @@ -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 +''' diff --git a/acceptance/cmd/aitools/telemetry/install/home/.claude/.gitkeep b/acceptance/cmd/aitools/telemetry/install/home/.claude/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/acceptance/cmd/aitools/telemetry/install/out.test.toml b/acceptance/cmd/aitools/telemetry/install/out.test.toml new file mode 100644 index 00000000000..18b1a88417e --- /dev/null +++ b/acceptance/cmd/aitools/telemetry/install/out.test.toml @@ -0,0 +1 @@ +Cloud = false diff --git a/acceptance/cmd/aitools/telemetry/install/output.txt b/acceptance/cmd/aitools/telemetry/install/output.txt new file mode 100644 index 00000000000..2aea215a26c --- /dev/null +++ b/acceptance/cmd/aitools/telemetry/install/output.txt @@ -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"; diff --git a/acceptance/cmd/aitools/telemetry/install/script b/acceptance/cmd/aitools/telemetry/install/script new file mode 100644 index 00000000000..25e724968df --- /dev/null +++ b/acceptance/cmd/aitools/telemetry/install/script @@ -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" < "$HOME/.databricks/token-cache.json" <