- 只翻注释/文档字符串:剥离注释后代码行逐字节不变(机械校验只剩允许的行尾注释形态) - 裁决编号与 design 节号(02.4.3 / 11.4.2 / design/05 §9 等)逐字保留 - 复核:go build 绿;orchestration 及其子包(audit/comm)测试绿;gofmt 干净
58 lines
1.8 KiB
Go
58 lines
1.8 KiB
Go
package orchestration
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/orchestration/audit"
|
|
)
|
|
|
|
// TestSchedulerAuditContext 走通 subagent_ask 审计路径的 full、tail 与 keyword 三种
|
|
// 窗口,以及未找到与查询为空两类错误。
|
|
func TestSchedulerAuditContext(t *testing.T) {
|
|
t.Parallel()
|
|
s := New(Options{MaxParallel: 2, AgentID: "orchestrator"})
|
|
ctx := context.Background()
|
|
|
|
msgs := []model.Message{
|
|
model.TextMessage(model.RoleUser, "hello"),
|
|
model.TextMessage(model.RoleAssistant, "hi there"),
|
|
}
|
|
s.mu.Lock()
|
|
s.agents["sub-1"] = &SubAgent{ID: "sub-1", Goal: "do it", Context: msgs, status: StatusRunning}
|
|
s.mu.Unlock()
|
|
|
|
full, err := s.AuditContext(ctx, "sub-1", AuditFull, 0, "")
|
|
if err != nil {
|
|
t.Fatalf("audit full: %v", err)
|
|
}
|
|
if full.AgentID != "sub-1" || full.Status != StatusRunning || len(full.Messages) != 2 {
|
|
t.Fatalf("full = %+v, want sub-1/running/2 msgs", full)
|
|
}
|
|
|
|
tail, err := s.AuditContext(ctx, "sub-1", AuditTail, 1, "")
|
|
if err != nil {
|
|
t.Fatalf("audit tail: %v", err)
|
|
}
|
|
if len(tail.Messages) != 1 || tail.Messages[0].Content[0].Text != "hi there" {
|
|
t.Fatalf("tail = %+v, want last message 'hi there'", tail)
|
|
}
|
|
|
|
kw, err := s.AuditContext(ctx, "sub-1", AuditKeyword, 0, "hello")
|
|
if err != nil {
|
|
t.Fatalf("audit keyword: %v", err)
|
|
}
|
|
if kw.Line != 1 || len(kw.Messages) != 2 {
|
|
t.Fatalf("keyword = %+v, want line 1 with 2 surrounding msgs", kw)
|
|
}
|
|
|
|
if _, err := s.AuditContext(ctx, "nope", AuditFull, 0, ""); !errors.Is(err, ErrAgentNotFound) {
|
|
t.Fatalf("want ErrAgentNotFound, got %v", err)
|
|
}
|
|
if _, err := s.AuditContext(ctx, "sub-1", AuditKeyword, 0, " "); !errors.Is(err, audit.ErrQueryEmpty) {
|
|
t.Fatalf("want ErrQueryEmpty, got %v", err)
|
|
}
|
|
}
|