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

@@ -9,10 +9,10 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/channel/adapter"
)
// deadSessionAdapter mimics a channel whose session dies while the bridge is
// running — today the iLink session rejection (errcode=-14): Connect
// reports success, the read loop then returns on its own (nothing cancelled it)
// and IsConnected reports false from that point on.
// deadSessionAdapter 模拟桥接器运行期间会话死掉的渠道
// ——目前就是 iLink 会话被拒(errcode=-14):Connect
// 报告成功,随后读取循环自行返回(没有任何东西取消它),
// 从那一刻起 IsConnected 报告 false。
type deadSessionAdapter struct {
name string
mu sync.Mutex
@@ -40,7 +40,7 @@ func (a *deadSessionAdapter) IsConnected() bool {
}
func (a *deadSessionAdapter) HealthCheck(context.Context) error { return adapter.ErrNotConnected }
func (a *deadSessionAdapter) ReadMessages(context.Context, func(adapter.UnifiedMessage)) {
// The session died: the read loop ends by itself, no cancellation involved.
// 会话已死:读取循环自行结束,没有任何取消参与其中。
a.mu.Lock()
a.up = false
a.mu.Unlock()
@@ -59,8 +59,8 @@ func (a *deadSessionAdapter) ListChannels(context.Context) ([]adapter.ChannelInf
return nil, nil
}
// signaledAdapter is a fakeAdapter whose read loop reports when it has returned,
// so a test can wait for a replaced adapter's exit deterministically.
// signaledAdapter 是一个 fakeAdapter,其读取循环在返回时发出信号,
// 使测试能确定性地等待被替换适配器的退出。
type signaledAdapter struct {
*fakeAdapter
exited chan struct{}
@@ -71,10 +71,10 @@ func (a *signaledAdapter) ReadMessages(ctx context.Context, _ func(adapter.Unifi
close(a.exited)
}
// TestReadLoopExitClearsConnectedFlag is the regression for "the adapter goes mute
// while the bridge still claims it is connected": the read loop ends with the
// session down and nothing cancelled it, so IsConnected/ConnectedCount must stop
// reporting a live channel.
// TestReadLoopExitClearsConnectedFlag 是针对「适配器已哑掉、桥接器
// 却仍声称它已连接」的回归测试:读取循环在会话中断、
// 无人取消的情况下结束,因此 IsConnected/ConnectedCount 必须停止
// 报告该渠道存活。
func TestReadLoopExitClearsConnectedFlag(t *testing.T) {
t.Parallel()
b := newReloadBridge(t, nil)
@@ -95,10 +95,10 @@ func TestReadLoopExitClearsConnectedFlag(t *testing.T) {
t.Fatal("bridge still reports weixin-ilink as connected after its read loop ended")
}
// TestReplacedAdapterExitKeepsReplacementConnected guards the other direction: the
// read-loop exit accounting must not undo a replacement installed by a hot reload.
// The replaced adapter's loop is cancelled by Reload (a deliberate stop), so its
// exit says nothing about the adapter that now owns the name.
// TestReplacedAdapterExitKeepsReplacementConnected 守住另一方向:
// 读取循环退出统计绝不能撤销热重载装入的替换适配器。
// 被替换适配器的循环由 Reload 取消(刻意停止),因此它的
// 退出对如今占用该名称的适配器毫无说明力。
func TestReplacedAdapterExitKeepsReplacementConnected(t *testing.T) {
t.Parallel()
old := &signaledAdapter{
@@ -116,8 +116,8 @@ func TestReplacedAdapterExitKeepsReplacementConnected(t *testing.T) {
t.Fatalf("Reload: %v", err)
}
<-old.exited
// The exit accounting runs immediately after the read path returns; a short
// settle window catches it without relying on a specific interleaving.
// 退出统计在读取路径返回后立即运行;短促的
// 静置窗口即可捕获,无需依赖特定的交错时序。
settle := time.Now().Add(50 * time.Millisecond)
for time.Now().Before(settle) {
if !b.IsConnected("kook:conf0") {