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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `databricks aitools install` now rejects an unknown `--agents` name before it shows the scope prompt, instead of after. ([#7469](https://github.com/databricks/cli/pull/7469))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = false
66 changes: 66 additions & 0 deletions acceptance/cmd/aitools/telemetry/install-failure/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

=== a skill missing from the manifest fails after the plan is confirmed

>>> [CLI] aitools install --skills-only --scope=global --agents=cursor --skills=nonexistent
Installing Databricks skills for Cursor...
Using skills version test-ref
Fetching skills manifest...
Error: skill "nonexistent" not found

>>> print_telemetry
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STARTED","interactive":false,"install_mode":"SKILLS_ONLY"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"FLAGS_VALIDATED","interactive":false,"install_mode":"SKILLS_ONLY"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"SCOPE_RESOLVED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"AGENTS_SELECTED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"PLAN_CONFIRMED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"FINISHED","outcome":"FAILURE","error_category":"SKILL_NOT_FOUND","interactive":false,"install_mode":"SKILLS_ONLY","agents":["CURSOR"],"scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":1,"aitools_install_event":{"agents":["CURSOR"],"scope":"GLOBAL","error_category":"SKILL_NOT_FOUND"}}

=== a manifest the server does not have is MANIFEST_NOT_FOUND

>>> DATABRICKS_SKILLS_REF=missing-ref [CLI] aitools install --skills-only --scope=global --agents=cursor
Installing Databricks skills for Cursor...
Using skills version missing-ref
Fetching skills manifest...
Error: skills manifest at databricks-agent-skills@missing-ref: not found

>>> print_telemetry
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STARTED","interactive":false,"install_mode":"SKILLS_ONLY"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"FLAGS_VALIDATED","interactive":false,"install_mode":"SKILLS_ONLY"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"SCOPE_RESOLVED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"AGENTS_SELECTED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"PLAN_CONFIRMED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"FINISHED","outcome":"FAILURE","error_category":"MANIFEST_NOT_FOUND","interactive":false,"install_mode":"SKILLS_ONLY","agents":["CURSOR"],"scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":1,"aitools_install_event":{"agents":["CURSOR"],"scope":"GLOBAL","error_category":"MANIFEST_NOT_FOUND"}}

=== any other HTTP error status from the manifest fetch is not classified yet (the error is untyped)

>>> DATABRICKS_SKILLS_REF=broken-ref [CLI] aitools install --skills-only --scope=global --agents=cursor
Installing Databricks skills for Cursor...
Using skills version broken-ref
Fetching skills manifest...
Error: failed to fetch manifest: HTTP 500

>>> print_telemetry
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STARTED","interactive":false,"install_mode":"SKILLS_ONLY"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"FLAGS_VALIDATED","interactive":false,"install_mode":"SKILLS_ONLY"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"SCOPE_RESOLVED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"AGENTS_SELECTED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"PLAN_CONFIRMED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"FINISHED","outcome":"FAILURE","error_category":"UNCATEGORIZED","interactive":false,"install_mode":"SKILLS_ONLY","agents":["CURSOR"],"scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":1,"aitools_install_event":{"agents":["CURSOR"],"scope":"GLOBAL","error_category":"UNCATEGORIZED"}}

=== a named agent skipped for the scope takes its category from the agent's outcome

>>> [CLI] aitools install --skills-only --scope=project --agents=cursor
Skipped Cursor: does not support project-scoped skills
Error: Cursor: does not support project-scoped skills

>>> print_telemetry
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STARTED","interactive":false,"install_mode":"SKILLS_ONLY"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"FLAGS_VALIDATED","interactive":false,"install_mode":"SKILLS_ONLY"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"SCOPE_RESOLVED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"PROJECT"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"AGENTS_SELECTED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"PROJECT"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"PLAN_CONFIRMED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"PROJECT"}}
{"command":"aitools_install","exit_code":1,"aitools_command_event":{"command":"INSTALL","stage":"FINISHED","outcome":"FAILURE","error_category":"UNSUPPORTED_SCOPE","interactive":false,"install_mode":"SKILLS_ONLY","agents":["CURSOR"],"scope":"PROJECT"}}
{"command":"aitools_install","exit_code":1,"aitools_install_event":{"agents":["CURSOR"],"scope":"PROJECT","error_category":"TYPE_UNSPECIFIED","agent_results":[{"agent":"CURSOR","error_category":"UNSUPPORTED_SCOPE"}]}}
24 changes: 24 additions & 0 deletions acceptance/cmd/aitools/telemetry/install-failure/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Isolate HOME so parallel aitools tests don't race on a shared ~/.databricks.
sethome home
mkdir -p "${USERPROFILE:-$HOME}/.cursor"

# Only runs past the plan confirmation are here: a run that ends earlier (a
# flag error, an unknown agent, a --path dump) uploads only if auth has already
# resolved, so whether its events show up depends on timing. The funnel unit
# tests in cmd/aitools cover those runs.

title "a skill missing from the manifest fails after the plan is confirmed"
musterr trace $CLI aitools install --skills-only --scope=global --agents=cursor --skills=nonexistent
trace print_telemetry

title "a manifest the server does not have is MANIFEST_NOT_FOUND"
musterr trace DATABRICKS_SKILLS_REF=missing-ref $CLI aitools install --skills-only --scope=global --agents=cursor
trace print_telemetry

title "any other HTTP error status from the manifest fetch is not classified yet (the error is untyped)"
musterr trace DATABRICKS_SKILLS_REF=broken-ref $CLI aitools install --skills-only --scope=global --agents=cursor
trace print_telemetry

title "a named agent skipped for the scope takes its category from the agent's outcome"
musterr trace $CLI aitools install --skills-only --scope=project --agents=cursor
trace print_telemetry
7 changes: 7 additions & 0 deletions acceptance/cmd/aitools/telemetry/install-failure/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[Server]]
Pattern = "GET /missing-ref/manifest.json"
Response.StatusCode = 404

[[Server]]
Pattern = "GET /broken-ref/manifest.json"
Response.StatusCode = 500
14 changes: 14 additions & 0 deletions acceptance/cmd/aitools/telemetry/install/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ Fetching skills manifest...
Installed 1 skill.

>>> print_telemetry
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"STARTED","interactive":false,"install_mode":"SKILLS_ONLY"}}
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"FLAGS_VALIDATED","interactive":false,"install_mode":"SKILLS_ONLY"}}
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"SCOPE_RESOLVED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"AGENTS_SELECTED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"PLAN_CONFIRMED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"SKILLS_INSTALLED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":0,"aitools_install_event":{"agents":["CLAUDE_CODE"],"scope":"GLOBAL","error_category":"TYPE_UNSPECIFIED"}}
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"FINISHED","outcome":"SUCCESS","interactive":false,"install_mode":"SKILLS_ONLY","agents":["CLAUDE_CODE"],"scope":"GLOBAL"}}

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

Expand All @@ -19,7 +26,14 @@ Fetching skills manifest...
Installed 1 skill.

>>> print_telemetry
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"STARTED","interactive":false,"install_mode":"SKILLS_ONLY"}}
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"FLAGS_VALIDATED","interactive":false,"install_mode":"SKILLS_ONLY"}}
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"SCOPE_RESOLVED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"AGENTS_SELECTED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"PLAN_CONFIRMED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"STEP_COMPLETED","step":"SKILLS_INSTALLED","interactive":false,"install_mode":"SKILLS_ONLY","scope":"GLOBAL"}}
{"command":"aitools_install","exit_code":0,"aitools_install_event":{"agents":["CLAUDE_CODE"],"scope":"GLOBAL","error_category":"TYPE_UNSPECIFIED"}}
{"command":"aitools_install","exit_code":0,"aitools_command_event":{"command":"INSTALL","stage":"FINISHED","outcome":"SUCCESS","interactive":false,"install_mode":"SKILLS_ONLY","agents":["CLAUDE_CODE"],"scope":"GLOBAL"}}

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

Expand Down
29 changes: 0 additions & 29 deletions acceptance/cmd/aitools/telemetry/install/test.toml

This file was deleted.

32 changes: 31 additions & 1 deletion acceptance/cmd/aitools/telemetry/test.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
# Telemetry payloads of the install hint.
# Telemetry payloads of the aitools commands and of the install hint.
# The mock server replaces raw.githubusercontent.com (skills manifest and files).
Env.DATABRICKS_SKILLS_BASE_URL = "$DATABRICKS_HOST"
Env.DATABRICKS_CLI_GITHUB_API_URL = "$DATABRICKS_HOST"
Env.DATABRICKS_SKILLS_REF = "test-ref"
Comment on lines +3 to +5

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.

[nit] This parent config now sets DATABRICKS_SKILLS_BASE_URL / DATABRICKS_SKILLS_REF and serves GET /test-ref/manifest.json, but install/test.toml still sets the same two variables and serves its own manifest on the same route. The leaf stub wins (acceptance/internal/prepare_server.go:248-251), so install runs against test-stable while its siblings use databricks-test, and a change to the parent manifest never reaches install. .agents/rules/testing.md asks to put common test.toml options in the parent. Drop the duplicated env lines and stubs from install/test.toml (its output only says "Installed 1 skill."), or keep the new stubs in the new leaf directories so hint/ and apps-init-tip/ don't inherit them.

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.

Done in 54514a6. Removed install/test.toml: install now uses the parent's env and manifest stubs like its siblings. Its output is unchanged ("Installed 1 skill.").

RecordRequests = true

Ignore = [
"home",
]

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

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

# Test skill
'''
36 changes: 34 additions & 2 deletions cmd/aitools/categorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,38 @@ import (
"github.com/databricks/cli/libs/telemetry/protos"
)

// categorizedError tags an error with a telemetry category at the site that
// knows what failed (flag validation, agent lookup, a prompt). The tag wins
// over the standard library types. Error() and Unwrap() pass through, so the
// user-visible message is unchanged.
type categorizedError struct {
err error
category protos.AitoolsErrorCategory
}

func (e *categorizedError) Error() string { return e.err.Error() }
func (e *categorizedError) Unwrap() error { return e.err }

// withCategory tags a non-nil err with category.
func withCategory(err error, category protos.AitoolsErrorCategory) error {
return &categorizedError{err: err, category: category}
}

// promptError tags a non-nil prompt failure. A user abort (Ctrl-C) keeps its own
// classification so the funnel reports it as CANCELLED, not as a failure.
// Any other error of a prompt step is PROMPT_FAILED, even one with an OS
// error type: the prompt library wraps a failure to open the terminal as an
// *fs.PathError, and FILESYSTEM would point at the skill files instead.
func promptError(err error) error {
if errors.Is(err, huh.ErrUserAborted) {
return err
}
return withCategory(err, protos.AitoolsErrorCategoryPromptFailed)
}

// classifyInstallError maps an aitools error to its telemetry category without
// reading any error text. Typed installer errors win, then standard library
// error types.
// reading any error text. Typed installer errors win, then categories tagged at
// the failure site, then standard library error types.
func classifyInstallError(err error) protos.AitoolsErrorCategory {
if err == nil {
return protos.AitoolsErrorCategoryUnspecified
Expand All @@ -28,6 +57,9 @@ func classifyInstallError(err error) protos.AitoolsErrorCategory {
if skill, ok := errors.AsType[*installer.SkillError](err); ok {
return skillErrorCategory(skill)
}
if tagged, ok := errors.AsType[*categorizedError](err); ok {
return tagged.category
}
return stdlibErrorCategory(err)
}

Expand Down
11 changes: 11 additions & 0 deletions cmd/aitools/categorize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func TestClassifyInstallErrorGenericCauses(t *testing.T) {
{"filesystem on rename", fmt.Errorf("replace skill: %w", &os.LinkError{Op: "rename", Old: "/a", New: "/b", Err: syscall.EBUSY}), protos.AitoolsErrorCategoryFilesystem},
{"filesystem syscall", fmt.Errorf("resolve cwd: %w", os.NewSyscallError("getwd", syscall.ENOENT)), protos.AitoolsErrorCategoryFilesystem},
{"user abort", huh.ErrUserAborted, protos.AitoolsErrorCategoryUserAborted},
{"tagged", withCategory(errors.New("bad flags"), protos.AitoolsErrorCategoryInvalidFlags), protos.AitoolsErrorCategoryInvalidFlags},
{"prompt failure", promptError(errors.New("no tty")), protos.AitoolsErrorCategoryPromptFailed},
{"prompt abort keeps abort", promptError(huh.ErrUserAborted), protos.AitoolsErrorCategoryUserAborted},
{"typed error beats tag", withCategory(&installer.BlockedError{Reason: installer.ReasonCLINotOnPath}, protos.AitoolsErrorCategoryInvalidFlags), protos.AitoolsErrorCategoryCLINotOnPath},
{"plain text stays uncategorized", errors.New("something"), protos.AitoolsErrorCategoryUncategorized},
}
for _, tc := range cases {
Expand All @@ -123,6 +127,13 @@ func TestClassifyInstallErrorGenericCauses(t *testing.T) {
}
}

func TestWithCategoryKeepsMessage(t *testing.T) {
cause := errors.New("cannot use --skills-only with --path")
err := withCategory(cause, protos.AitoolsErrorCategoryInvalidFlags)
assert.Equal(t, cause.Error(), err.Error())
assert.ErrorIs(t, err, cause)
}

// A corrupt install state must not be blamed on the remote manifest. It stays
// UNCATEGORIZED until the installer returns a typed state error, which should
// change this to STATE_INVALID.
Expand Down
Loading
Loading