From cf049345c2b3d68084e016227831193740283f01 Mon Sep 17 00:00:00 2001 From: Andrew A Date: Sun, 7 Jun 2026 20:30:37 +0200 Subject: [PATCH] fix: skip interactive config init when non-interactive Using the shared "confirm" helper has the consequence of opting into defaults in the ineraction install, which defeats the purpose of walking the user through the options. Prior to that, the install would've been waiting for input. --- cmd/install.go | 5 +++++ cmd/install_test.go | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 cmd/install_test.go diff --git a/cmd/install.go b/cmd/install.go index 6ce2e89..353d2fe 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -34,6 +34,11 @@ func promptInitConfig() error { return err } + if !isPromptTTY() { + fmt.Fprintln(os.Stderr, output.WarnStderr("bight: no config file found and stdin is not a TTY; skipping interactive setup. Create .bight.yml manually or re-run from a terminal.")) + return nil + } + if !confirm("bight: no config file found. Create .bight.yml?", true) { return nil } diff --git a/cmd/install_test.go b/cmd/install_test.go new file mode 100644 index 0000000..25e93b2 --- /dev/null +++ b/cmd/install_test.go @@ -0,0 +1,48 @@ +package cmd + +import ( + "os" + "strings" + "testing" +) + +func TestPromptInitConfig_NonTTYBailsOut(t *testing.T) { + // Isolate from any real ~/.bight.yml and from the worktree's .bight.yml + // so config.Load() returns os.ErrNotExist. + t.Setenv("HOME", t.TempDir()) + t.Chdir(t.TempDir()) + + withStubPrompt(t, false, "") + + if err := promptInitConfig(); err != nil { + t.Fatalf("promptInitConfig: %v", err) + } + + if _, err := os.Stat(".bight.yml"); !os.IsNotExist(err) { + t.Errorf("expected no .bight.yml to be written under non-TTY, stat err=%v", err) + } +} + +func TestPromptInitConfig_TTYCreatesConfig(t *testing.T) { + t.Setenv("HOME", t.TempDir()) + t.Chdir(t.TempDir()) + + // Accept "Create .bight.yml?" (Y), accept default project, default env + // file, decline seed, decline add vars. + withStubPrompt(t, true, strings.Join([]string{ + "y", // Create .bight.yml? + "", // Project name (default) + "", // Env file path (default) + "n", // Seed from another path? + "n", // Add env vars? + "", + }, "\n")) + + if err := promptInitConfig(); err != nil { + t.Fatalf("promptInitConfig: %v", err) + } + + if _, err := os.Stat(".bight.yml"); err != nil { + t.Errorf("expected .bight.yml to be written under TTY: %v", err) + } +}