Skip to content

Commit 4343e40

Browse files
committed
test(skill): merge isolated test into table
Signed-off-by: Babak K. Shandiz <babakks@github.com>
1 parent 7a89b91 commit 4343e40

2 files changed

Lines changed: 51 additions & 45 deletions

File tree

internal/skills/registry/registry_test.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func TestInstallDir(t *testing.T) {
4242

4343
tests := []struct {
4444
name string
45+
setup func(*testing.T)
4546
hostID string
4647
scope Scope
4748
gitRoot string
@@ -81,6 +82,17 @@ func TestInstallDir(t *testing.T) {
8182
homeDir: "/home/monalisa",
8283
wantDir: filepath.Join("/home/monalisa", ".claude", "skills"),
8384
},
85+
{
86+
name: "claude code user scope",
87+
setup: func(t *testing.T) {
88+
t.Setenv("CLAUDE_CONFIG_DIR", filepath.Join("/home", "monalisa", ".config", "claude"))
89+
},
90+
hostID: "claude-code",
91+
scope: ScopeUser,
92+
gitRoot: "/tmp/monalisa-repo",
93+
homeDir: "/home/monalisa",
94+
wantDir: filepath.Join("/home", "monalisa", ".config", "claude", "skills"),
95+
},
8496
{
8597
name: "cursor project scope",
8698
hostID: "cursor",
@@ -140,6 +152,10 @@ func TestInstallDir(t *testing.T) {
140152
}
141153
for _, tt := range tests {
142154
t.Run(tt.name, func(t *testing.T) {
155+
if tt.setup != nil {
156+
tt.setup(t)
157+
}
158+
143159
host, err := FindByID(tt.hostID)
144160
require.NoError(t, err)
145161

@@ -154,17 +170,6 @@ func TestInstallDir(t *testing.T) {
154170
}
155171
}
156172

157-
func TestInstallDir_ClaudeConfigDir(t *testing.T) {
158-
t.Setenv(claudeConfigDirEnv, filepath.Join("/home", "monalisa", ".config", "claude"))
159-
160-
host, err := FindByID("claude-code")
161-
require.NoError(t, err)
162-
163-
dir, err := host.InstallDir(ScopeUser, "/tmp/monalisa-repo", "/home/monalisa")
164-
require.NoError(t, err)
165-
assert.Equal(t, filepath.Join("/home", "monalisa", ".config", "claude", "skills"), dir)
166-
}
167-
168173
func TestRepoNameFromRemote(t *testing.T) {
169174
tests := []struct {
170175
remote string

pkg/cmd/skills/install/install_test.go

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ func TestInstallRun(t *testing.T) {
292292
wantErr string
293293
wantStdout string
294294
wantStderr string
295+
assert func(t *testing.T)
295296
}{
296297
{
297298
name: "non-interactive without repo errors",
@@ -1480,6 +1481,37 @@ func TestInstallRun(t *testing.T) {
14801481
wantStdout: "Installed hidden-skill",
14811482
wantStderr: "Skills in hidden directories",
14821483
},
1484+
{
1485+
name: "respect claude code config dir env var for user scope",
1486+
setup: func(t *testing.T) {
1487+
t.Setenv("CLAUDE_CONFIG_DIR", t.TempDir())
1488+
},
1489+
stubs: func(reg *httpmock.Registry) {
1490+
stubResolveVersion(reg, "monalisa", "skills-repo", "v1.0.0", "abc123")
1491+
stubDiscoverTree(reg, "monalisa", "skills-repo", "abc123",
1492+
singleSkillTreeJSON("git-commit", "treeSHA", "blobSHA"))
1493+
stubInstallFiles(reg, "monalisa", "skills-repo", "treeSHA", "blobSHA", gitCommitContent)
1494+
},
1495+
opts: func(ios *iostreams.IOStreams, reg *httpmock.Registry) *InstallOptions {
1496+
t.Helper()
1497+
return &InstallOptions{
1498+
IO: ios,
1499+
HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil },
1500+
GitClient: &git.Client{RepoDir: t.TempDir()},
1501+
SkillSource: "monalisa/skills-repo",
1502+
SkillName: "git-commit",
1503+
Agent: "claude-code",
1504+
Scope: "user",
1505+
ScopeChanged: true,
1506+
Telemetry: &telemetry.NoOpService{},
1507+
}
1508+
},
1509+
assert: func(t *testing.T) {
1510+
assert.FileExists(t, filepath.Join(os.Getenv("CLAUDE_CONFIG_DIR"), "skills", "git-commit", "SKILL.md"))
1511+
assert.NoFileExists(t, filepath.Join(os.Getenv("HOME"), ".claude", "skills", "git-commit", "SKILL.md"))
1512+
},
1513+
wantStdout: "Installed git-commit",
1514+
},
14831515
}
14841516

14851517
for _, tt := range tests {
@@ -1525,6 +1557,9 @@ func TestInstallRun(t *testing.T) {
15251557
if tt.verify != nil {
15261558
tt.verify(t)
15271559
}
1560+
if tt.assert != nil {
1561+
tt.assert(t)
1562+
}
15281563
})
15291564
}
15301565
}
@@ -1537,40 +1572,6 @@ func TestInstallProgress(t *testing.T) {
15371572
assert.NotNil(t, installProgress(ios, 2))
15381573
}
15391574

1540-
func TestInstallRun_ClaudeCodeUserScopeUsesConfigDir(t *testing.T) {
1541-
homeDir := t.TempDir()
1542-
claudeConfigDir := t.TempDir()
1543-
t.Setenv("HOME", homeDir)
1544-
t.Setenv("USERPROFILE", homeDir)
1545-
t.Setenv("CLAUDE_CONFIG_DIR", claudeConfigDir)
1546-
1547-
reg := &httpmock.Registry{}
1548-
defer reg.Verify(t)
1549-
1550-
stubResolveVersion(reg, "monalisa", "skills-repo", "v1.0.0", "abc123")
1551-
stubDiscoverTree(reg, "monalisa", "skills-repo", "abc123",
1552-
singleSkillTreeJSON("git-commit", "treeSHA", "blobSHA"))
1553-
stubInstallFiles(reg, "monalisa", "skills-repo", "treeSHA", "blobSHA", gitCommitContent)
1554-
1555-
ios, _, stdout, _ := iostreams.Test()
1556-
1557-
err := installRun(&InstallOptions{
1558-
IO: ios,
1559-
HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil },
1560-
GitClient: &git.Client{RepoDir: t.TempDir()},
1561-
SkillSource: "monalisa/skills-repo",
1562-
SkillName: "git-commit",
1563-
Agent: "claude-code",
1564-
Scope: "user",
1565-
ScopeChanged: true,
1566-
Telemetry: &telemetry.NoOpService{},
1567-
})
1568-
require.NoError(t, err)
1569-
assert.Contains(t, stdout.String(), "Installed git-commit")
1570-
assert.FileExists(t, filepath.Join(claudeConfigDir, "skills", "git-commit", "SKILL.md"))
1571-
assert.NoFileExists(t, filepath.Join(homeDir, ".claude", "skills", "git-commit", "SKILL.md"))
1572-
}
1573-
15741575
func TestInstallRun_DeduplicatesSharedProjectDirAcrossHosts(t *testing.T) {
15751576
homeDir := t.TempDir()
15761577
t.Setenv("HOME", homeDir)

0 commit comments

Comments
 (0)