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

+15 -15
View File
@@ -11,9 +11,9 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
)
// buildTurns builds a multi-turn conversation: n user/assistant turns followed by
// a trailing tool result, each message padded to around pad chars so the token
// estimate can be pushed over a small budget.
// buildTurns 构建一段多轮对话:n 个 user/assistant 轮,后接
// 一个尾部工具结果,每条消息填充到约 pad 个字符,以便把 token
// 估算推过一个小预算。
func buildTurns(n, pad int, withTool bool) []model.Message {
msgs := make([]model.Message, 0, n*2+1)
for i := 0; i < n; i++ {
@@ -58,17 +58,17 @@ func TestCompact_OverBudget_PreservesTrailingToolResult(t *testing.T) {
if len(got) >= len(msgs) {
t.Fatalf("compaction should shrink the conversation: got %d, want < %d", len(got), len(msgs))
}
// A leading summary system message marks the compaction.
// 一条前导摘要系统消息标记该压缩。
if got[0].Role != model.RoleSystem || !strings.HasPrefix(messageText(got[0]), summaryMarker) {
t.Fatalf("first message is not a compaction summary: %+v", got[0])
}
// The trailing tool result survives at the very end, unmodified.
// 尾部工具结果原样存活在最后。
last := got[len(got)-1]
if last.Role != model.RoleTool || !strings.Contains(last.Content[0].Text, "tool-result") {
t.Fatalf("trailing tool result was not preserved: %+v", last)
}
// Whenever a summary is emitted, the first kept message is a whole-turn
// boundary (a user message), so compaction never splits a turn.
// 只要发出摘要,第一条保留的消息就是一个整 turn
// 边界(用户消息),因此压缩绝不切开一个 turn。
if got[1].Role != model.RoleUser {
t.Fatalf("first kept message role = %q, want a turn-start user message", got[1].Role)
}
@@ -76,9 +76,9 @@ func TestCompact_OverBudget_PreservesTrailingToolResult(t *testing.T) {
func TestCompact_NeverSplitsTurn_MidConversation(t *testing.T) {
t.Parallel()
// Two turns of very different sizes: the second turn is huge, the first is
// small. Compaction must keep the whole huge last turn and summarize the
// small earlier turn(s), not slice the last turn apart.
// 两个大小悬殊的 turn:第二个极大,第一个
// 很小。压缩必须保留整个巨大的最后一个 turn,并摘要
// 更早的小 turn,而不是把最后一个 turn 切开。
big := strings.Repeat("b", 5000)
msgs := []model.Message{
model.TextMessage(model.RoleUser, "question one"),
@@ -96,8 +96,8 @@ func TestCompact_NeverSplitsTurn_MidConversation(t *testing.T) {
if got[0].Role != model.RoleSystem {
t.Fatalf("expected a leading summary, got %+v", got[0])
}
// The kept region begins at the second user turn and its assistant reply are
// both intact.
// 保留区域从第二个用户 turn 开始,其 assistant 回复
// 都完整无损。
if got[1].Role != model.RoleUser || got[1].Content[0].Text != "question two" {
t.Fatalf("kept region should start a whole turn: %+v", got[1])
}
@@ -108,8 +108,8 @@ func TestCompact_NeverSplitsTurn_MidConversation(t *testing.T) {
func TestCompact_SummaryCap(t *testing.T) {
t.Parallel()
// A huge prefix so the naive summary would try to sample long text, but each
// sampled message is truncated; verify the capped length stays bounded.
// 一个巨大的前缀,使朴素摘要会试图抽样长文本,但每条
// 被抽样的消息都被截断;验证被限额后的长度保持有界。
msgs := buildTurns(8, 5000, false)
got, err := (defaultCompactor{}).Compact(context.Background(), msgs, 5000)
if err != nil {
@@ -131,7 +131,7 @@ func TestCompact_ExistingSummaryMerged(t *testing.T) {
if err != nil {
t.Fatalf("Compact: %v", err)
}
// Only one leading summary remains and it merges the prior summary.
// 只剩一条前导摘要,且它合并了此前的摘要。
if got[0].Role != model.RoleSystem {
t.Fatalf("expected a leading summary")
}