Add opt-in live thinking-level checks and notes

This commit is contained in:
2026-11-09 20:22:33 +00:00
parent 66e6a7cb73
commit 9246c168ac
3 changed files with 225 additions and 0 deletions
+85
View File
@@ -0,0 +1,85 @@
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)
}
+42
View File
@@ -0,0 +1,42 @@
package codex
import (
"context"
"os"
"testing"
"time"
)
// TestCodexEffortCatalogLive reads the installed App Server's model/list
// through this adapter. It is read-only (no thread, no turn) and opt-in,
// because it attaches to the user's Codex connection host.
func TestCodexEffortCatalogLive(t *testing.T) {
if os.Getenv("PIPELINES_LIVE_CODEX_EFFORT") == "" {
t.Skip("set PIPELINES_LIVE_CODEX_EFFORT=1 to read the real Codex model catalog")
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
chat, err := Open(ctx)
if err != nil {
t.Fatal(err)
}
defer chat.Close()
catalog, err := chat.catalog(ctx)
if err != nil {
t.Fatal(err)
}
withLevels := 0
for _, model := range catalog {
ids := []string{}
for _, effort := range model.Efforts {
ids = append(ids, effort.ID)
}
t.Logf("%s default=%q levels=%v", model.ID, model.DefaultEffort, ids)
if len(model.Efforts) > 0 {
withLevels++
}
}
if withLevels == 0 {
t.Fatal("no Codex model reported reasoning efforts")
}
}