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:
1 parent
355f81d04a
commit
91e8d7a029
44 files changed
+1315
-1315
No files matched your search
@@ -18,17 +18,17 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/pkg/plugins/sdk"
|
||||
)
|
||||
|
||||
// mgResp is one scripted adapter result: a response plus an optional error.
|
||||
// mgResp 是一条脚本化的适配器结果:一个响应加可选错误。
|
||||
type mgResp struct {
|
||||
resp model.Response
|
||||
err error
|
||||
}
|
||||
|
||||
// mockAdapter is a configurable model.Adapter for loop tests. It keeps two
|
||||
// separate scripts and call counters (one for Chat, one for ChatStream) so a
|
||||
// single instance serves both the non-streaming and streaming paths. Every
|
||||
// request it is handed is recorded so tests can assert on the messages that were
|
||||
// fed to the model (e.g. the injected memory or a fed-back tool result).
|
||||
// mockAdapter 是供循环测试使用的可配置 model.Adapter。它维护两份
|
||||
// 独立的脚本与调用计数(一份给 Chat,一份给 ChatStream),使
|
||||
// 单个实例同时服务于非流式与流式路径。它收到的每个
|
||||
// 请求都被记录,使测试能断言喂给模型的
|
||||
// 消息(如注入的记忆或回灌的工具结果)。
|
||||
type mockAdapter struct {
|
||||
name string
|
||||
|
||||
@@ -76,7 +76,7 @@ func (m *mockAdapter) ChatStream(_ context.Context, req model.Request, on func(m
|
||||
return m.stream[i].resp, m.stream[i].err
|
||||
}
|
||||
|
||||
// mockGuard is a configurable guardrail.Guardrail for loop tests.
|
||||
// mockGuard 是供循环测试使用的可配置 guardrail.Guardrail。
|
||||
type mockGuard struct {
|
||||
inputVerdict *guardrail.Verdict
|
||||
outputVerdict *guardrail.Verdict
|
||||
@@ -92,9 +92,9 @@ func (m *mockGuard) CheckOutput(_ context.Context, _ *model.Response) (*guardrai
|
||||
return m.outputVerdict, m.outputErr
|
||||
}
|
||||
|
||||
// mockTool is a minimal sdk.Tool for loop tests. It supports a delay so a test
|
||||
// can exercise the per-invoke timeout, and an error so a test can verify that a
|
||||
// failed call is fed back to the model.
|
||||
// mockTool 是供循环测试使用的最小 sdk.Tool。它支持延迟,使测试
|
||||
// 能演练每次调用的超时;也支持错误,使测试能验证
|
||||
// 失败的调用被回灌给模型。
|
||||
type mockTool struct {
|
||||
name string
|
||||
desc string
|
||||
@@ -126,12 +126,12 @@ func (m *mockTool) Execute(ctx context.Context, _ any) (any, error) {
|
||||
return m.result, m.err
|
||||
}
|
||||
|
||||
// testLogger returns a logger that writes nowhere, keeping test output clean.
|
||||
// testLogger 返回一个不写任何地方的 logger,保持测试输出干净。
|
||||
func testLogger() *slog.Logger {
|
||||
return slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
}
|
||||
|
||||
// newTestAgent builds an Agent over ad with the given tools and no guardrails.
|
||||
// newTestAgent 用给定工具、无护栏地在 ad 之上构建一个 Agent。
|
||||
func newTestAgent(t *testing.T, ad model.Adapter, tools *tool.Dispatcher) *agent.Agent {
|
||||
t.Helper()
|
||||
a, err := agent.New("You are a helpful assistant.", tools, nil, agent.WithModel(ad, nil))
|
||||
@@ -141,14 +141,14 @@ func newTestAgent(t *testing.T, ad model.Adapter, tools *tool.Dispatcher) *agent
|
||||
return a
|
||||
}
|
||||
|
||||
// dispatcherWith builds a Dispatcher with the default tool timeout.
|
||||
// dispatcherWith 用默认工具超时构建一个 Dispatcher。
|
||||
func dispatcherWith(t *testing.T, tools ...sdk.Tool) *tool.Dispatcher {
|
||||
t.Helper()
|
||||
return dispatcherWithTimeout(t, 0, tools...)
|
||||
}
|
||||
|
||||
// dispatcherWithTimeout builds a Dispatcher applying a custom default timeout
|
||||
// (a non-positive value selects the package default) and registering tools.
|
||||
// dispatcherWithTimeout 构建一个应用自定义默认超时的 Dispatcher
|
||||
// (非正值选用包默认值)并注册工具。
|
||||
func dispatcherWithTimeout(t *testing.T, timeout time.Duration, tools ...sdk.Tool) *tool.Dispatcher {
|
||||
t.Helper()
|
||||
reg := registry.New()
|
||||
@@ -168,9 +168,9 @@ func dispatcherWithTimeout(t *testing.T, timeout time.Duration, tools ...sdk.Too
|
||||
return d
|
||||
}
|
||||
|
||||
// newTestMemoryStore opens an isolated in-memory SQLite database and returns a
|
||||
// memory.Store over it. Each call owns a private DB, so parallel tests are
|
||||
// isolated by construction.
|
||||
// newTestMemoryStore 打开一个隔离的内存 SQLite 数据库并返回
|
||||
// 基于它的 memory.Store。每次调用拥有私有 DB,因此并行测试
|
||||
// 天然隔离。
|
||||
func newTestMemoryStore(t *testing.T) *memory.Store {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
@@ -186,8 +186,8 @@ func newTestMemoryStore(t *testing.T) *memory.Store {
|
||||
return s
|
||||
}
|
||||
|
||||
// newTestCheckpointStore opens an isolated in-memory SQLite database and returns
|
||||
// a persist.Store over it.
|
||||
// newTestCheckpointStore 打开一个隔离的内存 SQLite 数据库并返回
|
||||
// 基于它的 persist.Store。
|
||||
func newTestCheckpointStore(t *testing.T) *persist.Store {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
|
||||
Reference in new issue
Block a user