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
@@ -12,9 +12,9 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/tool"
|
||||
)
|
||||
|
||||
// newPolicyDispatcher builds a fresh registry + dispatcher and registers one
|
||||
// mock tool per name, returning both so a test can set the group/stranger
|
||||
// markers on the registry before exercising the design/11 §3 security gate.
|
||||
// newPolicyDispatcher 构建全新的 registry + dispatcher,并为每个
|
||||
// 名字注册一个 mock 工具,两者都返回,使测试能在演练
|
||||
// design/11 §3 安全门之前在 registry 上设置群聊/陌生人标记。
|
||||
func newPolicyDispatcher(t *testing.T, names []string) (*registry.Registry, *tool.Dispatcher) {
|
||||
t.Helper()
|
||||
reg := registry.New()
|
||||
@@ -30,9 +30,9 @@ func newPolicyDispatcher(t *testing.T, names []string) (*registry.Registry, *too
|
||||
return reg, d
|
||||
}
|
||||
|
||||
// expectToolNames asserts got carries exactly the tool names in want, any order.
|
||||
// The registry List iterates a map, so registration order is not preserved;
|
||||
// a set comparison keeps these assertions order-independent.
|
||||
// expectToolNames 断言 got 恰好携带 want 中的工具名,顺序不限。
|
||||
// registry 的 List 遍历 map,因此注册顺序不保留;
|
||||
// 集合比较使这些断言与顺序无关。
|
||||
func expectToolNames(t *testing.T, got []model.ToolSpec, want ...string) {
|
||||
t.Helper()
|
||||
if len(got) != len(want) {
|
||||
@@ -49,16 +49,16 @@ func expectToolNames(t *testing.T, got []model.ToolSpec, want ...string) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestToolSchemas_RestrictedEnv_FiltersByMarkers proves a group/stranger session
|
||||
// is only shown the tools whose editable marker allows that environment, while
|
||||
// the owner session keeps the full set (design/11 §3).
|
||||
// TestToolSchemas_RestrictedEnv_FiltersByMarkers 证明群聊/陌生人会话
|
||||
// 只被展示其可编辑标记允许该环境的工具,而
|
||||
// owner 会话保留全集(design/11 §3)。
|
||||
func TestToolSchemas_RestrictedEnv_FiltersByMarkers(t *testing.T) {
|
||||
t.Parallel()
|
||||
reg, d := newPolicyDispatcher(t, []string{"groupOnly", "strangerOnly", "both", "ownerOnly"})
|
||||
mustSetPolicy(t, reg, "groupOnly", registry.ToolPolicy{AllowInGroup: true})
|
||||
mustSetPolicy(t, reg, "strangerOnly", registry.ToolPolicy{AllowInStranger: true})
|
||||
mustSetPolicy(t, reg, "both", registry.ToolPolicy{AllowInGroup: true, AllowInStranger: true})
|
||||
// ownerOnly stays default-closed (zero marker).
|
||||
// ownerOnly 保持默认关闭(零标记)。
|
||||
|
||||
l := New(Options{Tools: d})
|
||||
|
||||
@@ -74,13 +74,13 @@ func TestToolSchemas_RestrictedEnv_FiltersByMarkers(t *testing.T) {
|
||||
expectToolNames(t, owner, "groupOnly", "strangerOnly", "both", "ownerOnly")
|
||||
}
|
||||
|
||||
// TestToolSchemas_DefaultClosed_UnmarkedToolHidden proves the defaulted-closed
|
||||
// marker: an unmarked tool is not advertised to a group/stranger session, so a
|
||||
// session cannot even see (let alone call) an owner-only capability.
|
||||
// TestToolSchemas_DefaultClosed_UnmarkedToolHidden 证明默认关闭
|
||||
// 标记:未标记的工具不向群聊/陌生人会话广告,因此
|
||||
// 会话连看都看不到(更别说调用)主人专属能力。
|
||||
func TestToolSchemas_DefaultClosed_UnmarkedToolHidden(t *testing.T) {
|
||||
t.Parallel()
|
||||
reg, d := newPolicyDispatcher(t, []string{"secret", "shared"})
|
||||
// Only shared is opened to groups; secret is default-closed.
|
||||
// 只有 shared 对群聊开放;secret 默认关闭。
|
||||
mustSetPolicy(t, reg, "shared", registry.ToolPolicy{AllowInGroup: true})
|
||||
l := New(Options{Tools: d})
|
||||
|
||||
@@ -89,10 +89,10 @@ func TestToolSchemas_DefaultClosed_UnmarkedToolHidden(t *testing.T) {
|
||||
expectToolNames(t, l.toolSchemas(ctx, nil), "shared")
|
||||
}
|
||||
|
||||
// TestRun_Restricted_NotAllowed_BlockedAndAudited proves a group session calling
|
||||
// an owner-only tool never executes it: the call is fed back as a soft
|
||||
// not_allowed result (no panic/crash) and an AuditEvent is recorded for the
|
||||
// rejection.
|
||||
// TestRun_Restricted_NotAllowed_BlockedAndAudited 证明群聊会话调用
|
||||
// 主人专属工具绝不执行它:该调用作为软 not_allowed
|
||||
// 结果回灌(不 panic/崩溃),并为该拒绝记录一个
|
||||
// AuditEvent。
|
||||
func TestRun_Restricted_NotAllowed_BlockedAndAudited(t *testing.T) {
|
||||
t.Parallel()
|
||||
call := `{"tool_calls":[{"name":"ownerOnly","args":{}}]}`
|
||||
@@ -148,8 +148,8 @@ func TestRun_Restricted_NotAllowed_BlockedAndAudited(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestRun_Restricted_AllowedTool_Executes proves a group session may invoke a
|
||||
// tool whose AllowInGroup marker is set, and that it runs normally.
|
||||
// TestRun_Restricted_AllowedTool_Executes 证明群聊会话可以调用
|
||||
// 设置了 AllowInGroup 标记的工具,且它正常运行。
|
||||
func TestRun_Restricted_AllowedTool_Executes(t *testing.T) {
|
||||
t.Parallel()
|
||||
call := `{"tool_calls":[{"name":"shared","args":{"q":"hi"}}]}`
|
||||
@@ -177,8 +177,8 @@ func TestRun_Restricted_AllowedTool_Executes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestRun_Owner_AllToolsExecute proves the owner environment is unaffected by the
|
||||
// default-closed marker: the owner may invoke an owner-only (unmarked) tool.
|
||||
// TestRun_Owner_AllToolsExecute 证明 owner 环境不受
|
||||
// 默认关闭标记影响:主人可以调用主人专属(未标记)工具。
|
||||
func TestRun_Owner_AllToolsExecute(t *testing.T) {
|
||||
t.Parallel()
|
||||
call := `{"tool_calls":[{"name":"ownerOnly","args":{}}]}`
|
||||
@@ -187,7 +187,7 @@ func TestRun_Owner_AllToolsExecute(t *testing.T) {
|
||||
{resp: model.Response{Content: "done"}},
|
||||
}}
|
||||
_, d := newPolicyDispatcher(t, []string{"ownerOnly"})
|
||||
// Default-closed marker (never opened): owner must still be able to call it.
|
||||
// 默认关闭标记(从未开放):主人仍必须能调用它。
|
||||
a := newTestAgent(t, ad, d)
|
||||
l := New(Options{Agent: a, MaxRounds: 8})
|
||||
|
||||
@@ -204,8 +204,8 @@ func TestRun_Owner_AllToolsExecute(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestRun_Stranger_NotAllowed_Blocked proves the gate also applies to the
|
||||
// stranger private-chat environment, and that a group-only tool is denied there.
|
||||
// TestRun_Stranger_NotAllowed_Blocked 证明该门同样适用于
|
||||
// 陌生人私聊环境,且仅群聊的工具在那里被拒。
|
||||
func TestRun_Stranger_NotAllowed_Blocked(t *testing.T) {
|
||||
t.Parallel()
|
||||
call := `{"tool_calls":[{"name":"groupOnly","args":{}}]}`
|
||||
@@ -235,7 +235,7 @@ func TestRun_Stranger_NotAllowed_Blocked(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// mustSetPolicy applies a ToolPolicy to the named tool, failing the test on error.
|
||||
// mustSetPolicy 把 ToolPolicy 应用到具名工具,出错即让测试失败。
|
||||
func mustSetPolicy(t *testing.T, reg *registry.Registry, name string, pol registry.ToolPolicy) {
|
||||
t.Helper()
|
||||
if err := reg.SetPolicy(name, pol); err != nil {
|
||||
|
||||
Reference in new issue
Block a user