Files
cc-connect/agent/qoder/qoder_test.go
T
chenhg5andClaude cca838504a feat(qoder): add Qoder CLI agent support
generated by llmgit

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-03 22:43:20 +08:00

67 lines
1.4 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); 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)
}