diff --git a/libs/aitools/agents/registry_test.go b/libs/aitools/agents/registry_test.go index 20eca404cdf..2326a780326 100644 --- a/libs/aitools/agents/registry_test.go +++ b/libs/aitools/agents/registry_test.go @@ -11,60 +11,100 @@ import ( "github.com/stretchr/testify/require" ) -func TestSkillAgentRegistryPaths(t *testing.T) { +func TestDetectProjectInstalled(t *testing.T) { + cwd := t.TempDir() + for _, name := range []string{NamePi, NameGemini, NameGoose, NameKiro} { + dir := filepath.Join(ByName(name).ProjectSkillsDir(cwd), "databricks-core") + require.NoError(t, os.MkdirAll(dir, 0o755)) + } + // A non-databricks skill must not count as a Databricks install. + require.NoError(t, os.MkdirAll(filepath.Join(cwd, ".pi", "skills", "other-skill"), 0o755)) + + var names []string + for _, a := range DetectProjectInstalled(cwd) { + names = append(names, a.Name) + } + assert.ElementsMatch(t, []string{NamePi, NameGemini, NameGoose, NameKiro}, names) +} + +// TestRegistryContract pins each registry agent's name, display name, the +// binary probed on PATH, the plugin installed for it, its marker file, where +// its skills are written and whether it supports project scope. Adding, +// removing or changing one of these fields must update this table. The MCP +// spec and plugin manifest readers are not covered here. +func TestRegistryContract(t *testing.T) { home := t.TempDir() cwd := t.TempDir() ctx := env.WithUserHomeDir(t.Context(), home) - ctx = env.Set(ctx, "XDG_CONFIG_HOME", filepath.Join(home, ".config")) - ctx = env.Set(ctx, "APPDATA", "") + // Clear the per-agent overrides so these directories derive from home. + for _, v := range []string{"CLAUDE_CONFIG_DIR", "PI_CODING_AGENT_DIR", "GEMINI_CLI_HOME", "GOOSE_PATH_ROOT"} { + t.Setenv(v, "") + } + // Point the config roots away from their defaults so the OpenCode and Goose + // rows fail if either agent stops honoring them. + xdg := filepath.Join(home, "xdg") + appData := filepath.Join(home, "appdata") + t.Setenv("XDG_CONFIG_HOME", xdg) + t.Setenv("APPDATA", appData) - gooseGlobalDir := filepath.Join(home, ".config", "goose", "skills") + openCodeGlobalDir := filepath.Join(xdg, "opencode", "skills") + gooseGlobalDir := filepath.Join(xdg, "goose", "skills") if runtime.GOOS == "windows" { - gooseGlobalDir = filepath.Join(home, "AppData", "Roaming", "Block", "goose", "config", "skills") + openCodeGlobalDir = filepath.Join(appData, "opencode", "skills") + gooseGlobalDir = filepath.Join(appData, "Block", "goose", "config", "skills") } + databricks := &PluginSpec{Marketplace: "databricks-agent-skills", ID: "databricks", Source: "databricks/databricks-agent-skills"} + claude := &PluginSpec{Marketplace: "claude-plugins-official", ID: "databricks", Source: "anthropics/claude-plugins-official", Shared: true} tests := []struct { - name string - binary string - displayName string - globalDir string - projectDir string + name string + displayName string + binary string + plugin *PluginSpec + mandatoryFile string + globalDir string + // projectDir is empty for agents without project scope. + projectDir string }{ - {NamePi, "pi", "Pi", filepath.Join(home, ".pi", "agent", "skills"), filepath.Join(cwd, ".pi", "skills")}, - {NameGemini, "gemini", "Gemini CLI", filepath.Join(home, ".gemini", "skills"), filepath.Join(cwd, ".gemini", "skills")}, - {NameGoose, "goose", "Goose", gooseGlobalDir, filepath.Join(cwd, ".goose", "skills")}, - {NameKiro, "kiro", "Kiro", filepath.Join(home, ".kiro", "skills"), filepath.Join(cwd, ".kiro", "skills")}, + {"claude-code", "Claude Code", "claude", claude, "", filepath.Join(home, ".claude", "skills"), filepath.Join(cwd, ".claude", "skills")}, + {"cursor", "Cursor", "cursor-agent", nil, "", filepath.Join(home, ".cursor", "skills"), ""}, + {"codex", "Codex CLI", "codex", databricks, "", filepath.Join(home, ".codex", "skills"), ""}, + {"opencode", "OpenCode", "opencode", nil, "", openCodeGlobalDir, ""}, + {"copilot", "GitHub Copilot", "copilot", databricks, "", filepath.Join(home, ".copilot", "skills"), ""}, + {"antigravity", "Antigravity", "", nil, "", filepath.Join(home, ".gemini", "antigravity", "global_skills"), ""}, + {"pi", "Pi", "pi", nil, "", filepath.Join(home, ".pi", "agent", "skills"), filepath.Join(cwd, ".pi", "skills")}, + {"gemini", "Gemini CLI", "gemini", nil, "projects.json", filepath.Join(home, ".gemini", "skills"), filepath.Join(cwd, ".gemini", "skills")}, + {"goose", "Goose", "goose", nil, "", gooseGlobalDir, filepath.Join(cwd, ".goose", "skills")}, + {"kiro", "Kiro", "kiro", nil, "", filepath.Join(home, ".kiro", "skills"), filepath.Join(cwd, ".kiro", "skills")}, + } + + var names []string + for _, a := range Registry { + names = append(names, a.Name) } + var want []string + for _, tc := range tests { + want = append(want, tc.name) + } + require.Equal(t, want, names, "registry agents or their order changed; update this table") for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { a := ByName(tc.name) require.NotNil(t, a) - assert.Equal(t, tc.binary, a.Binary) assert.Equal(t, tc.displayName, a.DisplayName) - assert.True(t, a.SupportsProjectScope) - assert.Nil(t, a.Plugin) + assert.Equal(t, tc.binary, a.Binary) + assert.Equal(t, tc.plugin, a.Plugin) + assert.Equal(t, tc.mandatoryFile, a.MandatoryFile) globalDir, err := a.SkillsDir(ctx) require.NoError(t, err) assert.Equal(t, tc.globalDir, globalDir) - assert.Equal(t, tc.projectDir, a.ProjectSkillsDir(cwd)) - }) - } -} -func TestDetectProjectInstalled(t *testing.T) { - cwd := t.TempDir() - for _, name := range []string{NamePi, NameGemini, NameGoose, NameKiro} { - dir := filepath.Join(ByName(name).ProjectSkillsDir(cwd), "databricks-core") - require.NoError(t, os.MkdirAll(dir, 0o755)) - } - // A non-databricks skill must not count as a Databricks install. - require.NoError(t, os.MkdirAll(filepath.Join(cwd, ".pi", "skills", "other-skill"), 0o755)) - - var names []string - for _, a := range DetectProjectInstalled(cwd) { - names = append(names, a.Name) + assert.Equal(t, tc.projectDir != "", a.SupportsProjectScope) + if tc.projectDir != "" { + assert.Equal(t, tc.projectDir, a.ProjectSkillsDir(cwd)) + } + }) } - assert.ElementsMatch(t, []string{NamePi, NameGemini, NameGoose, NameKiro}, names) }