docs(comments): 注释中文化 · internal/runtime/orchestration(29 文件,纯替换)
- 只翻注释/文档字符串:剥离注释后代码行逐字节不变(机械校验只剩允许的行尾注释形态) - 裁决编号与 design 节号(02.4.3 / 11.4.2 / design/05 §9 等)逐字保留 - 复核:go build 绿;orchestration 及其子包(audit/comm)测试绿;gofmt 干净
This commit is contained in:
1 parent
fe90f64a56
commit
eb1828ee7a
29 files changed
+751
-949
No files matched your search
@@ -18,8 +18,8 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/tool"
|
||||
)
|
||||
|
||||
// countingRunner is a scheduler runner that records how many invocations overlap,
|
||||
// so a test can prove the batch still goes through the scheduler's parallel gate.
|
||||
// countingRunner 是一个调度器 runner,记录有多少次调用互相重叠,使测试能证明该批次
|
||||
// 仍走调度器的并行闸门。
|
||||
type countingRunner struct {
|
||||
delay time.Duration
|
||||
result *loop.Result
|
||||
@@ -64,16 +64,15 @@ func (r *countingRunner) peak() int {
|
||||
return r.maxActive
|
||||
}
|
||||
|
||||
// spawnToolFor builds a dispatch tool over a scheduler with the given options and
|
||||
// foreground window.
|
||||
// spawnToolFor 在带给定选项与前台窗口的调度器上构建派发工具。
|
||||
func spawnToolFor(t *testing.T, opts Options, wait time.Duration) (*Scheduler, *SpawnTool) {
|
||||
t.Helper()
|
||||
s := newScheduler(t, opts)
|
||||
return s, NewSpawnTool(s, WithSpawnWait(wait))
|
||||
}
|
||||
|
||||
// decodeSpawnResult re-reads the tool result through JSON, so a test asserts the
|
||||
// shape the model actually receives rather than the in-memory struct.
|
||||
// decodeSpawnResult 经 JSON 重新读取工具结果,使测试断言的是模型实际收到的形状,而不是
|
||||
// 内存里的结构体。
|
||||
func decodeSpawnResult(t *testing.T, raw any) SpawnResult {
|
||||
t.Helper()
|
||||
b, err := json.Marshal(raw)
|
||||
@@ -87,7 +86,7 @@ func decodeSpawnResult(t *testing.T, raw any) SpawnResult {
|
||||
return out
|
||||
}
|
||||
|
||||
// statusOf returns the status the scheduler reports for id, or "" when unknown.
|
||||
// statusOf 返回调度器为 id 报告的状态;未知时返回 ""。
|
||||
func statusOf(s *Scheduler, id string) Status {
|
||||
for _, a := range s.Agents() {
|
||||
if a.ID == id {
|
||||
@@ -159,8 +158,7 @@ func TestSpawnToolParallelBatchHonorsParallelLimit(t *testing.T) {
|
||||
t.Fatalf("agent %s status = %q, want done", a.ID, a.Status)
|
||||
}
|
||||
}
|
||||
// The batch went through the scheduler's semaphore: with MaxParallel=1 the
|
||||
// three sub-agents can never run at the same time.
|
||||
// 该批次确实走过了调度器的信号量:MaxParallel=1 时三个子代理绝不可能同时运行。
|
||||
if peak := r.peak(); peak != 1 {
|
||||
t.Fatalf("max concurrent runs = %d, want 1 (the parallel limit)", peak)
|
||||
}
|
||||
@@ -247,7 +245,7 @@ func TestSpawnToolMovesSlowBatchToBackground(t *testing.T) {
|
||||
func TestSpawnToolKeepsPerAgentTimeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := newScheduler(t, Options{MaxParallel: 1, PerAgentTimeout: 40 * time.Millisecond})
|
||||
s.runner = &mockRunner{gate: make(chan struct{})} // never closed: block until the timeout
|
||||
s.runner = &mockRunner{gate: make(chan struct{})} // 永不关闭:阻塞到超时
|
||||
sp := NewSpawnTool(s, WithSpawnWait(2*time.Second))
|
||||
|
||||
raw, err := sp.Execute(context.Background(), map[string]any{"goal": "hang"})
|
||||
@@ -337,9 +335,8 @@ func TestSpawnToolWithoutScheduler(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestSpawnToolThroughDispatcher drives the tool through the real dispatcher so the
|
||||
// advertised JSON Schema, the argument validation and the registry's reachability
|
||||
// markers are all exercised — not just Execute.
|
||||
// TestSpawnToolThroughDispatcher 让该工具走真实的 dispatcher,使对外广告的 JSON
|
||||
// Schema、参数校验与注册表的可达性标记都被演练到 —— 而不只是 Execute。
|
||||
func TestSpawnToolThroughDispatcher(t *testing.T) {
|
||||
t.Parallel()
|
||||
s, sp := spawnToolFor(t, Options{MaxParallel: 2}, time.Second)
|
||||
@@ -374,8 +371,8 @@ func TestSpawnToolThroughDispatcher(t *testing.T) {
|
||||
t.Fatalf("result = %+v, want one settled agent", got)
|
||||
}
|
||||
|
||||
// Registered with the default (both false) markers: owner-only, so a group or
|
||||
// stranger session can neither see nor invoke it (design/11 §3).
|
||||
// 以默认标记(两个都 false)注册:仅主人可用,因此群聊或陌生人会话既看不到也
|
||||
// 调不动它(design/11 §3)。
|
||||
if !restrict.SetContext(reg, restrict.ActorOwner).Allow(SpawnToolName) {
|
||||
t.Fatal("owner was denied the spawn tool")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user