86 lines
2.5 KiB
Go
86 lines
2.5 KiB
Go
package claude
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
)
|
|
|
|
// TestClaudeEffortLive drives the installed Claude Code through this adapter
|
|
// in a scratch directory: two short Haiku turns, each after a level change,
|
|
// and reads back the level the CLI applied (get_settings applied.effort). It
|
|
// runs inference on the signed-in account, so it is opt-in.
|
|
func TestClaudeEffortLive(t *testing.T) {
|
|
if os.Getenv("PIPELINES_LIVE_CLAUDE_EFFORT") == "" {
|
|
t.Skip("set PIPELINES_LIVE_CLAUDE_EFFORT=1 to run two short real Claude Code turns")
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Minute)
|
|
defer cancel()
|
|
chat := New(ctx)
|
|
defer chat.Close()
|
|
session, err := chat.Create(ctx, "Pipelines effort live check", t.TempDir())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := chat.SwitchModel(ctx, session.ID, Backend, "haiku"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
frames := make(chan protocol.ChatEventFrame, 4096)
|
|
go func() {
|
|
_ = chat.Stream(ctx, session.ID, nil, func(frame protocol.ChatEventFrame) error {
|
|
select {
|
|
case frames <- frame:
|
|
default:
|
|
}
|
|
return nil
|
|
})
|
|
}()
|
|
time.Sleep(200 * time.Millisecond)
|
|
for _, level := range []string{"low", "max"} {
|
|
if err := chat.SetEffort(ctx, session.ID, level); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := chat.Prompt(ctx, session.ID, "Reply with the single word OK."); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for ended := false; !ended; {
|
|
select {
|
|
case frame := <-frames:
|
|
ended = frame.Kind == protocol.ChatEventStep && frame.Step != nil && frame.Step.Status == protocol.ChatStepEnded
|
|
case <-ctx.Done():
|
|
t.Fatal("turn did not end")
|
|
}
|
|
}
|
|
s := chat.session(session.ID)
|
|
s.mu.Lock()
|
|
proc := s.proc
|
|
s.mu.Unlock()
|
|
raw, err := proc.request(ctx, "get_settings", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var settings struct {
|
|
Applied struct {
|
|
Model string `json:"model"`
|
|
Effort string `json:"effort"`
|
|
} `json:"applied"`
|
|
}
|
|
if err := json.Unmarshal(raw, &settings); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Logf("chose %s: CLI applied model=%s effort=%s", level, settings.Applied.Model, settings.Applied.Effort)
|
|
if settings.Applied.Effort != level {
|
|
t.Fatalf("CLI applied effort %q, want %q", settings.Applied.Effort, level)
|
|
}
|
|
}
|
|
efforts, _, err := chat.Efforts(ctx, protocol.ChatSession{ID: session.ID, Model: "haiku"})
|
|
if err != nil || len(efforts) == 0 {
|
|
t.Fatalf("haiku levels = %+v, %v", efforts, err)
|
|
}
|
|
t.Logf("haiku levels from initialize: %+v", efforts)
|
|
}
|