- agent/claudecode: Add tests for Name, CLIBinaryName, CLIDisplayName, SetWorkDir, GetWorkDir, SetModel, SetSessionEnv, SetPlatformPrompt, stripXMLTags - agent/opencode: Add tests for normalizeMode, Name, SetModel, GetMode, GetActiveProvider, ListProviders, SetActiveProvider - agent/qoder: Add tests for normalizeMode, Name, CLIBinaryName, CLIDisplayName, SetWorkDir, SetModel - platform/line: Add tests for Platform initialization, Name, credential validation, port/path configuration - platform/qq: Add tests for Platform initialization, ws URL, token, allowFrom, shareSessionInChannel - platform/qqbot: Add tests for Platform initialization, credential validation, intents, sandbox, markdown support Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
137 lines
2.9 KiB
Go
137 lines
2.9 KiB
Go
package qoder
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/chenhg5/cc-connect/core"
|
|
)
|
|
|
|
func TestQoderSession(t *testing.T) {
|
|
if os.Getenv("QODER_INTEGRATION") == "" {
|
|
t.Skip("set QODER_INTEGRATION=1 to run")
|
|
}
|
|
|
|
agent, err := New(map[string]any{
|
|
"work_dir": "/tmp",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("New: %v", err)
|
|
}
|
|
|
|
sess, err := agent.StartSession(context.Background(), "")
|
|
if err != nil {
|
|
t.Fatalf("StartSession: %v", err)
|
|
}
|
|
defer sess.Close()
|
|
|
|
if err := sess.Send("say hello in one word", nil, nil); err != nil {
|
|
t.Fatalf("Send: %v", err)
|
|
}
|
|
|
|
timeout := time.After(30 * time.Second)
|
|
var gotResult bool
|
|
for !gotResult {
|
|
select {
|
|
case ev, ok := <-sess.Events():
|
|
if !ok {
|
|
t.Fatal("events channel closed prematurely")
|
|
}
|
|
switch ev.Type {
|
|
case core.EventText:
|
|
fmt.Printf("[TEXT] %s\n", ev.Content)
|
|
case core.EventToolUse:
|
|
fmt.Printf("[TOOL] %s: %s\n", ev.ToolName, ev.ToolInput)
|
|
case core.EventResult:
|
|
fmt.Printf("[RESULT] sid=%s content=%s\n", ev.SessionID, ev.Content)
|
|
gotResult = true
|
|
case core.EventError:
|
|
t.Fatalf("[ERROR] %v", ev.Error)
|
|
default:
|
|
fmt.Printf("[%s] %s\n", ev.Type, ev.Content)
|
|
}
|
|
case <-timeout:
|
|
t.Fatal("timeout waiting for result")
|
|
}
|
|
}
|
|
|
|
sid := sess.CurrentSessionID()
|
|
if sid == "" {
|
|
t.Error("expected a session ID from init event")
|
|
}
|
|
fmt.Printf("Session ID: %s\n", sid)
|
|
}
|
|
|
|
// Unit tests that don't require real CLI
|
|
|
|
func TestNormalizeMode(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
expected string
|
|
}{
|
|
{"yolo", "yolo"},
|
|
{"YOLO", "yolo"},
|
|
{"bypass", "yolo"},
|
|
{"dangerously-skip-permissions", "yolo"},
|
|
{"default", "default"},
|
|
{"", "default"},
|
|
{"unknown", "default"},
|
|
{" yolo ", "yolo"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.input, func(t *testing.T) {
|
|
got := normalizeMode(tt.input)
|
|
if got != tt.expected {
|
|
t.Errorf("normalizeMode(%q) = %q, want %q", tt.input, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAgent_Name(t *testing.T) {
|
|
a := &Agent{}
|
|
if got := a.Name(); got != "qoder" {
|
|
t.Errorf("Name() = %q, want %q", got, "qoder")
|
|
}
|
|
}
|
|
|
|
func TestAgent_CLIBinaryName(t *testing.T) {
|
|
a := &Agent{}
|
|
if got := a.CLIBinaryName(); got != "qodercli" {
|
|
t.Errorf("CLIBinaryName() = %q, want %q", got, "qodercli")
|
|
}
|
|
}
|
|
|
|
func TestAgent_CLIDisplayName(t *testing.T) {
|
|
a := &Agent{}
|
|
if got := a.CLIDisplayName(); got != "Qoder" {
|
|
t.Errorf("CLIDisplayName() = %q, want %q", got, "Qoder")
|
|
}
|
|
}
|
|
|
|
func TestAgent_SetWorkDir(t *testing.T) {
|
|
a := &Agent{}
|
|
a.SetWorkDir("/tmp/test")
|
|
if got := a.GetWorkDir(); got != "/tmp/test" {
|
|
t.Errorf("GetWorkDir() = %q, want %q", got, "/tmp/test")
|
|
}
|
|
}
|
|
|
|
func TestAgent_SetModel(t *testing.T) {
|
|
a := &Agent{}
|
|
a.SetModel("gpt-4")
|
|
a.mu.Lock()
|
|
got := a.model
|
|
a.mu.Unlock()
|
|
if got != "gpt-4" {
|
|
t.Errorf("model = %q, want %q", got, "gpt-4")
|
|
}
|
|
}
|
|
|
|
// verify Agent implements core.Agent
|
|
var _ core.Agent = (*Agent)(nil)
|