GitLabgitlab-org

cli

main
ply8 git calls319 ms102 KiB5 cachedprotocol v2
645 lines23 KiBRaw
1//go:build !integration
3package doctor
5import (
6 "context"
7 "encoding/json"
8 "errors"
9 "fmt"
10 "io"
11 "os"
12 "os/exec"
13 "path/filepath"
14 "strings"
15 "testing"
16 "time"
18 "github.com/stretchr/testify/assert"
19 "github.com/stretchr/testify/require"
20 "go.uber.org/mock/gomock"
22 "gitlab.com/gitlab-org/cli/internal/api"
23 "gitlab.com/gitlab-org/cli/internal/cmdutils"
24 "gitlab.com/gitlab-org/cli/internal/commands/govern/internal/claudehooks"
25 "gitlab.com/gitlab-org/cli/internal/commands/govern/internal/fallbacksync"
26 "gitlab.com/gitlab-org/cli/internal/commands/govern/internal/opencodeplugin"
27 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
28 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
31func TestCheckClaudeHooks_HooksPresent(t *testing.T) {
32 dir := t.TempDir()
33 path := filepath.Join(dir, "settings.json")
35 existingHooks := map[string][]claudehooks.HookGroup{
36 "Stop": {
37 {Hooks: []claudehooks.HookEntry{{Type: "command", Command: claudehooks.StopHookCommand}}},
38 },
39 "SessionEnd": {
40 {Hooks: []claudehooks.HookEntry{{Type: "command", Command: claudehooks.SessionEndHookCommand}}},
41 },
42 }
44 hooksJSON, err := json.Marshal(existingHooks)
45 require.NoError(t, err)
47 raw := map[string]json.RawMessage{"hooks": hooksJSON}
48 require.NoError(t, claudehooks.WriteSettings(path, raw))
50 // Override the settings path for testing
51 t.Setenv("HOME", dir)
52 require.NoError(t, os.MkdirAll(filepath.Join(dir, ".claude"), 0o755))
53 require.NoError(t, claudehooks.WriteSettings(filepath.Join(dir, ".claude", "settings.json"), raw))
55 result := checkClaudeHooks()
57 assert.True(t, result.ok)
58 assert.Equal(t, "Stop and SessionEnd hooks installed", result.message)
61func TestCheckClaudeHooks_HooksFromBeforeTheRename(t *testing.T) {
62 dir := t.TempDir()
63 t.Setenv("HOME", dir)
64 path := filepath.Join(dir, ".claude", "settings.json")
65 require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755))
66 require.NoError(t, os.WriteFile(path, []byte(`{"hooks":{
67 "Stop":[{"hooks":[{"type":"command","command":"glab govern audit sync --silent >/dev/null 2>&1 &"}]}],
68 "SessionEnd":[{"hooks":[{"type":"command","command":"glab govern audit sync --silent --complete >/dev/null 2>&1 &"}]}]
69 }}`), 0o644))
71 result := checkClaudeHooks()
73 assert.True(t, result.ok, "the old hooks still sync")
74 assert.Contains(t, result.message, "run 'glab minder setup' to update them")
77func TestCheckClaudeHooks_HooksMissing(t *testing.T) {
78 dir := t.TempDir()
79 t.Setenv("HOME", dir)
81 // No settings file exists
82 result := checkClaudeHooks()
84 assert.True(t, result.ok, "missing Claude Code should be advisory")
85 assert.Contains(t, result.message, "No hook-based agent detected")
88func TestCheckClaudeHooks_StopHookMissing(t *testing.T) {
89 dir := t.TempDir()
90 t.Setenv("HOME", dir)
92 // Only SessionEnd hook present
93 existingHooks := map[string][]claudehooks.HookGroup{
94 "SessionEnd": {
95 {Hooks: []claudehooks.HookEntry{{Type: "command", Command: claudehooks.SessionEndHookCommand}}},
96 },
97 }
99 hooksJSON, err := json.Marshal(existingHooks)
100 require.NoError(t, err)
102 raw := map[string]json.RawMessage{"hooks": hooksJSON}
103 require.NoError(t, claudehooks.WriteSettings(filepath.Join(dir, ".claude", "settings.json"), raw))
105 result := checkClaudeHooks()
107 assert.False(t, result.ok)
108 assert.Contains(t, result.message, "Stop")
111func TestCheckGlabInPath_NotFound(t *testing.T) {
112 t.Setenv("PATH", "")
114 result := checkGlabInPath()
116 assert.False(t, result.ok)
117 assert.Contains(t, result.message, "not found")
118 assert.NotEmpty(t, result.fix)
121func TestNewCmd_DoctorCommand(t *testing.T) {
122 t.Parallel()
123 ios, _, _, _ := cmdtest.TestIOStreams()
124 f := cmdtest.NewTestFactory(ios)
125 cmd := NewCmd(f)
127 assert.Equal(t, "doctor", cmd.Name())
128 assert.NotNil(t, cmd.Args)
129 assert.NotNil(t, cmd.RunE)
132func TestRunDoctor_ExitCodeOnFailure(t *testing.T) {
133 dir := t.TempDir()
134 t.Setenv("HOME", dir)
136 ios, _, _, _ := cmdtest.TestIOStreams()
137 f := cmdtest.NewTestFactory(ios)
139 opts := &options{
140 io: ios,
141 config: f.Config,
142 apiClient: func(repoHost string) (*api.Client, error) {
143 return nil, fmt.Errorf("not authenticated")
144 },
145 hostname: "gitlab.com",
146 }
148 err := runDoctor(t.Context(), opts)
149 assert.ErrorIs(t, err, cmdutils.SilentError)
152func TestMCPSafeAnnotation(t *testing.T) {
153 t.Parallel()
154 ios, _, _, _ := cmdtest.TestIOStreams()
155 cmd := NewCmd(cmdtest.NewTestFactory(ios))
156 assert.Equal(t, "true", cmd.Annotations[mcpannotations.Safe])
159func installTestJob(t *testing.T, home, glabPath string) {
160 t.Helper()
161 units, err := fallbacksync.Units("linux", home, fallbacksync.Job{GlabPath: glabPath, ConfigDir: home})
162 require.NoError(t, err)
163 for _, u := range units {
164 require.NoError(t, os.MkdirAll(filepath.Dir(u.Path), 0o755))
165 require.NoError(t, os.WriteFile(u.Path, []byte(u.Content), 0o644))
166 }
169// linuxJobState returns an executor reporting the systemd timer as active or
170// not, and the service properties in show.
171func linuxJobState(t *testing.T, active bool, show string) *cmdtest.MockExecutor {
172 t.Helper()
173 mExec := cmdtest.NewMockExecutor(gomock.NewController(t))
174 var activeErr error
175 if !active {
176 activeErr = &exec.ExitError{}
177 }
178 mExec.EXPECT().
179 ExecWithCombinedOutput(gomock.Any(), "systemctl", []string{"--user", "is-active", "--quiet", "glab-govern-audit-sync.timer"}, nil).
180 Return(nil, activeErr)
181 if active {
182 mExec.EXPECT().
183 ExecWithCombinedOutput(gomock.Any(), "systemctl", []string{"--user", "show", "glab-govern-audit-sync.service", "--property=ExecMainStartTimestampMonotonic,ExecMainStatus"}, nil).
184 Return([]byte(show), nil)
185 }
186 return mExec
189var testBuild = api.BuildInfo{Version: "v1.121.0", Commit: "abc1234"}
191var testVersion = fallbacksync.BuildVersion(testBuild)
193// healthyLinuxJob returns an executor reporting the systemd timer as loaded
194// with a successful last run, and glab as reporting versionOutput.
195func healthyLinuxJob(t *testing.T, glab, versionOutput string) cmdutils.Executor {
196 t.Helper()
197 mExec := linuxJobState(t, true, "ExecMainStartTimestampMonotonic=1234\nExecMainStatus=0\n")
198 expectVersion(mExec, glab, versionOutput, nil)
199 return mExec
202func expectVersion(mExec *cmdtest.MockExecutor, glab, versionOutput string, err error) {
203 mExec.EXPECT().
204 ExecWithIO(gomock.Any(), glab, []string{"version"}, nil, nil, gomock.Any(), gomock.Any()).
205 DoAndReturn(func(_ context.Context, _ string, _, _ []string, _ io.Reader, stdout, _ io.Writer) error {
206 _, _ = io.WriteString(stdout, versionOutput+"\n")
207 return err
208 })
211func TestCheckFallbackSync_VersionDrift(t *testing.T) {
212 home := t.TempDir()
213 t.Setenv("HOME", home)
214 t.Setenv("GLAB_CONFIG_DIR", home)
215 glab, err := os.Executable()
216 require.NoError(t, err)
217 installTestJob(t, home, glab)
219 result := checkFallbackSync(t.Context(), healthyLinuxJob(t, glab, "glab 1.100.0 (old1234)"), "linux", testBuild, time.Now())
221 assert.False(t, result.ok)
222 assert.Equal(t, fmt.Sprintf("the job runs %s, which reports %q, not %q like this glab", glab, "glab 1.100.0 (old1234)", testVersion), result.message)
223 assert.Equal(t, "Run: glab minder setup", result.fix)
226func TestCheckFallbackSync_VersionUnreadable(t *testing.T) {
227 home := t.TempDir()
228 t.Setenv("HOME", home)
229 glab, err := os.Executable()
230 require.NoError(t, err)
231 installTestJob(t, home, glab)
233 mExec := linuxJobState(t, true, "ExecMainStartTimestampMonotonic=1234\nExecMainStatus=0\n")
234 expectVersion(mExec, glab, "", errors.New("exec format error"))
236 result := checkFallbackSync(t.Context(), mExec, "linux", testBuild, time.Now())
238 assert.False(t, result.ok)
239 assert.Equal(t, fmt.Sprintf("could not run %s version: exec format error", glab), result.message)
240 assert.Equal(t, "Run: glab minder setup", result.fix)
243func TestCheckFallbackSync_NotLoaded(t *testing.T) {
244 home := t.TempDir()
245 t.Setenv("HOME", home)
246 glab, err := os.Executable()
247 require.NoError(t, err)
248 installTestJob(t, home, glab)
250 result := checkFallbackSync(t.Context(), linuxJobState(t, false, ""), "linux", testBuild, time.Now())
252 assert.False(t, result.ok)
253 assert.Equal(t, "the job is installed but not loaded, so it never runs", result.message)
254 assert.Equal(t, "Run: glab minder setup", result.fix)
257func TestCheckFallbackSync_LastRunFailedToStart(t *testing.T) {
258 home := t.TempDir()
259 t.Setenv("HOME", home)
260 t.Setenv("GLAB_CONFIG_DIR", home)
261 glab, err := os.Executable()
262 require.NoError(t, err)
263 installTestJob(t, home, glab)
265 // An older glab without --all exits 1 before it can write a status.
266 result := checkFallbackSync(t.Context(), linuxJobState(t, true, "ExecMainStartTimestampMonotonic=1234\nExecMainStatus=1\n"), "linux", testBuild, time.Now())
268 assert.False(t, result.ok)
269 assert.Equal(t, "the job's last run exited with code 1", result.message)
270 assert.Contains(t, result.fix, glab+" minder audit sync --all")
273func TestCheckFallbackSync_NotInstalled(t *testing.T) {
274 t.Setenv("HOME", t.TempDir())
276 result := checkFallbackSync(t.Context(), nil, "linux", testBuild, time.Now())
278 assert.True(t, result.ok, "a machine set up with --no-fallback-sync is healthy")
279 assert.Contains(t, result.message, "not installed; sessions sync only through the hooks")
280 assert.NotContains(t, result.message, "optional")
283func TestCheckFallbackSync_Unsupported(t *testing.T) {
284 t.Setenv("HOME", t.TempDir())
286 result := checkFallbackSync(t.Context(), nil, "windows", testBuild, time.Now())
288 assert.True(t, result.ok)
289 assert.Contains(t, result.message, "not supported on windows")
292func TestCheckFallbackSync_BinaryMissing(t *testing.T) {
293 home := t.TempDir()
294 t.Setenv("HOME", home)
295 installTestJob(t, home, "/opt/homebrew/Cellar/glab/1.0.0/bin/glab")
297 result := checkFallbackSync(t.Context(), nil, "linux", testBuild, time.Now())
299 assert.False(t, result.ok)
300 assert.Contains(t, result.message, "/opt/homebrew/Cellar/glab/1.0.0/bin/glab, which no longer exists")
301 assert.Equal(t, "Run: glab minder setup", result.fix)
304func TestCheckFallbackSync_NoRunYet(t *testing.T) {
305 home := t.TempDir()
306 t.Setenv("HOME", home)
307 t.Setenv("GLAB_CONFIG_DIR", home)
308 glab, err := os.Executable()
309 require.NoError(t, err)
310 installTestJob(t, home, glab)
312 result := checkFallbackSync(t.Context(), healthyLinuxJob(t, glab, testVersion), "linux", testBuild, time.Now())
314 assert.True(t, result.ok)
315 assert.Equal(t, fmt.Sprintf("installed (%s); no run recorded yet", glab), result.message)
318func TestCheckFallbackSync_LastRun(t *testing.T) {
319 home := t.TempDir()
320 t.Setenv("HOME", home)
321 t.Setenv("GLAB_CONFIG_DIR", home)
322 glab, err := os.Executable()
323 require.NoError(t, err)
324 installTestJob(t, home, glab)
326 now := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
327 require.NoError(t, fallbacksync.WriteStatus(fallbacksync.Status{
328 FinishedAt: now.Add(-10 * time.Minute),
329 SessionsSynced: 2,
330 SessionsCompleted: 1,
331 EventsPosted: 9,
332 Errors: []string{"session a: could not resolve project"},
333 }))
335 result := checkFallbackSync(t.Context(), healthyLinuxJob(t, glab, testVersion), "linux", testBuild, now)
337 assert.True(t, result.ok)
338 assert.Equal(t,
339 fmt.Sprintf("installed (%s); last run 10m0s ago: 2 sessions synced, 1 completed, 9 events posted, 1 error (first: session a: could not resolve project)", glab),
340 result.message)
343func TestCheckFallbackSync_LastRunOnlyFailed(t *testing.T) {
344 home := t.TempDir()
345 t.Setenv("HOME", home)
346 t.Setenv("GLAB_CONFIG_DIR", home)
347 glab, err := os.Executable()
348 require.NoError(t, err)
349 installTestJob(t, home, glab)
351 now := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
352 require.NoError(t, fallbacksync.WriteStatus(fallbacksync.Status{
353 FinishedAt: now.Add(-5 * time.Minute),
354 Errors: []string{
355 "session a: could not create session: 404 Not Found",
356 "session b: could not create session: 404 Not Found",
357 },
358 }))
360 result := checkFallbackSync(t.Context(), healthyLinuxJob(t, glab, testVersion), "linux", testBuild, now)
362 assert.False(t, result.ok, "a run where every session failed must not look healthy")
363 assert.Equal(t,
364 fmt.Sprintf("installed (%s), but the last run synced nothing; last run 5m0s ago: 0 sessions synced, 0 completed, 0 events posted, 2 errors (first: session a: could not create session: 404 Not Found)", glab),
365 result.message)
366 assert.Equal(t, fmt.Sprintf("Run '%s minder audit sync --all' to see the errors", glab), result.fix)
369func TestDescribeLastRun_Singular(t *testing.T) {
370 t.Parallel()
372 now := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
373 got := describeLastRun(&fallbacksync.Status{
374 FinishedAt: now,
375 SessionsSynced: 1,
376 EventsPosted: 1,
377 Errors: []string{"session a: boom"},
378 }, now)
379 assert.Equal(t, "last run 0s ago: 1 session synced, 0 completed, 1 event posted, 1 error (first: session a: boom)", got)
382func TestDescribeLastRun_EventsTooLarge(t *testing.T) {
383 now := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
384 got := describeLastRun(&fallbacksync.Status{
385 FinishedAt: now,
386 SessionsSynced: 1,
387 EventsPosted: 19,
388 EventsTooLarge: 1,
389 }, now)
390 assert.Equal(t, "last run 0s ago: 1 session synced, 0 completed, 19 events posted, 1 event too large to post", got)
393func TestCheckFallbackSync_GovernanceNotEnabledStaysHealthy(t *testing.T) {
394 home := t.TempDir()
395 t.Setenv("HOME", home)
396 t.Setenv("GLAB_CONFIG_DIR", home)
397 glab, err := os.Executable()
398 require.NoError(t, err)
399 installTestJob(t, home, glab)
400 now := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
401 require.NoError(t, fallbacksync.WriteStatus(fallbacksync.Status{
402 FinishedAt: now,
403 GovernanceNotEnabled: []string{"gitlab.com/me/dotfiles", "gitlab.com/gitlab-org/cli"},
404 }))
406 result := checkFallbackSync(t.Context(), healthyLinuxJob(t, glab, testVersion), "linux", testBuild, now)
408 assert.True(t, result.ok, "sessions in projects without governance are expected")
409 assert.Contains(t, result.message, "governance not enabled for 2 projects (gitlab.com/me/dotfiles, gitlab.com/gitlab-org/cli), ask a group Owner or administrator to turn it on")
412func TestCheckFallbackSync_ProjectNotFoundStaysHealthy(t *testing.T) {
413 home := t.TempDir()
414 t.Setenv("HOME", home)
415 t.Setenv("GLAB_CONFIG_DIR", home)
416 glab, err := os.Executable()
417 require.NoError(t, err)
418 installTestJob(t, home, glab)
419 now := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
420 require.NoError(t, fallbacksync.WriteStatus(fallbacksync.Status{
421 FinishedAt: now,
422 ProjectNotFound: []string{"gitlab.com/gitlab-org/cli-docs-test-nonexistent"},
423 }))
425 result := checkFallbackSync(t.Context(), healthyLinuxJob(t, glab, testVersion), "linux", testBuild, now)
427 assert.True(t, result.ok, "sessions in projects the user can't see are expected")
428 assert.Contains(t, result.message, "1 project not found or not accessible (gitlab.com/gitlab-org/cli-docs-test-nonexistent)")
431func TestCheckFallbackSync_NoTokenFails(t *testing.T) {
432 home := t.TempDir()
433 t.Setenv("HOME", home)
434 t.Setenv("GLAB_CONFIG_DIR", home)
435 glab, err := os.Executable()
436 require.NoError(t, err)
437 installTestJob(t, home, glab)
438 now := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
439 require.NoError(t, fallbacksync.WriteStatus(fallbacksync.Status{
440 FinishedAt: now,
441 NoToken: []string{"gitlab.com"},
442 ProjectNotFound: []string{"gitlab.com/my-group/private-project"},
443 }))
445 result := checkFallbackSync(t.Context(), healthyLinuxJob(t, glab, testVersion), "linux", testBuild, now)
447 assert.False(t, result.ok, "GitLab needs a token to create sessions and audit events")
448 assert.Contains(t, result.message, "the last run had no token for gitlab.com and could not sync some sessions there")
449 assert.Contains(t, result.fix, "glab auth login --hostname gitlab.com")
452func TestCheckFallbackSync_AgentTypeNotSupportedStaysHealthy(t *testing.T) {
453 home := t.TempDir()
454 t.Setenv("HOME", home)
455 t.Setenv("GLAB_CONFIG_DIR", home)
456 glab, err := os.Executable()
457 require.NoError(t, err)
458 installTestJob(t, home, glab)
459 now := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
460 require.NoError(t, fallbacksync.WriteStatus(fallbacksync.Status{
461 FinishedAt: now,
462 AgentTypeNotSupported: []string{"codex on gitlab.example.com"},
463 Skipped: []string{"the Cursor workspace x matches 2 directories (a, b), and its sessions do not show which"},
464 }))
466 result := checkFallbackSync(t.Context(), healthyLinuxJob(t, glab, testVersion), "linux", testBuild, now)
468 assert.True(t, result.ok)
469 assert.Contains(t, result.message, "not supported by GitLab yet: codex on gitlab.example.com")
470 assert.Contains(t, result.message, "not synced: the Cursor workspace x matches 2 directories")
473func TestCheckFallbackSync_ShowsDiscoveredAgents(t *testing.T) {
474 home := t.TempDir()
475 t.Setenv("HOME", home)
476 t.Setenv("GLAB_CONFIG_DIR", home)
477 glab, err := os.Executable()
478 require.NoError(t, err)
479 installTestJob(t, home, glab)
480 now := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
481 require.NoError(t, fallbacksync.WriteStatus(fallbacksync.Status{FinishedAt: now}))
482 require.NoError(t, fallbacksync.SetDiscoveredAgents([]string{"codex", "cursor"}))
484 result := checkFallbackSync(t.Context(), healthyLinuxJob(t, glab, testVersion), "linux", testBuild, now)
486 assert.True(t, result.ok)
487 assert.True(t, strings.HasSuffix(result.message, "; also syncing codex, cursor sessions"), result.message)
490func TestCheckFallbackSync_Overdue(t *testing.T) {
491 home := t.TempDir()
492 t.Setenv("HOME", home)
493 t.Setenv("GLAB_CONFIG_DIR", home)
494 glab, err := os.Executable()
495 require.NoError(t, err)
496 installTestJob(t, home, glab)
498 now := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
499 require.NoError(t, fallbacksync.WriteStatus(fallbacksync.Status{
500 FinishedAt: now.Add(-3 * time.Hour),
501 Paused: []string{"claude-code: the glab Stop hook is not installed in ~/.claude/settings.json"},
502 }))
504 result := checkFallbackSync(t.Context(), healthyLinuxJob(t, glab, testVersion), "linux", testBuild, now)
506 assert.Contains(t, result.message, "last run 3h0m0s ago (expected every 30 minutes; the job may not be running): 0 sessions synced, 0 completed, 0 events posted; paused for claude-code: the glab Stop hook is not installed")
509func TestChecks_ReportHomeDirError(t *testing.T) {
510 t.Setenv("HOME", "")
512 hooks := checkClaudeHooks()
513 assert.False(t, hooks.ok)
514 assert.Contains(t, hooks.message, "home directory: $HOME is not defined")
516 fallback := checkFallbackSync(t.Context(), nil, "linux", testBuild, time.Now())
517 assert.False(t, fallback.ok)
518 assert.Contains(t, fallback.message, "could not determine home directory: $HOME is not defined")
521func TestCheckOpenCodePlugin(t *testing.T) {
522 // setup points glab and OpenCode at new directories and returns where the
523 // plugin goes, with OpenCode chosen in setup when enabled is true.
524 setup := func(t *testing.T, enabled bool) string {
525 t.Helper()
526 t.Setenv("XDG_CONFIG_HOME", t.TempDir())
527 t.Setenv("GLAB_CONFIG_DIR", t.TempDir())
528 if enabled {
529 require.NoError(t, fallbacksync.SetHookAgents([]string{"opencode"}))
530 }
531 path, err := opencodeplugin.Path()
532 require.NoError(t, err)
533 return path
534 }
536 t.Run("not chosen and OpenCode not found", func(t *testing.T) {
537 setup(t, false)
538 result := checkOpenCodePlugin()
539 assert.True(t, result.ok)
540 assert.Equal(t, "OpenCode sessions are not synced", result.message)
541 })
543 t.Run("not chosen but OpenCode found", func(t *testing.T) {
544 setup(t, false)
545 dir, err := opencodeplugin.ConfigDir()
546 require.NoError(t, err)
547 require.NoError(t, os.MkdirAll(dir, 0o755))
548 result := checkOpenCodePlugin()
549 assert.True(t, result.ok, "not syncing an agent you did not choose is not a failure")
550 assert.Contains(t, result.message, "run 'glab minder setup --agents opencode'")
551 })
553 t.Run("chosen without the plugin", func(t *testing.T) {
554 setup(t, true)
555 result := checkOpenCodePlugin()
556 assert.False(t, result.ok)
557 assert.Contains(t, result.message, "not installed")
558 assert.Equal(t, "Run: glab minder setup", result.fix)
559 })
561 t.Run("plugin installed", func(t *testing.T) {
562 path := setup(t, true)
563 _, err := opencodeplugin.Install(path)
564 require.NoError(t, err)
565 result := checkOpenCodePlugin()
566 assert.True(t, result.ok)
567 assert.Equal(t, "installed in "+opencodeplugin.Display(path), result.message)
568 })
570 t.Run("plugin out of date", func(t *testing.T) {
571 path := setup(t, true)
572 require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755))
573 require.NoError(t, os.WriteFile(path, []byte("// Installed by glab govern setup.\n// an older version\n"), 0o644))
574 result := checkOpenCodePlugin()
575 assert.False(t, result.ok)
576 assert.Contains(t, result.message, "is out of date")
577 })
579 t.Run("older glab installed the plugin", func(t *testing.T) {
580 path := setup(t, false)
581 _, err := opencodeplugin.Install(path)
582 require.NoError(t, err)
583 result := checkOpenCodePlugin()
584 assert.True(t, result.ok)
585 assert.Contains(t, result.message, "installed in", "an installed plugin counts as set up when nothing is recorded")
586 })
588 t.Run("unreadable list of agents", func(t *testing.T) {
589 setup(t, false)
590 path := filepath.Join(os.Getenv("GLAB_CONFIG_DIR"), "gaig", "hook-agents.json")
591 require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755))
592 require.NoError(t, os.WriteFile(path, []byte("{not json"), 0o600))
593 result := checkOpenCodePlugin()
594 assert.False(t, result.ok)
595 assert.Contains(t, result.fix, "glab minder setup --uninstall")
596 })
598 t.Run("file not installed by glab", func(t *testing.T) {
599 path := setup(t, true)
600 require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755))
601 require.NoError(t, os.WriteFile(path, []byte("// the user's own plugin\n"), 0o644))
602 result := checkOpenCodePlugin()
603 assert.False(t, result.ok)
604 assert.Contains(t, result.message, "was not installed by glab")
605 })
608func TestCheckClaudeHooks_NotChosen(t *testing.T) {
609 dir := t.TempDir()
610 t.Setenv("HOME", dir)
611 t.Setenv("GLAB_CONFIG_DIR", filepath.Join(dir, "glab"))
612 require.NoError(t, fallbacksync.SetHookAgents([]string{"opencode"}))
614 result := checkClaudeHooks()
615 assert.True(t, result.ok, "Claude Code not chosen is not a failure")
616 assert.Contains(t, result.message, "Claude Code sessions are not synced")
619func TestCheckClaudeHooks_UnreadableAgents(t *testing.T) {
620 uninstallFix := "Fix it, or run 'glab minder setup --uninstall' to start again"
621 tests := map[string]struct {
622 file []string
623 wantFix string
624 }{
625 "Claude Code settings": {file: []string{".claude", "settings.json"}, wantFix: "Fix it, then run 'glab minder setup' again"},
626 "setup's hook agents": {file: []string{"glab", "gaig", "hook-agents.json"}, wantFix: uninstallFix},
627 "setup's discovered list": {file: []string{"glab", "gaig", "discovered-agents.json"}, wantFix: uninstallFix},
628 }
629 for name, tc := range tests {
630 t.Run(name, func(t *testing.T) {
631 dir := t.TempDir()
632 t.Setenv("HOME", dir)
633 t.Setenv("GLAB_CONFIG_DIR", filepath.Join(dir, "glab"))
634 path := filepath.Join(append([]string{dir}, tc.file...)...)
635 require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755))
636 require.NoError(t, os.WriteFile(path, []byte("{not json"), 0o600))
638 result := checkClaudeHooks()
640 assert.False(t, result.ok)
641 assert.Contains(t, result.message, path)
642 assert.Equal(t, tc.wantFix, result.fix, "uninstalling only helps when setup's own lists are unreadable")
643 })
644 }
Diagnostics8 git calls · 319 ms
CallStatusSizeTime0319 ms
discover200185 B2 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 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 · hit3 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=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=4
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 · 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=261
git.response.cache=HIT
git.response.duration_ms=4
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:0200166 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=303
git.response.bytes=166
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=80253e44f30f16fe5863321899003ff50f0609ce
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=166
git.pkt.payload.max=139
git.sideband.band1.bytes=139
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=139
git.pack.trailer=6218fb7fe13d59e0a344caa8ba4fe78bdec166bd
Open pack map
fetch2004.7 KiB303 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=4857
git.response.cache=MISS
git.response.duration_ms=303
git.fetch.wants=cd688448cbff861cc38af24c551b5e90d6a37f54
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=4857
git.pkt.payload.max=4830
git.sideband.band1.bytes=4830
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
a5e345e4de22f4d4
Request
236982a2…
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