docs(comments): 注释中文化 · internal/runtime/orchestration(29 文件,纯替换)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

- 只翻注释/文档字符串:剥离注释后代码行逐字节不变(机械校验只剩允许的行尾注释形态)
- 裁决编号与 design 节号(02.4.3 / 11.4.2 / design/05 §9 等)逐字保留
- 复核:go build 绿;orchestration 及其子包(audit/comm)测试绿;gofmt 干净
This commit is contained in:
AskaEth committed 2026-10-04 13:30:04 +08:00
1 parent fe90f64a56
commit eb1828ee7a
29 files changed
+751 -949

No files matched your search

@@ -17,10 +17,9 @@ import (
const waitTimeout = 3 * time.Second
// mockRunner is a configurable runner for scheduler tests. It counts concurrent
// invocations (for the parallel-limit test), captures the messages it receives
// (for the context-isolation test), and can block on a gate channel until closed
// or until ctx is done (to hold a sub-agent "running" for abort/timeout tests).
// mockRunner 是供调度器测试使用的可配置 runner。它统计并发调用数(供并行上限测试)、
// 捕获收到的消息(供上下文隔离测试),并可在 gate channel 上阻塞,直到它被关闭或 ctx
// 结束(供中止/超时测试把一个子代理维持在「运行中」)。
type mockRunner struct {
mu sync.Mutex
gate chan struct{}
@@ -85,8 +84,8 @@ func (m *mockRunner) captured(i int) []model.Message {
return m.calls[i]
}
// mockAdapter is a minimal model.Adapter so a real loop.Loop can be driven in
// tests without a provider. Chat returns a scripted final response.
// mockAdapter 是一个最小 model.Adapter,使真实 loop.Loop 无需供应商即可在测试中驱动。
// Chat 返回一个脚本化的最终响应。
type mockAdapter struct {
name string
resp model.Response
@@ -108,9 +107,8 @@ func (m *mockAdapter) ChatStream(context.Context, model.Request, func(model.Stre
return m.resp, m.err
}
// newScheduler builds a Scheduler over a fresh in-process bus, wiring the default
// comm probe. The bus is closed on test cleanup. Callers set sched.runner after
// the call, or pass Options.Loop to drive a real loop.
// newScheduler 在一个全新的进程内总线上构建 Scheduler,并接上默认 comm 探针。总线在
// 测试清理时关闭。调用方在调用之后再设置 sched.runner,或传 Options.Loop 驱动真实循环。
func newScheduler(t *testing.T, opts Options) *Scheduler {
t.Helper()
b := bus.New()
@@ -141,8 +139,7 @@ func countStatus(subs []*SubAgent, st Status) int {
return n
}
// collectEventNames reads events from ch until a terminal event or the deadline
// elapses, returning the event names in order.
// collectEventNames 从 ch 读取事件,直到出现终结态事件或期限到期,按顺序返回事件名。
func collectEventNames(t *testing.T, ch <-chan comm.Event, d time.Duration) []string {
t.Helper()
var names []string
@@ -180,7 +177,7 @@ func TestSpawnStatusFlow(t *testing.T) {
t.Fatal("sub-agent has no isolated working memory")
}
// pending -> running -> done.
// pending -> running -> done。
waitFor(t, func() bool { return sub.Status() == StatusRunning }, waitTimeout)
close(m.gate)
waitFor(t, func() bool { return sub.Status() == StatusDone }, waitTimeout)
@@ -227,8 +224,7 @@ func TestParallelLimit(t *testing.T) {
subs = append(subs, sub)
}
// Wait until the two parallel slots are occupied, then confirm never more
// than MaxParallel run concurrently.
// 等到两个并行槽位都被占用,再确认并发运行数从未超过 MaxParallel。
waitFor(t, func() bool { return countStatus(subs, StatusRunning) == 2 }, waitTimeout)
if got := m.maxActiveCount(); got != 2 {
t.Fatalf("max concurrent runs = %d, want 2 while gated", got)
@@ -255,7 +251,7 @@ func TestParallelLimit(t *testing.T) {
func TestPerAgentTimeout(t *testing.T) {
t.Parallel()
s := newScheduler(t, Options{MaxParallel: 1, PerAgentTimeout: 50 * time.Millisecond})
m := &mockRunner{gate: make(chan struct{})} // never closed: block until timeout
m := &mockRunner{gate: make(chan struct{})} // 永不关闭:阻塞到超时
s.runner = m
sub, err := s.Spawn(context.Background(), AgentSpec{Goal: "slow"})
@@ -289,7 +285,7 @@ func TestAbort(t *testing.T) {
}
waitFor(t, func() bool { return sub.Status() == StatusAborted }, waitTimeout)
// Aborting an unknown id reports ErrAgentNotFound.
// 中止一个未知 id 报告 ErrAgentNotFound。
if err := s.Abort(context.Background(), "ghost"); !errors.Is(err, ErrAgentNotFound) {
t.Fatalf("Abort(ghost) err = %v, want ErrAgentNotFound", err)
}