Skip to content
Draft
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
26 changes: 26 additions & 0 deletions cmd/aitools/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,3 +624,29 @@ func TestListScopeFlag(t *testing.T) {
})
}
}

// TestLoadStateForScopeIgnoresMCPOnlyState checks that a state file holding only MCP records is not an
// install of skills or plugins, so the scope is not reported as loaded.
func TestLoadStateForScopeIgnoresMCPOnlyState(t *testing.T) {
ctx := env.WithUserHomeDir(t.Context(), t.TempDir())
dir, err := installer.GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, installer.SaveMCPState(dir, &installer.MCPState{Servers: []installer.MCPEntry{{Name: "github-logfood"}}}))

state := loadStateForScope(ctx, "", installer.ScopeProject, installer.GlobalSkillsDir, "global")
assert.Nil(t, state)
}

// TestLoadStateForScopeKeepsSkillsState checks that a state file with skills is loaded, with or without
// MCP records next to them.
func TestLoadStateForScopeKeepsSkillsState(t *testing.T) {
ctx := env.WithUserHomeDir(t.Context(), t.TempDir())
dir, err := installer.GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, installer.SaveState(dir, &installer.InstallState{SchemaVersion: installer.CurrentSchemaVersion, Skills: map[string]string{"databricks": "1.0.0"}}))
require.NoError(t, installer.SaveMCPState(dir, &installer.MCPState{Servers: []installer.MCPEntry{{Name: "github-logfood"}}}))

state := loadStateForScope(ctx, "", installer.ScopeProject, installer.GlobalSkillsDir, "global")
require.NotNil(t, state)
assert.Equal(t, "1.0.0", state.Skills["databricks"])
}
15 changes: 15 additions & 0 deletions cmd/aitools/scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,18 @@ func TestResolveScopeForUpdateProjectFlagHintsUpdate(t *testing.T) {
require.Error(t, err)
assert.Contains(t, err.Error(), "with --scope=global to update those")
}

// TestDetectInstalledScopesIgnoresMCPOnlyState checks that MCP records alone do not make a scope
// installed.
func TestDetectInstalledScopesIgnoresMCPOnlyState(t *testing.T) {
globalDir, projectDir := setupScopeTest(t)
require.NoError(t, installer.SaveMCPState(globalDir, &installer.MCPState{Servers: []installer.MCPEntry{{Name: "github-logfood"}}}))

hasGlobal, hasProject, err := detectInstalledScopes(globalDir, projectDir)
require.NoError(t, err)
assert.False(t, hasGlobal)
assert.False(t, hasProject)

_, err = withExplicitScopeCheck(globalDir, installer.ScopeGlobal, "update", projectDir, false, false)
assert.Error(t, err)
}
14 changes: 14 additions & 0 deletions cmd/aitools/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,17 @@ func TestUninstallConfirmMessage(t *testing.T) {
require.True(t, ask3)
assert.Contains(t, msg3, "from cursor")
}

// TestUninstallConfirmMessageMCPOnlyState checks that an explicit skill list does not prompt when
// the state file holds only MCP records, as loaded for uninstall.
func TestUninstallConfirmMessageMCPOnlyState(t *testing.T) {
dir := t.TempDir()
require.NoError(t, installer.SaveMCPState(dir, &installer.MCPState{Servers: []installer.MCPEntry{{Name: "github-logfood"}}}))
st, err := installer.LoadState(dir)
require.NoError(t, err)

_, ask := uninstallConfirmMessage(st, installer.UninstallOptions{Scope: installer.ScopeGlobal})
assert.False(t, ask)
_, ask = uninstallConfirmMessage(st, installer.UninstallOptions{Scope: installer.ScopeGlobal, Skills: []string{"databricks-sql"}})
assert.False(t, ask)
}
18 changes: 18 additions & 0 deletions cmd/aitools/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,3 +616,21 @@ func TestUpdateWithoutStateKeepsTheInstallGuidance(t *testing.T) {
err := cmd.Execute()
require.ErrorIs(t, err, installer.ErrNothingInstalled)
}

// TestUpdateMCPOnlyStateReachesSkillsUpdate checks that a state file holding only MCP records still
// runs the skills update, which reports that nothing is installed.
func TestUpdateMCPOnlyStateReachesSkillsUpdate(t *testing.T) {
home := setupTestAgents(t)
t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.6")
calls := setupUpdateMock(t)

globalDir := filepath.Join(home, ".databricks", "aitools", "skills")
require.NoError(t, installer.SaveMCPState(globalDir, &installer.MCPState{Servers: []installer.MCPEntry{{Name: "github-logfood"}}}))

ctx, _ := cmdio.NewTestContextWithStderr(t.Context())
cmd := NewUpdateCmd()
cmd.SetContext(ctx)
cmd.SetArgs([]string{"--scope", "global", "--check"})
require.NoError(t, cmd.Execute())
assert.Len(t, *calls, 1)
}
20 changes: 20 additions & 0 deletions cmd/aitools/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,23 @@ func TestVersionAlwaysLabelsScope(t *testing.T) {
assert.Contains(t, output, "Skills (global): v0.1.0")
assert.NotContains(t, output, "Skills (project)")
}

// TestVersionMCPOnlyStateReportsNothingInstalled checks that a state file holding only MCP records
// is reported as having no skills or plugins.
func TestVersionMCPOnlyStateReportsNothingInstalled(t *testing.T) {
tmp := t.TempDir()
t.Setenv("HOME", tmp)
t.Setenv("USERPROFILE", tmp)
t.Chdir(tmp)

globalDir := filepath.Join(tmp, ".databricks", "aitools", "skills")
require.NoError(t, installer.SaveMCPState(globalDir, &installer.MCPState{Servers: []installer.MCPEntry{{Name: "github-logfood"}}}))

ctx, stderr := cmdio.NewTestContextWithStderr(t.Context())
cmd := NewVersionCmd()
cmd.SetContext(ctx)
require.NoError(t, cmd.RunE(cmd, nil))

assert.Contains(t, stderr.String(), "No Databricks skills or plugins installed.")
assert.NotContains(t, stderr.String(), "Databricks skills and plugins:")
}
4 changes: 2 additions & 2 deletions libs/aitools/installer/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestRemoveLegacyRawSkills(t *testing.T) {
require.NoError(t, os.WriteFile(filepath.Join(agentDir, "delta", "extra.md"), []byte("mine"), 0o644))

require.NoError(t, SaveState(baseDir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Files: map[string]FileRecord{
"alpha/SKILL.md": {SHA256: sha("alpha")},
"beta/SKILL.md": {SHA256: sha("beta-content")},
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestHasManagedRawSkillsForAgent(t *testing.T) {
require.NoError(t, os.WriteFile(filepath.Join(agentDir, "thirdparty", "SKILL.md"), []byte("mine"), 0o644))

require.NoError(t, SaveState(baseDir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Files: map[string]FileRecord{
"alpha/SKILL.md": {SHA256: sha("alpha")},
},
Expand Down
2 changes: 1 addition & 1 deletion libs/aitools/installer/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func savePluginState(t *testing.T, dirFn func(context.Context) (string, error),
dir, err := dirFn(t.Context())
require.NoError(t, err)
require.NoError(t, SaveState(dir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Plugins: plugins,
}))
}
2 changes: 1 addition & 1 deletion libs/aitools/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func InstallSkillsForAgents(ctx context.Context, src ManifestSource, targetAgent
// previous installs (e.g., experimental skills from a prior run) are preserved.
if state == nil {
state = &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Skills: make(map[string]string, len(targetSkills)),
RepoDirs: make(map[string]string, len(targetSkills)),
}
Expand Down
39 changes: 38 additions & 1 deletion libs/aitools/installer/installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func TestInstallSkillsForAgentsWritesState(t *testing.T) {
state, err := LoadState(globalDir)
require.NoError(t, err)
require.NotNil(t, state)
assert.Equal(t, schemaVersionV2, state.SchemaVersion)
assert.Equal(t, CurrentSchemaVersion, state.SchemaVersion)
assert.Equal(t, testSkillsRef, state.Release)
assert.Len(t, state.Skills, 2)
assert.Equal(t, "0.1.0", state.Skills["databricks-sql"])
Expand Down Expand Up @@ -1654,3 +1654,40 @@ func TestInstallAllSkillsWithNoSkillToInstall(t *testing.T) {
require.NoError(t, InstallAllSkills(ctx))
assert.Contains(t, stderr.String(), NoSkillsResolvedMessage)
}

// TestLegacyTargetedInstallBlockedWithMCPOnlyState checks that MCP records in the state file do not
// count as tracked skills, so skills on disk without a skills record still block a targeted install.
func TestLegacyTargetedInstallBlockedWithMCPOnlyState(t *testing.T) {
tmp := setupTestHome(t)
ctx := cmdio.MockDiscard(t.Context())
setupFetchMock(t)
t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef)

globalDir := filepath.Join(tmp, ".databricks", "aitools", "skills")
require.NoError(t, os.MkdirAll(filepath.Join(globalDir, "databricks-sql"), 0o755))
require.NoError(t, SaveMCPState(globalDir, &MCPState{Servers: []MCPEntry{{Name: "github-logfood"}}}))

src := &mockManifestSource{manifest: testManifest()}
err := InstallSkillsForAgents(ctx, src, []*agents.Agent{testAgent(tmp)}, InstallOptions{
SpecificSkills: []string{"databricks-sql"},
})
require.Error(t, err)
assert.Contains(t, err.Error(), "legacy install detected")
}

// TestInstallSpecificSkillWithEmptyStateFile checks that an empty state file, as an update that pruned
// every skill leaves, does not count as a legacy install, so a targeted install still runs.
func TestInstallSpecificSkillWithEmptyStateFile(t *testing.T) {
tmp := setupTestHome(t)
ctx := cmdio.MockDiscard(t.Context())
setupFetchMock(t)
t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef)
globalDir := filepath.Join(tmp, ".databricks", "aitools", "skills")
require.NoError(t, os.MkdirAll(filepath.Join(globalDir, "databricks-old"), 0o755))
require.NoError(t, os.WriteFile(filepath.Join(globalDir, ".state.json"), []byte(`{"schema_version": 2, "skills": {}}`+"\n"), 0o600))

err := InstallSkillsForAgents(ctx, &mockManifestSource{manifest: testManifest()}, []*agents.Agent{testAgent(tmp)}, InstallOptions{
SpecificSkills: []string{"databricks-sql"},
})
require.NoError(t, err)
}
2 changes: 1 addition & 1 deletion libs/aitools/installer/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func RecordPluginInstalls(ctx context.Context, cliScope string, records map[stri
// Initialize all maps so a later skills install/update can assign into a
// plugin-only state without hitting a nil map.
state = &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Skills: map[string]string{},
RepoDirs: map[string]string{},
Files: map[string]FileRecord{},
Expand Down
24 changes: 12 additions & 12 deletions libs/aitools/installer/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func TestUninstallSkillsWithResultTearsDownPlugin(t *testing.T) {
dir, err := GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, SaveState(dir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Release: "v0.2.6",
Plugins: map[string]PluginRecord{
agents.NameCopilot: {Marketplace: "databricks-agent-skills", Plugin: "databricks", Scope: "user", InstalledMarketplace: true},
Expand Down Expand Up @@ -411,7 +411,7 @@ func TestUninstallSkillsWithResultTargetsPluginAgents(t *testing.T) {
dir, err := GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, SaveState(dir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Release: "v0.2.6",
Plugins: map[string]PluginRecord{
agents.NameClaudeCode: {Marketplace: "claude-plugins-official", Plugin: "databricks", Scope: "user"},
Expand Down Expand Up @@ -447,7 +447,7 @@ func TestUninstallNeverDeregistersSharedMarketplace(t *testing.T) {
// Claude's claude-plugins-official is a Shared marketplace; even a stale
// InstalledMarketplace=true must never trigger a de-register.
require.NoError(t, SaveState(dir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Plugins: map[string]PluginRecord{
agents.NameClaudeCode: {Marketplace: "claude-plugins-official", Plugin: "databricks", InstalledMarketplace: true},
},
Expand Down Expand Up @@ -476,7 +476,7 @@ func TestUninstallKeepMarketplace(t *testing.T) {
dir, err := GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, SaveState(dir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Plugins: map[string]PluginRecord{
agents.NameCopilot: {Marketplace: "databricks-agent-skills", Plugin: "databricks", InstalledMarketplace: true},
},
Expand All @@ -497,7 +497,7 @@ func TestUninstallKeepsUnknownAgentRecord(t *testing.T) {
dir, err := GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, SaveState(dir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Plugins: map[string]PluginRecord{
"mystery-agent": {Marketplace: "databricks-agent-skills", Plugin: "databricks"},
},
Expand Down Expand Up @@ -526,7 +526,7 @@ func TestUninstallClearsRecordWhenMarketplaceRemoveFails(t *testing.T) {
dir, err := GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, SaveState(dir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Plugins: map[string]PluginRecord{
agents.NameCopilot: {Marketplace: "databricks-agent-skills", Plugin: "databricks", InstalledMarketplace: true},
},
Expand All @@ -551,7 +551,7 @@ func TestUpdateInstalledPlugins(t *testing.T) {
dir, err := GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, SaveState(dir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Release: "v0.2.6",
Plugins: map[string]PluginRecord{
agents.NameCopilot: {Marketplace: "databricks-agent-skills", Plugin: "databricks", Scope: "user", Version: "0.2.6"},
Expand Down Expand Up @@ -596,7 +596,7 @@ func TestUpdateInstalledPluginsRecordsUnknownVersionWhenRefreshFails(t *testing.
dir, err := GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, SaveState(dir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Release: "v" + tc.recorded,
Plugins: map[string]PluginRecord{
agents.NameClaudeCode: {Marketplace: "claude-plugins-official", Plugin: "databricks", Scope: "user", Version: tc.recorded},
Expand Down Expand Up @@ -635,7 +635,7 @@ func TestUpdateInstalledPluginsUsesRecordedClaudeScope(t *testing.T) {
dir, err := GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, SaveState(dir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Release: "v0.2.6",
Plugins: map[string]PluginRecord{
agents.NameClaudeCode: {Marketplace: "claude-plugins-official", Plugin: "databricks", Scope: scope, Version: "0.2.6"},
Expand Down Expand Up @@ -729,7 +729,7 @@ func saveUnknownAgentPlugin(t *testing.T) (context.Context, string) {
dir, err := GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, SaveState(dir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Release: "v0.2.6",
Plugins: map[string]PluginRecord{
"future-agent": {Marketplace: "databricks-agent-skills", Plugin: "databricks", Scope: "user", Version: "0.2.6"},
Expand All @@ -748,7 +748,7 @@ func saveCopilotPlugin(t *testing.T) (context.Context, string) {
dir, err := GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, SaveState(dir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Release: "v0.2.6",
Plugins: map[string]PluginRecord{
agents.NameCopilot: {Marketplace: "databricks-agent-skills", Plugin: "databricks", Scope: "user", Version: "0.2.6"},
Expand All @@ -769,7 +769,7 @@ func TestUninstallSkillsWithResultUsesRecordedClaudeScope(t *testing.T) {
dir, err := GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, SaveState(dir, &InstallState{
SchemaVersion: schemaVersionV2,
SchemaVersion: CurrentSchemaVersion,
Plugins: map[string]PluginRecord{
agents.NameClaudeCode: {Marketplace: "claude-plugins-official", Plugin: "databricks", Scope: scope},
},
Expand Down
Loading
Loading