mirror of
https://github.com/mudler/cogito.git
synced 2026-07-23 10:25:44 -04:00
81ce500344
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>
29 lines
864 B
Go
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
|
|
}
|