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

@@ -10,10 +10,10 @@ import (
"time"
)
// scriptedTransport answers the weixin_ilink endpoints without network I/O. It
// records the host each get_qrcode_status poll hits so tests can assert the IDC
// redirect routing, and returns get_bot_qrcode with a fixed QR plus get_qrcode_status
// bodies from statusFn (n is the 1-based poll count).
// scriptedTransport 不做网络 I/O 即可应答 weixin_ilink 的各个端点。它记录每次
// get_qrcode_status 轮询命中的主机,便于测试断言 IDC 重定向路由;并用固定二维码
// 应答 get_bot_qrcode,用 statusFn 返回 get_qrcode_status 的响应体(n 是从 1 开始的
// 轮询次数)。
type scriptedTransport struct {
qr []byte
statusFn func(n int) []byte
@@ -54,8 +54,8 @@ func (t *scriptedTransport) hosts() []string {
return append([]string(nil), t.statusHosts...)
}
// newScriptedAdapter builds an Adapter wired to a scripted transport (no real
// network), with a base URL that does not resolve — the transport intercepts it.
// newScriptedAdapter 构造一个接到脚本化传输层的 Adapter(无真实网络),其基础 URL
// 无法解析——由该传输层拦截。
func newScriptedAdapter(cfg Config, tr http.RoundTripper) (*Adapter, error) {
return New(cfg, &http.Client{Transport: tr}, nil)
}
@@ -63,9 +63,9 @@ func newScriptedAdapter(cfg Config, tr http.RoundTripper) (*Adapter, error) {
const scriptedQR = `{"qrcode":"qr-r","qrcode_img_content":"https://img/r"}`
const scriptedBaseURL = "https://ilinkai.weixin.qq.com"
// TestStartLogin_ScanButRedirectRoutesPoll verifies that a scaned_but_redirect
// response with a redirect_host switches subsequent get_qrcode_status polls to
// the https://<redirect_host> IDC host.
// TestStartLogin_ScanButRedirectRoutesPoll 验证带 redirect_host 的
// scaned_but_redirect 响应会把后续 get_qrcode_status 轮询切到
// https://<redirect_host> 这个 IDC 主机。
func TestStartLogin_ScanButRedirectRoutesPoll(t *testing.T) {
t.Parallel()
tr := &scriptedTransport{
@@ -106,8 +106,7 @@ func TestStartLogin_ScanButRedirectRoutesPoll(t *testing.T) {
}
}
// TestStartLogin_VerifyCodeBlocked verifies verify_code_blocked transitions the
// login to failed.
// TestStartLogin_VerifyCodeBlocked 验证 verify_code_blocked 会把登录转为失败。
func TestStartLogin_VerifyCodeBlocked(t *testing.T) {
t.Parallel()
tr := &scriptedTransport{
@@ -132,8 +131,8 @@ func TestStartLogin_VerifyCodeBlocked(t *testing.T) {
}
}
// TestStartLogin_BindedRedirect verifies binded_redirect is treated as already
// bound (LoginStatus confirmed) rather than a failure.
// TestStartLogin_BindedRedirect 验证 binded_redirect 被当作已绑定(LoginStatus 为
// confirmed)而非失败。
func TestStartLogin_BindedRedirect(t *testing.T) {
t.Parallel()
tr := &scriptedTransport{
@@ -158,8 +157,8 @@ func TestStartLogin_BindedRedirect(t *testing.T) {
}
}
// TestStartLogin_NeedVerifyCode verifies need_verifycode surfaces a dedicated
// LoginStatus sub-state with a hint detail, then times out to failed.
// TestStartLogin_NeedVerifyCode 验证 need_verifycode 会暴露一个专属的 LoginStatus
// 子状态并附提示详情,随后超时转为失败。
func TestStartLogin_NeedVerifyCode(t *testing.T) {
t.Parallel()
tr := &scriptedTransport{
@@ -182,7 +181,7 @@ func TestStartLogin_NeedVerifyCode(t *testing.T) {
if _, detail := ad.LoginStatus(context.Background()); detail != loginNeedVerifyCodeHint {
t.Fatalf("need_verifycode detail = %q, want %q", detail, loginNeedVerifyCodeHint)
}
// Without a verify-code回传 path the flow eventually times out to failed.
// 在没有验证码回传路径的情况下,流程最终超时转为失败。
waitFor(t, func() bool {
s, _ := ad.LoginStatus(context.Background())
return s == LoginStatusFailed