GitLabgitlab-org

cli

main
ply8 git calls333 ms98 KiB6 cachedprotocol v2
90 lines2.6 KiBRaw
1//go:build !integration
3package setup
5import (
6 "go/parser"
7 "go/token"
8 "io/fs"
9 "os"
10 "path/filepath"
11 "strconv"
12 "strings"
13 "testing"
15 "github.com/stretchr/testify/assert"
16 "github.com/stretchr/testify/require"
19const (
20 governPackage = "gitlab.com/gitlab-org/cli/internal/commands/govern"
21 setupPackage = governPackage + "/setup"
24// Setup is reached through its package, or through the govern package, which
25// registers it under glab minder and the legacy glab govern. These checks
26// don't see a command that runs glab itself, in process or as a subprocess.
27func TestOnlyTheCommandTreeReachesSetup(t *testing.T) {
28 root := moduleRoot(t)
29 importers := importersOf(t, root, governPackage, setupPackage)
31 assert.Equal(t, []string{"internal/commands/govern/govern.go"}, importers[setupPackage],
32 "only the user may run glab minder setup, so no other command may call it")
33 assert.ElementsMatch(t, []string{"internal/commands/minder/minder.go", "internal/commands/root.go"}, importers[governPackage],
34 "only the command tree may register the governance commands")
37// importersOf returns, for each of packages, the non-test Go files under root
38// that import it, relative to root and with forward slashes.
39func importersOf(t *testing.T, root string, packages ...string) map[string][]string {
40 t.Helper()
41 importers := map[string][]string{}
42 err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
43 if err != nil {
44 return err
45 }
46 if d.IsDir() {
47 // The go tool ignores these too. In CI the module cache is under .go.
48 name := d.Name()
49 if path != root && (name == "vendor" || name == "testdata" || name == "node_modules" ||
50 strings.HasPrefix(name, ".") || strings.HasPrefix(name, "_")) {
51 return filepath.SkipDir
52 }
53 return nil
54 }
55 if !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") {
56 return nil
57 }
58 file, err := parser.ParseFile(token.NewFileSet(), path, nil, parser.ImportsOnly)
59 if err != nil {
60 return err
61 }
62 for _, imp := range file.Imports {
63 p, _ := strconv.Unquote(imp.Path.Value)
64 for _, want := range packages {
65 if p == want {
66 rel, err := filepath.Rel(root, path)
67 require.NoError(t, err)
68 importers[want] = append(importers[want], filepath.ToSlash(rel))
69 }
70 }
71 }
72 return nil
73 })
74 require.NoError(t, err)
75 return importers
78func moduleRoot(t *testing.T) string {
79 t.Helper()
80 dir, err := os.Getwd()
81 require.NoError(t, err)
82 for {
83 if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
84 return dir
85 }
86 parent := filepath.Dir(dir)
87 require.NotEqual(t, dir, parent, "go.mod not found")
88 dir = parent
89 }
Diagnostics8 git calls · 333 ms
CallStatusSizeTime0333 ms
discover200185 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
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 KiB · hit8 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=8
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
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 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=4273
git.response.cache=HIT
git.response.duration_ms=2
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: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=2
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
fetchtree:02001.8 KiB · hit2 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=1857
git.response.cache=HIT
git.response.duration_ms=2
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=3
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:0200198 B · hit5 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=198
git.response.cache=HIT
git.response.duration_ms=5
git.fetch.filter=tree:0
git.fetch.wants=a2b28db4d943a407ac72661e73be16d6e3d0cc25
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=198
git.pkt.payload.max=171
git.sideband.band1.bytes=171
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=171
git.pack.trailer=230772abb145f332cba4850a222435de3a0d1655
Open pack map
fetch2001.2 KiB313 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=313
git.response.bytes=1206
git.response.cache=MISS
git.response.duration_ms=313
git.fetch.wants=43313e3069747f6529467dc98fd33bd876b1e557
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=1206
git.pkt.payload.max=1179
git.sideband.band1.bytes=1179
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
a5e2cb71a9087929
Request
8b7809fc…
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