v0.9.1 406ddf4

config_command_test.go RawHistoryFolder

1package agent
2
3import (
4	"context"
5	"encoding/json"
6	"fmt"
7	"os"
8	"path/filepath"
9	"strings"
10	"testing"
11
12	"github.com/bnema/zut/packages/provider/auth"
13)
14
15func TestAgentAPIKeyCommandHelperProcess(t *testing.T) {
16	if os.Getenv("ZUT_AGENT_API_KEY_COMMAND_HELPER") != "1" {
17		return
18	}
19	args := os.Args
20	for len(args) > 0 && args[0] != "--" {
21		args = args[1:]
22	}
23	if len(args) != 2 {
24		os.Exit(2)
25	}
26	if err := os.WriteFile(args[1], []byte("ran\n"), 0o600); err != nil {
27		os.Exit(3)
28	}
29	fmt.Print("resolved-secret\n")
30	os.Exit(0)
31}
32
33func TestCommandCredentialIsLazy(t *testing.T) {
34	home := t.TempDir()
35	t.Setenv("ZUT_HOME", home)
36	t.Setenv("LAZY_PROVIDER_API_KEY", "")
37	t.Setenv("ZUT_AGENT_API_KEY_COMMAND_HELPER", "1")
38	marker := filepath.Join(home, "command-ran")
39	credentials := auth.Credentials{AdditionalAPIKeyCreds: map[string]auth.ProviderCreds{
40		"lazy-provider": {
41			APIKeyCommand: &auth.APIKeyCommand{
42				Program: os.Args[0],
43				Args:    []string{"-test.run=^TestAgentAPIKeyCommandHelperProcess$", "--", marker},
44			},
45		},
46	}}
47	encoded, err := json.Marshal(credentials)
48	if err != nil {
49		t.Fatal(err)
50	}
51	if err := os.WriteFile(AuthPath(), encoded, 0o600); err != nil {
52		t.Fatal(err)
53	}
54
55	if !CredentialAvailable("lazy-provider") {
56		t.Fatal("command-backed credential was not reported as available")
57	}
58	if _, _, err := resolveCredentialForBackground(context.Background(), "lazy-provider"); err == nil {
59		t.Fatal("background resolution unexpectedly returned the command-backed credential")
60	}
61	if _, err := os.Stat(marker); !os.IsNotExist(err) {
62		t.Fatalf("credential command ran during availability checks: %v", err)
63	}
64
65	cred, method, _, err := ResolveCredentialFull("lazy-provider", "")
66	if err != nil {
67		t.Fatal(err)
68	}
69	if cred != "resolved-secret" || method != "apikey" {
70		t.Fatalf("resolved (%q, %q), want command API key", cred, method)
71	}
72	if contents, err := os.ReadFile(marker); err != nil || !strings.Contains(string(contents), "ran") {
73		t.Fatalf("credential command marker = %q, %v", contents, err)
74	}
75}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close