docs(comments): 注释中文化 · internal/services/channelbridge(纯替换)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

- 只翻注释/文档字符串:剥掉注释后代码行逐字节不变(机械校验只剩允许的行尾注释形态)
- 术语对齐既有译法(owner→主人、persona→角色、engage→参与度判定、quiet hours→安静时段、backoff→退避)
- 复核:go build 绿 + channelbridge 包测试绿;gofmt 干净
This commit is contained in:
AskaEth committed 2026-10-04 13:33:06 +08:00
1 parent 61cf80d5ee
commit 093f38d986
28 files changed
+1089 -1089

No files matched your search

+22 -22
View File
@@ -14,7 +14,7 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/user"
)
// stubLightJudge is a configurable LightJudge recording how often it was consulted.
// stubLightJudge 是可配置的 LightJudge,记录自己被咨询了多少次。
type stubLightJudge struct {
resp LightDecision
err error
@@ -26,8 +26,8 @@ func (s *stubLightJudge) Judge(context.Context, LightInput) (LightDecision, erro
return s.resp, s.err
}
// nonOwnerGroupMsg returns a third-party group message from a member sender, with
// the given mentions. Content is left untouched so tests control the signal.
// nonOwnerGroupMsg 返回一条来自成员发送者的第三方群消息,带
// 指定的提及。内容不做加工,便于测试自行控制信号。
func nonOwnerGroupMsg(content string, mentions ...adapter.Mention) adapter.UnifiedMessage {
return adapter.UnifiedMessage{
Platform: "telegram", ChannelID: "-20", ChannelType: adapter.ChannelGroup,
@@ -37,8 +37,8 @@ func nonOwnerGroupMsg(content string, mentions ...adapter.Mention) adapter.Unifi
}
}
// nonOwnerSession is the restricted (group / stranger) session binding used by the
// non-owner tests: read-only memory, no owner.
// nonOwnerSession 是非主人测试所用的受限(群聊 / 陌生人)会话
// 绑定:记忆只读、无主人。
func nonOwnerSession() session.Session {
return session.Session{SessionID: "sess-g", IsGroup: true, Owner: false, MemWritable: false}
}
@@ -57,8 +57,8 @@ func TestNonOwnerSilencedRegisteredOnly(t *testing.T) {
t.Fatalf("New: %v", err)
}
// A non-owner message with no @/keyword/name signal is silenced (设计/12 §6 策略二):
// it is registered to the isolated session log but never drives the loop.
// 无 @/关键词/名字信号的非主人消息被静默(设计/12 §6 策略二):
// 它只登记到隔离会话日志,绝不驱动循环。
b.process(context.Background(), nonOwnerGroupMsg("hello all"))
if chat.sessionID != "" || len(chat.messages) != 0 {
@@ -87,15 +87,15 @@ func TestNonOwnerMentionResponds(t *testing.T) {
t.Fatalf("New: %v", err)
}
// An addressed (mentioned) non-owner message is worth a response (策略二), so it
// drives the full loop against the isolated group session.
// 被点名(提及)的非主人消息值得回复(策略二),因此它
// 针对隔离群会话驱动完整循环。
b.process(context.Background(), nonOwnerGroupMsg("hello", adapter.Mention{UserID: "bot"}))
if chat.sessionID != "sess-g" {
t.Fatalf("loop session = %q, want isolated sess-g", chat.sessionID)
}
// Restricted group context → the third-party boundary system message plus the
// user message (design/16 §4.6 §1), mirroring TestGroupMessageThirdPartySenderNameAndBoundary.
// 受限群上下文 → 第三方边界系统消息加上
// 用户消息(design/16 §4.6 §1),与 TestGroupMessageThirdPartySenderNameAndBoundary 一致。
if len(chat.messages) != 2 || chat.messages[1].Role != model.RoleUser {
t.Fatalf("loop messages = %+v, want boundary + user", chat.messages)
}
@@ -120,7 +120,7 @@ func TestNonOwnerHighValueKeywordResponds(t *testing.T) {
t.Fatalf("New: %v", err)
}
// A high-value keyword (求助) is worth a response even without an @ (策略二).
// 高价值关键词(求助)即使没有 @ 也值得回复(策略二)。
b.process(context.Background(), nonOwnerGroupMsg("有人在吗,紧急求助"))
if chat.sessionID != "sess-g" {
t.Fatalf("loop session = %q, want isolated sess-g for a high-value keyword", chat.sessionID)
@@ -142,8 +142,8 @@ func TestNonOwnerQuietHoursSilenced(t *testing.T) {
t.Fatalf("New: %v", err)
}
// 策略五: during quiet hours a no-signal non-owner message is silenced — it is
// registered but not answered.
// 策略五:安静时段内无信号的非主人消息被静默——
// 只登记、不回复。
b.process(context.Background(), nonOwnerGroupMsg("hello all"))
if chat.sessionID != "" || len(chat.messages) != 0 {
@@ -168,8 +168,8 @@ func TestNonOwnerQuietHoursMentionResponds(t *testing.T) {
t.Fatalf("New: %v", err)
}
// 策略五 is not a hard silence: a directly-addressed message during quiet hours
// still gets a response.
// 策略五不是硬性静默:被直接点名的消息在安静时段
// 仍会得到回复。
b.process(context.Background(), nonOwnerGroupMsg("在吗", adapter.Mention{UserID: "bot"}))
if chat.sessionID != "sess-g" {
t.Fatalf("loop session = %q, want sess-g (mention should break quiet-hours silence)", chat.sessionID)
@@ -192,9 +192,9 @@ func TestOwnerUnaffectedInQuietHours(t *testing.T) {
}
b.Add(ad)
// An owner message is never gated, even during quiet hours (策略五 only ever
// governs non-owner traffic): owner-private chat still routes to the main web
// session and replies.
// 主人消息绝不被拦,即使处于安静时段(策略五只管
// 非主人流量):主人私聊仍路由到 Web 主会话
// 并回复。
b.process(context.Background(), directMessage())
if chat.sessionID != history.MainSessionID {
@@ -208,8 +208,8 @@ func TestOwnerUnaffectedInQuietHours(t *testing.T) {
func TestLightJudgeConsultedWhenInconclusive(t *testing.T) {
t.Parallel()
// A no-signal daytime message is inconclusive to the rules, so the injected
// LightJudge gets a chance to decide (设计/12 §6 策略二: 规则不确定才轻 LLM).
// 白天无信号的消息对规则而言无结论,因此注入的
// LightJudge 获得一次判断机会(设计/12 §6 策略二:规则不确定才轻 LLM)。
judge := &stubLightJudge{resp: LightDecision{Respond: true, Reason: "值得回"}}
chat := &stubChatter{res: &loop.Result{Text: "嗯"}}
sess := &stubSessions{sess: nonOwnerSession()}
@@ -275,7 +275,7 @@ func TestLightJudgeErrorFailsClosedToSilence(t *testing.T) {
t.Fatalf("New: %v", err)
}
// A failing light judge is fail-closed toward silence (不打扰为第一原则).
// 轻量判定器出错时失败关闭为静默(不打扰为第一原则)。
b.process(context.Background(), nonOwnerGroupMsg("今天天气不错"))
if judge.calls != 1 {
t.Fatalf("light judge calls = %d, want 1", judge.calls)