diff --git a/.commentlint/go-baseline.json b/.commentlint/go-baseline.json index 2738579..116e97c 100644 --- a/.commentlint/go-baseline.json +++ b/.commentlint/go-baseline.json @@ -14765,3570 +14765,6 @@ "kind": "local-variable", "name": "err" }, - { - "file": "internal/notify/http_client_test.go", - "line": 10, - "kind": "function", - "name": "init" - }, - { - "file": "internal/notify/notifier.go", - "line": 35, - "kind": "const", - "name": "EventAccountOffline" - }, - { - "file": "internal/notify/notifier.go", - "line": 36, - "kind": "const", - "name": "EventAccountRecovered" - }, - { - "file": "internal/notify/notifier.go", - "line": 37, - "kind": "const", - "name": "EventAccountDisabled" - }, - { - "file": "internal/notify/notifier.go", - "line": 38, - "kind": "const", - "name": "EventSecurityVerification" - }, - { - "file": "internal/notify/notifier.go", - "line": 39, - "kind": "const", - "name": "EventTokenRenewal" - }, - { - "file": "internal/notify/notifier.go", - "line": 40, - "kind": "const", - "name": "EventDeliveryResult" - }, - { - "file": "internal/notify/notifier.go", - "line": 41, - "kind": "const", - "name": "EventSystemError" - }, - { - "file": "internal/notify/notifier.go", - "line": 65, - "kind": "var", - "name": "newOutboundHTTPClient" - }, - { - "file": "internal/notify/notifier.go", - "line": 66, - "kind": "var", - "name": "dialPublicSMTP" - }, - { - "file": "internal/notify/notifier.go", - "line": 145, - "kind": "local-variable", - "name": "channels" - }, - { - "file": "internal/notify/notifier.go", - "line": 145, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 149, - "kind": "local-variable", - "name": "full" - }, - { - "file": "internal/notify/notifier.go", - "line": 150, - "kind": "local-variable", - "name": "eligible" - }, - { - "file": "internal/notify/notifier.go", - "line": 151, - "kind": "range-variable", - "name": "ch" - }, - { - "file": "internal/notify/notifier.go", - "line": 152, - "kind": "local-variable", - "name": "allowed" - }, - { - "file": "internal/notify/notifier.go", - "line": 152, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 163, - "kind": "local-variable", - "name": "messages" - }, - { - "file": "internal/notify/notifier.go", - "line": 164, - "kind": "range-variable", - "name": "ch" - }, - { - "file": "internal/notify/notifier.go", - "line": 167, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 174, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 180, - "kind": "function", - "name": "runOutbox" - }, - { - "file": "internal/notify/notifier.go", - "line": 182, - "kind": "local-variable", - "name": "ticker" - }, - { - "file": "internal/notify/notifier.go", - "line": 194, - "kind": "function", - "name": "drainOutbox" - }, - { - "file": "internal/notify/notifier.go", - "line": 195, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 195, - "kind": "local-variable", - "name": "workerToken" - }, - { - "file": "internal/notify/notifier.go", - "line": 200, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 200, - "kind": "local-variable", - "name": "messages" - }, - { - "file": "internal/notify/notifier.go", - "line": 207, - "kind": "range-variable", - "name": "message" - }, - { - "file": "internal/notify/notifier.go", - "line": 208, - "kind": "local-variable", - "name": "channel" - }, - { - "file": "internal/notify/notifier.go", - "line": 208, - "kind": "local-variable", - "name": "getErr" - }, - { - "file": "internal/notify/notifier.go", - "line": 217, - "kind": "local-variable", - "name": "sendErr" - }, - { - "file": "internal/notify/notifier.go", - "line": 222, - "kind": "local-variable", - "name": "completeErr" - }, - { - "file": "internal/notify/notifier.go", - "line": 222, - "kind": "local-variable", - "name": "completed" - }, - { - "file": "internal/notify/notifier.go", - "line": 230, - "kind": "function", - "name": "retryOutbox" - }, - { - "file": "internal/notify/notifier.go", - "line": 231, - "kind": "local-variable", - "name": "permanent" - }, - { - "file": "internal/notify/notifier.go", - "line": 232, - "kind": "local-variable", - "name": "shift" - }, - { - "file": "internal/notify/notifier.go", - "line": 233, - "kind": "local-variable", - "name": "delay" - }, - { - "file": "internal/notify/notifier.go", - "line": 234, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 234, - "kind": "local-variable", - "name": "updated" - }, - { - "file": "internal/notify/notifier.go", - "line": 242, - "kind": "function", - "name": "notificationWorkerToken" - }, - { - "file": "internal/notify/notifier.go", - "line": 243, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/notify/notifier.go", - "line": 244, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 255, - "kind": "local-variable", - "name": "ch" - }, - { - "file": "internal/notify/notifier.go", - "line": 255, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 265, - "kind": "function", - "name": "levelLabel" - }, - { - "file": "internal/notify/notifier.go", - "line": 278, - "kind": "function", - "name": "eventLabel" - }, - { - "file": "internal/notify/notifier.go", - "line": 302, - "kind": "function", - "name": "classifyAccountAlertEvent" - }, - { - "file": "internal/notify/notifier.go", - "line": 303, - "kind": "local-variable", - "name": "msg" - }, - { - "file": "internal/notify/notifier.go", - "line": 322, - "kind": "function", - "name": "formatEvent" - }, - { - "file": "internal/notify/notifier.go", - "line": 323, - "kind": "var", - "name": "b" - }, - { - "file": "internal/notify/notifier.go", - "line": 324, - "kind": "local-variable", - "name": "label" - }, - { - "file": "internal/notify/notifier.go", - "line": 325, - "kind": "local-variable", - "name": "level" - }, - { - "file": "internal/notify/notifier.go", - "line": 329, - "kind": "local-variable", - "name": "title" - }, - { - "file": "internal/notify/notifier.go", - "line": 346, - "kind": "local-variable", - "name": "keys" - }, - { - "file": "internal/notify/notifier.go", - "line": 347, - "kind": "range-variable", - "name": "k" - }, - { - "file": "internal/notify/notifier.go", - "line": 351, - "kind": "range-variable", - "name": "k" - }, - { - "file": "internal/notify/notifier.go", - "line": 352, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/notify/notifier.go", - "line": 362, - "kind": "local-variable", - "name": "body" - }, - { - "file": "internal/notify/notifier.go", - "line": 370, - "kind": "function", - "name": "eventAllowed" - }, - { - "file": "internal/notify/notifier.go", - "line": 375, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 375, - "kind": "local-variable", - "name": "events" - }, - { - "file": "internal/notify/notifier.go", - "line": 385, - "kind": "function", - "name": "parseEventTypes" - }, - { - "file": "internal/notify/notifier.go", - "line": 390, - "kind": "var", - "name": "arr" - }, - { - "file": "internal/notify/notifier.go", - "line": 392, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 403, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/notify/notifier.go", - "line": 404, - "kind": "range-variable", - "name": "v" - }, - { - "file": "internal/notify/notifier.go", - "line": 413, - "kind": "function", - "name": "sortStrings" - }, - { - "file": "internal/notify/notifier.go", - "line": 414, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/notify/notifier.go", - "line": 415, - "kind": "local-variable", - "name": "j" - }, - { - "file": "internal/notify/notifier.go", - "line": 421, - "kind": "function", - "name": "send" - }, - { - "file": "internal/notify/notifier.go", - "line": 422, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "internal/notify/notifier.go", - "line": 451, - "kind": "var", - "name": "m" - }, - { - "file": "internal/notify/notifier.go", - "line": 452, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 460, - "kind": "local-variable", - "name": "webhook" - }, - { - "file": "internal/notify/notifier.go", - "line": 461, - "kind": "local-variable", - "name": "secret" - }, - { - "file": "internal/notify/notifier.go", - "line": 466, - "kind": "local-variable", - "name": "ts" - }, - { - "file": "internal/notify/notifier.go", - "line": 467, - "kind": "local-variable", - "name": "stringToSign" - }, - { - "file": "internal/notify/notifier.go", - "line": 468, - "kind": "local-variable", - "name": "h" - }, - { - "file": "internal/notify/notifier.go", - "line": 470, - "kind": "local-variable", - "name": "sign" - }, - { - "file": "internal/notify/notifier.go", - "line": 471, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 471, - "kind": "local-variable", - "name": "parsed" - }, - { - "file": "internal/notify/notifier.go", - "line": 475, - "kind": "local-variable", - "name": "query" - }, - { - "file": "internal/notify/notifier.go", - "line": 481, - "kind": "local-variable", - "name": "payload" - }, - { - "file": "internal/notify/notifier.go", - "line": 493, - "kind": "local-variable", - "name": "webhook" - }, - { - "file": "internal/notify/notifier.go", - "line": 494, - "kind": "local-variable", - "name": "secret" - }, - { - "file": "internal/notify/notifier.go", - "line": 498, - "kind": "local-variable", - "name": "ts" - }, - { - "file": "internal/notify/notifier.go", - "line": 499, - "kind": "local-variable", - "name": "data" - }, - { - "file": "internal/notify/notifier.go", - "line": 505, - "kind": "local-variable", - "name": "stringToSign" - }, - { - "file": "internal/notify/notifier.go", - "line": 506, - "kind": "local-variable", - "name": "h" - }, - { - "file": "internal/notify/notifier.go", - "line": 514, - "kind": "function", - "name": "sendBark" - }, - { - "file": "internal/notify/notifier.go", - "line": 515, - "kind": "local-variable", - "name": "server" - }, - { - "file": "internal/notify/notifier.go", - "line": 516, - "kind": "local-variable", - "name": "deviceKey" - }, - { - "file": "internal/notify/notifier.go", - "line": 520, - "kind": "local-variable", - "name": "data" - }, - { - "file": "internal/notify/notifier.go", - "line": 527, - "kind": "local-variable", - "name": "icon" - }, - { - "file": "internal/notify/notifier.go", - "line": 530, - "kind": "local-variable", - "name": "u" - }, - { - "file": "internal/notify/notifier.go", - "line": 537, - "kind": "function", - "name": "sendWebhook" - }, - { - "file": "internal/notify/notifier.go", - "line": 538, - "kind": "local-variable", - "name": "webhook" - }, - { - "file": "internal/notify/notifier.go", - "line": 542, - "kind": "local-variable", - "name": "method" - }, - { - "file": "internal/notify/notifier.go", - "line": 543, - "kind": "local-variable", - "name": "headers" - }, - { - "file": "internal/notify/notifier.go", - "line": 544, - "kind": "local-variable", - "name": "h" - }, - { - "file": "internal/notify/notifier.go", - "line": 547, - "kind": "local-variable", - "name": "data" - }, - { - "file": "internal/notify/notifier.go", - "line": 552, - "kind": "local-variable", - "name": "body" - }, - { - "file": "internal/notify/notifier.go", - "line": 553, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 553, - "kind": "local-variable", - "name": "req" - }, - { - "file": "internal/notify/notifier.go", - "line": 558, - "kind": "range-variable", - "name": "k" - }, - { - "file": "internal/notify/notifier.go", - "line": 558, - "kind": "range-variable", - "name": "v" - }, - { - "file": "internal/notify/notifier.go", - "line": 561, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 561, - "kind": "local-variable", - "name": "resp" - }, - { - "file": "internal/notify/notifier.go", - "line": 566, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 577, - "kind": "local-variable", - "name": "webhook" - }, - { - "file": "internal/notify/notifier.go", - "line": 588, - "kind": "function", - "name": "sendTelegram" - }, - { - "file": "internal/notify/notifier.go", - "line": 589, - "kind": "local-variable", - "name": "botToken" - }, - { - "file": "internal/notify/notifier.go", - "line": 590, - "kind": "local-variable", - "name": "chatID" - }, - { - "file": "internal/notify/notifier.go", - "line": 594, - "kind": "local-variable", - "name": "endpoint" - }, - { - "file": "internal/notify/notifier.go", - "line": 603, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "internal/notify/notifier.go", - "line": 603, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/notify/notifier.go", - "line": 605, - "kind": "local-variable", - "name": "server" - }, - { - "file": "internal/notify/notifier.go", - "line": 606, - "kind": "local-variable", - "name": "port" - }, - { - "file": "internal/notify/notifier.go", - "line": 607, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/notify/notifier.go", - "line": 608, - "kind": "local-variable", - "name": "pass" - }, - { - "file": "internal/notify/notifier.go", - "line": 609, - "kind": "local-variable", - "name": "useTLS" - }, - { - "file": "internal/notify/notifier.go", - "line": 610, - "kind": "local-variable", - "name": "useSSL" - }, - { - "file": "internal/notify/notifier.go", - "line": 611, - "kind": "local-variable", - "name": "fromAddress" - }, - { - "file": "internal/notify/notifier.go", - "line": 612, - "kind": "local-variable", - "name": "fromName" - }, - { - "file": "internal/notify/notifier.go", - "line": 613, - "kind": "local-variable", - "name": "legacyFrom" - }, - { - "file": "internal/notify/notifier.go", - "line": 614, - "kind": "local-variable", - "name": "to" - }, - { - "file": "internal/notify/notifier.go", - "line": 619, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 619, - "kind": "local-variable", - "name": "parsed" - }, - { - "file": "internal/notify/notifier.go", - "line": 633, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 633, - "kind": "local-variable", - "name": "from" - }, - { - "file": "internal/notify/notifier.go", - "line": 637, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 637, - "kind": "local-variable", - "name": "recipient" - }, - { - "file": "internal/notify/notifier.go", - "line": 642, - "kind": "local-variable", - "name": "fromHeader" - }, - { - "file": "internal/notify/notifier.go", - "line": 646, - "kind": "local-variable", - "name": "toHeader" - }, - { - "file": "internal/notify/notifier.go", - "line": 650, - "kind": "local-variable", - "name": "addr" - }, - { - "file": "internal/notify/notifier.go", - "line": 651, - "kind": "local-variable", - "name": "auth" - }, - { - "file": "internal/notify/notifier.go", - "line": 652, - "kind": "local-variable", - "name": "msg" - }, - { - "file": "internal/notify/notifier.go", - "line": 667, - "kind": "type", - "name": "smtpTransportOptions" - }, - { - "file": "internal/notify/notifier.go", - "line": 672, - "kind": "function", - "name": "sendPublicSMTP" - }, - { - "file": "internal/notify/notifier.go", - "line": 673, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 673, - "kind": "local-variable", - "name": "rawPort" - }, - { - "file": "internal/notify/notifier.go", - "line": 677, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 677, - "kind": "local-variable", - "name": "port" - }, - { - "file": "internal/notify/notifier.go", - "line": 681, - "kind": "local-variable", - "name": "conn" - }, - { - "file": "internal/notify/notifier.go", - "line": 681, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 687, - "kind": "local-variable", - "name": "transport" - }, - { - "file": "internal/notify/notifier.go", - "line": 692, - "kind": "local-variable", - "name": "tlsConn" - }, - { - "file": "internal/notify/notifier.go", - "line": 693, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 698, - "kind": "local-variable", - "name": "client" - }, - { - "file": "internal/notify/notifier.go", - "line": 698, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 704, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/notify/notifier.go", - "line": 707, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 712, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 716, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 719, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 722, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 722, - "kind": "local-variable", - "name": "w" - }, - { - "file": "internal/notify/notifier.go", - "line": 726, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 730, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 736, - "kind": "function", - "name": "parseConfigBool" - }, - { - "file": "internal/notify/notifier.go", - "line": 747, - "kind": "function", - "name": "configOrSetting" - }, - { - "file": "internal/notify/notifier.go", - "line": 748, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/notify/notifier.go", - "line": 752, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 752, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/notify/notifier.go", - "line": 761, - "kind": "function", - "name": "smtpConfigValue" - }, - { - "file": "internal/notify/notifier.go", - "line": 762, - "kind": "local-variable", - "name": "hasExplicitMode" - }, - { - "file": "internal/notify/notifier.go", - "line": 762, - "kind": "local-variable", - "name": "modeValue" - }, - { - "file": "internal/notify/notifier.go", - "line": 767, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/notify/notifier.go", - "line": 773, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 773, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/notify/notifier.go", - "line": 782, - "kind": "local-variable", - "name": "body" - }, - { - "file": "internal/notify/notifier.go", - "line": 782, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 786, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 786, - "kind": "local-variable", - "name": "req" - }, - { - "file": "internal/notify/notifier.go", - "line": 791, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 791, - "kind": "local-variable", - "name": "resp" - }, - { - "file": "internal/notify/notifier.go", - "line": 796, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 796, - "kind": "local-variable", - "name": "responseBody" - }, - { - "file": "internal/notify/notifier.go", - "line": 803, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 809, - "kind": "function", - "name": "notificationBusinessError" - }, - { - "file": "internal/notify/notifier.go", - "line": 813, - "kind": "var", - "name": "payload" - }, - { - "file": "internal/notify/notifier.go", - "line": 817, - "kind": "local-variable", - "name": "message" - }, - { - "file": "internal/notify/notifier.go", - "line": 818, - "kind": "local-variable", - "name": "code" - }, - { - "file": "internal/notify/notifier.go", - "line": 818, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/notify/notifier.go", - "line": 821, - "kind": "local-variable", - "name": "code" - }, - { - "file": "internal/notify/notifier.go", - "line": 821, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/notify/notifier.go", - "line": 824, - "kind": "local-variable", - "name": "code" - }, - { - "file": "internal/notify/notifier.go", - "line": 824, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/notify/notifier.go", - "line": 827, - "kind": "local-variable", - "name": "exists" - }, - { - "file": "internal/notify/notifier.go", - "line": 827, - "kind": "local-variable", - "name": "okValue" - }, - { - "file": "internal/notify/notifier.go", - "line": 833, - "kind": "function", - "name": "mapNumber" - }, - { - "file": "internal/notify/notifier.go", - "line": 834, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/notify/notifier.go", - "line": 834, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/notify/notifier.go", - "line": 838, - "kind": "local-variable", - "name": "typed" - }, - { - "file": "internal/notify/notifier.go", - "line": 842, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier.go", - "line": 842, - "kind": "local-variable", - "name": "number" - }, - { - "file": "internal/notify/notifier.go", - "line": 849, - "kind": "function", - "name": "firstMapString" - }, - { - "file": "internal/notify/notifier.go", - "line": 850, - "kind": "range-variable", - "name": "key" - }, - { - "file": "internal/notify/notifier.go", - "line": 851, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/notify/notifier.go", - "line": 851, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/notify/notifier.go", - "line": 860, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/notify/notifier.go", - "line": 860, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/notify/notifier.go", - "line": 861, - "kind": "local-variable", - "name": "x" - }, - { - "file": "internal/notify/notifier.go", - "line": 871, - "kind": "function", - "name": "fallback" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 22, - "kind": "function", - "name": "RoundTrip" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 32, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 40, - "kind": "var", - "name": "m" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 41, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 52, - "kind": "var", - "name": "gotURL" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 53, - "kind": "var", - "name": "got" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 54, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 56, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 62, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 65, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 78, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 79, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 86, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 90, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 91, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 98, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 101, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 108, - "kind": "var", - "name": "got" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 109, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 110, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 115, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 120, - "kind": "local-variable", - "name": "md" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 130, - "kind": "var", - "name": "got" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 131, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 132, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 137, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 138, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 144, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 147, - "kind": "local-variable", - "name": "content" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 153, - "kind": "function", - "name": "TestSendFeishu_EmptyWebhook" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 154, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 155, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 160, - "kind": "function", - "name": "TestSendFeishu_HTTPError" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 161, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 165, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 166, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 175, - "kind": "var", - "name": "got" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 176, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 180, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 185, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 186, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 195, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 212, - "kind": "var", - "name": "hitPath" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 213, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 218, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 219, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 227, - "kind": "function", - "name": "TestSendBark_EmptyDeviceKey" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 228, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 229, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 234, - "kind": "function", - "name": "TestSendBark_HTTPError" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 235, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 239, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 240, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 247, - "kind": "function", - "name": "TestSendWeChat" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 248, - "kind": "var", - "name": "got" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 249, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 250, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 255, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 256, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 262, - "kind": "local-variable", - "name": "text" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 268, - "kind": "function", - "name": "TestSendWeChat_EmptyWebhook" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 269, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 270, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 275, - "kind": "function", - "name": "TestSendWeChat_HTTPError" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 276, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 280, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 281, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 290, - "kind": "var", - "name": "got" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 291, - "kind": "var", - "name": "gotPath" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 292, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 294, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 299, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 300, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 303, - "kind": "local-variable", - "name": "wantPath" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 310, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 315, - "kind": "function", - "name": "TestPostJSONRejectsBusinessErrors" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 316, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 321, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 322, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 327, - "kind": "function", - "name": "TestSendTelegram_MissingConfig" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 328, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 329, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 332, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 337, - "kind": "function", - "name": "TestSendTelegram_HTTPError" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 338, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 342, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 343, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 352, - "kind": "var", - "name": "gotMethod" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 353, - "kind": "var", - "name": "gotAuth" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 354, - "kind": "var", - "name": "gotBody" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 355, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 358, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 363, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 364, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 369, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 383, - "kind": "function", - "name": "TestSendWebhook_EmptyWebhook" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 384, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 385, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 390, - "kind": "function", - "name": "TestSendWebhook_HTTPError" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 391, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 395, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 396, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 403, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 407, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 408, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 409, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 420, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 420, - "kind": "local-variable", - "name": "ln" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 424, - "kind": "var", - "name": "received" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 427, - "kind": "local-variable", - "name": "conn" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 427, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 438, - "kind": "function", - "name": "handleSMTP" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 440, - "kind": "local-variable", - "name": "r" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 441, - "kind": "local-variable", - "name": "write" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 444, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 444, - "kind": "local-variable", - "name": "line" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 448, - "kind": "local-variable", - "name": "upper" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 461, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 461, - "kind": "local-variable", - "name": "l" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 484, - "kind": "local-variable", - "name": "addr" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 484, - "kind": "local-variable", - "name": "received" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 485, - "kind": "local-variable", - "name": "host" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 485, - "kind": "local-variable", - "name": "port" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 486, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 487, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 495, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 498, - "kind": "local-variable", - "name": "body" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 506, - "kind": "local-variable", - "name": "addr" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 506, - "kind": "local-variable", - "name": "received" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 507, - "kind": "local-variable", - "name": "host" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 507, - "kind": "local-variable", - "name": "port" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 508, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 509, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 517, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 525, - "kind": "function", - "name": "TestSendEmail_SeparatesDisplayNameAndEnvelopeAddress" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 526, - "kind": "local-variable", - "name": "addr" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 526, - "kind": "local-variable", - "name": "received" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 527, - "kind": "local-variable", - "name": "host" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 527, - "kind": "local-variable", - "name": "port" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 528, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 529, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 534, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 537, - "kind": "local-variable", - "name": "body" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 543, - "kind": "function", - "name": "TestSendEmail_UsesSystemSMTPFallback" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 544, - "kind": "local-variable", - "name": "addr" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 544, - "kind": "local-variable", - "name": "received" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 545, - "kind": "local-variable", - "name": "host" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 545, - "kind": "local-variable", - "name": "port" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 546, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 546, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 548, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 549, - "kind": "range-variable", - "name": "key" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 549, - "kind": "range-variable", - "name": "value" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 556, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 561, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 562, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 565, - "kind": "local-variable", - "name": "body" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 571, - "kind": "function", - "name": "TestSMTPConfigValueUsesExclusiveExplicitModes" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 572, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 572, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 574, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 575, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 578, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 580, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 586, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 591, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 600, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 601, - "kind": "local-variable", - "name": "cases" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 606, - "kind": "range-variable", - "name": "cfg" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 607, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 613, - "kind": "function", - "name": "TestParseSMTPTransportFlags" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 629, - "kind": "local-variable", - "name": "host" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 629, - "kind": "local-variable", - "name": "port" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 631, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 632, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 639, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 646, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 655, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 659, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 660, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 667, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 670, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 677, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 681, - "kind": "local-variable", - "name": "hj" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 681, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 682, - "kind": "local-variable", - "name": "conn" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 687, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 688, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 695, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 698, - "kind": "local-variable", - "name": "hj" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 698, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 699, - "kind": "local-variable", - "name": "conn" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 704, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 705, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 712, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 715, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 722, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 723, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 724, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 733, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 739, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 740, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 741, - "kind": "local-variable", - "name": "types" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 742, - "kind": "range-variable", - "name": "typ" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 743, - "kind": "local-variable", - "name": "ch" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 744, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 762, - "kind": "var", - "name": "got" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 763, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 764, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 769, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 770, - "kind": "local-variable", - "name": "ch" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 771, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_channels_test.go", - "line": 774, - "kind": "local-variable", - "name": "md" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 27, - "kind": "local-variable", - "name": "d" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 27, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 31, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 33, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 41, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 41, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 47, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 48, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 58, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 65, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 65, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 67, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 73, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 73, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 76, - "kind": "var", - "name": "gotBody" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 77, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 78, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 85, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 96, - "kind": "function", - "name": "TestNotifyEventUsesPersistentOutboxWhenStarted" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 97, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 97, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 99, - "kind": "var", - "name": "calls" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 100, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 106, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 110, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 113, - "kind": "var", - "name": "queued" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 114, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 118, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 121, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 128, - "kind": "local-variable", - "name": "cases" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 134, - "kind": "range-variable", - "name": "level" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 134, - "kind": "range-variable", - "name": "want" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 135, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 143, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 143, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 146, - "kind": "var", - "name": "gotBody" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 147, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 148, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 154, - "kind": "local-variable", - "name": "chID" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 155, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 156, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 168, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 172, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 172, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 174, - "kind": "local-variable", - "name": "n2" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 183, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 183, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 186, - "kind": "var", - "name": "okCount" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 204, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 206, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 213, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 213, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 216, - "kind": "var", - "name": "gotBody" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 217, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 218, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 225, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 228, - "kind": "range-variable", - "name": "want" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 237, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 237, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 240, - "kind": "var", - "name": "gotBody" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 241, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 242, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 249, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 258, - "kind": "local-variable", - "name": "m" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 266, - "kind": "local-variable", - "name": "m" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 271, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 274, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 277, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 280, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 287, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 290, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 297, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 297, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 298, - "kind": "local-variable", - "name": "d" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 301, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 308, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 308, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 316, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 316, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 319, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 326, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 326, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 329, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 335, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 342, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 342, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_dispatch_test.go", - "line": 344, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 15, - "kind": "function", - "name": "newNotifyStore" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 17, - "kind": "local-variable", - "name": "d" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 17, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 21, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 23, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 30, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 30, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 33, - "kind": "var", - "name": "got" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 34, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 35, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 41, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 42, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 43, - "kind": "local-variable", - "name": "ch" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 44, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 50, - "kind": "local-variable", - "name": "md" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 58, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 58, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 61, - "kind": "var", - "name": "got" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 62, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 63, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 69, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 85, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 85, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 87, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 102, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 102, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 104, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 111, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 111, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 113, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 114, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 117, - "kind": "var", - "name": "gotBody" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 118, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 119, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 129, - "kind": "local-variable", - "name": "chID" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 133, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 143, - "kind": "function", - "name": "TestNotifyEvent_FiltersByChannelEventTypes" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 144, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 144, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 146, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 148, - "kind": "local-variable", - "name": "hits" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 149, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 155, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 155, - "kind": "local-variable", - "name": "resOffline" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 161, - "kind": "local-variable", - "name": "offlineID" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 162, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 162, - "kind": "local-variable", - "name": "resDisabled" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 168, - "kind": "local-variable", - "name": "disabledID" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 169, - "kind": "range-variable", - "name": "id" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 170, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 176, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 186, - "kind": "function", - "name": "TestNotifyAccountAlertClassifiesLegacyAlerts" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 187, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 187, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 189, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 191, - "kind": "local-variable", - "name": "hits" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 192, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 198, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 198, - "kind": "local-variable", - "name": "resSecurity" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 204, - "kind": "local-variable", - "name": "securityID" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 205, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 205, - "kind": "local-variable", - "name": "resToken" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 211, - "kind": "local-variable", - "name": "tokenID" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 212, - "kind": "range-variable", - "name": "id" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 213, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 219, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 229, - "kind": "function", - "name": "TestNotifyEventRejectsMalformedEventTypes" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 230, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 230, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 232, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 234, - "kind": "local-variable", - "name": "hits" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 235, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 241, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 241, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 247, - "kind": "local-variable", - "name": "channelID" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 248, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 253, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 279, - "kind": "function", - "name": "contains" - }, - { - "file": "internal/notify/notifier_test.go", - "line": 280, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/notify/smtp_guard_test.go", - "line": 14, - "kind": "function", - "name": "TestSendPublicSMTPRejectsInvalidPortAndLoopback" - }, - { - "file": "internal/notify/smtp_guard_test.go", - "line": 15, - "kind": "local-variable", - "name": "testDialer" - }, - { - "file": "internal/notify/smtp_guard_test.go", - "line": 18, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/smtp_guard_test.go", - "line": 21, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/notify/smtp_guard_test.go", - "line": 26, - "kind": "function", - "name": "TestSendPublicSMTPRequiresAdvertisedSTARTTLS" - }, - { - "file": "internal/notify/smtp_guard_test.go", - "line": 27, - "kind": "local-variable", - "name": "original" - }, - { - "file": "internal/notify/smtp_guard_test.go", - "line": 29, - "kind": "local-variable", - "name": "client" - }, - { - "file": "internal/notify/smtp_guard_test.go", - "line": 29, - "kind": "local-variable", - "name": "server" - }, - { - "file": "internal/notify/smtp_guard_test.go", - "line": 32, - "kind": "local-variable", - "name": "reader" - }, - { - "file": "internal/notify/smtp_guard_test.go", - "line": 40, - "kind": "local-variable", - "name": "err" - }, { "file": "internal/version/version.go", "line": 7, diff --git a/docs/architecture/refactoring-master-plan.md b/docs/architecture/refactoring-master-plan.md index eafa402..3553efb 100644 --- a/docs/architecture/refactoring-master-plan.md +++ b/docs/architecture/refactoring-master-plan.md @@ -635,3 +635,4 @@ npm --prefix frontend run build | 2026-08-15 | 完成阶段 10 第九个 PR 切片“Go internal/account 注释基线按领域清零” | 为账号管理器、凭证作用域、运行时启动/停止和生命周期测试补齐函数、变量、字段及常量中文注释;`internal/account` 注释基线清零;Account 定向测试、`go test -race ./internal/account`、全量 Go/React 门禁通过,合并为一个可回滚提交 | 阶段 10:继续清理 Go internal/adapter、internal/renewal、internal/notify、internal/chat 等领域注释基线 | | 2026-08-15 | 完成阶段 10 第十个 PR 切片“Go internal/adapter 注释基线按领域清零” | 为 adapter 装配、平台运行视图、远端 Token CAPTCHA 流程及其测试补齐函数、变量、字段和常量中文注释;`internal/adapter` 注释基线清零;Adapter 定向测试和全量 Go/React 门禁通过,合并为一个可回滚提交 | 阶段 10:继续清理 Go internal/renewal、internal/notify、internal/chat 等领域注释基线 | | 2026-08-15 | 完成阶段 10 第十一个 PR 切片“Go internal/renewal 注释基线按领域清零” | 为续期冷却、调度器、平台运行凭证范围和相关测试补齐函数、变量、字段及常量中文注释;`internal/renewal` 注释基线清零;Renewal 定向测试、`go test -race ./internal/renewal`、全量 Go/React 门禁通过,合并为一个可回滚提交 | 阶段 10:继续清理 Go internal/notify、internal/chat 等领域注释基线 | +| 2026-08-15 | 完成阶段 10 第十二个 PR 切片“Go internal/notify 注释基线按领域清零” | 为通知器、渠道与账号绑定、通知 outbox、SMTP 守卫及其测试补齐函数、变量、字段和常量中文注释;`internal/notify` 注释基线清零;Notify 定向测试、`go test -race ./internal/notify`、全量 Go/React 门禁通过,合并为一个可回滚提交 | 阶段 10:继续清理 Go internal/chat 领域注释基线 | diff --git a/internal/notify/http_client_test.go b/internal/notify/http_client_test.go index 35e6f09..0c64448 100644 --- a/internal/notify/http_client_test.go +++ b/internal/notify/http_client_test.go @@ -7,6 +7,7 @@ import ( "time" ) +// init 负责init相关处理。 func init() { // 通知单测使用 httptest 的 loopback 服务;生产构造器仍使用 netguard。 newOutboundHTTPClient = func() *http.Client { return &http.Client{Timeout: 10 * time.Second} } diff --git a/internal/notify/notifier.go b/internal/notify/notifier.go index 4ebfcbc..48ab05e 100644 --- a/internal/notify/notifier.go +++ b/internal/notify/notifier.go @@ -31,6 +31,7 @@ import ( "xianyu-go/internal/netguard" ) +// EventAccountOffline 保存Event账号Offline,供当前处理流程使用 const ( EventAccountOffline = "account_offline" EventAccountRecovered = "account_recovered" @@ -62,7 +63,10 @@ type Notifier struct { workers sync.WaitGroup } +// newOutboundHTTPClient 保存newOutboundHTTPClient,供当前处理流程使用 var newOutboundHTTPClient = func() *http.Client { return netguard.PublicHTTPClient(10 * time.Second) } + +// dialPublicSMTP 保存dialPublicSMTP,供当前处理流程使用 var dialPublicSMTP = netguard.DialPublicContext // New 构造。 @@ -85,6 +89,7 @@ func NewWithRepository(cookieID string, repository Repository, logger *slog.Logg // Start 启动持久化 outbox worker。调用返回前会先标记为异步模式,之后的业务 // 通知只写数据库,不在订单/账号处理调用栈中等待外部网络。 +// Start 启动当前值。 func (n *Notifier) Start(ctx context.Context) { if n == nil || n.repository == nil || !n.started.CompareAndSwap(false, true) { return @@ -101,6 +106,7 @@ func (n *Notifier) Wait() { n.workers.Wait() } // NotifyDelivery 发送发货结果通知。 // accountID 为 cookie_id。向该账号所有已启用渠道发送发货通知。 +// NotifyDelivery 负责Notify发货相关处理。 func (n *Notifier) NotifyDelivery(accountID, buyerName, buyerID, itemID, message, chatID string) { n.NotifyEvent(context.Background(), NotificationEvent{ AccountID: accountID, @@ -119,6 +125,7 @@ func (n *Notifier) NotifyDelivery(accountID, buyerName, buyerID, itemID, message // NotifyAccountAlert 发送账号告警通知(token 失效/自动恢复失败/风控验证等)。 // level 取 AlertLevel* 常量。向该账号所有已启用渠道发送。 +// NotifyAccountAlert 负责Notify账号Alert相关处理。 func (n *Notifier) NotifyAccountAlert(accountID, level, title, body string) { n.NotifyAccountEvent(accountID, classifyAccountAlertEvent(title, body), level, title, body) } @@ -142,13 +149,18 @@ func (n *Notifier) NotifyEvent(ctx context.Context, ev NotificationEvent) { if ev.Time.IsZero() { ev.Time = time.Now() } + // channels、err 保存channels、err,供当前处理流程使用 channels, err := n.repository.AccountChannels(ctx, ev.AccountID) if err != nil || len(channels) == 0 { return } + // full 保存full,供当前处理流程使用 full := formatEvent(ev) + // eligible 保存eligible,供当前处理流程使用 eligible := make([]db.NotificationChannel, 0, len(channels)) + // ch 表示当前遍历过程中的ch for _, ch := range channels { + // allowed、err 保存allowed、err,供当前处理流程使用 allowed, err := eventAllowed(ch.EventTypes, ev.Type) if err != nil { n.logger.Warn("通知事件订阅配置无效,跳过渠道", "channel", ch.ID, "event_types", ch.EventTypes, "err", err) @@ -160,25 +172,31 @@ func (n *Notifier) NotifyEvent(ctx context.Context, ev NotificationEvent) { eligible = append(eligible, ch) } if n.started.Load() { + // messages 保存消息列表,供当前处理流程使用 messages := make([]db.NotificationOutboxInput, 0, len(eligible)) + // ch 表示当前遍历过程中的ch for _, ch := range eligible { messages = append(messages, db.NotificationOutboxInput{ChannelID: ch.ID, EventType: ev.Type, Body: full}) } - if err := n.repository.EnqueueOutbox(ctx, messages); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.repository.EnqueueOutbox(ctx, messages); err != nil { n.logger.Error("持久化通知失败", "event_type", ev.Type, "err", err) } return } // 未启动 worker 的独立使用场景保持同步行为,便于 CLI 和单元测试显式使用。 for _, ch := range eligible { - if err := n.send(ch, full); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.send(ch, full); err != nil { n.logger.Error("发送通知失败", "channel", ch.Type, "event_type", ev.Type, "err", err) } } } +// runOutbox 负责运行Outbox相关处理。 func (n *Notifier) runOutbox(ctx context.Context) { n.drainOutbox(ctx) + // ticker 保存ticker,供当前处理流程使用 ticker := time.NewTicker(2 * time.Second) defer ticker.Stop() for { @@ -191,12 +209,15 @@ func (n *Notifier) runOutbox(ctx context.Context) { } } +// drainOutbox 负责drainOutbox相关处理。 func (n *Notifier) drainOutbox(ctx context.Context) { + // workerToken、err 保存工作器Token、err,供当前处理流程使用 workerToken, err := notificationWorkerToken() if err != nil { n.logger.Error("生成通知 worker token 失败", "err", err) return } + // messages、err 保存messages、err,供当前处理流程使用 messages, err := n.repository.ClaimOutbox(ctx, workerToken, time.Now(), 20) if err != nil { if ctx.Err() == nil { @@ -204,7 +225,9 @@ func (n *Notifier) drainOutbox(ctx context.Context) { } return } + // message 表示当前遍历过程中的消息 for _, message := range messages { + // channel、getErr 保存channel、getErr,供当前处理流程使用 channel, getErr := n.repository.GetChannel(ctx, message.ChannelID) if getErr != nil { n.retryOutbox(ctx, message, workerToken, getErr) @@ -214,12 +237,14 @@ func (n *Notifier) drainOutbox(ctx context.Context) { _, _ = n.repository.CompleteOutbox(ctx, message.ID, workerToken) continue } - if sendErr := n.send(*channel, message.Body); sendErr != nil { + if // sendErr 保存sendErr,供当前处理流程使用 + sendErr := n.send(*channel, message.Body); sendErr != nil { n.logger.Error("发送通知失败", "channel", channel.Type, "event_type", message.EventType, "attempt", message.AttemptCount, "err", sendErr) n.retryOutbox(ctx, message, workerToken, sendErr) continue } - if completed, completeErr := n.repository.CompleteOutbox(ctx, message.ID, workerToken); completeErr != nil { + if // completed、completeErr 保存completed、completeErr,供当前处理流程使用 + completed, completeErr := n.repository.CompleteOutbox(ctx, message.ID, workerToken); completeErr != nil { n.logger.Warn("确认通知投递完成失败", "outbox_id", message.ID, "err", completeErr) } else if !completed { n.logger.Warn("通知 outbox 租约已转移", "outbox_id", message.ID) @@ -227,10 +252,15 @@ func (n *Notifier) drainOutbox(ctx context.Context) { } } +// retryOutbox 负责重试Outbox相关处理。 func (n *Notifier) retryOutbox(ctx context.Context, message db.NotificationOutboxMessage, workerToken string, cause error) { + // permanent 保存permanent,供当前处理流程使用 permanent := message.AttemptCount >= 10 + // shift 保存shift,供当前处理流程使用 shift := min(max(message.AttemptCount-1, 0), 7) + // delay 保存延迟,供当前处理流程使用 delay := 5 * time.Second * time.Duration(1< 0 { + // keys 保存keys,供当前处理流程使用 keys := make([]string, 0, len(ev.Fields)) + // k 表示当前遍历过程中的k for k := range ev.Fields { keys = append(keys, k) } sortStrings(keys) + // k 表示当前遍历过程中的k for _, k := range keys { + // v 保存v,供当前处理流程使用 v := strings.TrimSpace(ev.Fields[k]) if v == "" { continue @@ -359,6 +406,7 @@ func formatEvent(ev NotificationEvent) string { b.WriteString(v) } } + // body 保存请求体,供当前处理流程使用 body := strings.TrimSpace(ev.Body) if body != "" { b.WriteString("\n\n") @@ -367,11 +415,13 @@ func formatEvent(ev NotificationEvent) string { return b.String() } +// eventAllowed 负责eventAllowed相关处理。 func eventAllowed(raw, eventType string) (bool, error) { eventType = strings.TrimSpace(eventType) if eventType == "" { return true, nil } + // events、err 保存events、err,供当前处理流程使用 events, err := parseEventTypes(raw) if err != nil { return false, err @@ -382,14 +432,17 @@ func eventAllowed(raw, eventType string) (bool, error) { return events[eventType], nil } +// parseEventTypes 负责parseEventTypes相关处理。 func parseEventTypes(raw string) (map[string]bool, error) { raw = strings.TrimSpace(raw) if raw == "" { return nil, nil } + // arr 保存arr,供当前处理流程使用 var arr []string if strings.HasPrefix(raw, "[") { - if err := json.Unmarshal([]byte(raw), &arr); err != nil { + if // err 保存err,供当前处理流程使用 + err := json.Unmarshal([]byte(raw), &arr); err != nil { return nil, err } } else { @@ -400,7 +453,9 @@ func parseEventTypes(raw string) (map[string]bool, error) { if len(arr) == 0 { return nil, nil } + // out 保存out,供当前处理流程使用 out := make(map[string]bool, len(arr)) + // v 表示当前遍历过程中的v for _, v := range arr { v = strings.TrimSpace(v) if v != "" { @@ -410,15 +465,20 @@ func parseEventTypes(raw string) (map[string]bool, error) { return out, nil } +// sortStrings 负责sortStrings相关处理。 func sortStrings(values []string) { - for i := 1; i < len(values); i++ { - for j := i; j > 0 && values[j-1] > values[j]; j-- { + for // i 保存i,供当前处理流程使用 + i := 1; i < len(values); i++ { + for // j 保存j,供当前处理流程使用 + j := i; j > 0 && values[j-1] > values[j]; j-- { values[j-1], values[j] = values[j], values[j-1] } } } +// send 负责send相关处理。 func (n *Notifier) send(ch db.NotificationChannel, message string) error { + // cfg 保存cfg,供当前处理流程使用 cfg := parseConfig(ch.Config) switch ch.Type { case "ding_talk", "dingtalk": @@ -448,8 +508,10 @@ func parseConfig(config string) map[string]any { if config == "" { return map[string]any{} } + // m 保存m,供当前处理流程使用 var m map[string]any - if err := json.Unmarshal([]byte(config), &m); err != nil { + if // err 保存err,供当前处理流程使用 + err := json.Unmarshal([]byte(config), &m); err != nil { return map[string]any{"config": config} } return m @@ -457,27 +519,36 @@ func parseConfig(config string) map[string]any { // ---- 钉钉 ---- func (n *Notifier) sendDingTalk(cfg map[string]any, message string) error { + // webhook 保存webhook,供当前处理流程使用 webhook := strOr(cfg, "webhook_url", strOr(cfg, "config", "")) + // secret 保存secret,供当前处理流程使用 secret := strOr(cfg, "secret", "") if webhook == "" { return fmt.Errorf("钉钉 webhook_url 为空") } if secret != "" { + // ts 保存ts,供当前处理流程使用 ts := strconv.FormatInt(time.Now().UnixMilli(), 10) + // stringToSign 保存stringToSign,供当前处理流程使用 stringToSign := ts + "\n" + secret + // h 保存h,供当前处理流程使用 h := hmac.New(sha256.New, []byte(secret)) h.Write([]byte(stringToSign)) + // sign 保存sign,供当前处理流程使用 sign := base64.StdEncoding.EncodeToString(h.Sum(nil)) + // parsed、err 保存parsed、err,供当前处理流程使用 parsed, err := url.Parse(webhook) if err != nil { return fmt.Errorf("钉钉 webhook 地址无效: %w", err) } + // query 保存查询,供当前处理流程使用 query := parsed.Query() query.Set("timestamp", ts) query.Set("sign", sign) parsed.RawQuery = query.Encode() webhook = parsed.String() } + // payload 保存请求载荷,供当前处理流程使用 payload := map[string]any{ "msgtype": "markdown", "markdown": map[string]any{ @@ -490,19 +561,25 @@ func (n *Notifier) sendDingTalk(cfg map[string]any, message string) error { // ---- 飞书 ---- func (n *Notifier) sendFeishu(cfg map[string]any, message string) error { + // webhook 保存webhook,供当前处理流程使用 webhook := strOr(cfg, "webhook_url", "") + // secret 保存secret,供当前处理流程使用 secret := strOr(cfg, "secret", "") if webhook == "" { return fmt.Errorf("飞书 webhook_url 为空") } + // ts 保存ts,供当前处理流程使用 ts := strconv.FormatInt(time.Now().Unix(), 10) + // data 保存数据,供当前处理流程使用 data := map[string]any{ "msg_type": "text", "content": map[string]any{"text": message}, "timestamp": ts, } if secret != "" { + // stringToSign 保存stringToSign,供当前处理流程使用 stringToSign := ts + "\n" + secret + // h 保存h,供当前处理流程使用 h := hmac.New(sha256.New, []byte(stringToSign)) h.Write([]byte("")) data["sign"] = base64.StdEncoding.EncodeToString(h.Sum(nil)) @@ -511,12 +588,16 @@ func (n *Notifier) sendFeishu(cfg map[string]any, message string) error { } // ---- Bark ---- +// sendBark 负责sendBark相关处理。 func (n *Notifier) sendBark(cfg map[string]any, message string) error { + // server 保存server,供当前处理流程使用 server := strings.TrimRight(strOr(cfg, "server_url", "https://api.day.app"), "/") + // deviceKey 保存deviceKey,供当前处理流程使用 deviceKey := strOr(cfg, "device_key", "") if deviceKey == "" { return fmt.Errorf("bark device_key 为空") } + // data 保存数据,供当前处理流程使用 data := map[string]any{ "device_key": deviceKey, "title": strOr(cfg, "title", "闲鱼自动回复通知"), @@ -524,46 +605,59 @@ func (n *Notifier) sendBark(cfg map[string]any, message string) error { "sound": strOr(cfg, "sound", "default"), "group": strOr(cfg, "group", "xianyu"), } - if icon := strOr(cfg, "icon", ""); icon != "" { + if // icon 保存icon,供当前处理流程使用 + icon := strOr(cfg, "icon", ""); icon != "" { data["icon"] = icon } - if u := strOr(cfg, "url", ""); u != "" { + if // u 保存u,供当前处理流程使用 + u := strOr(cfg, "url", ""); u != "" { data["url"] = u } return n.postJSON(server+"/push", data) } // ---- Webhook ---- +// sendWebhook 负责sendWebhook相关处理。 func (n *Notifier) sendWebhook(cfg map[string]any, message string) error { + // webhook 保存webhook,供当前处理流程使用 webhook := strOr(cfg, "webhook_url", "") if webhook == "" { return fmt.Errorf("webhook_url 为空") } + // method 保存方法,供当前处理流程使用 method := strings.ToUpper(strOr(cfg, "http_method", "POST")) + // headers 保存headers,供当前处理流程使用 headers := map[string]any{} - if h := strOr(cfg, "headers", ""); h != "" { + if // h 保存h,供当前处理流程使用 + h := strOr(cfg, "headers", ""); h != "" { _ = json.Unmarshal([]byte(h), &headers) } + // data 保存数据,供当前处理流程使用 data := map[string]any{ "message": message, "timestamp": time.Now().Format("2006-01-02 15:04:05"), "source": "xianyu-auto-reply", } + // body 保存请求体,供当前处理流程使用 body, _ := json.Marshal(data) + // req、err 保存req、err,供当前处理流程使用 req, err := http.NewRequest(method, webhook, bytes.NewReader(body)) if err != nil { return err } req.Header.Set("Content-Type", "application/json") + // k、v 表示当前遍历过程中的k、v for k, v := range headers { req.Header.Set(k, fmt.Sprintf("%v", v)) } + // resp、err 保存resp、err,供当前处理流程使用 resp, err := n.httpc.Do(req) if err != nil { return err } defer resp.Body.Close() - if _, err := io.Copy(io.Discard, resp.Body); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := io.Copy(io.Discard, resp.Body); err != nil { return err } if resp.StatusCode >= 300 { @@ -574,6 +668,7 @@ func (n *Notifier) sendWebhook(cfg map[string]any, message string) error { // ---- 企业微信 ---- func (n *Notifier) sendWeChat(cfg map[string]any, message string) error { + // webhook 保存webhook,供当前处理流程使用 webhook := strOr(cfg, "webhook_url", "") if webhook == "" { return fmt.Errorf("微信 webhook_url 为空") @@ -585,12 +680,16 @@ func (n *Notifier) sendWeChat(cfg map[string]any, message string) error { } // ---- Telegram ---- +// sendTelegram 负责sendTelegram相关处理。 func (n *Notifier) sendTelegram(cfg map[string]any, message string) error { + // botToken 保存bot令牌,供当前处理流程使用 botToken := strOr(cfg, "bot_token", "") + // chatID 保存聊天ID,供当前处理流程使用 chatID := strOr(cfg, "chat_id", "") if botToken == "" || chatID == "" { return fmt.Errorf("telegram bot_token/chat_id 不完整") } + // endpoint 保存endpoint,供当前处理流程使用 endpoint := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", botToken) return n.postJSON(endpoint, map[string]any{ "chat_id": chatID, @@ -600,23 +699,35 @@ func (n *Notifier) sendTelegram(cfg map[string]any, message string) error { // ---- 邮件 ---- func (n *Notifier) sendEmail(cfg map[string]any, message string) error { + // ctx、cancel 保存ctx、cancel,供当前处理流程使用 ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() + // server 保存server,供当前处理流程使用 server := n.smtpConfigValue(ctx, cfg, "smtp_server", "") + // port 保存port,供当前处理流程使用 port := n.smtpConfigValue(ctx, cfg, "smtp_port", "587") + // user 保存用户,供当前处理流程使用 user := n.smtpConfigValue(ctx, cfg, "smtp_user", "") + // pass 保存pass,供当前处理流程使用 pass := n.smtpConfigValue(ctx, cfg, "smtp_password", "") + // useTLS 保存useTLS,供当前处理流程使用 useTLS := parseConfigBool(n.smtpConfigValue(ctx, cfg, "smtp_use_tls", "true"), true) + // useSSL 保存useSSL,供当前处理流程使用 useSSL := parseConfigBool(n.smtpConfigValue(ctx, cfg, "smtp_use_ssl", "false"), false) + // fromAddress 保存fromAddress,供当前处理流程使用 fromAddress := n.smtpConfigValue(ctx, cfg, "smtp_from_address", "") + // fromName 保存from名称,供当前处理流程使用 fromName := n.smtpConfigValue(ctx, cfg, "smtp_from_name", "") + // legacyFrom 保存legacyFrom,供当前处理流程使用 legacyFrom := n.smtpConfigValue(ctx, cfg, "smtp_from", "") + // to 保存to,供当前处理流程使用 to := strOr(cfg, "to_email", strOr(cfg, "email", "")) if server == "" || user == "" || to == "" { return fmt.Errorf("邮件配置不完整:请配置系统 SMTP 或在邮件渠道中覆盖 SMTP,并填写收件邮箱") } if legacyFrom != "" { - if parsed, err := mail.ParseAddress(legacyFrom); err == nil && strings.Contains(parsed.Address, "@") { + if // parsed、err 保存parsed、err,供当前处理流程使用 + parsed, err := mail.ParseAddress(legacyFrom); err == nil && strings.Contains(parsed.Address, "@") { if fromAddress == "" { fromAddress = parsed.Address } @@ -630,25 +741,32 @@ func (n *Notifier) sendEmail(cfg map[string]any, message string) error { if fromAddress == "" { fromAddress = user } + // from、err 保存from、err,供当前处理流程使用 from, err := mail.ParseAddress(fromAddress) if err != nil || !strings.Contains(from.Address, "@") { return fmt.Errorf("发件邮箱地址无效") } + // recipient、err 保存recipient、err,供当前处理流程使用 recipient, err := mail.ParseAddress(to) if err != nil || !strings.Contains(recipient.Address, "@") { return fmt.Errorf("收件邮箱地址无效") } from.Name = fromName + // fromHeader 保存fromHeader,供当前处理流程使用 fromHeader := from.Address if from.Name != "" { fromHeader = from.String() } + // toHeader 保存toHeader,供当前处理流程使用 toHeader := recipient.Address if recipient.Name != "" { toHeader = recipient.String() } + // addr 保存addr,供当前处理流程使用 addr := server + ":" + port + // auth 保存auth,供当前处理流程使用 auth := smtp.PlainAuth("", user, pass, server) + // msg 保存msg,供当前处理流程使用 msg := strings.Join([]string{ "From: " + fromHeader, "To: " + toHeader, @@ -664,75 +782,93 @@ func (n *Notifier) sendEmail(cfg map[string]any, message string) error { }) } +// smtpTransportOptions 保存smtpTransportOptions,供当前处理流程使用 type smtpTransportOptions struct { UseSTARTTLS bool UseImplicitTLS bool } +// sendPublicSMTP 负责sendPublicSMTP相关处理。 func sendPublicSMTP(ctx context.Context, addr, server string, auth smtp.Auth, from, to string, message []byte, options ...smtpTransportOptions) error { + // rawPort、err 保存原始Port、err,供当前处理流程使用 _, rawPort, err := net.SplitHostPort(addr) if err != nil { return fmt.Errorf("SMTP 地址无效") } + // port、err 保存port、err,供当前处理流程使用 port, err := strconv.Atoi(strings.TrimSpace(rawPort)) if err != nil || port < 1 || port > 65535 { return fmt.Errorf("SMTP 端口无效") } + // conn、err 保存conn、err,供当前处理流程使用 conn, err := dialPublicSMTP(ctx, "tcp", addr, 10*time.Second) if err != nil { return fmt.Errorf("连接 SMTP 服务器失败: %w", err) } defer func() { _ = conn.Close() }() _ = conn.SetDeadline(time.Now().Add(20 * time.Second)) + // transport 保存transport,供当前处理流程使用 transport := smtpTransportOptions{UseSTARTTLS: true} if len(options) > 0 { transport = options[0] } if transport.UseImplicitTLS { + // tlsConn 保存tlsConn,供当前处理流程使用 tlsConn := tls.Client(conn, &tls.Config{MinVersion: tls.VersionTLS12, ServerName: server}) - if err := tlsConn.HandshakeContext(ctx); err != nil { + if // err 保存err,供当前处理流程使用 + err := tlsConn.HandshakeContext(ctx); err != nil { return fmt.Errorf("SMTP SSL 握手失败: %w", err) } conn = tlsConn } + // client、err 保存client、err,供当前处理流程使用 client, err := smtp.NewClient(conn, server) if err != nil { return err } defer func() { _ = client.Close() }() if transport.UseSTARTTLS { - if ok, _ := client.Extension("STARTTLS"); !ok { + if // ok 保存ok,供当前处理流程使用 + ok, _ := client.Extension("STARTTLS"); !ok { return fmt.Errorf("SMTP 服务器不支持要求的 STARTTLS") } - if err := client.StartTLS(&tls.Config{MinVersion: tls.VersionTLS12, ServerName: server}); err != nil { + if // err 保存err,供当前处理流程使用 + err := client.StartTLS(&tls.Config{MinVersion: tls.VersionTLS12, ServerName: server}); err != nil { return err } } if auth != nil { - if err := client.Auth(auth); err != nil { + if // err 保存err,供当前处理流程使用 + err := client.Auth(auth); err != nil { return err } } - if err := client.Mail(from); err != nil { + if // err 保存err,供当前处理流程使用 + err := client.Mail(from); err != nil { return err } - if err := client.Rcpt(to); err != nil { + if // err 保存err,供当前处理流程使用 + err := client.Rcpt(to); err != nil { return err } + // w、err 保存w、err,供当前处理流程使用 w, err := client.Data() if err != nil { return err } - if _, err := w.Write(message); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := w.Write(message); err != nil { _ = w.Close() return err } - if err := w.Close(); err != nil { + if // err 保存err,供当前处理流程使用 + err := w.Close(); err != nil { return err } return client.Quit() } +// parseConfigBool 负责parse配置Bool相关处理。 func parseConfigBool(raw string, fallback bool) bool { switch strings.ToLower(strings.TrimSpace(raw)) { case "1", "true", "yes", "on": @@ -744,12 +880,15 @@ func parseConfigBool(raw string, fallback bool) bool { } } +// configOrSetting 负责配置Or设置相关处理。 func (n *Notifier) configOrSetting(ctx context.Context, cfg map[string]any, key, fallbackValue string) string { - if v := strings.TrimSpace(strOr(cfg, key, "")); v != "" { + if // v 保存v,供当前处理流程使用 + v := strings.TrimSpace(strOr(cfg, key, "")); v != "" { return v } if n.repository != nil { - if v, err := n.repository.GetSetting(ctx, key); err == nil && strings.TrimSpace(v) != "" { + if // v、err 保存v、err,供当前处理流程使用 + v, err := n.repository.GetSetting(ctx, key); err == nil && strings.TrimSpace(v) != "" { return strings.TrimSpace(v) } } @@ -758,19 +897,23 @@ func (n *Notifier) configOrSetting(ctx context.Context, cfg map[string]any, key, // smtpConfigValue keeps legacy per-field fallback behavior for existing rows, // while new rows use an explicit all-system or all-channel SMTP mode. +// smtpConfigValue 负责smtp配置值相关处理。 func (n *Notifier) smtpConfigValue(ctx context.Context, cfg map[string]any, key, fallbackValue string) string { + // modeValue、hasExplicitMode 保存模式Value、hasExplicit模式,供当前处理流程使用 modeValue, hasExplicitMode := cfg["use_custom_smtp"] if !hasExplicitMode { return n.configOrSetting(ctx, cfg, key, fallbackValue) } if parseConfigBool(fmt.Sprintf("%v", modeValue), false) { - if value := strings.TrimSpace(strOr(cfg, key, "")); value != "" { + if // value 保存值,供当前处理流程使用 + value := strings.TrimSpace(strOr(cfg, key, "")); value != "" { return value } return fallbackValue } if n.repository != nil { - if value, err := n.repository.GetSetting(ctx, key); err == nil && strings.TrimSpace(value) != "" { + if // value、err 保存value、err,供当前处理流程使用 + value, err := n.repository.GetSetting(ctx, key); err == nil && strings.TrimSpace(value) != "" { return strings.TrimSpace(value) } } @@ -779,20 +922,24 @@ func (n *Notifier) smtpConfigValue(ctx context.Context, cfg map[string]any, key, // postJSON 通用 JSON POST。 func (n *Notifier) postJSON(url string, payload any) error { + // body、err 保存body、err,供当前处理流程使用 body, err := json.Marshal(payload) if err != nil { return err } + // req、err 保存req、err,供当前处理流程使用 req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, url, bytes.NewReader(body)) if err != nil { return err } req.Header.Set("Content-Type", "application/json") + // resp、err 保存resp、err,供当前处理流程使用 resp, err := n.httpc.Do(req) if err != nil { return err } defer resp.Body.Close() + // responseBody、err 保存响应Body、err,供当前处理流程使用 responseBody, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20)) if err != nil { return err @@ -800,45 +947,57 @@ func (n *Notifier) postJSON(url string, payload any) error { if resp.StatusCode >= 300 { return fmt.Errorf("状态码 %d", resp.StatusCode) } - if err := notificationBusinessError(responseBody); err != nil { + if // err 保存err,供当前处理流程使用 + err := notificationBusinessError(responseBody); err != nil { return err } return nil } +// notificationBusinessError 负责通知Business错误相关处理。 func notificationBusinessError(body []byte) error { if len(bytes.TrimSpace(body)) == 0 { return nil } + // payload 保存请求载荷,供当前处理流程使用 var payload map[string]any if json.Unmarshal(body, &payload) != nil { return nil } + // message 保存消息,供当前处理流程使用 message := strings.TrimSpace(firstMapString(payload, "errmsg", "msg", "message", "description")) - if code, ok := mapNumber(payload, "errcode"); ok && code != 0 { + if // code、ok 保存code、ok,供当前处理流程使用 + code, ok := mapNumber(payload, "errcode"); ok && code != 0 { return fmt.Errorf("通知渠道返回错误 %.0f: %s", code, message) } - if code, ok := mapNumber(payload, "StatusCode"); ok && code != 0 { + if // code、ok 保存code、ok,供当前处理流程使用 + code, ok := mapNumber(payload, "StatusCode"); ok && code != 0 { return fmt.Errorf("通知渠道返回错误 %.0f: %s", code, message) } - if code, ok := mapNumber(payload, "code"); ok && code != 0 && code != 200 { + if // code、ok 保存code、ok,供当前处理流程使用 + code, ok := mapNumber(payload, "code"); ok && code != 0 && code != 200 { return fmt.Errorf("通知渠道返回错误 %.0f: %s", code, message) } - if okValue, exists := payload["ok"].(bool); exists && !okValue { + if // okValue、exists 保存okValue、exists,供当前处理流程使用 + okValue, exists := payload["ok"].(bool); exists && !okValue { return fmt.Errorf("通知渠道返回失败: %s", message) } return nil } +// mapNumber 负责mapNumber相关处理。 func mapNumber(payload map[string]any, key string) (float64, bool) { + // value、ok 保存value、ok,供当前处理流程使用 value, ok := payload[key] if !ok { return 0, false } - switch typed := value.(type) { + switch // typed 保存typed,供当前处理流程使用 + typed := value.(type) { case float64: return typed, true case string: + // number、err 保存number、err,供当前处理流程使用 number, err := strconv.ParseFloat(typed, 64) return number, err == nil default: @@ -846,9 +1005,12 @@ func mapNumber(payload map[string]any, key string) (float64, bool) { } } +// firstMapString 负责firstMapString相关处理。 func firstMapString(payload map[string]any, keys ...string) string { + // key 表示当前遍历过程中的key for _, key := range keys { - if value, ok := payload[key].(string); ok && value != "" { + if // value、ok 保存value、ok,供当前处理流程使用 + value, ok := payload[key].(string); ok && value != "" { return value } } @@ -857,8 +1019,10 @@ func firstMapString(payload map[string]any, keys ...string) string { // strOr 从 map 取字符串,缺失返回 fallback。 func strOr(m map[string]any, key, fallback string) string { - if v, ok := m[key]; ok { - switch x := v.(type) { + if // v、ok 保存v、ok,供当前处理流程使用 + v, ok := m[key]; ok { + switch // x 保存x,供当前处理流程使用 + x := v.(type) { case string: return x default: @@ -868,6 +1032,7 @@ func strOr(m map[string]any, key, fallback string) string { return fallback } +// fallback 负责fallback相关处理。 func fallback(s, def string) string { if s == "" { return def diff --git a/internal/notify/notifier_channels_test.go b/internal/notify/notifier_channels_test.go index eb28877..abc904c 100644 --- a/internal/notify/notifier_channels_test.go +++ b/internal/notify/notifier_channels_test.go @@ -17,8 +17,10 @@ import ( // redirectTransport 将所有请求重定向到指定 httptest.Server,保留原 path/query。 // 用于测试 URL 硬编码(telegram)或 https-only 的渠道。 +// redirectTransport 保存redirectTransport,供当前处理流程使用 type redirectTransport struct{ target string } +// RoundTrip 负责RoundTrip相关处理。 func (t *redirectTransport) RoundTrip(req *http.Request) (*http.Response, error) { req = req.Clone(req.Context()) req.URL.Scheme = "http" @@ -29,6 +31,7 @@ func (t *redirectTransport) RoundTrip(req *http.Request) (*http.Response, error) // notifierWithRedirectClient 构造一个把所有 HTTP 请求重定向到 target 的 Notifier。 func notifierWithRedirectClient(target string) *Notifier { + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) n.httpc = &http.Client{Timeout: 10 * time.Second, Transport: &redirectTransport{target: target}} return n @@ -37,8 +40,10 @@ func notifierWithRedirectClient(target string) *Notifier { // readJSONBody 读取并反序列化请求 body。 func readJSONBody(t *testing.T, b []byte) map[string]any { t.Helper() + // m 保存m,供当前处理流程使用 var m map[string]any - if err := json.Unmarshal(b, &m); err != nil { + if // err 保存err,供当前处理流程使用 + err := json.Unmarshal(b, &m); err != nil { t.Fatalf("unmarshal: %v body=%s", err, string(b)) } return m @@ -48,21 +53,28 @@ func readJSONBody(t *testing.T, b []byte) map[string]any { // TestSendDingTalk_WithSecret 带签名时 URL 携带 timestamp/sign。 // 注:生产代码用 "&" 拼接签名参数,需 webhook 已带查询串;此处补一个占位参数。 +// TestSendDingTalk_WithSecret 负责TestSendDingTalkWithSecret相关处理。 func TestSendDingTalk_WithSecret(t *testing.T) { + // gotURL 保存gotURL,供当前处理流程使用 var gotURL string + // got 保存got,供当前处理流程使用 var got map[string]any + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { gotURL = r.URL.String() + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) got = readJSONBody(t, b) w.WriteHeader(200) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) // webhook 已带占位查询参数,使 "×tamp=..." 拼接合法。 cfg := map[string]any{"webhook_url": srv.URL + "?token=x", "secret": "SECxxxx"} - if err := n.sendDingTalk(cfg, "内容"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.sendDingTalk(cfg, "内容"); err != nil { t.Fatalf("sendDingTalk: %v", err) } if !strings.Contains(gotURL, "timestamp=") || !strings.Contains(gotURL, "sign=") { @@ -75,48 +87,60 @@ func TestSendDingTalk_WithSecret(t *testing.T) { // TestSendDingTalk_EmptyWebhook webhook 缺失应报错。 func TestSendDingTalk_EmptyWebhook(t *testing.T) { + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendDingTalk(map[string]any{}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendDingTalk(map[string]any{}, "x"); err == nil { t.Fatal("缺 webhook_url 应报错") } } // TestSendDingTalk_HTTPError 服务端 4xx/5xx 应返回错误。 func TestSendDingTalk_HTTPError(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadRequest) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendDingTalk(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendDingTalk(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { t.Fatal("4xx 应报错") } } // TestSendDingTalk_NetworkError 连接失败应返回错误。 func TestSendDingTalk_NetworkError(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) srv.Close() // 立即关闭,制造连接失败 n := New("cid", nil, nil) - if err := n.sendDingTalk(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendDingTalk(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { t.Fatal("网络错误应报错") } } // TestSendDingTalk_OldConfigFormat 旧格式 webhook 直接是 URL。 func TestSendDingTalk_OldConfigFormat(t *testing.T) { + // got 保存got,供当前处理流程使用 var got map[string]any + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) got = readJSONBody(t, b) w.WriteHeader(200) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) // config 字段存放旧 URL。 if err := n.sendDingTalk(map[string]any{"config": srv.URL}, "旧格式"); err != nil { t.Fatalf("sendDingTalk 旧格式: %v", err) } + // md 保存md,供当前处理流程使用 md, _ := got["markdown"].(map[string]any) if md["text"] != "旧格式" { t.Errorf("旧格式正文: %v", md["text"]) @@ -127,43 +151,57 @@ func TestSendDingTalk_OldConfigFormat(t *testing.T) { // TestSendFeishu 成功 + 带签名 + 空 webhook + HTTP 错误。 func TestSendFeishu(t *testing.T) { + // got 保存got,供当前处理流程使用 var got map[string]any + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) got = readJSONBody(t, b) w.WriteHeader(200) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendFeishu(map[string]any{"webhook_url": srv.URL, "secret": "SEC"}, "飞书消息"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.sendFeishu(map[string]any{"webhook_url": srv.URL, "secret": "SEC"}, "飞书消息"); err != nil { t.Fatalf("sendFeishu: %v", err) } if got["msg_type"] != "text" { t.Errorf("msg_type=%v", got["msg_type"]) } - if _, ok := got["sign"]; !ok { + if // ok 保存ok,供当前处理流程使用 + _, ok := got["sign"]; !ok { t.Errorf("带 secret 应有 sign 字段: %v", got) } + // content 保存内容,供当前处理流程使用 content, _ := got["content"].(map[string]any) if content["text"] != "飞书消息" { t.Errorf("text=%v", content["text"]) } } +// TestSendFeishu_EmptyWebhook 负责TestSendFeishuEmptyWebhook相关处理。 func TestSendFeishu_EmptyWebhook(t *testing.T) { + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendFeishu(map[string]any{}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendFeishu(map[string]any{}, "x"); err == nil { t.Fatal("缺 webhook_url 应报错") } } +// TestSendFeishu_HTTPError 负责TestSendFeishuHTTP错误相关处理。 func TestSendFeishu_HTTPError(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendFeishu(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendFeishu(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { t.Fatal("5xx 应报错") } } @@ -172,17 +210,22 @@ func TestSendFeishu_HTTPError(t *testing.T) { // TestSendBark 成功 + 可选字段 + 空 device_key + HTTP 错误。 func TestSendBark(t *testing.T) { + // got 保存got,供当前处理流程使用 var got map[string]any + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/push" { t.Errorf("path=%s want /push", r.URL.Path) } + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) got = readJSONBody(t, b) w.WriteHeader(200) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) + // cfg 保存cfg,供当前处理流程使用 cfg := map[string]any{ "server_url": srv.URL, "device_key": "KEY", @@ -192,7 +235,8 @@ func TestSendBark(t *testing.T) { "sound": "bell", "group": "g1", } - if err := n.sendBark(cfg, "正文"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.sendBark(cfg, "正文"); err != nil { t.Fatalf("sendBark: %v", err) } if got["device_key"] != "KEY" || got["title"] != "标题" || got["body"] != "正文" { @@ -208,15 +252,20 @@ func TestSendBark(t *testing.T) { // TestSendBark_DefaultServerURL 缺省 server_url 时使用默认 https://api.day.app。 // 用 redirect client 拦截默认 host 的请求。 +// TestSendBark_DefaultServerURL 负责TestSendBarkDefaultServerURL相关处理。 func TestSendBark_DefaultServerURL(t *testing.T) { + // hitPath 保存hit路径,供当前处理流程使用 var hitPath string + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { hitPath = r.URL.Path w.WriteHeader(200) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := notifierWithRedirectClient(srv.Listener.Addr().String()) - if err := n.sendBark(map[string]any{"device_key": "K"}, "x"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.sendBark(map[string]any{"device_key": "K"}, "x"); err != nil { t.Fatalf("sendBark 默认 server: %v", err) } if hitPath != "/push" { @@ -224,61 +273,82 @@ func TestSendBark_DefaultServerURL(t *testing.T) { } } +// TestSendBark_EmptyDeviceKey 负责TestSendBarkEmptyDeviceKey相关处理。 func TestSendBark_EmptyDeviceKey(t *testing.T) { + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendBark(map[string]any{"server_url": "https://api.day.app"}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendBark(map[string]any{"server_url": "https://api.day.app"}, "x"); err == nil { t.Fatal("缺 device_key 应报错") } } +// TestSendBark_HTTPError 负责TestSendBarkHTTP错误相关处理。 func TestSendBark_HTTPError(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusBadGateway) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendBark(map[string]any{"server_url": srv.URL, "device_key": "K"}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendBark(map[string]any{"server_url": srv.URL, "device_key": "K"}, "x"); err == nil { t.Fatal("5xx 应报错") } } // ---------------- 企业微信 ---------------- +// TestSendWeChat 负责TestSendWe聊天相关处理。 func TestSendWeChat(t *testing.T) { + // got 保存got,供当前处理流程使用 var got map[string]any + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) got = readJSONBody(t, b) w.WriteHeader(200) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendWeChat(map[string]any{"webhook_url": srv.URL}, "微信消息"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.sendWeChat(map[string]any{"webhook_url": srv.URL}, "微信消息"); err != nil { t.Fatalf("sendWeChat: %v", err) } if got["msgtype"] != "text" { t.Errorf("msgtype=%v", got["msgtype"]) } + // text 保存文本,供当前处理流程使用 text, _ := got["text"].(map[string]any) if text["content"] != "微信消息" { t.Errorf("content=%v", text["content"]) } } +// TestSendWeChat_EmptyWebhook 负责TestSendWe聊天EmptyWebhook相关处理。 func TestSendWeChat_EmptyWebhook(t *testing.T) { + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendWeChat(map[string]any{}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendWeChat(map[string]any{}, "x"); err == nil { t.Fatal("缺 webhook_url 应报错") } } +// TestSendWeChat_HTTPError 负责TestSendWe聊天HTTP错误相关处理。 func TestSendWeChat_HTTPError(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusForbidden) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendWeChat(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendWeChat(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { t.Fatal("4xx 应报错") } } @@ -287,19 +357,26 @@ func TestSendWeChat_HTTPError(t *testing.T) { // TestSendTelegram_Success 通过 redirect transport 拦截 telegram API。 func TestSendTelegram_Success(t *testing.T) { + // got 保存got,供当前处理流程使用 var got map[string]any + // gotPath 保存got路径,供当前处理流程使用 var gotPath string + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { gotPath = r.URL.Path + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) got = readJSONBody(t, b) w.WriteHeader(200) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := notifierWithRedirectClient(srv.Listener.Addr().String()) - if err := n.sendTelegram(map[string]any{"bot_token": "TOK", "chat_id": "123"}, "TG消息"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.sendTelegram(map[string]any{"bot_token": "TOK", "chat_id": "123"}, "TG消息"); err != nil { t.Fatalf("sendTelegram: %v", err) } + // wantPath 保存want路径,供当前处理流程使用 wantPath := "/botTOK/sendMessage" if gotPath != wantPath { t.Errorf("path=%s want %s", gotPath, wantPath) @@ -307,40 +384,53 @@ func TestSendTelegram_Success(t *testing.T) { if got["chat_id"] != "123" || got["text"] != "TG消息" { t.Errorf("telegram payload: %v", got) } - if _, ok := got["parse_mode"]; ok { + if // ok 保存ok,供当前处理流程使用 + _, ok := got["parse_mode"]; ok { t.Errorf("动态文本不应启用未转义的 HTML 模式: %v", got) } } +// TestPostJSONRejectsBusinessErrors 负责TestPostJSONRejectsBusiness错误列表相关处理。 func TestPostJSONRejectsBusinessErrors(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") _, _ = w.Write([]byte(`{"errcode":310000,"errmsg":"signature invalid"}`)) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendDingTalk(map[string]any{"webhook_url": srv.URL}, "x"); err == nil || !strings.Contains(err.Error(), "signature invalid") { + if // err 保存err,供当前处理流程使用 + err := n.sendDingTalk(map[string]any{"webhook_url": srv.URL}, "x"); err == nil || !strings.Contains(err.Error(), "signature invalid") { t.Fatalf("business error=%v", err) } } +// TestSendTelegram_MissingConfig 负责TestSendTelegramMissing配置相关处理。 func TestSendTelegram_MissingConfig(t *testing.T) { + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendTelegram(map[string]any{"bot_token": ""}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendTelegram(map[string]any{"bot_token": ""}, "x"); err == nil { t.Fatal("缺 bot_token 应报错") } - if err := n.sendTelegram(map[string]any{"bot_token": "T", "chat_id": ""}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendTelegram(map[string]any{"bot_token": "T", "chat_id": ""}, "x"); err == nil { t.Fatal("缺 chat_id 应报错") } } +// TestSendTelegram_HTTPError 负责TestSendTelegramHTTP错误相关处理。 func TestSendTelegram_HTTPError(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusTooManyRequests) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := notifierWithRedirectClient(srv.Listener.Addr().String()) - if err := n.sendTelegram(map[string]any{"bot_token": "T", "chat_id": "1"}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendTelegram(map[string]any{"bot_token": "T", "chat_id": "1"}, "x"); err == nil { t.Fatal("4xx 应报错") } } @@ -349,24 +439,32 @@ func TestSendTelegram_HTTPError(t *testing.T) { // TestSendWebhook_CustomHeadersAndMethod 自定义 headers + GET 方法。 func TestSendWebhook_CustomHeadersAndMethod(t *testing.T) { + // gotMethod 保存got方法,供当前处理流程使用 var gotMethod string + // gotAuth 保存gotAuth,供当前处理流程使用 var gotAuth string + // gotBody 保存got请求体,供当前处理流程使用 var gotBody string + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { gotMethod = r.Method gotAuth = r.Header.Get("Authorization") + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) gotBody = string(b) w.WriteHeader(200) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) + // cfg 保存cfg,供当前处理流程使用 cfg := map[string]any{ "webhook_url": srv.URL, "http_method": "get", "headers": `{"Authorization":"Bearer abc","X-Custom":"v"}`, } - if err := n.sendWebhook(cfg, "消息"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.sendWebhook(cfg, "消息"); err != nil { t.Fatalf("sendWebhook: %v", err) } if gotMethod != http.MethodGet { @@ -380,33 +478,44 @@ func TestSendWebhook_CustomHeadersAndMethod(t *testing.T) { } } +// TestSendWebhook_EmptyWebhook 负责TestSendWebhookEmptyWebhook相关处理。 func TestSendWebhook_EmptyWebhook(t *testing.T) { + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendWebhook(map[string]any{}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendWebhook(map[string]any{}, "x"); err == nil { t.Fatal("缺 webhook_url 应报错") } } +// TestSendWebhook_HTTPError 负责TestSendWebhookHTTP错误相关处理。 func TestSendWebhook_HTTPError(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusServiceUnavailable) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendWebhook(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendWebhook(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { t.Fatal("5xx 应报错") } } // TestSendWebhook_InvalidHeaders headers 非法 JSON 时静默忽略。 func TestSendWebhook_InvalidHeaders(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) + // cfg 保存cfg,供当前处理流程使用 cfg := map[string]any{"webhook_url": srv.URL, "headers": "{bad json"} - if err := n.sendWebhook(cfg, "x"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.sendWebhook(cfg, "x"); err != nil { t.Fatalf("非法 headers 不应报错: %v", err) } } @@ -415,15 +524,19 @@ func TestSendWebhook_InvalidHeaders(t *testing.T) { // fakeSMTPServer 启动一个最小化 SMTP 服务器,响应 EHLO/MAIL/RCPT/DATA/QUIT。 // 返回监听地址与接收到的 DATA 正文 builder。 +// fakeSMTPServer 负责fakeSMTPServer相关处理。 func fakeSMTPServer(t *testing.T) (string, *strings.Builder) { t.Helper() + // ln、err 保存ln、err,供当前处理流程使用 ln, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatalf("listen: %v", err) } + // received 保存received,供当前处理流程使用 var received strings.Builder go func() { for { + // conn、err 保存conn、err,供当前处理流程使用 conn, err := ln.Accept() if err != nil { return @@ -435,16 +548,21 @@ func fakeSMTPServer(t *testing.T) (string, *strings.Builder) { return ln.Addr().String(), &received } +// handleSMTP 负责handleSMTP相关处理。 func handleSMTP(conn net.Conn, received *strings.Builder) { defer conn.Close() + // r 保存r,供当前处理流程使用 r := bufio.NewReader(conn) + // write 保存write,供当前处理流程使用 write := func(s string) { _, _ = conn.Write([]byte(s)) } write("220 mock smtp\r\n") for { + // line、err 保存line、err,供当前处理流程使用 line, err := r.ReadString('\n') if err != nil { return } + // upper 保存upper,供当前处理流程使用 upper := strings.ToUpper(strings.TrimSpace(line)) switch { case strings.HasPrefix(upper, "EHLO"), strings.HasPrefix(upper, "HELO"): @@ -458,6 +576,7 @@ func handleSMTP(conn net.Conn, received *strings.Builder) { case strings.HasPrefix(upper, "DATA"): write("354 End data with .\r\n") for { + // l、err 保存l、err,供当前处理流程使用 l, err := r.ReadString('\n') if err != nil { return @@ -481,9 +600,13 @@ func handleSMTP(conn net.Conn, received *strings.Builder) { // TestSendEmail_Success 通过 mock SMTP 服务器验证邮件发送。 func TestSendEmail_Success(t *testing.T) { + // addr、received 保存addr、received,供当前处理流程使用 addr, received := fakeSMTPServer(t) + // host、port 保存host、port,供当前处理流程使用 host, port, _ := strings.Cut(addr, ":") + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) + // cfg 保存cfg,供当前处理流程使用 cfg := map[string]any{ "smtp_server": host, "smtp_port": port, @@ -492,9 +615,11 @@ func TestSendEmail_Success(t *testing.T) { "smtp_use_tls": false, "to_email": "to@e.com", } - if err := n.sendEmail(cfg, "邮件正文"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.sendEmail(cfg, "邮件正文"); err != nil { t.Fatalf("sendEmail: %v", err) } + // body 保存请求体,供当前处理流程使用 body := received.String() if !strings.Contains(body, "Subject:") || !strings.Contains(body, "邮件正文") { t.Errorf("邮件内容异常: %s", body) @@ -503,9 +628,13 @@ func TestSendEmail_Success(t *testing.T) { // TestSendEmail_DefaultFrom 缺省 smtp_from 时回退为 smtp_user。 func TestSendEmail_DefaultFrom(t *testing.T) { + // addr、received 保存addr、received,供当前处理流程使用 addr, received := fakeSMTPServer(t) + // host、port 保存host、port,供当前处理流程使用 host, port, _ := strings.Cut(addr, ":") + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) + // cfg 保存cfg,供当前处理流程使用 cfg := map[string]any{ "smtp_server": host, "smtp_port": port, @@ -514,7 +643,8 @@ func TestSendEmail_DefaultFrom(t *testing.T) { "smtp_use_tls": false, "to_email": "to@e.com", } - if err := n.sendEmail(cfg, "x"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.sendEmail(cfg, "x"); err != nil { t.Fatalf("sendEmail: %v", err) } if !strings.Contains(received.String(), "From: from@e.com") { @@ -522,30 +652,43 @@ func TestSendEmail_DefaultFrom(t *testing.T) { } } +// TestSendEmail_SeparatesDisplayNameAndEnvelopeAddress 负责TestSend邮箱SeparatesDisplay名称AndEnvelopeAddress相关处理。 func TestSendEmail_SeparatesDisplayNameAndEnvelopeAddress(t *testing.T) { + // addr、received 保存addr、received,供当前处理流程使用 addr, received := fakeSMTPServer(t) + // host、port 保存host、port,供当前处理流程使用 host, port, _ := strings.Cut(addr, ":") + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) + // cfg 保存cfg,供当前处理流程使用 cfg := map[string]any{ "smtp_server": host, "smtp_port": port, "smtp_user": "login@e.com", "smtp_password": "pw", "smtp_use_tls": false, "smtp_from_name": "闲鱼自动回复系统", "smtp_from_address": "sender@e.com", "to_email": "to@e.com", } - if err := n.sendEmail(cfg, "x"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.sendEmail(cfg, "x"); err != nil { t.Fatal(err) } + // body 保存请求体,供当前处理流程使用 body := received.String() if !strings.Contains(body, "sender@e.com") || !strings.Contains(body, "From: =?utf-8?") { t.Fatalf("smtp envelope/header mismatch: %s", body) } } +// TestSendEmail_UsesSystemSMTPFallback 负责TestSend邮箱Uses系统SMTPFallback相关处理。 func TestSendEmail_UsesSystemSMTPFallback(t *testing.T) { + // addr、received 保存addr、received,供当前处理流程使用 addr, received := fakeSMTPServer(t) + // host、port 保存host、port,供当前处理流程使用 host, port, _ := strings.Cut(addr, ":") + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newNotifyStoreBare(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // key、value 表示当前遍历过程中的key、value for key, value := range map[string]string{ "smtp_server": host, "smtp_port": port, @@ -553,42 +696,54 @@ func TestSendEmail_UsesSystemSMTPFallback(t *testing.T) { "smtp_password": "pw", "smtp_use_tls": "false", } { - if err := store.Settings.Set(ctx, key, value); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, key, value); err != nil { t.Fatalf("set %s: %v", key, err) } } + // n 保存n,供当前处理流程使用 n := New("cid", store, nil) - if err := n.sendEmail(map[string]any{"to_email": "to@e.com"}, "系统SMTP正文"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.sendEmail(map[string]any{"to_email": "to@e.com"}, "系统SMTP正文"); err != nil { t.Fatalf("sendEmail with system fallback: %v", err) } + // body 保存请求体,供当前处理流程使用 body := received.String() if !strings.Contains(body, "From: system@e.com") || !strings.Contains(body, "系统SMTP正文") { t.Fatalf("system SMTP fallback body mismatch: %s", body) } } +// TestSMTPConfigValueUsesExclusiveExplicitModes 负责TestSMTP配置值UsesExclusiveExplicitModes相关处理。 func TestSMTPConfigValueUsesExclusiveExplicitModes(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newNotifyStoreBare(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if err := store.Settings.Set(ctx, "smtp_server", "system.example.com"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, "smtp_server", "system.example.com"); err != nil { t.Fatal(err) } + // n 保存n,供当前处理流程使用 n := New("cid", store, nil) - if got := n.smtpConfigValue(ctx, map[string]any{ + if // got 保存got,供当前处理流程使用 + got := n.smtpConfigValue(ctx, map[string]any{ "use_custom_smtp": false, "smtp_server": "stale-channel.example.com", }, "smtp_server", ""); got != "system.example.com" { t.Fatalf("system mode mixed in channel override: %q", got) } - if got := n.smtpConfigValue(ctx, map[string]any{ + if // got 保存got,供当前处理流程使用 + got := n.smtpConfigValue(ctx, map[string]any{ "use_custom_smtp": true, }, "smtp_server", ""); got != "" { t.Fatalf("custom mode inherited system value: %q", got) } - if got := n.smtpConfigValue(ctx, map[string]any{ + if // got 保存got,供当前处理流程使用 + got := n.smtpConfigValue(ctx, map[string]any{ "smtp_server": "legacy-channel.example.com", }, "smtp_server", ""); got != "legacy-channel.example.com" { t.Fatalf("legacy channel override compatibility lost: %q", got) @@ -597,19 +752,24 @@ func TestSMTPConfigValueUsesExclusiveExplicitModes(t *testing.T) { // TestSendEmail_IncompleteConfig 配置不完整应报错。 func TestSendEmail_IncompleteConfig(t *testing.T) { + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) + // cases 保存cases,供当前处理流程使用 cases := []map[string]any{ {"smtp_user": "u", "to_email": "t@e.com"}, // 缺 server {"smtp_server": "s", "to_email": "t@e.com"}, // 缺 user {"smtp_server": "s", "smtp_user": "u"}, // 缺 to } + // cfg 表示当前遍历过程中的cfg for _, cfg := range cases { - if err := n.sendEmail(cfg, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendEmail(cfg, "x"); err == nil { t.Fatalf("配置不完整应报错: %v", cfg) } } } +// TestParseSMTPTransportFlags 负责TestParseSMTPTransportFlags相关处理。 func TestParseSMTPTransportFlags(t *testing.T) { if !parseConfigBool("true", false) || !parseConfigBool("1", false) || parseConfigBool("off", true) { t.Fatal("SMTP boolean settings were not parsed consistently") @@ -626,9 +786,12 @@ func TestSendEmail_ConnectionFailed(t *testing.T) { if err != nil { t.Fatalf("listen: %v", err) } + // host、port 保存host、port,供当前处理流程使用 host, port, _ := strings.Cut(ln.Addr().String(), ":") _ = ln.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) + // cfg 保存cfg,供当前处理流程使用 cfg := map[string]any{ "smtp_server": host, "smtp_port": port, @@ -636,13 +799,15 @@ func TestSendEmail_ConnectionFailed(t *testing.T) { "smtp_password": "p", "to_email": "t@e.com", } - if err := n.sendEmail(cfg, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendEmail(cfg, "x"); err == nil { t.Fatal("连接失败应报错") } } // TestPostJSON_NetworkError postJSON 网络错误路径。 func TestPostJSON_NetworkError(t *testing.T) { + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) // 非法 URL(无 host)。 if err := n.postJSON("http://", map[string]any{"a": 1}); err == nil { @@ -652,76 +817,96 @@ func TestPostJSON_NetworkError(t *testing.T) { // TestPostJSON_HTTPError 覆盖状态码 >=300 分支。 func TestPostJSON_HTTPError(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusUnauthorized) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.postJSON(srv.URL, map[string]any{"a": 1}); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.postJSON(srv.URL, map[string]any{"a": 1}); err == nil { t.Fatal("401 应报错") } } // TestPostJSON_MarshalError 传入无法序列化的值触发 json.Marshal 错误。 func TestPostJSON_MarshalError(t *testing.T) { + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) // chan 无法被 json.Marshal 序列化。 bad := map[string]any{"ch": make(chan int)} - if err := n.postJSON("http://127.0.0.1:1", bad); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.postJSON("http://127.0.0.1:1", bad); err == nil { t.Fatal("无法序列化的 payload 应报错") } } // TestPostJSON_BodyReadError 服务端声明 Content-Length 但提前断开,触发 io.Copy 错误。 func TestPostJSON_BodyReadError(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // 声明 100 字节但只写 5 字节后立即关闭底层连接。 w.Header().Set("Content-Length", "100") _, _ = w.Write([]byte("short")) - if hj, ok := w.(http.Hijacker); ok { + if // hj、ok 保存hj、ok,供当前处理流程使用 + hj, ok := w.(http.Hijacker); ok { + // conn 保存conn,供当前处理流程使用 conn, _, _ := hj.Hijack() _ = conn.Close() } })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.postJSON(srv.URL, map[string]any{"a": 1}); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.postJSON(srv.URL, map[string]any{"a": 1}); err == nil { t.Fatal("body 读取错误应报错") } } // TestSendWebhook_BodyReadError webhook 渠道触发 io.Copy 错误。 func TestSendWebhook_BodyReadError(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Length", "100") _, _ = w.Write([]byte("x")) - if hj, ok := w.(http.Hijacker); ok { + if // hj、ok 保存hj、ok,供当前处理流程使用 + hj, ok := w.(http.Hijacker); ok { + // conn 保存conn,供当前处理流程使用 conn, _, _ := hj.Hijack() _ = conn.Close() } })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) - if err := n.sendWebhook(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendWebhook(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { t.Fatal("body 读取错误应报错") } } // TestSendWebhook_NetworkError 服务端不可达触发 httpc.Do 错误。 func TestSendWebhook_NetworkError(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) srv.Close() // 关闭使连接失败 n := New("cid", nil, nil) - if err := n.sendWebhook(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendWebhook(map[string]any{"webhook_url": srv.URL}, "x"); err == nil { t.Fatal("网络错误应报错") } } // TestSendWebhook_NewRequestError URL 含空格导致 http.NewRequest 失败。 func TestSendWebhook_NewRequestError(t *testing.T) { + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) + // cfg 保存cfg,供当前处理流程使用 cfg := map[string]any{"webhook_url": "http://in valid host/path"} - if err := n.sendWebhook(cfg, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.sendWebhook(cfg, "x"); err == nil { t.Fatal("非法 URL 应触发 NewRequest 错误") } } @@ -729,19 +914,27 @@ func TestSendWebhook_NewRequestError(t *testing.T) { // TestSend_RouteAllTypes 通过 send 入口覆盖各渠道类型分发分支。 // HTTP 渠道用 redirect client 拦截到本地 httptest server;email 走 SMTP 必然失败, // 但能覆盖 send 的 email case。 +// TestSend_RouteAllTypes 负责TestSendRouteAllTypes相关处理。 func TestSend_RouteAllTypes(t *testing.T) { + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _, _ = io.Copy(io.Discard, r.Body) w.WriteHeader(200) })) defer srv.Close() + // cfg 保存cfg,供当前处理流程使用 cfg := `{"webhook_url":"` + srv.URL + `","server_url":"` + srv.URL + `","device_key":"K","bot_token":"T","chat_id":"1"}` + // n 保存n,供当前处理流程使用 n := notifierWithRedirectClient(srv.Listener.Addr().String()) + // types 保存types,供当前处理流程使用 types := []string{"feishu", "lark", "bark", "webhook", "wechat", "telegram", "ding_talk"} + // typ 表示当前遍历过程中的typ for _, typ := range types { + // ch 保存ch,供当前处理流程使用 ch := dbNotificationChannel(typ, cfg) - if err := n.send(ch, "分发测试"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.send(ch, "分发测试"); err != nil { t.Errorf("send(%s): %v", typ, err) } } @@ -759,18 +952,25 @@ func dbNotificationChannel(typ, cfg string) db.NotificationChannel { // TestSend_DingTalkAlias 钉钉别名 dingtalk 也能路由。 func TestSend_DingTalkAlias(t *testing.T) { + // got 保存got,供当前处理流程使用 var got map[string]any + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) got = readJSONBody(t, b) w.WriteHeader(200) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", nil, nil) + // ch 保存ch,供当前处理流程使用 ch := dbNotificationChannel("dingtalk", `{"webhook_url":"`+srv.URL+`"}`) - if err := n.send(ch, "别名"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.send(ch, "别名"); err != nil { t.Fatalf("send(dingtalk): %v", err) } + // md 保存md,供当前处理流程使用 md, _ := got["markdown"].(map[string]any) if md["text"] != "别名" { t.Errorf("别名路由正文: %v", md["text"]) diff --git a/internal/notify/notifier_dispatch_test.go b/internal/notify/notifier_dispatch_test.go index 734468e..52d055a 100644 --- a/internal/notify/notifier_dispatch_test.go +++ b/internal/notify/notifier_dispatch_test.go @@ -22,14 +22,18 @@ func nilLogger() *slog.Logger { // newNotifyStoreBare 提供一个独立 store,方便各测试用例自由构造数据。 // 预置一个 admin 用户和一个 cookie_id="cid" 的 cookie 记录以满足外键约束。 +// newNotifyStoreBare 负责newNotifyStoreBare相关处理。 func newNotifyStoreBare(t *testing.T) (*db.Store, func()) { t.Helper() + // d、err 保存d、err,供当前处理流程使用 d, _, err := db.Open(context.Background(), filepath.Join(t.TempDir(), "test.db")) if err != nil { t.Fatalf("Open: %v", err) } + // s 保存s,供当前处理流程使用 s := db.NewStore(d, db.DialectSQLite) s.Users.Create(context.Background(), "admin", "a@e.com", "pw") + // admin 保存admin,供当前处理流程使用 admin, _ := s.Users.GetByUsername(context.Background(), "admin") s.Cookies.Save(context.Background(), "cid", "unb=123; _m_h5_tk=tk_1;", admin.ID) return s, func() { _ = d.Close() } @@ -38,14 +42,17 @@ func newNotifyStoreBare(t *testing.T) (*db.Store, func()) { // addWebhookChannel 插入一个 webhook 渠道并绑定到 cookieID,返回渠道 ID。 func addWebhookChannel(t *testing.T, s *db.Store, cookieID, name, webhookURL string) int64 { t.Helper() + // res、err 保存res、err,供当前处理流程使用 res, err := s.DB.ExecContext(context.Background(), `INSERT INTO notification_channels (name,type,config,enabled,user_id) VALUES (?,?,?,1,1)`, name, "webhook", `{"webhook_url":"`+webhookURL+`"}`) if err != nil { t.Fatalf("insert channel: %v", err) } + // id 保存标识,供当前处理流程使用 id, _ := res.LastInsertId() - if _, err := s.DB.ExecContext(context.Background(), + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(context.Background(), `INSERT INTO message_notifications (cookie_id,channel_id,enabled) VALUES (?,?,1)`, cookieID, id); err != nil { t.Fatalf("insert binding: %v", err) @@ -55,6 +62,7 @@ func addWebhookChannel(t *testing.T, s *db.Store, cookieID, name, webhookURL str // TestNotifyAccountAlert_NoStore store 为 nil 时安全返回。 func TestNotifyAccountAlert_NoStore(t *testing.T) { + // n 保存n,供当前处理流程使用 n := &Notifier{logger: nilLogger()} // 不应 panic。 n.NotifyAccountAlert("cid", "warn", "标题", "正文") @@ -62,19 +70,25 @@ func TestNotifyAccountAlert_NoStore(t *testing.T) { // TestNotifyAccountAlert_NoChannels 无绑定渠道时不报错。 func TestNotifyAccountAlert_NoChannels(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStoreBare(t) defer cleanup() + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) n.NotifyAccountAlert("cid", "warn", "标题", "正文") } // TestNotifyAccountAlert_WithChannel 告警通知发送并包含标题与正文。 func TestNotifyAccountAlert_WithChannel(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStoreBare(t) defer cleanup() + // gotBody 保存got请求体,供当前处理流程使用 var gotBody string + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) gotBody = string(b) w.WriteHeader(200) @@ -82,6 +96,7 @@ func TestNotifyAccountAlert_WithChannel(t *testing.T) { defer srv.Close() addWebhookChannel(t, s, "cid", "告警渠道", srv.URL) + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) n.NotifyAccountAlert("cid", "critical", "Token失效", "请重新登录") @@ -93,46 +108,59 @@ func TestNotifyAccountAlert_WithChannel(t *testing.T) { } } +// TestNotifyEventUsesPersistentOutboxWhenStarted 负责TestNotifyEventUsesPersistentOutboxWhenStarted相关处理。 func TestNotifyEventUsesPersistentOutboxWhenStarted(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStoreBare(t) defer cleanup() + // calls 保存calls,供当前处理流程使用 var calls int32 + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { atomic.AddInt32(&calls, 1) w.WriteHeader(http.StatusOK) })) defer srv.Close() addWebhookChannel(t, s, "cid", "outbox", srv.URL) + // n 保存n,供当前处理流程使用 n := New("cid", s, nilLogger()) // 标记异步模式但不启动循环,精确验证调用返回时尚未发生外部网络请求。 n.started.Store(true) n.NotifyAccountAlert("cid", "warn", "持久化通知", "正文") - if got := atomic.LoadInt32(&calls); got != 0 { + if // got 保存got,供当前处理流程使用 + got := atomic.LoadInt32(&calls); got != 0 { t.Fatalf("business call performed synchronous network I/O: %d", got) } + // queued 保存queued,供当前处理流程使用 var queued int - if err := s.DB.QueryRow(`SELECT COUNT(*) FROM notification_outbox WHERE status='pending'`).Scan(&queued); err != nil || queued != 1 { + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRow(`SELECT COUNT(*) FROM notification_outbox WHERE status='pending'`).Scan(&queued); err != nil || queued != 1 { t.Fatalf("queued=%d err=%v", queued, err) } n.drainOutbox(context.Background()) - if got := atomic.LoadInt32(&calls); got != 1 { + if // got 保存got,供当前处理流程使用 + got := atomic.LoadInt32(&calls); got != 1 { t.Fatalf("outbox delivery calls=%d", got) } - if err := s.DB.QueryRow(`SELECT COUNT(*) FROM notification_outbox`).Scan(&queued); err != nil || queued != 0 { + if // err 保存err,供当前处理流程使用 + err := s.DB.QueryRow(`SELECT COUNT(*) FROM notification_outbox`).Scan(&queued); err != nil || queued != 0 { t.Fatalf("remaining=%d err=%v", queued, err) } } // TestNotifyAccountAlert_LevelLabels 覆盖 levelLabel 各分支。 func TestNotifyAccountAlert_LevelLabels(t *testing.T) { + // cases 保存cases,供当前处理流程使用 cases := map[string]string{ "critical": "严重", "warn": "警告", "info": "提示", "unknown": "unknown", } + // level、want 表示当前遍历过程中的level、want for level, want := range cases { - if got := levelLabel(level); got != want { + if // got 保存got,供当前处理流程使用 + got := levelLabel(level); got != want { t.Errorf("levelLabel(%q)=%q want %q", level, got, want) } } @@ -140,20 +168,27 @@ func TestNotifyAccountAlert_LevelLabels(t *testing.T) { // TestSendToChannel 直接发送到指定渠道。 func TestSendToChannel(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStoreBare(t) defer cleanup() + // gotBody 保存got请求体,供当前处理流程使用 var gotBody string + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) gotBody = string(b) w.WriteHeader(200) })) defer srv.Close() + // chID 保存chID,供当前处理流程使用 chID := addWebhookChannel(t, s, "cid", "直发渠道", srv.URL) + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) - if err := n.SendToChannel(chID, "直发测试"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.SendToChannel(chID, "直发测试"); err != nil { t.Fatalf("SendToChannel: %v", err) } if !strings.Contains(gotBody, "直发测试") { @@ -165,12 +200,15 @@ func TestSendToChannel(t *testing.T) { func TestSendToChannel_Errors(t *testing.T) { // store 为 nil。 n := &Notifier{logger: nilLogger()} - if err := n.SendToChannel(1, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.SendToChannel(1, "x"); err == nil { t.Fatal("store 为 nil 应报错") } + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStoreBare(t) defer cleanup() + // n2 保存n2,供当前处理流程使用 n2 := New("cid", s, nil) // 不存在的渠道 ID。 if err := n2.SendToChannel(99999, "x"); err == nil { @@ -180,9 +218,11 @@ func TestSendToChannel_Errors(t *testing.T) { // TestNotifyDelivery_MultiChannel 某渠道失败不影响其他渠道。 func TestNotifyDelivery_MultiChannel(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStoreBare(t) defer cleanup() + // okCount 保存ok数量,供当前处理流程使用 var okCount int32 // 成功渠道。 okSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -201,20 +241,26 @@ func TestNotifyDelivery_MultiChannel(t *testing.T) { addWebhookChannel(t, s, "cid", "成功渠道", okSrv.URL) addWebhookChannel(t, s, "cid", "失败渠道", failSrv.URL) + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) n.NotifyDelivery("cid", "买家", "b1", "item1", "成功", "chat1") - if got := atomic.LoadInt32(&okCount); got != 1 { + if // got 保存got,供当前处理流程使用 + got := atomic.LoadInt32(&okCount); got != 1 { t.Errorf("成功渠道应收到 1 次,实际 %d", got) } } // TestNotifyDelivery_TemplateVars 通知正文应包含买家名、商品ID、结果等变量。 func TestNotifyDelivery_TemplateVars(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStoreBare(t) defer cleanup() + // gotBody 保存got请求体,供当前处理流程使用 var gotBody string + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) gotBody = string(b) w.WriteHeader(200) @@ -222,9 +268,11 @@ func TestNotifyDelivery_TemplateVars(t *testing.T) { defer srv.Close() addWebhookChannel(t, s, "cid", "模板渠道", srv.URL) + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) n.NotifyDelivery("cid", "张三", "BID123", "ITEM456", "发货成功", "CHAT789") + // want 表示当前遍历过程中的want for _, want := range []string{"张三", "BID123", "ITEM456", "发货成功", "CHAT789"} { if !strings.Contains(gotBody, want) { t.Errorf("正文缺少 %q: %s", want, gotBody) @@ -234,11 +282,15 @@ func TestNotifyDelivery_TemplateVars(t *testing.T) { // TestNotifyDelivery_EmptyChatID chatID 为空时回退为“未知”。 func TestNotifyDelivery_EmptyChatID(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStoreBare(t) defer cleanup() + // gotBody 保存got请求体,供当前处理流程使用 var gotBody string + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) gotBody = string(b) w.WriteHeader(200) @@ -246,6 +298,7 @@ func TestNotifyDelivery_EmptyChatID(t *testing.T) { defer srv.Close() addWebhookChannel(t, s, "cid", "渠道", srv.URL) + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) n.NotifyDelivery("cid", "买家", "b1", "item1", "结果", "") if !strings.Contains(gotBody, "未知") { @@ -255,6 +308,7 @@ func TestNotifyDelivery_EmptyChatID(t *testing.T) { // TestParseConfig_InvalidJSON 非法 JSON 走旧格式兼容分支。 func TestParseConfig_InvalidJSON(t *testing.T) { + // m 保存m,供当前处理流程使用 m := parseConfig("{not json") if m["config"] != "{not json" { t.Errorf("非法 JSON 应放入 config: %v", m) @@ -263,41 +317,51 @@ func TestParseConfig_InvalidJSON(t *testing.T) { // TestStrOr 覆盖 string / 非 string / 缺失三个分支。 func TestStrOr(t *testing.T) { + // m 保存m,供当前处理流程使用 m := map[string]any{ "s": "abc", "n": 42, "b": true, } - if got := strOr(m, "s", "x"); got != "abc" { + if // got 保存got,供当前处理流程使用 + got := strOr(m, "s", "x"); got != "abc" { t.Errorf("strOr(s)=%q", got) } - if got := strOr(m, "n", "x"); got != "42" { + if // got 保存got,供当前处理流程使用 + got := strOr(m, "n", "x"); got != "42" { t.Errorf("strOr(n)=%q", got) } - if got := strOr(m, "b", "x"); got != "true" { + if // got 保存got,供当前处理流程使用 + got := strOr(m, "b", "x"); got != "true" { t.Errorf("strOr(b)=%q", got) } - if got := strOr(m, "missing", "def"); got != "def" { + if // got 保存got,供当前处理流程使用 + got := strOr(m, "missing", "def"); got != "def" { t.Errorf("strOr(missing)=%q", got) } } // TestFallback fallback 空串与非空串。 func TestFallback(t *testing.T) { - if got := fallback("", "默认"); got != "默认" { + if // got 保存got,供当前处理流程使用 + got := fallback("", "默认"); got != "默认" { t.Errorf("fallback('')=%q", got) } - if got := fallback("值", "默认"); got != "值" { + if // got 保存got,供当前处理流程使用 + got := fallback("值", "默认"); got != "值" { t.Errorf("fallback('值')=%q", got) } } // TestNotifyAccountAlert_DBError 查询出错时不 panic(err != nil 分支)。 func TestNotifyAccountAlert_DBError(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStoreBare(t) + // d 保存d,供当前处理流程使用 d := s.DB cleanup() // 提前关闭 DB,使查询返回错误 _ = d + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) // store 非 nil 但 DB 已关闭,查询会报错;不应 panic。 n.NotifyAccountAlert("cid", "warn", "标题", "正文") @@ -305,6 +369,7 @@ func TestNotifyAccountAlert_DBError(t *testing.T) { // TestNotifyDelivery_DBError 查询出错时不 panic(err != nil 分支)。 func TestNotifyDelivery_DBError(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStoreBare(t) cleanup() // 提前关闭 DB n := New("cid", s, nil) @@ -313,25 +378,30 @@ func TestNotifyDelivery_DBError(t *testing.T) { // TestSendToChannel_DBError 查询渠道出错时返回包装错误。 func TestSendToChannel_DBError(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStoreBare(t) cleanup() // 提前关闭 DB n := New("cid", s, nil) - if err := n.SendToChannel(1, "x"); err == nil { + if // err 保存err,供当前处理流程使用 + err := n.SendToChannel(1, "x"); err == nil { t.Fatal("DB 查询出错应返回 error") } } // TestNotifyAccountAlert_SendError 某渠道发送失败时记录错误但不中断。 func TestNotifyAccountAlert_SendError(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStoreBare(t) defer cleanup() + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) })) defer srv.Close() addWebhookChannel(t, s, "cid", "失败渠道", srv.URL) + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) // 渠道返回 5xx,send 报错 → 走 logger.Error 分支,但不应 panic。 n.NotifyAccountAlert("cid", "warn", "标题", "正文") @@ -339,8 +409,10 @@ func TestNotifyAccountAlert_SendError(t *testing.T) { // TestNew_DefaultLogger logger 为 nil 时使用默认 logger。 func TestNew_DefaultLogger(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStoreBare(t) defer cleanup() + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) if n == nil || n.logger == nil || n.httpc == nil { t.Fatal("New 未正确初始化字段") diff --git a/internal/notify/notifier_test.go b/internal/notify/notifier_test.go index c6163be..fed3b9f 100644 --- a/internal/notify/notifier_test.go +++ b/internal/notify/notifier_test.go @@ -12,14 +12,18 @@ import ( "xianyu-go/internal/db" ) +// newNotifyStore 负责newNotifyStore相关处理。 func newNotifyStore(t *testing.T) (*db.Store, func()) { t.Helper() + // d、err 保存d、err,供当前处理流程使用 d, _, err := db.Open(context.Background(), filepath.Join(t.TempDir(), "test.db")) if err != nil { t.Fatalf("Open: %v", err) } + // s 保存s,供当前处理流程使用 s := db.NewStore(d, db.DialectSQLite) s.Users.Create(context.Background(), "admin", "a@e.com", "pw") + // admin 保存admin,供当前处理流程使用 admin, _ := s.Users.GetByUsername(context.Background(), "admin") s.Cookies.Save(context.Background(), "cid", "unb=123; _m_h5_tk=tk_1;", admin.ID) return s, func() { d.Close() } @@ -27,26 +31,35 @@ func newNotifyStore(t *testing.T) (*db.Store, func()) { // TestSendDingTalk 钉钉渠道 POST 正确 payload。 func TestSendDingTalk(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStore(t) defer cleanup() + // got 保存got,供当前处理流程使用 var got map[string]any + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) _ = json.Unmarshal(b, &got) w.WriteHeader(200) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) + // cfg 保存cfg,供当前处理流程使用 cfg := `{"webhook_url":"` + srv.URL + `"}` + // ch 保存ch,供当前处理流程使用 ch := db.NotificationChannel{ID: 1, Name: "钉钉", Type: "ding_talk", Config: cfg} - if err := n.send(ch, "测试消息"); err != nil { + if // err 保存err,供当前处理流程使用 + err := n.send(ch, "测试消息"); err != nil { t.Fatalf("send dingtalk: %v", err) } if got["msgtype"] != "markdown" { t.Errorf("msgtype=%v want markdown", got["msgtype"]) } + // md 保存md,供当前处理流程使用 md, _ := got["markdown"].(map[string]any) if md["text"] != "测试消息" { t.Errorf("text=%v", md["text"]) @@ -55,17 +68,22 @@ func TestSendDingTalk(t *testing.T) { // TestSendTelegram Telegram 渠道。 func TestSendTelegram(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStore(t) defer cleanup() + // got 保存got,供当前处理流程使用 var got map[string]any + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) _ = json.Unmarshal(b, &got) w.WriteHeader(200) })) defer srv.Close() + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) // 用 config 覆盖 API URL 不可行(硬编码),故直接调内部 sendTelegram。 cfg := map[string]any{"bot_token": "TOKEN", "chat_id": "123"} @@ -82,8 +100,10 @@ func TestSendTelegram(t *testing.T) { // TestRouteByChannelType 渠道类型路由。 func TestRouteByChannelType(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStore(t) defer cleanup() + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) // 不支持的类型应返回 error。 @@ -99,8 +119,10 @@ func TestRouteByChannelType(t *testing.T) { // TestNotifyDelivery_NoChannels 无通知配置时不报错。 func TestNotifyDelivery_NoChannels(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStore(t) defer cleanup() + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) // 不应 panic。 n.NotifyDelivery("cid", "买家", "b1", "item1", "发货成功", "chat1") @@ -108,14 +130,20 @@ func TestNotifyDelivery_NoChannels(t *testing.T) { // TestNotifyDelivery_WithChannel 有渠道时发送。 func TestNotifyDelivery_WithChannel(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := s.Users.GetByUsername(ctx, "admin") _ = admin + // gotBody 保存got请求体,供当前处理流程使用 var gotBody string + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // b 保存b,供当前处理流程使用 b, _ := io.ReadAll(r.Body) gotBody = string(b) w.WriteHeader(200) @@ -126,10 +154,12 @@ func TestNotifyDelivery_WithChannel(t *testing.T) { res, _ := s.DB.ExecContext(ctx, `INSERT INTO notification_channels (name,type,config,enabled,user_id) VALUES ('测试','webhook',?,1,1)`, `{"webhook_url":"`+srv.URL+`"}`) + // chID 保存chID,供当前处理流程使用 chID, _ := res.LastInsertId() s.DB.ExecContext(ctx, `INSERT INTO message_notifications (cookie_id,channel_id,enabled) VALUES ('cid',?,1)`, chID) + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) n.NotifyDelivery("cid", "买家甲", "b1", "item1", "发货成功", "chat1") if gotBody == "" { @@ -140,39 +170,51 @@ func TestNotifyDelivery_WithChannel(t *testing.T) { } } +// TestNotifyEvent_FiltersByChannelEventTypes 负责TestNotifyEventFiltersBy渠道EventTypes相关处理。 func TestNotifyEvent_FiltersByChannelEventTypes(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // hits 保存hits,供当前处理流程使用 hits := map[string]int{} + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { hits[r.URL.Path]++ w.WriteHeader(200) })) defer srv.Close() + // resOffline、err 保存响应Offline、err,供当前处理流程使用 resOffline, err := s.DB.ExecContext(ctx, `INSERT INTO notification_channels (name,type,config,event_types,enabled,user_id) VALUES ('掉线','webhook',?,?,1,1)`, `{"webhook_url":"`+srv.URL+`/offline"}`, `["`+EventAccountOffline+`"]`) if err != nil { t.Fatalf("insert offline channel: %v", err) } + // offlineID 保存offlineID,供当前处理流程使用 offlineID, _ := resOffline.LastInsertId() + // resDisabled、err 保存响应Disabled、err,供当前处理流程使用 resDisabled, err := s.DB.ExecContext(ctx, `INSERT INTO notification_channels (name,type,config,event_types,enabled,user_id) VALUES ('禁用','webhook',?,?,1,1)`, `{"webhook_url":"`+srv.URL+`/disabled"}`, `["`+EventAccountDisabled+`"]`) if err != nil { t.Fatalf("insert disabled channel: %v", err) } + // disabledID 保存disabledID,供当前处理流程使用 disabledID, _ := resDisabled.LastInsertId() + // id 表示当前遍历过程中的标识 for _, id := range []int64{offlineID, disabledID} { - if _, err := s.DB.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `INSERT INTO message_notifications (cookie_id,channel_id,enabled) VALUES ('cid',?,1)`, id); err != nil { t.Fatalf("insert binding: %v", err) } } + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) n.NotifyAccountEvent("cid", EventAccountOffline, "warn", "掉线", "正在恢复") if hits["/offline"] != 1 { @@ -183,39 +225,51 @@ func TestNotifyEvent_FiltersByChannelEventTypes(t *testing.T) { } } +// TestNotifyAccountAlertClassifiesLegacyAlerts 负责TestNotify账号AlertClassifiesLegacyAlerts相关处理。 func TestNotifyAccountAlertClassifiesLegacyAlerts(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // hits 保存hits,供当前处理流程使用 hits := map[string]int{} + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { hits[r.URL.Path]++ w.WriteHeader(200) })) defer srv.Close() + // resSecurity、err 保存响应Security、err,供当前处理流程使用 resSecurity, err := s.DB.ExecContext(ctx, `INSERT INTO notification_channels (name,type,config,event_types,enabled,user_id) VALUES ('风控','webhook',?,?,1,1)`, `{"webhook_url":"`+srv.URL+`/security"}`, `["`+EventSecurityVerification+`"]`) if err != nil { t.Fatalf("insert security channel: %v", err) } + // securityID 保存securityID,供当前处理流程使用 securityID, _ := resSecurity.LastInsertId() + // resToken、err 保存响应Token、err,供当前处理流程使用 resToken, err := s.DB.ExecContext(ctx, `INSERT INTO notification_channels (name,type,config,event_types,enabled,user_id) VALUES ('续期','webhook',?,?,1,1)`, `{"webhook_url":"`+srv.URL+`/token"}`, `["`+EventTokenRenewal+`"]`) if err != nil { t.Fatalf("insert token channel: %v", err) } + // tokenID 保存令牌ID,供当前处理流程使用 tokenID, _ := resToken.LastInsertId() + // id 表示当前遍历过程中的标识 for _, id := range []int64{securityID, tokenID} { - if _, err := s.DB.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `INSERT INTO message_notifications (cookie_id,channel_id,enabled) VALUES ('cid',?,1)`, id); err != nil { t.Fatalf("insert binding: %v", err) } } + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) n.NotifyAccountAlert("cid", "warn", "闲鱼要求滑块验证", "请完成 captcha") if hits["/security"] != 1 { @@ -226,30 +280,39 @@ func TestNotifyAccountAlertClassifiesLegacyAlerts(t *testing.T) { } } +// TestNotifyEventRejectsMalformedEventTypes 负责TestNotifyEventRejectsMalformedEventTypes相关处理。 func TestNotifyEventRejectsMalformedEventTypes(t *testing.T) { + // s、cleanup 保存s、cleanup,供当前处理流程使用 s, cleanup := newNotifyStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // hits 保存hits,供当前处理流程使用 hits := 0 + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { hits++ w.WriteHeader(200) })) defer srv.Close() + // res、err 保存res、err,供当前处理流程使用 res, err := s.DB.ExecContext(ctx, `INSERT INTO notification_channels (name,type,config,event_types,enabled,user_id) VALUES ('坏配置','webhook',?,?,1,1)`, `{"webhook_url":"`+srv.URL+`"}`, `["`+EventAccountOffline+`"`) if err != nil { t.Fatalf("insert malformed channel: %v", err) } + // channelID 保存渠道ID,供当前处理流程使用 channelID, _ := res.LastInsertId() - if _, err := s.DB.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := s.DB.ExecContext(ctx, `INSERT INTO message_notifications (cookie_id,channel_id,enabled) VALUES ('cid',?,1)`, channelID); err != nil { t.Fatalf("insert binding: %v", err) } + // n 保存n,供当前处理流程使用 n := New("cid", s, nil) n.NotifyAccountEvent("cid", EventAccountOffline, "warn", "掉线", "正在恢复") if hits != 0 { @@ -276,8 +339,10 @@ func TestParseConfig(t *testing.T) { } } +// contains 负责contains相关处理。 func contains(s, sub string) bool { - for i := 0; i+len(sub) <= len(s); i++ { + for // i 保存i,供当前处理流程使用 + i := 0; i+len(sub) <= len(s); i++ { if s[i:i+len(sub)] == sub { return true } diff --git a/internal/notify/smtp_guard_test.go b/internal/notify/smtp_guard_test.go index 948a94d..132b557 100644 --- a/internal/notify/smtp_guard_test.go +++ b/internal/notify/smtp_guard_test.go @@ -11,24 +11,32 @@ import ( "xianyu-go/internal/netguard" ) +// TestSendPublicSMTPRejectsInvalidPortAndLoopback 负责TestSendPublicSMTPRejectsInvalidPortAndLoopback相关处理。 func TestSendPublicSMTPRejectsInvalidPortAndLoopback(t *testing.T) { + // testDialer 保存testDialer,供当前处理流程使用 testDialer := dialPublicSMTP dialPublicSMTP = netguard.DialPublicContext t.Cleanup(func() { dialPublicSMTP = testDialer }) - if err := sendPublicSMTP(context.Background(), "smtp.example.com:not-a-port", "smtp.example.com", nil, "a@example.com", "b@example.com", nil); err == nil || !strings.Contains(err.Error(), "端口无效") { + if // err 保存err,供当前处理流程使用 + err := sendPublicSMTP(context.Background(), "smtp.example.com:not-a-port", "smtp.example.com", nil, "a@example.com", "b@example.com", nil); err == nil || !strings.Contains(err.Error(), "端口无效") { t.Fatalf("invalid port must be rejected, got %v", err) } - if err := sendPublicSMTP(context.Background(), "127.0.0.1:25", "127.0.0.1", nil, "a@example.com", "b@example.com", nil); err == nil || !strings.Contains(err.Error(), "非公网") { + if // err 保存err,供当前处理流程使用 + err := sendPublicSMTP(context.Background(), "127.0.0.1:25", "127.0.0.1", nil, "a@example.com", "b@example.com", nil); err == nil || !strings.Contains(err.Error(), "非公网") { t.Fatalf("loopback SMTP must be rejected, got %v", err) } } +// TestSendPublicSMTPRequiresAdvertisedSTARTTLS 负责TestSendPublicSMTPRequiresAdvertisedSTARTTLS相关处理。 func TestSendPublicSMTPRequiresAdvertisedSTARTTLS(t *testing.T) { + // original 保存original,供当前处理流程使用 original := dialPublicSMTP dialPublicSMTP = func(context.Context, string, string, time.Duration) (net.Conn, error) { + // client、server 保存client、server,供当前处理流程使用 client, server := net.Pipe() go func() { defer server.Close() + // reader 保存reader,供当前处理流程使用 reader := bufio.NewReader(server) _, _ = server.Write([]byte("220 smtp.example.test ESMTP\r\n")) _, _ = reader.ReadString('\n') @@ -37,6 +45,7 @@ func TestSendPublicSMTPRequiresAdvertisedSTARTTLS(t *testing.T) { return client, nil } t.Cleanup(func() { dialPublicSMTP = original }) + // err 保存err,供当前处理流程使用 err := sendPublicSMTP(context.Background(), "smtp.example.test:587", "smtp.example.test", nil, "a@example.test", "b@example.test", nil, smtpTransportOptions{UseSTARTTLS: true}) if err == nil || !strings.Contains(err.Error(), "STARTTLS") {