feat: add session auto-planning and resource-based concurrency scheduling

This commit is contained in:
lpf
2026-03-04 12:44:31 +08:00
parent ba8cfbe131
commit 154ab3f7f9
16 changed files with 1193 additions and 486 deletions

View File

@@ -0,0 +1,54 @@
package agent
import (
"context"
"testing"
"clawgo/pkg/bus"
"clawgo/pkg/providers"
)
func TestSplitPlannedSegments_Bullets(t *testing.T) {
parts := splitPlannedSegments("- 修复 a.go\n- 补充 b.go 测试")
if len(parts) != 2 {
t.Fatalf("unexpected parts: %#v", parts)
}
}
func TestPlanSessionTasks_Semicolon(t *testing.T) {
loop := &AgentLoop{sessionAutoPlan: true, sessionAutoPlanMax: 4}
tasks := loop.planSessionTasks(bus.InboundMessage{Channel: "cli", Content: "修复 pkg/a.go修复 pkg/b.go"})
if len(tasks) != 2 {
t.Fatalf("expected 2 tasks, got %#v", tasks)
}
if tasks[0].Content == tasks[1].Content {
t.Fatalf("expected distinct tasks: %#v", tasks)
}
}
func TestProcessPlannedMessage_AggregatesResults(t *testing.T) {
rp := &recordingProvider{responses: []providers.LLMResponse{
{Content: "done-a", FinishReason: "stop"},
{Content: "done-b", FinishReason: "stop"},
}}
loop := setupLoop(t, rp)
loop.sessionAutoPlan = true
loop.sessionAutoPlanMax = 4
resp, err := loop.processPlannedMessage(context.Background(), bus.InboundMessage{
Channel: "cli",
SenderID: "u",
ChatID: "direct",
SessionKey: "sess-plan",
Content: "修复 pkg/a.go补充 pkg/b.go 测试",
})
if err != nil {
t.Fatalf("processPlannedMessage error: %v", err)
}
if len(rp.calls) != 2 {
t.Fatalf("expected 2 provider calls, got %d", len(rp.calls))
}
if resp == "" {
t.Fatalf("expected aggregate response")
}
}