Files
cogito/agent_background_test.go
Ettore Di Giacinto 81ce500344 feat(agent): expose AgentState.Background for spawned background agents (#54)
Add an exported Background flag on AgentState, set true for background
spawns (spawn_agent background=true) and false for foreground ones. This
lets embedders tell unattended background work apart from a foreground
sub-agent whose result is consumed inline — e.g. to auto-notify on
completion only for background agents.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 23:16:48 +02:00

29 lines
864 B
Go

package cogito
import (
"context"
"testing"
)
// TestBackgroundSpawnSetsBackgroundFlag verifies that a background spawn marks
// the AgentState so embedders can tell it apart from a foreground sub-agent.
func TestBackgroundSpawnSetsBackgroundFlag(t *testing.T) {
m := NewAgentManager()
llm := newBlockingLLM(make(chan struct{})) // blocks; background spawn returns immediately
runner := &spawnAgentRunner{llm: llm, manager: m, ctx: context.Background()}
_, idAny, err := runner.Run(SpawnAgentArgs{Task: "bg job", Background: true})
if err != nil {
t.Fatalf("background Run: %v", err)
}
id, _ := idAny.(string)
a, ok := m.Get(id)
if !ok {
t.Fatal("background agent should be registered")
}
if !a.Background {
t.Fatal("a background spawn should set AgentState.Background = true")
}
a.Cancel() // unblock the goroutine so the test cleans up
}