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

+25 -25
View File
@@ -10,19 +10,19 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
)
// The LLM extractor is the async-capable implementation behind design/03 §1: the
// loop type-asserts this capability to detach extraction to a background
// goroutine, so the contract is locked here rather than discovered at runtime.
// LLM extractor 是 design/03 §1 背后具备异步能力的实现:循环
// 对此能力做类型断言,把提取脱离到后台
// goroutine,因此该契约在此锁定,而不是在运行时才发现。
var (
_ memory.Extractor = (*memory.LLMExtractor)(nil)
_ asyncExtractor = (*memory.LLMExtractor)(nil)
_ memory.Extractor = (*memory.ManualExtractor)(nil)
)
// gatedExtractor is a memory.Extractor that also implements asyncExtractor. Its
// extraction blocks until release is closed (or ctx is canceled), so a test can
// prove the loop's turn finishes while extraction is still in flight, and that
// the extraction survives the caller's own cancellation.
// gatedExtractor 是一个同时实现 asyncExtractor 的 memory.Extractor。
// 它的提取会阻塞直到 release 被关闭(或 ctx 被取消),使测试能
// 证明循环的 turn 在提取仍在途时就结束,且
// 提取能在调用方自身的取消下存活。
type gatedExtractor struct {
release chan struct{}
started chan struct{}
@@ -68,10 +68,10 @@ func (g *gatedExtractor) ExtractAsync(ctx context.Context, conv []model.Message)
return out, nil
}
// TestExtractMemoryAsync_LLMExtractorThroughLoop wires the real LLM extractor
// (not a fake) into the loop: after the turn settles, the extractor's own model
// call runs in the background and its parsed items land in the store, so the
// production path (design/03 §1 LLM 异步自动提取) is exercised end to end.
// TestExtractMemoryAsync_LLMExtractorThroughLoop 把真实的 LLM extractor
// (非假实现)接入循环:turn 落定后,extractor 自身的模型
// 调用在后台运行,其解析出的条目落入 store,因此
// 生产路径(design/03 §1 LLM 异步自动提取)被端到端演练。
func TestExtractMemoryAsync_LLMExtractorThroughLoop(t *testing.T) {
t.Parallel()
store := newTestMemoryStore(t)
@@ -112,8 +112,8 @@ func TestExtractMemoryAsync_LLMExtractorThroughLoop(t *testing.T) {
}
}
// waitForMemoryCount polls the persona's stored memories until want is reached,
// failing the test when the extraction never lands.
// waitForMemoryCount 轮询该角色已存的记忆直到达到 want,
// 提取始终未落定时让测试失败。
func waitForMemoryCount(t *testing.T, store *memory.Store, personaID string, want int) {
t.Helper()
deadline := time.Now().Add(2 * time.Second)
@@ -132,10 +132,10 @@ func waitForMemoryCount(t *testing.T, store *memory.Store, personaID string, wan
}
}
// TestExtractMemoryAsync_DoesNotBlockTurn proves the turn returns while the LLM
// extraction is still running, and that the extraction completes (and persists)
// after the caller's context has already been canceled — the detached context
// keeps a request-scoped cancellation from aborting the background extraction.
// TestExtractMemoryAsync_DoesNotBlockTurn 证明 turn 在 LLM
// 提取仍在运行时返回,且提取在调用方的 context 已被取消之后
// 仍能完成(并持久化)—— 脱离的 context
// 使请求作用域的取消无法中止后台提取。
func TestExtractMemoryAsync_DoesNotBlockTurn(t *testing.T) {
t.Parallel()
store := newTestMemoryStore(t)
@@ -171,8 +171,8 @@ func TestExtractMemoryAsync_DoesNotBlockTurn(t *testing.T) {
t.Fatalf("store already holds %d items after Run, want 0 (extraction still in flight)", len(items))
}
// The turn is over, so its context is canceled; the background extraction
// must still finish and persist.
// 该 turn 已结束,因此其 context 被取消;后台提取
// 仍必须完成并持久化。
cancel()
select {
case <-ext.started:
@@ -183,9 +183,9 @@ func TestExtractMemoryAsync_DoesNotBlockTurn(t *testing.T) {
waitForMemoryCount(t, store, "persona-a", 1)
}
// TestExtractMemoryAsync_RestrictedEnvNeverDispatches proves the group-chat /
// stranger isolation still gates the async path: nothing is dispatched, so no
// owner-private memory can be written from a read-only conversation.
// TestExtractMemoryAsync_RestrictedEnvNeverDispatches 证明群聊 /
// 陌生人隔离对异步路径同样设门:什么也不派发,因此从只读
// 对话绝无法写入主人私有记忆。
func TestExtractMemoryAsync_RestrictedEnvNeverDispatches(t *testing.T) {
t.Parallel()
store := newTestMemoryStore(t)
@@ -207,9 +207,9 @@ func TestExtractMemoryAsync_RestrictedEnvNeverDispatches(t *testing.T) {
}
}
// TestExtractMemoryAsync_ManualExtractorStaysSync proves the deterministic path
// is unchanged: an extractor without the async capability is still run inline, so
// the explicit "记住 X" memory is stored by the time the call returns.
// TestExtractMemoryAsync_ManualExtractorStaysSync 证明确定性路径
// 未变:不具备异步能力的 extractor 仍就地运行,因此
// 显式的 "记住 X" 记忆在该调用返回时已存入。
func TestExtractMemoryAsync_ManualExtractorStaysSync(t *testing.T) {
t.Parallel()
store := newTestMemoryStore(t)