Skip to content

Commit d5e1dd8

Browse files
committed
split setup CLI tests
1 parent 09b940a commit d5e1dd8

2 files changed

Lines changed: 70 additions & 60 deletions

File tree

internal/cli/cli_test.go

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -951,66 +951,6 @@ func TestSetupNonInteractiveJSON(t *testing.T) {
951951
}
952952
}
953953

954-
func TestSetupWizardCanInstallTerminalWithoutMCP(t *testing.T) {
955-
t.Setenv("npm_command", "exec")
956-
svc := &fakeService{setupResult: &cli.SetupReport{Operation: "setup", Steps: []cli.SetupStep{{Name: "terminal", Status: "installed"}}}}
957-
c, _, stderr := newTestCLI(svc, nil)
958-
c.SetInput(strings.NewReader("\nnone\nnone\n\n"))
959-
960-
if err := c.Run(context.Background(), []string{"setup"}); err != nil {
961-
t.Fatal(err)
962-
}
963-
if !svc.lastSetup.InstallCLI || !svc.lastSetup.SkipMCP || len(svc.lastSetup.Clients) != 0 {
964-
t.Fatalf("options = %+v", svc.lastSetup)
965-
}
966-
for _, prompt := range []string{
967-
"Install the terminal app for CLI and TUI? [Y/n]:",
968-
"Set up which MCP clients? [codex,claude,none]:",
969-
} {
970-
if !strings.Contains(stderr.String(), prompt) {
971-
t.Fatalf("missing prompt %q in %q", prompt, stderr.String())
972-
}
973-
}
974-
}
975-
976-
func TestSetupWizardPreviewsPlanBeforeConfirmation(t *testing.T) {
977-
t.Setenv("npm_command", "exec")
978-
svc := &fakeService{setupResult: &cli.SetupReport{
979-
Operation: "setup",
980-
DryRun: true,
981-
Steps: []cli.SetupStep{{
982-
Name: "terminal", Status: "would install",
983-
Message: "npm install --global gitcontribute@0.1.1",
984-
}},
985-
}}
986-
c, stdout, stderr := newTestCLI(svc, nil)
987-
c.SetInput(strings.NewReader("\ncodex\nnone\nn\n"))
988-
989-
if err := c.Run(context.Background(), []string{"setup"}); err != nil {
990-
t.Fatal(err)
991-
}
992-
if len(svc.setupCalls) != 1 || !svc.setupCalls[0].DryRun || !svc.setupCalls[0].InstallCLI {
993-
t.Fatalf("setup calls = %+v", svc.setupCalls)
994-
}
995-
if !strings.Contains(stdout.String(), "Setup plan") || !strings.Contains(stdout.String(), "npm install --global gitcontribute@0.1.1") {
996-
t.Fatalf("stdout = %q", stdout.String())
997-
}
998-
if !strings.Contains(stderr.String(), "Setup cancelled; no changes were made.") {
999-
t.Fatalf("stderr = %q", stderr.String())
1000-
}
1001-
}
1002-
1003-
func TestRemoveAllNonInteractive(t *testing.T) {
1004-
svc := &fakeService{setupResult: &cli.SetupReport{Operation: "remove", Steps: []cli.SetupStep{{Name: "codex", Status: "removed"}}}}
1005-
c := cli.New(svc, &fakeMCPRunner{}, io.Discard, io.Discard)
1006-
if err := c.Run(context.Background(), []string{"remove", "--all-clients", "--yes"}); err != nil {
1007-
t.Fatal(err)
1008-
}
1009-
if !svc.lastSetup.Remove || !svc.lastSetup.AllClients {
1010-
t.Fatalf("options = %+v", svc.lastSetup)
1011-
}
1012-
}
1013-
1014954
func TestInvestigationStartShowAndList(t *testing.T) {
1015955
svc := &fakeService{
1016956
startInvResult: &cli.InvestigationResult{

internal/cli/setup_cli_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package cli_test
2+
3+
import (
4+
"context"
5+
"io"
6+
"strings"
7+
"testing"
8+
9+
"github.com/morluto/gitcontribute/internal/cli"
10+
)
11+
12+
func TestRemoveAllNonInteractive(t *testing.T) {
13+
svc := &fakeService{setupResult: &cli.SetupReport{Operation: "remove", Steps: []cli.SetupStep{{Name: "codex", Status: "removed"}}}}
14+
c := cli.New(svc, &fakeMCPRunner{}, io.Discard, io.Discard)
15+
if err := c.Run(context.Background(), []string{"remove", "--all-clients", "--yes"}); err != nil {
16+
t.Fatal(err)
17+
}
18+
if !svc.lastSetup.Remove || !svc.lastSetup.AllClients {
19+
t.Fatalf("options = %+v", svc.lastSetup)
20+
}
21+
}
22+
23+
func TestSetupWizardCanInstallTerminalWithoutMCP(t *testing.T) {
24+
t.Setenv("npm_command", "exec")
25+
svc := &fakeService{setupResult: &cli.SetupReport{Operation: "setup", Steps: []cli.SetupStep{{Name: "terminal", Status: "installed"}}}}
26+
c, _, stderr := newTestCLI(svc, nil)
27+
c.SetInput(strings.NewReader("\nnone\nnone\n\n"))
28+
29+
if err := c.Run(context.Background(), []string{"setup"}); err != nil {
30+
t.Fatal(err)
31+
}
32+
if !svc.lastSetup.InstallCLI || !svc.lastSetup.SkipMCP || len(svc.lastSetup.Clients) != 0 {
33+
t.Fatalf("options = %+v", svc.lastSetup)
34+
}
35+
for _, prompt := range []string{
36+
"Install the terminal app for CLI and TUI? [Y/n]:",
37+
"Set up which MCP clients? [codex,claude,none]:",
38+
} {
39+
if !strings.Contains(stderr.String(), prompt) {
40+
t.Fatalf("missing prompt %q in %q", prompt, stderr.String())
41+
}
42+
}
43+
}
44+
45+
func TestSetupWizardPreviewsPlanBeforeConfirmation(t *testing.T) {
46+
t.Setenv("npm_command", "exec")
47+
svc := &fakeService{setupResult: &cli.SetupReport{
48+
Operation: "setup",
49+
DryRun: true,
50+
Steps: []cli.SetupStep{{
51+
Name: "terminal", Status: "would install",
52+
Message: "npm install --global gitcontribute@0.1.1",
53+
}},
54+
}}
55+
c, stdout, stderr := newTestCLI(svc, nil)
56+
c.SetInput(strings.NewReader("\ncodex\nnone\nn\n"))
57+
58+
if err := c.Run(context.Background(), []string{"setup"}); err != nil {
59+
t.Fatal(err)
60+
}
61+
if len(svc.setupCalls) != 1 || !svc.setupCalls[0].DryRun || !svc.setupCalls[0].InstallCLI {
62+
t.Fatalf("setup calls = %+v", svc.setupCalls)
63+
}
64+
if !strings.Contains(stdout.String(), "Setup plan") || !strings.Contains(stdout.String(), "npm install --global gitcontribute@0.1.1") {
65+
t.Fatalf("stdout = %q", stdout.String())
66+
}
67+
if !strings.Contains(stderr.String(), "Setup cancelled; no changes were made.") {
68+
t.Fatalf("stderr = %q", stderr.String())
69+
}
70+
}

0 commit comments

Comments
 (0)