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

+13 -13
View File
@@ -9,9 +9,9 @@ import (
"time"
)
// TestStartLogin_ScanStatusTransition drives the QR bind flow via the out-of-band
// API: StartLogin mints the QR, the background poll walks wait→scaned→confirmed and
// stores the credentials, and LoginStatus surfaces confirmed.
// TestStartLogin_ScanStatusTransition 经带外 API 驱动二维码绑定流程:StartLogin
// 生成二维码,后台轮询走过 wait→scaned→confirmed 并保存凭据,LoginStatus 呈现
// confirmed。
func TestStartLogin_ScanStatusTransition(t *testing.T) {
t.Parallel()
rec := &reqRecorder{}
@@ -52,7 +52,7 @@ func TestStartLogin_ScanStatusTransition(t *testing.T) {
t.Fatal("StartLogin returned empty qrcode")
}
// Poll LoginStatus until the background flow confirms.
// 轮询 LoginStatus,直到后台流程确认。
deadline := time.Now().Add(3 * time.Second)
for time.Now().Before(deadline) {
status, _ := ad.LoginStatus(context.Background())
@@ -70,7 +70,7 @@ func TestStartLogin_ScanStatusTransition(t *testing.T) {
if got := ad.Config()["bot_id"]; got != "bot-x" {
t.Fatalf("bot_id = %v, want bot-x", got)
}
// Confirm the qrcode id is echoed in the status poll query and the auth header.
// 确认 qrcode id 在状态轮询的查询串与认证头中被回传。
for _, q := range rec.find(func(q recordedReq) bool { return q.path == "/ilink/bot/get_qrcode_status" }) {
if q.query != "qrcode=qr-1" {
t.Fatalf("status poll query = %q, want qrcode=qr-1", q.query)
@@ -79,8 +79,8 @@ func TestStartLogin_ScanStatusTransition(t *testing.T) {
t.Fatalf("status poll AuthorizationType = %q, want ilink_bot_token", q.authType)
}
}
// Confirm the QR mint follows the official protocol: POST, the iLink
// App identify headers, and a local_token_list body (empty on a fresh bind).
// 确认取码遵循官方协议:POST、iLink App 标识头,以及携带 local_token_list 的
// 请求体(全新绑定时为空)。
for _, q := range rec.find(func(q recordedReq) bool { return q.path == "/ilink/bot/get_bot_qrcode" }) {
if q.method != http.MethodPost {
t.Fatalf("get_bot_qrcode method = %q, want POST", q.method)
@@ -104,8 +104,8 @@ func TestStartLogin_ScanStatusTransition(t *testing.T) {
}
}
// TestStartLogin_Timeout verifies the bind aborts with ErrLoginTimeout when the QR
// is never confirmed, and Connect with an empty token does NOT block (ErrNeedsLogin).
// TestStartLogin_Timeout 验证二维码始终未确认时绑定以 ErrLoginTimeout 终止,且空 token
// 的 Connect **不**阻塞(ErrNeedsLogin)。
func TestStartLogin_Timeout(t *testing.T) {
t.Parallel()
srv := newJSONServer(t, nil, func(req recordedReq) handlerResult {
@@ -117,12 +117,12 @@ func TestStartLogin_Timeout(t *testing.T) {
cfg := Config{BaseURL: srv.URL, LoginInterval: time.Millisecond, LoginTimeout: 25 * time.Millisecond}
ad := newAdapter(t, cfg, srv)
// Connect with no token must NOT block on the QR — it surfaces ErrNeedsLogin so
// the caller routes the owner to the out-of-band 扫码登录 panel.
// 无 token 的 Connect 绝不能阻塞在二维码上——它上报 ErrNeedsLogin,让调用方把
// 主人引向带外的扫码登录面板。
if err := ad.Connect(context.Background()); !errors.Is(err, ErrNeedsLogin) {
t.Fatalf("Connect(empty token) = %v, want ErrNeedsLogin", err)
}
// The out-of-band bind still times out if never confirmed.
// 带外绑定若始终未确认,同样会超时。
if _, err := ad.StartLogin(context.Background()); err != nil {
t.Fatalf("StartLogin: %v", err)
}
@@ -143,4 +143,4 @@ func TestStartLogin_Timeout(t *testing.T) {
}
}
var _ = json.RawMessage{} // keep encoding/json imported for future cases
var _ = json.RawMessage{} // 保留 encoding/json 的导入,供后续用例使用