fix(agent): fix data races, add tests, and fix raw protocol detection
- Fix data race on output strings.Builder in codex backend by adding mutex and waiting for reader goroutine before reading final output - Fix data race on onTurnDone by initializing it before reader starts - Fix bug where notificationProtocol zero value "" never matched "unknown", silently dropping all raw v2 notifications from codex - Add round-robin polling to prevent runtime starvation in poll loop - Log errors in claude handleControlRequest instead of silently dropping - Add 35 tests for pkg/agent covering claude parsing, codex JSON-RPC, protocol detection, event handling, and helper functions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
0d9b687d92
commit
96cfdc2e27
6 changed files with 864 additions and 15 deletions
53
server/pkg/agent/agent_test.go
Normal file
53
server/pkg/agent/agent_test.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewReturnsClaudeBackend(t *testing.T) {
|
||||
t.Parallel()
|
||||
b, err := New("claude", Config{ExecutablePath: "/nonexistent/claude"})
|
||||
if err != nil {
|
||||
t.Fatalf("New(claude) error: %v", err)
|
||||
}
|
||||
if _, ok := b.(*claudeBackend); !ok {
|
||||
t.Fatalf("expected *claudeBackend, got %T", b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewReturnsCodexBackend(t *testing.T) {
|
||||
t.Parallel()
|
||||
b, err := New("codex", Config{ExecutablePath: "/nonexistent/codex"})
|
||||
if err != nil {
|
||||
t.Fatalf("New(codex) error: %v", err)
|
||||
}
|
||||
if _, ok := b.(*codexBackend); !ok {
|
||||
t.Fatalf("expected *codexBackend, got %T", b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRejectsUnknownType(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := New("gpt", Config{})
|
||||
if err == nil {
|
||||
t.Fatal("expected error for unknown agent type")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewDefaultsLogger(t *testing.T) {
|
||||
t.Parallel()
|
||||
b, _ := New("claude", Config{})
|
||||
cb := b.(*claudeBackend)
|
||||
if cb.cfg.Logger == nil {
|
||||
t.Fatal("expected non-nil logger")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectVersionFailsForMissingBinary(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := DetectVersion(context.Background(), "/nonexistent/binary")
|
||||
if err == nil {
|
||||
t.Fatal("expected error for missing binary")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue