cli/internal/bugseti/ghcheck_test.go
Athena bee56c3fe1 fix(bugseti): add gh CLI availability check with helpful error
Adds a startup check that verifies gh is in PATH and authenticated
before initializing services. Provides clear install/auth instructions
on failure instead of cryptic exec errors at runtime.

Closes #61

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 05:53:52 +00:00

37 lines
991 B
Go

package bugseti
import (
"os/exec"
"strings"
"testing"
)
func TestCheckGHCLI_Good(t *testing.T) {
// Only run if gh is actually available (CI-friendly skip)
if _, err := exec.LookPath("gh"); err != nil {
t.Skip("gh CLI not installed, skipping")
}
err := CheckGHCLI()
// We can't guarantee auth status in all environments,
// but if gh is present the function should at least not panic.
if err != nil {
t.Logf("CheckGHCLI returned error (may be expected if not authenticated): %v", err)
}
}
func TestCheckGHCLI_Bad_MissingBinary(t *testing.T) {
// Save and clear PATH to simulate missing gh
t.Setenv("PATH", t.TempDir())
err := CheckGHCLI()
if err == nil {
t.Fatal("expected error when gh is not in PATH")
}
if !strings.Contains(err.Error(), "gh CLI not found") {
t.Errorf("error should mention 'gh CLI not found', got: %v", err)
}
if !strings.Contains(err.Error(), "https://cli.github.com") {
t.Errorf("error should include install URL, got: %v", err)
}
}