Commit a1e67e455d

a1e67e455d64a286b13e7929a822afb17edfdb5b

parent: a8523b10b1

Verified · cmc

cmc <hello@cleberg.net> · 2026-09-28 06:57 UTC

e2e: usage prints the CLI's own path, stock ssh the registered one

Ref #267

Layout: unified · split

e2e/cliusage_test.go added +55
@@ -0,0 +1,55 @@
1package e2e
2
3import (
4 "fmt"
5 "path/filepath"
6 "strings"
7 "testing"
8)
9
10// The CLI sends its own path where it differs from the registered one, so
11// usage and help print a command that exists: gitbay auth keys remove,
12// never gitbay keys remove (#267). Stock ssh sends none and sees the
13// registered path, the only one it can type.
14func TestCLIUsagePrintsTheInvokingPath(t *testing.T) {
15 t.Parallel()
16 inst := startInstance(t)
17 key := inst.newKey(t, "alice")
18 inst.admin(t, "admin", "user", "create", "alice", "--key", key+".pub",
19 "--email", "alice@example.test", "--verified")
20
21 c := &cli{bin: buildGitbayCLI(t), configDir: t.TempDir(), inst: inst, key: key}
22 c.must(t, "", "", "remote", "add", "test", "127.0.0.1",
23 "--port", fmt.Sprint(inst.port),
24 "--ssh-option", "-i", "--ssh-option", key,
25 "--ssh-option", "-oIdentitiesOnly=yes",
26 "--ssh-option", "-oStrictHostKeyChecking=no",
27 "--ssh-option", "-oUserKnownHostsFile="+filepath.Join(inst.sshDir, "kh"),
28 "--ssh-option", "-oBatchMode=yes",
29 "--default")
30
31 _, errOut, code := c.run(t, "", "", "auth", "keys", "remove")
32 if code == 0 || !strings.Contains(errOut, "usage: gitbay auth keys remove <fingerprint>") {
33 t.Errorf("CLI refusal: exit %d, stderr %q", code, errOut)
34 }
35
36 out, errOut, code := c.run(t, "", "", "auth", "keys", "remove", "--help")
37 if code != 0 || !strings.Contains(out, "gitbay auth keys remove <fingerprint>") {
38 t.Errorf("CLI help: exit %d, stdout %q, stderr %q", code, out, errOut)
39 }
40
41 // A command whose CLI path matches sends no --path=, and off a
42 // terminal prints the ssh form as before.
43 _, errOut, code = c.run(t, "", "", "issue", "show", "alice/app")
44 if code == 0 || !strings.Contains(errOut, "usage: ssh git@") || !strings.Contains(errOut, " issue show <owner/name> <n>") {
45 t.Errorf("matching command: exit %d, stderr %q", code, errOut)
46 }
47
48 _, errOut, code = inst.ssh(t, key, "", "keys", "remove")
49 if code == 0 || !strings.Contains(errOut, "usage: ssh git@") || !strings.Contains(errOut, " keys remove <fingerprint>") {
50 t.Errorf("stock ssh: exit %d, stderr %q", code, errOut)
51 }
52 if strings.Contains(errOut, "auth") {
53 t.Errorf("stock ssh saw the CLI's auth grouping: %q", errOut)
54 }
55}