GitLabgitlab-org

cli

main
ply9 git calls299 ms99 KiB7 cachedprotocol v2
127 lines3.5 KiBRaw
1//go:build !integration
3package opencodeplugin
5import (
6 "bytes"
7 "os"
8 "path/filepath"
9 "testing"
11 "github.com/stretchr/testify/assert"
12 "github.com/stretchr/testify/require"
15func TestPath(t *testing.T) {
16 home := t.TempDir()
17 t.Setenv("HOME", home)
19 t.Setenv("XDG_CONFIG_HOME", "")
20 path, err := Path()
21 require.NoError(t, err)
22 assert.Equal(t, filepath.Join(home, ".config", "opencode", "plugins", "glab-govern.js"), path)
24 xdg := t.TempDir()
25 t.Setenv("XDG_CONFIG_HOME", xdg)
26 path, err = Path()
27 require.NoError(t, err)
28 assert.Equal(t, filepath.Join(xdg, "opencode", "plugins", "glab-govern.js"), path)
31func TestDisplay(t *testing.T) {
32 home := t.TempDir()
33 t.Setenv("HOME", home)
35 assert.Equal(t, filepath.Join("~", ".config", "opencode"), Display(filepath.Join(home, ".config", "opencode")))
36 assert.Equal(t, "/elsewhere/opencode", Display("/elsewhere/opencode"))
39func TestDetected(t *testing.T) {
40 t.Setenv("XDG_CONFIG_HOME", t.TempDir())
42 detected, err := Detected()
43 require.NoError(t, err)
44 assert.False(t, detected)
46 dir, err := ConfigDir()
47 require.NoError(t, err)
48 require.NoError(t, os.MkdirAll(dir, 0o755))
49 detected, err = Detected()
50 require.NoError(t, err)
51 assert.True(t, detected)
54func TestSourceStartsWithMarker(t *testing.T) {
55 assert.True(t, bytes.HasPrefix(Source, markers[0]), "Check and Remove recognise the plugin by its first line")
58func TestInstall(t *testing.T) {
59 path := filepath.Join(t.TempDir(), "plugins", FileName)
61 changed, err := Install(path)
62 require.NoError(t, err)
63 assert.True(t, changed)
64 assert.Equal(t, Current, check(t, path))
66 changed, err = Install(path)
67 require.NoError(t, err)
68 assert.False(t, changed, "installing the same version again changes nothing")
70 for _, marker := range markers {
71 require.NoError(t, os.WriteFile(path, append(bytes.Clone(marker), "\n// an older version\n"...), 0o644))
72 assert.Equal(t, Outdated, check(t, path))
73 changed, err = Install(path)
74 require.NoError(t, err)
75 assert.True(t, changed, "an older version is replaced")
76 assert.Equal(t, Current, check(t, path))
77 }
80func TestInstall_RefusesForeignFile(t *testing.T) {
81 path := filepath.Join(t.TempDir(), FileName)
82 require.NoError(t, os.WriteFile(path, []byte("// the user's own plugin\n"), 0o644))
83 assert.Equal(t, Foreign, check(t, path))
85 _, err := Install(path)
86 require.Error(t, err)
87 assert.Contains(t, err.Error(), "was not installed by glab")
89 data, err := os.ReadFile(path)
90 require.NoError(t, err)
91 assert.Equal(t, "// the user's own plugin\n", string(data))
94func TestRemove(t *testing.T) {
95 dir := t.TempDir()
96 path := filepath.Join(dir, FileName)
98 removed, err := Remove(path)
99 require.NoError(t, err)
100 assert.False(t, removed, "nothing to remove")
102 _, err = Install(path)
103 require.NoError(t, err)
104 removed, err = Remove(path)
105 require.NoError(t, err)
106 assert.True(t, removed)
107 assert.NoFileExists(t, path)
109 require.NoError(t, os.WriteFile(path, append(bytes.Clone(markers[1]), "\n// an older version\n"...), 0o644))
110 removed, err = Remove(path)
111 require.NoError(t, err)
112 assert.True(t, removed, "a plugin installed before the rename to glab minder is removed")
113 assert.NoFileExists(t, path)
115 require.NoError(t, os.WriteFile(path, []byte("// the user's own plugin\n"), 0o644))
116 removed, err = Remove(path)
117 require.NoError(t, err)
118 assert.False(t, removed)
119 assert.FileExists(t, path, "a file glab did not install is kept")
122func check(t *testing.T, path string) State {
123 t.Helper()
124 state, err := Check(path)
125 require.NoError(t, err)
126 return state
Diagnostics9 git calls · 299 ms
CallStatusSizeTime0299 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=3
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 KiB · hit2 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=HIT
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 · hit3 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=32926
git.response.cache=HIT
git.response.duration_ms=3
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=3
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:0200261 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=261
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=3bb9946301aa8c0dc8d202b83bc9f84bf0400f6d
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=261
git.pkt.payload.max=234
git.sideband.band1.bytes=234
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=234
git.pack.trailer=e0a52f164f79506da6b0dcc275ed62911f5383bf
Open pack map
fetchtree:0200273 B · hit2 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=273
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=5fa160737ad30857ff606d64de1d596bb211ac3d
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=273
git.pkt.payload.max=246
git.sideband.band1.bytes=246
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=246
git.pack.trailer=06dd39b7545811625e04a7645a0a64c9a62c99c6
Open pack map
fetchtree:0200185 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=281
git.response.bytes=185
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=b97e092ad09f2ba787b9764e83b6dbf8477ee2a1
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=185
git.pkt.payload.max=158
git.sideband.band1.bytes=158
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=158
git.pack.trailer=4d24c4711408fe0a3a34dd470aa37740bf7101b2
Open pack map
fetch2001.0 KiB281 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1066
git.response.cache=MISS
git.response.duration_ms=281
git.fetch.wants=201a4dafe6ec98ee13e846c5fbf0699375e48906
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=1066
git.pkt.payload.max=1039
git.sideband.band1.bytes=1039
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
a5e23a713ff14bc2
Request
83d24f24…
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