GitLabgitlab-org

cli

main
ply8 git calls212 ms99 KiB5 cachedprotocol v2
229 lines6.7 KiBRaw
1//go:build !integration
3package install
5import (
6 "os"
7 "path/filepath"
8 "strings"
9 "testing"
11 "github.com/stretchr/testify/assert"
12 "github.com/stretchr/testify/require"
14 "gitlab.com/gitlab-org/cli/internal/commands/skills/skill"
15 "gitlab.com/gitlab-org/cli/internal/git"
16 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
19func TestNewCmdInstall_PathFlag(t *testing.T) {
20 t.Parallel()
22 tmpDir := t.TempDir()
23 exec := cmdtest.SetupCmdForTest(t, NewCmdInstall, false)
24 out, err := exec("--path " + filepath.ToSlash(tmpDir))
26 require.NoError(t, err)
27 assert.Contains(t, out.String(), "Installed")
28 assert.FileExists(t, filepath.Join(tmpDir, "glab", skill.FileName))
29 // Default install should only ship the core `glab` skill; other
30 // bundled skills are opt-in by name to avoid context-window
31 // pollution. Guard against regressing back to "install all".
32 assert.NoFileExists(t, filepath.Join(tmpDir, "glab-stack", skill.FileName),
33 "default install must not include glab-stack")
36func TestNewCmdInstall_GlobalFlag(t *testing.T) {
37 home := t.TempDir()
38 // Set both HOME (Unix/macOS) and USERPROFILE (Windows) for cross-platform compatibility
39 t.Setenv("HOME", home)
40 t.Setenv("USERPROFILE", home)
42 exec := cmdtest.SetupCmdForTest(t, NewCmdInstall, false)
43 out, err := exec("--global")
45 require.NoError(t, err)
46 assert.Contains(t, out.String(), "Installed")
47 assert.FileExists(t, filepath.Join(home, skillsRelDir, "glab", skill.FileName))
50func TestNewCmdInstall_DefaultScopeOutsideRepo(t *testing.T) {
51 t.Chdir(t.TempDir())
53 exec := cmdtest.SetupCmdForTest(t, NewCmdInstall, false)
54 _, err := exec("")
56 require.Error(t, err)
57 assert.Contains(t, err.Error(), "not in a Git repository")
60func TestNewCmdInstall_DefaultScopeInsideRepo(t *testing.T) {
61 repoDir := git.InitGitRepo(t)
62 exec := cmdtest.SetupCmdForTest(t, NewCmdInstall, false)
63 out, err := exec("")
65 require.NoError(t, err)
66 assert.Contains(t, out.String(), "Installed")
67 assert.FileExists(t, filepath.Join(repoDir, skillsRelDir, "glab", skill.FileName))
70func TestNewCmdInstall_GlobalAndPathMutuallyExclusive(t *testing.T) {
71 t.Parallel()
73 exec := cmdtest.SetupCmdForTest(t, NewCmdInstall, false)
74 _, err := exec("--global --path /tmp/skills")
76 require.Error(t, err)
77 assert.Contains(t, err.Error(), "if any flags in the group [global path] are set none of the others can be")
80func TestNewCmdInstall_ForceOverwrites(t *testing.T) {
81 t.Parallel()
83 tmpDir := t.TempDir()
84 exec := cmdtest.SetupCmdForTest(t, NewCmdInstall, false)
86 _, err := exec("--path " + filepath.ToSlash(tmpDir))
87 require.NoError(t, err)
89 out, err := exec("--force --path " + filepath.ToSlash(tmpDir))
90 require.NoError(t, err)
91 assert.Contains(t, out.String(), "Overwrote")
94func TestNewCmdInstall_SkipsWithoutForce(t *testing.T) {
95 t.Parallel()
97 tmpDir := t.TempDir()
98 exec := cmdtest.SetupCmdForTest(t, NewCmdInstall, false)
100 _, err := exec("--path " + filepath.ToSlash(tmpDir))
101 require.NoError(t, err)
103 out, err := exec("--path " + filepath.ToSlash(tmpDir))
104 require.NoError(t, err)
105 assert.Contains(t, out.Stderr(), "already exists. Use --force to overwrite")
108func TestNewCmdInstall_FreshInstallNoWarnings(t *testing.T) {
109 t.Parallel()
111 tmpDir := t.TempDir()
112 exec := cmdtest.SetupCmdForTest(t, NewCmdInstall, false)
113 out, err := exec("--path " + filepath.ToSlash(tmpDir))
115 require.NoError(t, err)
116 assert.Contains(t, out.String(), "Installed")
117 assert.Empty(t, out.Stderr(), "expected no stderr output on fresh install")
120func TestNewCmdInstall_NamedSkill(t *testing.T) {
121 t.Parallel()
123 tmpDir := t.TempDir()
124 exec := cmdtest.SetupCmdForTest(t, NewCmdInstall, false)
125 out, err := exec("glab --path " + filepath.ToSlash(tmpDir))
127 require.NoError(t, err)
128 assert.Contains(t, out.String(), "Installed")
130 dest := filepath.Join(tmpDir, "glab", skill.FileName)
131 assert.FileExists(t, dest)
133 content, err := os.ReadFile(dest)
134 require.NoError(t, err)
135 assert.Contains(t, string(content), "name: glab")
138func TestNewCmdInstall_UnknownSkill(t *testing.T) {
139 t.Parallel()
141 tmpDir := t.TempDir()
142 exec := cmdtest.SetupCmdForTest(t, NewCmdInstall, false)
143 _, err := exec("does-not-exist --path " + filepath.ToSlash(tmpDir))
145 require.Error(t, err)
146 assert.Contains(t, err.Error(), `unknown skill "does-not-exist"`)
147 assert.Contains(t, err.Error(), "glab skills list")
150func TestInstallOne_WritesAllFiles(t *testing.T) {
151 t.Parallel()
153 tmpDir := t.TempDir()
154 ios, _, _, _ := cmdtest.TestIOStreams()
155 o := &options{io: ios, targetDir: tmpDir}
157 s := skill.Skill{
158 Name: "demo",
159 Description: "demo skill",
160 Files: map[string][]byte{
161 skill.FileName: []byte("---\nname: demo\ndescription: x\n---\nbody\n"),
162 "scripts/extract.sh": []byte("#!/bin/sh\necho hi\n"),
163 "references/REFERENCE.md": []byte("# Reference\n"),
164 "assets/templates/default.tpl": []byte("template body\n"),
165 },
166 }
168 require.NoError(t, o.installOne(s))
170 for rel, want := range s.Files {
171 got, err := os.ReadFile(filepath.Join(tmpDir, "demo", filepath.FromSlash(rel)))
172 require.NoError(t, err, "expected %s to exist", rel)
173 assert.Equal(t, want, got, "contents differ for %s", rel)
174 }
177func TestNewCmdInstall_NoNameSkipsRemoteSkills(t *testing.T) {
178 t.Parallel()
180 // "glab skills install" (no name) must only install bundled skills.
181 // Remote skills are opt-in by name; `registry.All()` returns them with
182 // Files == nil, and before this guarded path the installer would print
183 // a false "Installed" success without writing anything to disk.
184 tmpDir := t.TempDir()
185 exec := cmdtest.SetupCmdForTest(t, NewCmdInstall, false)
186 out, err := exec("--path " + filepath.ToSlash(tmpDir))
188 require.NoError(t, err)
190 // The `orbit` skill is a remote-only skill in the curated registry. It
191 // should not appear in install output and its directory must not exist.
192 combined := out.String() + out.Stderr()
193 assert.NotContains(t, combined, "Installed "+filepath.Join(tmpDir, "orbit"))
194 assert.NoDirExists(t, filepath.Join(tmpDir, "orbit"))
196 // And the bundled skills still install.
197 assert.FileExists(t, filepath.Join(tmpDir, "glab", skill.FileName))
200func TestNewCmdInstall_TooManyArgs(t *testing.T) {
201 t.Parallel()
203 tmpDir := t.TempDir()
204 exec := cmdtest.SetupCmdForTest(t, NewCmdInstall, false)
205 _, err := exec("glab extra --path " + filepath.ToSlash(tmpDir))
207 require.Error(t, err)
210func TestComplete(t *testing.T) {
211 t.Parallel()
213 t.Run("with --path", func(t *testing.T) {
214 t.Parallel()
216 o := &options{path: "/custom/path"}
217 require.NoError(t, o.complete(nil))
218 assert.Equal(t, "/custom/path", o.targetDir)
219 })
221 t.Run("with --global", func(t *testing.T) {
222 t.Parallel()
224 o := &options{global: true}
225 require.NoError(t, o.complete(nil))
226 assert.True(t, filepath.IsAbs(o.targetDir), "expected absolute path, got %s", o.targetDir)
227 assert.True(t, strings.HasSuffix(o.targetDir, skillsRelDir))
228 })
Diagnostics8 git calls · 212 ms
CallStatusSizeTime0212 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=UPDATING
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 1020032 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:02001.8 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=5
git.response.bytes=1857
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1857
git.pkt.payload.max=1830
git.sideband.band1.bytes=1830
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1830
git.pack.trailer=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200370 B · hit5 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=370
git.response.cache=HIT
git.response.duration_ms=5
git.fetch.filter=tree:0
git.fetch.wants=290ae7a62f76e23cbbd60697570f19b90ddcece6
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=370
git.pkt.payload.max=343
git.sideband.band1.bytes=343
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=343
git.pack.trailer=0795a26d2b25022c69da2ef2e68cfb92a77ef4bb
Open pack map
fetchtree:0200138 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=194
git.response.bytes=138
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=18b12de8710078c4768dfa464446990cb36bac1c
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=138
git.pkt.payload.max=111
git.sideband.band1.bytes=111
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=111
git.pack.trailer=f412c8fc7c405fded327f13a7b6b0effe29f99d4
Open pack map
fetch2001.8 KiB194 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1880
git.response.cache=MISS
git.response.duration_ms=194
git.fetch.wants=98115b96281b7c0f1c3ce42b09ad7f437db75b7b
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1880
git.pkt.payload.max=1853
git.sideband.band1.bytes=1853
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e2e6433b352947
Request
2ce9466b…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format