mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-13 19:20:06 +00:00
0703dd1602
Each spinner created a new tea.NewProgram which sent DECRQM queries for synchronized output mode 2026. When the program exited and restored cooked terminal mode, the terminal's DECRPM response leaked as visible ^[[?2026;2$y characters. Replace Bubble Tea spinner with a simple goroutine animation loop writing directly to stderr via lipgloss.
91 lines
2.0 KiB
Go
91 lines
2.0 KiB
Go
package sdk_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/mark3labs/mcphost/sdk"
|
|
)
|
|
|
|
func TestNew(t *testing.T) {
|
|
if os.Getenv("ANTHROPIC_API_KEY") == "" {
|
|
t.Skip("Skipping test: ANTHROPIC_API_KEY not set")
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
// Test default initialization
|
|
host, err := sdk.New(ctx, nil)
|
|
if err != nil {
|
|
t.Fatalf("Failed to create MCPHost with defaults: %v", err)
|
|
}
|
|
defer host.Close()
|
|
|
|
if host.GetModelString() == "" {
|
|
t.Error("Model string should not be empty")
|
|
}
|
|
}
|
|
|
|
func TestNewWithOptions(t *testing.T) {
|
|
if os.Getenv("ANTHROPIC_API_KEY") == "" {
|
|
t.Skip("Skipping test: ANTHROPIC_API_KEY not set")
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
opts := &sdk.Options{
|
|
Model: "anthropic:claude-sonnet-4-20250514",
|
|
MaxSteps: 5,
|
|
Quiet: true,
|
|
}
|
|
|
|
host, err := sdk.New(ctx, opts)
|
|
if err != nil {
|
|
t.Fatalf("Failed to create MCPHost with options: %v", err)
|
|
}
|
|
defer host.Close()
|
|
|
|
if host.GetModelString() != opts.Model {
|
|
t.Errorf("Expected model %s, got %s", opts.Model, host.GetModelString())
|
|
}
|
|
}
|
|
|
|
func TestSessionManagement(t *testing.T) {
|
|
if os.Getenv("ANTHROPIC_API_KEY") == "" {
|
|
t.Skip("Skipping test: ANTHROPIC_API_KEY not set")
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
host, err := sdk.New(ctx, &sdk.Options{Quiet: true})
|
|
if err != nil {
|
|
t.Fatalf("Failed to create MCPHost: %v", err)
|
|
}
|
|
defer host.Close()
|
|
|
|
// Test clear session
|
|
host.ClearSession()
|
|
mgr := host.GetSessionManager()
|
|
if mgr.MessageCount() != 0 {
|
|
t.Error("Session should be empty after clear")
|
|
}
|
|
|
|
// Test save/load session (would need actual implementation)
|
|
tempFile := t.TempDir() + "/session.json"
|
|
|
|
// Add a message first
|
|
_, err = host.Prompt(ctx, "test message")
|
|
if err == nil { // Only if we have a working model
|
|
if err := host.SaveSession(tempFile); err != nil {
|
|
t.Errorf("Failed to save session: %v", err)
|
|
}
|
|
|
|
// Clear and reload
|
|
host.ClearSession()
|
|
if err := host.LoadSession(tempFile); err != nil {
|
|
t.Errorf("Failed to load session: %v", err)
|
|
}
|
|
}
|
|
}
|