docs(runtime): internal/runtime/loop 44 个文件注释改中文(逐行 1:1,代码零字节改动)

主人 2026-10-03 拍板「注释一律中文」;本模块按长期分批协议(一个模块一次派工)执行。
注释行数 1329 → 1329 逐行 1:1(含中文 33 → 1304);行尾注释 5 条一并译。
校验:机械校验(非注释改动行)= 空;独立 Go AST 程序(剥注释复渲)证明 44/44 文件代码全等;
全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
gofmt:capacity_loop_test.go / flow.go 改动前即未格式化,按铁律保留原样未动。
This commit is contained in:
AskaEth committed 2026-10-03 22:28:21 +08:00
1 parent 355f81d04a
commit 91e8d7a029
44 files changed
+1315 -1315

No files matched your search

+28 -28
View File
@@ -10,10 +10,10 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/persist"
)
// fakeCheckpointStore is a seam for asserting the resume path without a real
// database. It records every LoadLatest call and returns a scripted checkpoint or
// error, so a test can prove the loop asks the store for the session's checkpoint
// and resumes (or stays fresh) based on what comes back.
// fakeCheckpointStore 是在没有真实数据库的情况下断言恢复路径的
// 接缝。它记录每次 LoadLatest 调用并返回脚本化的 checkpoint 或
// 错误,使测试能证明循环向 store 索要该会话的 checkpoint,
// 并据此恢复(或保持全新)。
type fakeCheckpointStore struct {
latest *persist.Checkpoint
latestErr error
@@ -27,12 +27,12 @@ func (f *fakeCheckpointStore) LoadLatest(_ context.Context, agentID string) (*pe
return f.latest, f.latestErr
}
// TestRun_ResumeFromCheckpoint_ContinuesNoRepeat simulates a long task that was
// interrupted mid-tool-loop: the loop left a tool_calls checkpoint at step 2 with
// the message window as it stood after folding two tool batches in, then the
// process died before step 3 could run. A fresh Run on the same sessionID must
// resume at step 3 — rebuilding the context from the checkpoint rather than
// restarting — and must not re-execute the already-completed steps.
// TestRun_ResumeFromCheckpoint_ContinuesNoRepeat 模拟一个在工具循环中途
// 被中断的长任务:循环在步 2 留下了 tool_calls checkpoint,其消息
// 窗口是并入两批工具结果后的样子,随后进程在步 3 能运行前
// 死亡。同一 sessionID 上全新的 Run 必须从步 3 恢复 ——
// 由该 checkpoint 重建上下文而非重启 ——
// 且不得重跑已完成的步骤。
func TestRun_ResumeFromCheckpoint_ContinuesNoRepeat(t *testing.T) {
t.Parallel()
ctx := context.Background()
@@ -47,8 +47,8 @@ func TestRun_ResumeFromCheckpoint_ContinuesNoRepeat(t *testing.T) {
model.TextMessage(model.RoleTool, "tool aa result: va"),
model.TextMessage(model.RoleTool, "tool bb result: vb"),
}
// Seed exactly what a crashed run leaves behind: a tool_calls checkpoint at
// step 2 with the window computed after step 2's tool batch.
// 精确播种崩溃的 run 留下的东西:步 2 的 tool_calls checkpoint,
// 其窗口在步 2 的工具批次之后算出。
l.saveCheckpoint(ctx, sess, 2, interrupted, agent.StopReasonToolCalls)
res, err := l.Run(ctx, sess, []model.Message{model.TextMessage(model.RoleUser, "do the task")})
@@ -56,11 +56,11 @@ func TestRun_ResumeFromCheckpoint_ContinuesNoRepeat(t *testing.T) {
t.Fatalf("Run: %v", err)
}
// Resume continues at step 3 (the interrupted step), not step 1.
// 恢复从步 3(被中断的那一步)继续,而不是步 1。
if res.Steps != 3 {
t.Fatalf("Steps = %d, want 3 (resumed at step 3)", res.Steps)
}
// No completed step's tool call is re-executed.
// 已完成步骤的工具调用不会重跑。
if res.ToolCallsExecuted != 0 {
t.Fatalf("ToolCallsExecuted = %d, want 0 (completed steps not re-run)", res.ToolCallsExecuted)
}
@@ -68,8 +68,8 @@ func TestRun_ResumeFromCheckpoint_ContinuesNoRepeat(t *testing.T) {
t.Fatalf("Text = %q, want final", res.Text)
}
// The resumed run makes exactly one model call (step 3), fed the restored
// window — not a restart with a fresh conversation.
// 恢复后的 run 恰好做一次模型调用(步 3),喂入恢复的
// 窗口 —— 而不是以全新对话重启。
if len(ad.reqs) != 1 {
t.Fatalf("resumed run made %d model calls, want 1", len(ad.reqs))
}
@@ -87,9 +87,9 @@ func TestRun_ResumeFromCheckpoint_ContinuesNoRepeat(t *testing.T) {
}
}
// TestRun_NewSession_NotResumed proves a different sessionID never resurrects an
// old checkpoint: the caller opens a brand-new session, LoadLatest misses, and the
// loop runs fresh from step 1 with the caller's own messages.
// TestRun_NewSession_NotResumed 证明不同的 sessionID 绝不复活
// 旧的 checkpoint:调用方打开全新会话,LoadLatest 未命中,
// 循环以自己的消息从步 1 全新运行。
func TestRun_NewSession_NotResumed(t *testing.T) {
t.Parallel()
ctx := context.Background()
@@ -103,7 +103,7 @@ func TestRun_NewSession_NotResumed(t *testing.T) {
cp := newTestCheckpointStore(t)
l := New(Options{Agent: a, Checkpoint: cp, MaxRounds: 8})
// sess-a holds an interrupted run's checkpoint.
// sess-a 持有一个被中断 run 的 checkpoint。
l.saveCheckpoint(ctx, "sess-a", 2, []model.Message{
model.TextMessage(model.RoleUser, "a task"),
model.TextMessage(model.RoleTool, "tool echo result: hi"),
@@ -119,8 +119,8 @@ func TestRun_NewSession_NotResumed(t *testing.T) {
if res.ToolCallsExecuted != 1 {
t.Fatalf("ToolCallsExecuted = %d, want 1", res.ToolCallsExecuted)
}
// The first model call must start from the caller's fresh message, never from
// sess-a's restored window.
// 第一次模型调用必须从调用方的新消息开始,绝不从
// sess-a 恢复的窗口开始。
first := ad.reqs[0].Messages
if len(first) != 2 {
t.Fatalf("fresh run first request messages = %d, want 2 (system + user)", len(first))
@@ -130,9 +130,9 @@ func TestRun_NewSession_NotResumed(t *testing.T) {
}
}
// TestRun_Resume_LoadLatestCalled asserts Run asks the store for the session's
// latest checkpoint and resumes from it (LoadLatest → tool_calls checkpoint →
// continue at the next step).
// TestRun_Resume_LoadLatestCalled 断言 Run 向 store 索要该会话
// 最新的 checkpoint 并据此恢复(LoadLatest → tool_calls checkpoint →
// 从下一步继续)。
func TestRun_Resume_LoadLatestCalled(t *testing.T) {
t.Parallel()
ctx := context.Background()
@@ -166,9 +166,9 @@ func TestRun_Resume_LoadLatestCalled(t *testing.T) {
}
}
// TestRun_Resume_NotFound_Fresh asserts LoadLatest is still called on the fresh
// path and that ErrNotFound yields a full restart from step 1 with the caller's
// messages (no checkpoint to resurrect).
// TestRun_Resume_NotFound_Fresh 断言全新路径上仍会调用 LoadLatest,
// 且 ErrNotFound 会以调用方的消息从步 1 完全重启
// (没有可复活的 checkpoint)。
func TestRun_Resume_NotFound_Fresh(t *testing.T) {
t.Parallel()
ctx := context.Background()