GitLabgitlab-org
cli
main
1//go:build !integration
3package update
5import (
6 "bytes"
7 "testing"
9 "github.com/stretchr/testify/assert"
10 "github.com/stretchr/testify/require"
12 "gitlab.com/gitlab-org/cli/internal/api"
13 "gitlab.com/gitlab-org/cli/internal/config"
14 "gitlab.com/gitlab-org/cli/internal/iostreams"
15 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
16)
18func newBannerTest(t *testing.T, currentVersion, lastSeen, showWhatsNew, codingAgent string) (*iostreams.IOStreams, config.Config, api.BuildInfo, *bytes.Buffer) {
19 t.Helper()
20 cfg := config.NewBlankConfig()
21 if lastSeen != "" {
22 require.NoError(t, cfg.Set("", LastSeenVersionKey, lastSeen))
23 }
24 if showWhatsNew != "" {
25 require.NoError(t, cfg.Set("", "show_whats_new", showWhatsNew))
26 }
27 ios, _, _, stderr := cmdtest.TestIOStreams(cmdtest.WithTestIOStreamsAsTTY(true))
28 return ios, cfg, api.BuildInfo{Version: currentVersion, CodingAgent: codingAgent}, stderr
29}
31func TestMaybeShowPostUpgradeBanner(t *testing.T) {
32 t.Parallel()
33 stubNoInstalledSkills(t)
35 tests := []struct {
36 name string
37 currentVersion string
38 lastSeen string
39 showWhatsNew string
40 codingAgent string
41 stderrNotTTY bool
42 wantBanner bool
43 wantLastSeen string
44 }{
45 {
46 name: "no stored value, current newer than seeded default fires banner",
47 currentVersion: "1.101.0",
48 lastSeen: "",
49 wantBanner: true,
50 wantLastSeen: "1.101.0",
51 },
52 {
53 name: "no stored value, current at seeded default is silent",
54 currentVersion: "1.100.0",
55 lastSeen: "",
56 wantBanner: false,
57 wantLastSeen: "v1.100.0", // defaultFor() value
58 },
59 {
60 name: "stored value older than current fires banner and updates marker",
61 currentVersion: "1.85.0",
62 lastSeen: "1.84.0",
63 wantBanner: true,
64 wantLastSeen: "1.85.0",
65 },
66 {
67 name: "same version is silent",
68 currentVersion: "1.85.0",
69 lastSeen: "1.85.0",
70 wantBanner: false,
71 wantLastSeen: "1.85.0",
72 },
73 {
74 name: "downgrade is silent",
75 currentVersion: "1.84.0",
76 lastSeen: "1.85.0",
77 wantBanner: false,
78 wantLastSeen: "1.85.0",
79 },
80 {
81 name: "config opt-out suppresses banner",
82 currentVersion: "1.85.0",
83 lastSeen: "1.84.0",
84 showWhatsNew: "false",
85 wantBanner: false,
86 wantLastSeen: "1.84.0",
87 },
88 {
89 name: "coding agent is silent",
90 currentVersion: "1.85.0",
91 lastSeen: "1.84.0",
92 codingAgent: "claude-code",
93 wantBanner: false,
94 wantLastSeen: "1.84.0",
95 },
96 {
97 name: "stderr not a terminal is silent",
98 currentVersion: "1.85.0",
99 lastSeen: "1.84.0",
100 stderrNotTTY: true,
101 wantBanner: false,
102 wantLastSeen: "1.84.0",
103 },
104 {
105 name: "unparseable current version is silent",
106 currentVersion: "DEV",
107 lastSeen: "1.84.0",
108 wantBanner: false,
109 wantLastSeen: "1.84.0",
110 },
111 {
112 name: "unparseable last_seen is silent",
113 currentVersion: "1.85.0",
114 lastSeen: "garbage",
115 wantBanner: false,
116 wantLastSeen: "garbage",
117 },
118 }
120 for _, tc := range tests {
121 t.Run(tc.name, func(t *testing.T) {
122 t.Parallel()
123 ios, cfg, buildInfo, stderr := newBannerTest(t, tc.currentVersion, tc.lastSeen, tc.showWhatsNew, tc.codingAgent)
124 ios.IsErrTTY = !tc.stderrNotTTY
125 maybeShowPostUpgradeBanner(ios, cfg, buildInfo, false)
127 if tc.wantBanner {
128 assert.Contains(t, stderr.String(), "What's new in glab")
129 assert.Contains(t, stderr.String(), tc.currentVersion)
130 assert.Contains(t, stderr.String(), "glab whatsnew")
131 } else {
132 assert.Empty(t, stderr.String())
133 }
135 got, _ := cfg.Get("", LastSeenVersionKey)
136 assert.Equal(t, tc.wantLastSeen, got)
137 })
138 }
139}
141// envOverride covers GLAB_SHOW_WHATS_NEW separately because t.Setenv is
142// incompatible with t.Parallel.
143func TestMaybeShowPostUpgradeBanner_envOverride(t *testing.T) {
144 stubNoInstalledSkills(t)
145 t.Setenv("GLAB_SHOW_WHATS_NEW", "false")
147 ios, cfg, buildInfo, stderr := newBannerTest(t, "1.85.0", "1.84.0", "", "")
148 maybeShowPostUpgradeBanner(ios, cfg, buildInfo, false)
150 assert.Empty(t, stderr.String())
151 got, _ := cfg.Get("", LastSeenVersionKey)
152 assert.Equal(t, "1.84.0", got)
153}
155func TestMaybeShowPostUpgradeBanner_ci(t *testing.T) {
156 stubNoInstalledSkills(t)
158 tests := []struct {
159 name string
160 ci string
161 gitlabCI string
162 wantBanner bool
163 wantLastSeen string
164 }{
165 {name: "CI set is silent", ci: "true", wantLastSeen: "1.84.0"},
166 {name: "GITLAB_CI set is silent", gitlabCI: "true", wantLastSeen: "1.84.0"},
167 {name: "outside CI fires banner", wantBanner: true, wantLastSeen: "1.85.0"},
168 }
170 for _, tc := range tests {
171 t.Run(tc.name, func(t *testing.T) {
172 t.Setenv("CI", tc.ci)
173 t.Setenv("GITLAB_CI", tc.gitlabCI)
175 ios, cfg, buildInfo, stderr := newBannerTest(t, "1.85.0", "1.84.0", "", "")
176 MaybeShowPostUpgradeBanner(ios, cfg, buildInfo)
178 if tc.wantBanner {
179 assert.Contains(t, stderr.String(), "What's new in glab 1.85.0")
180 } else {
181 assert.Empty(t, stderr.String())
182 }
183 got, _ := cfg.Get("", LastSeenVersionKey)
184 assert.Equal(t, tc.wantLastSeen, got)
185 })
186 }
187}
Diagnostics7 git calls · 295 ms
CallStatusSizeTime0295 ms
discover200185 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs 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 · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=59849 git.response.cache=HIT git.response.duration_ms=3 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=3 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=44Open 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=fb03183b7909876778f740d196d7516811003517Open pack map
fetchtree:0200329 B · 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=329 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=8b36f3db012b2c3ab0120649b10a85336c3bf03e 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=329 git.pkt.payload.max=302 git.sideband.band1.bytes=302 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=302 git.pack.trailer=616b294f8a6e9b6163f51633333a4ad7b16f0d98Open pack map
fetch2001.4 KiB286 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=286 git.response.bytes=1396 git.response.cache=MISS git.response.duration_ms=286 git.fetch.wants=5bedac1f219cfe6dc5ab1638bde22d97c9b97b6f 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=1396 git.pkt.payload.max=1369 git.sideband.band1.bytes=1369 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
- a5e2cda4ad247929
- Request
- 267986e0…
- 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