GitLabgitlab-org

cli

main
ply6 git calls318 ms97 KiB4 cachedprotocol v2
105 lines3.3 KiBRaw
1package api
3import (
4 "strings"
5 "testing"
7 "github.com/stretchr/testify/assert"
8 "github.com/stretchr/testify/require"
10 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
12 "gitlab.com/gitlab-org/cli/internal/config"
15// GitLab Duo Agent Platform workloads install a pinned glab and authenticate it
16// without `glab auth login`. The configuration file and environment below
17// mirror what gitlab-org/gitlab writes, so update them together:
18//
19// - config.yml: GlabSetup#config_file_command in
20// ee/lib/gitlab/duo_workflow/glab_setup.rb
21// - environment: StartWorkflowService in
22// ee/app/services/ai/duo_workflows/start_workflow_service.rb
23//
24// A failure here means the next pin bump in gitlab-org/gitlab breaks API calls
25// from those workloads (see https://gitlab.com/gitlab-org/cli/-/work_items/8482).
26func TestNewClientFromConfig_DuoAgentPlatformContract(t *testing.T) {
27 for _, kd := range config.KeySchema {
28 for _, k := range kd.EnvVars {
29 t.Setenv(k, "")
30 }
31 }
32 t.Setenv("GLAB_ENABLE_CI_AUTOLOGIN", "")
33 t.Setenv("GLAB_CONFIG_DIR", "")
35 t.Setenv("GITLAB_TOKEN", "doorkeeper-access-token")
36 t.Setenv("GLAB_IS_OAUTH2", "true")
38 tests := []struct {
39 name string
40 host string
41 protocol string
42 subfolder string
43 expectedBaseURL string
44 }{
45 {
46 name: "default HTTPS port",
47 host: "gitlab.example.com",
48 protocol: "https",
49 expectedBaseURL: "https://gitlab.example.com/api/v4/",
50 },
51 {
52 name: "non-default port",
53 host: "gitlab.example.com:8443",
54 protocol: "https",
55 expectedBaseURL: "https://gitlab.example.com:8443/api/v4/",
56 },
57 {
58 name: "relative URL root",
59 host: "gitlab.example.com",
60 protocol: "https",
61 subfolder: "gitlab",
62 expectedBaseURL: "https://gitlab.example.com/gitlab/api/v4/",
63 },
64 {
65 name: "HTTP instance",
66 host: "gdk.test:3000",
67 protocol: "http",
68 expectedBaseURL: "http://gdk.test:3000/api/v4/",
69 },
70 }
72 for _, tt := range tests {
73 t.Run(tt.name, func(t *testing.T) {
74 cfg := config.NewFromString(duoAgentPlatformConfig(tt.host, tt.protocol, tt.subfolder))
76 client, err := NewClientFromConfig(tt.host, cfg, false, "test-agent")
77 require.NoError(t, err)
79 key, value, err := client.AuthSource().Header(t.Context())
80 require.NoError(t, err)
81 assert.Equal(t, gitlab.OAuthTokenHeaderName, key)
82 assert.Equal(t, "Bearer doorkeeper-access-token", value)
83 assert.Equal(t, tt.expectedBaseURL, client.BaseURL())
84 })
85 }
88// Matches the Ruby `to_yaml` output of GlabSetup#config_file_command.
89func duoAgentPlatformConfig(host, protocol, subfolder string) string {
90 var b strings.Builder
91 b.WriteString("---\nhosts:\n " + host + ":\n")
92 b.WriteString(" is_oauth2: 'true'\n")
93 b.WriteString(" client_id: bypass\n")
94 b.WriteString(" oauth2_refresh_token: ''\n")
95 b.WriteString(" oauth2_expiry_date: 01 Jan 2050 00:00 UTC\n")
96 b.WriteString(" api_host: " + host + "\n")
97 b.WriteString(" api_protocol: " + protocol + "\n")
98 b.WriteString(" user: duo-user\n")
99 if subfolder != "" {
100 b.WriteString(" subfolder: " + subfolder + "\n")
101 }
102 b.WriteString("check_update: 'false'\n")
103 b.WriteString("git_protocol: " + protocol + "\n")
104 return b.String()
Diagnostics6 git calls · 318 ms
CallStatusSizeTime0318 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
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 · 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=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
fetchtree:02001.1 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=311
git.response.bytes=1165
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=71c8407e0ff0e0af10f6a041ae330f754b68e7eb
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=1165
git.pkt.payload.max=1138
git.sideband.band1.bytes=1138
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1138
git.pack.trailer=61886367c69619d8db2b2cf2d7d24dca2016141c
Open pack map
fetch2001.3 KiB311 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1360
git.response.cache=MISS
git.response.duration_ms=311
git.fetch.wants=5e2c83c65f170cf36a3ccf338f03eb593a9ac712
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=1360
git.pkt.payload.max=1333
git.sideband.band1.bytes=1333
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
a5e233568d90a594
Request
d087cfb2…
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