docs(comments): 注释中文化 · plugins/channels/weixin_ilink(20 文件,纯替换)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

- 只翻注释/文档字符串:剥掉行尾注释后,每条「-」都有逐字节相同的「+」对应行(8 组,代码零改动)
- 保留协议/线上标识符原文:errcode、bot_token、context_token、getupdates、binded_redirect、PKCS#7、ECB 等
- 术语对齐既有译法:owner→主人、peer→对端、long poll→长轮询、backoff→退避、sentinel error→哨兵错误
- 已知既有欠债(未顺手修):login_reuse_test.go 在 HEAD 上就未 gofmt 干净;login_test.go 的 TestStartLogin_ScanStatusTransition 91 行 >80(HEAD 同为 91 行)
This commit is contained in:
AskaEth committed 2026-10-04 12:29:05 +08:00
1 parent 09fba77f87
commit 95f97f5df3
20 files changed
+488 -590

No files matched your search

+21 -23
View File
@@ -14,21 +14,21 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/channel/adapter"
)
// handlerResult is the decision a test's fake handler returns for a request.
// handlerResult 是测试里的假处理器对一次请求给出的裁决。
type handlerResult struct {
status int
body []byte
ctype string
}
// reqRecorder captures the requests a fake server receives so tests can assert
// that the adapter sent the expected cursor, bearer token, payload, etc.
// reqRecorder 捕获假服务端收到的请求,使测试能断言适配器发送了预期的游标、
// bearer token、载荷等。
type reqRecorder struct {
mu sync.Mutex
reqs []recordedReq
}
// recordedReq is a normalized snapshot of an inbound HTTP request.
// recordedReq 是一条入站 HTTP 请求的归一化快照。
type recordedReq struct {
method string
path string
@@ -59,7 +59,7 @@ func (r *reqRecorder) reset() {
r.reqs = nil
}
// find returns requests matching pred.
// find 返回匹配 pred 的请求。
func (r *reqRecorder) find(pred func(recordedReq) bool) []recordedReq {
r.mu.Lock()
defer r.mu.Unlock()
@@ -72,7 +72,7 @@ func (r *reqRecorder) find(pred func(recordedReq) bool) []recordedReq {
return out
}
// bodyJSON decodes a request body into a plain map, returning nil on failure.
// bodyJSON 把请求体解码为普通 map,失败时返回 nil。
func (q recordedReq) bodyJSON() map[string]any {
var m map[string]any
if err := json.Unmarshal(q.body, &m); err != nil {
@@ -81,24 +81,24 @@ func (q recordedReq) bodyJSON() map[string]any {
return m
}
// jsonBody marshals v into a JSON byte slice.
// jsonBody 把 v 序列化成 JSON 字节切片。
func jsonBody(v any) []byte {
b, _ := json.Marshal(v)
return b
}
// inlineJSON builds a json.RawMessage that inlines when placed in an []any, so
// the fake server can embed pre-serialized message objects into a msgs array.
// inlineJSON 构造一个放进 []any 时会内联的 json.RawMessage,便于假服务端把预序列化
// 的消息对象嵌进 msgs 数组。
func inlineJSON(v any) json.RawMessage { return json.RawMessage(jsonBody(v)) }
// encodeToken builds a base64 bot_token whose trailing bytes are a known key, so
// deriveInboundKey yields a deterministic AES key (design/08 §3.3).
// encodeToken 构造一个 base64 bot_token,其末尾字节是已知密钥,使 deriveInboundKey
// 得到确定性的 AES 密钥(design/08 §3.3)。
func encodeToken(key []byte) string {
return base64.StdEncoding.EncodeToString(append([]byte("prefix!"), key...))
}
// newJSONServer starts an httptest server whose handler records each request
// and answers via fn. The server is closed on test cleanup.
// newJSONServer 启动一个 httptest 服务端,其处理器记录每个请求并通过 fn 作答。
// 测试清理时该服务端会被关闭。
func newJSONServer(t *testing.T, rec *reqRecorder, fn func(r recordedReq) handlerResult) *httptest.Server {
t.Helper()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -132,8 +132,8 @@ func newJSONServer(t *testing.T, rec *reqRecorder, fn func(r recordedReq) handle
return srv
}
// newAdapter builds an Adapter wired to a test server. The caller controls the
// Config (BaseURL overridden from the server when left blank).
// newAdapter 构造一个接到测试服务端的 Adapter。Config 由调用方掌控(BaseURL 留空时
// 用服务端地址覆盖)。
func newAdapter(t *testing.T, cfg Config, srv *httptest.Server) *Adapter {
t.Helper()
if srv != nil && cfg.BaseURL == "" {
@@ -150,7 +150,7 @@ func newAdapter(t *testing.T, cfg Config, srv *httptest.Server) *Adapter {
return ad
}
// newConnectedAdapter builds a connected Adapter carrying a bot token.
// newConnectedAdapter 构造一个带 bot token 的已连接 Adapter。
func newConnectedAdapter(t *testing.T, cfg Config, srv *httptest.Server) *Adapter {
t.Helper()
ad := newAdapter(t, cfg, srv)
@@ -160,12 +160,10 @@ func newConnectedAdapter(t *testing.T, cfg Config, srv *httptest.Server) *Adapte
return ad
}
// conformance guards that the production adapter satisfies the contract at
// compile time.
// conformance 在编译期守护生产适配器满足该契约。
var _ adapter.PlatformAdapter = (*Adapter)(nil)
// waitFor polls fn until it returns true or the timeout elapses, failing the
// test on timeout.
// waitFor 轮询 fn 直到它返回 true 或超时,超时则让测试失败。
func waitFor(t *testing.T, fn func() bool) {
t.Helper()
deadline := time.Now().Add(3 * time.Second)
@@ -178,13 +176,13 @@ func waitFor(t *testing.T, fn func() bool) {
t.Fatal("condition not met within timeout")
}
// getupdatesReqs returns the recorded getupdates requests.
// getupdatesReqs 返回已记录的 getupdates 请求。
func getupdatesReqs(rec *reqRecorder) []recordedReq {
return rec.find(func(q recordedReq) bool { return q.path == "/ilink/bot/getupdates" })
}
// onceUpdates serves first (a raw getupdates body) exactly once, then empty
// polls. Read-loop tests use it so a repeated message is not double-emitted.
// onceUpdates 恰好一次返回 first(一份原始 getupdates 响应体),之后返回空轮询。
// 读循环测试用它,避免重复的消息被重复投递。
func onceUpdates(t *testing.T, rec *reqRecorder, first []byte) *httptest.Server {
t.Helper()
calls := 0