Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/alcove/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func main() {
Use: "alcove",
Short: "Alcove — sandboxed AI coding agents",
Long: "Alcove CLI for dispatching and managing AI coding sessions via the Bridge API.",
Version: Version,
SilenceUsage: true,
SilenceErrors: true,
}
Expand Down
63 changes: 63 additions & 0 deletions cmd/alcove/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,67 @@ func TestSaveConfigCreatesDirectory(t *testing.T) {
if loaded.Server != "https://test.example.com" {
t.Errorf("server: got %q, want %q", loaded.Server, "https://test.example.com")
}
}

func TestVersionFlag(t *testing.T) {
// Create the root command to test version flag
root := &cobra.Command{
Use: "alcove",
Version: "test-version",
SilenceUsage: true,
SilenceErrors: true,
}

// Test --version flag
root.SetArgs([]string{"--version"})
output := captureOutput(t, func() {
if err := root.Execute(); err != nil {
t.Fatalf("command execution failed: %v", err)
}
})

expected := "alcove version test-version"
if output != expected {
t.Errorf("--version output: got %q, want %q", output, expected)
}

// Test -v flag (short version)
root.SetArgs([]string{"-v"})
output = captureOutput(t, func() {
if err := root.Execute(); err != nil {
t.Fatalf("command execution failed: %v", err)
}
})

if output != expected {
t.Errorf("-v output: got %q, want %q", output, expected)
}
}

func captureOutput(t *testing.T, fn func()) string {
t.Helper()

// Create a pipe to capture output
r, w, err := os.Pipe()
if err != nil {
t.Fatalf("failed to create pipe: %v", err)
}

// Save original stdout
oldStdout := os.Stdout
os.Stdout = w

// Run the function
fn()

// Restore stdout
os.Stdout = oldStdout
w.Close()

// Read captured output
output := make([]byte, 1024)
n, _ := r.Read(output)
r.Close()

return string(output[:n])
}
Loading