# chore(agent-help): satisfy lint checks

`055b145`·

dipree·2d ago·2 files·+28 added/-23 removed

## Sessions

01KXJZSETQZKJW961HE1547HSVView transcript

## Changes

2

- cmd/entire/cli

- Magent_help_cmd.go+4/-1

- Magent_help_cmd_test.go+24/-22

```
7 unmodified lines
8
9
10
11
12
13
14
97 unmodified lines

112
113
114
114
115
116
117
118
119
120

7 unmodified lines

"time"
	"unicode"

"github.com/entireio/cli/cmd/entire/cli/logging"
	"github.com/spf13/cobra"
	flag "github.com/spf13/pflag"
)
97 unmodified lines

// A separate short backoff keeps an offline authenticated user from paying
	// this timeout on every agent-help invocation. It must not alter the shared
	// enablement decision, which SessionStart uses for context injection.
	_ = saveAgentHelpTrailsRefreshFailure(ctx, scope, time.Now())
	if cacheErr := saveAgentHelpTrailsRefreshFailure(ctx, scope, time.Now()); cacheErr != nil {
		logging.Debug(ctx, "failed to save agent-help trails refresh backoff", "error", cacheErr)
	}
	return repoLine, false
}
return repoLine, cachedTrailsEnablementForScope(ctx, scope, time.Now()) == trailEnablementCacheEnabled
```

Mcmd/entire/cli/agent_help_cmd.go+4/-1

```
14 unmodified lines

15
16
17
18
19
20
21
22
93 unmodified lines

116
117
118
117
118
119
120
121
122
123
1 unmodified line

125
126
127
126
127
128
129
130
131
132
82 unmodified lines

215
216
217
216
217
218
219
220
221
222
5 unmodified lines

228
229
230
229
231
232
233
232
234
235
236
237
25 unmodified lines

263
264
265
264
266
267
268
269
4 unmodified lines

274
275
276
275
277
278
279
280
13 unmodified lines

294
295
296
295
297
298
299
300
299
301
302
303
304
5 unmodified lines

310
311
312
311
313
314
315
316
43 unmodified lines

360
361
362
361
363
364
365
366
3 unmodified lines

370
371
372
371
373
374
375
376
10 unmodified lines

387
388
389
388
390
391
392
393
394
395
394
396
397
398
399
10 unmodified lines

410
411
412
411
413
414
415
416
1 unmodified line

418
419
420
419
421
422
423
424
1 unmodified line

426
427
428
427
429
430
431
432
10 unmodified lines

443
444
445
444
445
446
447
448
449
450

14 unmodified lines

"github.com/spf13/cobra"
)

const agentHelpTestRepo = "gh/acme/app"

// commandNames returns the Use-name of each command, for assertions.
func commandNames(cmds []*cobra.Command) []string {
	names := make([]string, 0, len(cmds))
93 unmodified lines

refreshCalls := 0
	repoLine, enabled := agentHelpRepoContextWithRefresh(t.Context(), func(ctx context.Context, scope trailEnablementScope) error {
		refreshCalls++
		if scope.RepoKey != "gh/acme/app" {
			t.Fatalf("refresh scope repo = %q, want gh/acme/app", scope.RepoKey)
			if scope.RepoKey != agentHelpTestRepo {
				t.Fatalf("refresh scope repo = %q, want %s", scope.RepoKey, agentHelpTestRepo)
			}
			return saveTrailsEnabledForScope(ctx, scope, true, time.Now())
		})
1 unmodified line

if refreshCalls != 1 {
		t.Fatalf("refresh calls = %d, want 1", refreshCalls)
	}
	if repoLine != "gh/acme/app" {
		t.Errorf("repo line = %q, want gh/acme/app", repoLine)
		if repoLine != agentHelpTestRepo {
			t.Errorf("repo line = %q, want %s", repoLine, agentHelpTestRepo)
		}
	}
	if !enabled {
		t.Fatal("trails should be enabled after the availability refresh succeeds")
	}
82 unmodified lines

if refreshCalls != 0 {
		t.Fatalf("refresh calls = %d, want 0 without a local auth identity", refreshCalls)
	}
	if repoLine != "gh/acme/app" {
		t.Errorf("repo line = %q, want gh/acme/app", repoLine)
		if repoLine != agentHelpTestRepo {
			t.Errorf("repo line = %q, want %s", repoLine, agentHelpTestRepo)
		}
	}
	if enabled {
		t.Fatal("trails should not be advertised without a local auth identity")
	}
5 unmodified lines

t.Parallel()
	root := NewRootCmd()

if _, err := runAgentHelp(root, []string{"trail"}, "gh/acme/app", false, true); err != nil {
		if _, err := runAgentHelp(root, []string{"trail"}, agentHelpTestRepo, false, true); err != nil {
			t.Errorf("trail drill should resolve when trails enabled: %v", err)
		}
		_, err := runAgentHelp(root, []string{"trail"}, "gh/acme/app", false, false)
		_, err := runAgentHelp(root, []string{"trail"}, agentHelpTestRepo, false, false)
		if err == nil {
			t.Fatalf("trail drill should be unavailable when trails disabled")
		}
25 unmodified lines

return false
	}

disabled, err := runAgentHelp(NewRootCmd(), nil, "gh/acme/app", true /*json*/, false /*trailsDisabled*/)
	disabled, err := runAgentHelp(NewRootCmd(), nil, agentHelpTestRepo, true /*json*/, false /*trailsDisabled*/)
	if err != nil {
		t.Fatalf("json top (trails disabled): %v", err)
	}
4 unmodified lines

t.Errorf("checkpoint should always appear in --json subcommands:\n%s", disabled)
	}

enabled, err := runAgentHelp(NewRootCmd(), nil, "gh/acme/app", true, true)
	enabled, err := runAgentHelp(NewRootCmd(), nil, agentHelpTestRepo, true, true)
	if err != nil {
		t.Fatalf("json top (trails enabled): %v", err)
	}

root.AddCommand(&cobra.Command{Use: "hooks", Short: "infra", Hidden: true})
	root.AddCommand(&cobra.Command{Use: "reset", Short: "old", Deprecated: "use clean"})

if _, err := runAgentHelp(root, []string{"status"}, "gh/acme/app", false, true); err != nil {
		if _, err := runAgentHelp(root, []string{"status"}, agentHelpTestRepo, false, true); err != nil {
			t.Errorf("visible command should be drillable: %v", err)
		}
		for _, name := range []string{"hooks", "reset"} {
			if _, err := runAgentHelp(root, []string{name}, "gh/acme/app", false, true); err == nil {
				if _, err := runAgentHelp(root, []string{name}, agentHelpTestRepo, false, true); err == nil {
					t.Errorf("drilling unadvertised command %q should error, matching the advertised listing", name)
				}
			}
		}
5 unmodified lines

func TestRenderAgentHelpTop_DisabledExampleIsNonTrail(t *testing.T) {
	t.Parallel()

out := renderAgentHelpTop(NewRootCmd(), "gh/acme/app", false)
	out := renderAgentHelpTop(NewRootCmd(), agentHelpTestRepo, false)
	if !strings.Contains(out, "entire agent-help checkpoint") {
		t.Errorf("disabled top should use checkpoint as the drill example:\n%s", out)
	}
43 unmodified lines

cmd.AddCommand(&cobra.Command{Use: "show", Short: "Show a trail"})
	cmd.AddCommand(&cobra.Command{Use: "list", Short: "List trails"})

out := renderAgentHelpCommand(cmd, "gh/acme/app", true)
	out := renderAgentHelpCommand(cmd, agentHelpTestRepo, true)

for _, want := range []string{
		"trail",
3 unmodified lines

"--branch",
		"show",
		"list",
		"gh/acme/app",
		agentHelpTestRepo,
	} {
		if !strings.Contains(out, want) {
			t.Fatalf("agent-help command output missing %q:\n%s", want, out)
		}
10 unmodified lines

t.Parallel()

root := NewRootCmd()
	out := renderAgentHelpTop(root, "gh/acme/app", true)
	out := renderAgentHelpTop(root, agentHelpTestRepo, true)

for _, want := range []string{
		"trail",             // hidden but revealed via annotation
		"checkpoint",        // visible
		"status",            // visible
		"gh/acme/app",       // auto-detected repo
		agentHelpTestRepo,   // auto-detected repo
		"entire agent-help", // drill-down pointer
		"never ask",         // the standing repo-inference rule
	} {
10 unmodified lines

root := NewRootCmd()

top, err := runAgentHelp(root, nil, "gh/acme/app", false, true)
	top, err := runAgentHelp(root, nil, agentHelpTestRepo, false, true)
	if err != nil {
		t.Fatalf("top: unexpected error: %v", err)
	}
1 unmodified line

t.Fatalf("top output unexpected:\n%s", top)
	}

drill, err := runAgentHelp(root, []string{"trail"}, "gh/acme/app", false, true)
	drill, err := runAgentHelp(root, []string{"trail"}, agentHelpTestRepo, false, true)
	if err != nil {
		t.Fatalf("drill: unexpected error: %v", err)
	}
1 unmodified line

t.Fatalf("drill output unexpected:\n%s", drill)
	}

jsonOut, err := runAgentHelp(root, []string{"trail"}, "gh/acme/app", true, true)
	jsonOut, err := runAgentHelp(root, []string{"trail"}, agentHelpTestRepo, true, true)
	if err != nil {
		t.Fatalf("json: unexpected error: %v", err)
	}
10 unmodified lines

if parsed.Command != "entire trail" {
		t.Errorf("json command = %q, want %q", parsed.Command, "entire trail")
	}
	if parsed.Repo != "gh/acme/app" {
		t.Errorf("json repo = %q, want %q", parsed.Repo, "gh/acme/app")
		if parsed.Repo != agentHelpTestRepo {
		t.Errorf("json repo = %q, want %q", parsed.Repo, agentHelpTestRepo)
		}
	}
	var hasRepoFlag bool
	for _, f := range parsed.Flags {
