diff --git a/.commentlint/go-baseline.json b/.commentlint/go-baseline.json index 5be6921..2738579 100644 --- a/.commentlint/go-baseline.json +++ b/.commentlint/go-baseline.json @@ -18329,2388 +18329,6 @@ "kind": "local-variable", "name": "err" }, - { - "file": "internal/renewal/cooldown.go", - "line": 21, - "kind": "function", - "name": "NewCooldownManager" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 29, - "kind": "function", - "name": "MarkSessionExpired" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 38, - "kind": "function", - "name": "IsSessionCooled" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 44, - "kind": "local-variable", - "name": "last" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 48, - "kind": "local-variable", - "name": "remain" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 52, - "kind": "function", - "name": "TryPasswordLogin" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 53, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 53, - "kind": "local-variable", - "name": "remain" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 70, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 71, - "kind": "local-variable", - "name": "last" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 73, - "kind": "local-variable", - "name": "remain" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 78, - "kind": "local-variable", - "name": "lastErr" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 80, - "kind": "local-variable", - "name": "remain" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 88, - "kind": "function", - "name": "MarkPasswordLogin" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 94, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 98, - "kind": "function", - "name": "MarkPasswordError" - }, - { - "file": "internal/renewal/cooldown.go", - "line": 107, - "kind": "function", - "name": "Reset" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 8, - "kind": "function", - "name": "TestPasswordLoginAllowedDoesNotStartCooldown" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 9, - "kind": "local-variable", - "name": "m" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 10, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 11, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 11, - "kind": "local-variable", - "name": "reason" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 11, - "kind": "local-variable", - "name": "remain" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 18, - "kind": "function", - "name": "TestPasswordLoginCooldownStartsOnlyWhenMarked" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 19, - "kind": "local-variable", - "name": "m" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 21, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 21, - "kind": "local-variable", - "name": "reason" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 21, - "kind": "local-variable", - "name": "remain" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 27, - "kind": "function", - "name": "TestPasswordErrorCooldownReason" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 28, - "kind": "local-variable", - "name": "m" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 30, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 30, - "kind": "local-variable", - "name": "reason" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 30, - "kind": "local-variable", - "name": "remain" - }, - { - "file": "internal/renewal/cooldown_test.go", - "line": 35, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 22, - "kind": "const", - "name": "loginRenewInterval" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 23, - "kind": "const", - "name": "cookiesRefreshInterval" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 24, - "kind": "const", - "name": "apiCookieRenewInterval" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 25, - "kind": "const", - "name": "accountRequestInterval" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 26, - "kind": "const", - "name": "sessionExpiredCooldown" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 27, - "kind": "const", - "name": "passwordLoginCooldown" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 28, - "kind": "const", - "name": "passwordErrorCooldown" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 32, - "kind": "const", - "name": "loginRenewEnabledSetting" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 33, - "kind": "const", - "name": "loginRenewIntervalSetting" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 34, - "kind": "const", - "name": "apiCookieRenewEnabledSetting" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 35, - "kind": "const", - "name": "apiCookieRenewIntervalSetting" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 36, - "kind": "const", - "name": "cookiesRefreshEnabledSetting" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 37, - "kind": "const", - "name": "cookiesRefreshIntervalSetting" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 40, - "kind": "type", - "name": "AccountStarter" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 44, - "kind": "type", - "name": "accountRestarter" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 48, - "kind": "type", - "name": "PasswordRefresher" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 52, - "kind": "type", - "name": "Scheduler" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 67, - "kind": "type", - "name": "RenewalNotifier" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 76, - "kind": "var", - "name": "notifier" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 93, - "kind": "function", - "name": "Run" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 127, - "kind": "function", - "name": "runAPICookieRenewFixed" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 132, - "kind": "local-variable", - "name": "timer" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 147, - "kind": "function", - "name": "runFixed" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 152, - "kind": "local-variable", - "name": "interval" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 153, - "kind": "local-variable", - "name": "timer" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 168, - "kind": "function", - "name": "executeLoginRenew" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 170, - "kind": "local-variable", - "name": "batchID" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 171, - "kind": "local-variable", - "name": "accounts" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 171, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 176, - "kind": "range-variable", - "name": "account" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 176, - "kind": "range-variable", - "name": "i" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 188, - "kind": "function", - "name": "loginRenewOne" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 189, - "kind": "local-variable", - "name": "credentialUnlock" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 190, - "kind": "local-variable", - "name": "credentialUpdated" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 191, - "kind": "local-variable", - "name": "sessionExpired" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 207, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 208, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 208, - "kind": "local-variable", - "name": "latest" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 217, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 217, - "kind": "local-variable", - "name": "runCtx" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 219, - "kind": "var", - "name": "mtopCtx" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 220, - "kind": "var", - "name": "cookieSession" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 221, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 221, - "kind": "local-variable", - "name": "snapshot" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 226, - "kind": "local-variable", - "name": "callErr" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 226, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 232, - "kind": "local-variable", - "name": "changed" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 232, - "kind": "local-variable", - "name": "snapshot" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 232, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 238, - "kind": "local-variable", - "name": "metadata" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 242, - "kind": "local-variable", - "name": "persistErr" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 268, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 284, - "kind": "function", - "name": "executeAPICookieRenew" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 286, - "kind": "local-variable", - "name": "batchID" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 287, - "kind": "local-variable", - "name": "accounts" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 287, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 292, - "kind": "range-variable", - "name": "account" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 292, - "kind": "range-variable", - "name": "i" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 300, - "kind": "function", - "name": "apiCookieRenewOne" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 301, - "kind": "local-variable", - "name": "credentialUnlock" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 302, - "kind": "local-variable", - "name": "credentialLocked" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 303, - "kind": "local-variable", - "name": "credentialChanged" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 304, - "kind": "local-variable", - "name": "credentialPersisted" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 305, - "kind": "local-variable", - "name": "restartHandled" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 317, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 318, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 318, - "kind": "local-variable", - "name": "latest" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 328, - "kind": "local-variable", - "name": "callErr" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 328, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 330, - "kind": "local-variable", - "name": "message" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 341, - "kind": "local-variable", - "name": "stepDetails" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 342, - "kind": "range-variable", - "name": "step" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 346, - "kind": "local-variable", - "name": "updated" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 348, - "kind": "local-variable", - "name": "metadata" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 375, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 375, - "kind": "local-variable", - "name": "restarter" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 378, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 386, - "kind": "local-variable", - "name": "status" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 417, - "kind": "function", - "name": "restartAfterCredentialUpdate" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 421, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 421, - "kind": "local-variable", - "name": "restarter" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 426, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 431, - "kind": "function", - "name": "renewAPI" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 432, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 432, - "kind": "local-variable", - "name": "runCtx" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 437, - "kind": "function", - "name": "watchPendingAPIRenew" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 444, - "kind": "local-variable", - "name": "waitCancel" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 444, - "kind": "local-variable", - "name": "waitCtx" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 445, - "kind": "local-variable", - "name": "late" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 445, - "kind": "local-variable", - "name": "waitErr" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 454, - "kind": "local-variable", - "name": "opCancel" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 454, - "kind": "local-variable", - "name": "opCtx" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 456, - "kind": "var", - "name": "finalErr" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 457, - "kind": "local-variable", - "name": "changed" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 458, - "kind": "local-variable", - "name": "unlock" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 469, - "kind": "local-variable", - "name": "changed" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 469, - "kind": "local-variable", - "name": "metadata" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 469, - "kind": "local-variable", - "name": "newCookies" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 473, - "kind": "local-variable", - "name": "saveErr" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 485, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 485, - "kind": "local-variable", - "name": "restarter" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 486, - "kind": "local-variable", - "name": "enabled" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 486, - "kind": "local-variable", - "name": "statusErr" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 494, - "kind": "local-variable", - "name": "restartErr" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 508, - "kind": "local-variable", - "name": "status" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 509, - "kind": "local-variable", - "name": "errorMessage" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 530, - "kind": "function", - "name": "wakeCredentialBlockedAutomation" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 534, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 541, - "kind": "function", - "name": "apiRenewEnabled" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 548, - "kind": "function", - "name": "apiRenewInterval" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 555, - "kind": "function", - "name": "settingConfigured" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 559, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 559, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 563, - "kind": "function", - "name": "reloadRenewalAccount" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 587, - "kind": "function", - "name": "saveRenewedCookies" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 588, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 595, - "kind": "function", - "name": "addLoginLog" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 609, - "kind": "function", - "name": "addAPILog" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 610, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 617, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 617, - "kind": "local-variable", - "name": "statuses" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 624, - "kind": "local-variable", - "name": "reason" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 634, - "kind": "function", - "name": "cleanupExpiredLogs" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 638, - "kind": "local-variable", - "name": "days" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 639, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 644, - "kind": "function", - "name": "markSessionExpired" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 648, - "kind": "function", - "name": "isSessionCooled" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 649, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 653, - "kind": "function", - "name": "settingEnabled" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 657, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 657, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 671, - "kind": "function", - "name": "settingInterval" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 675, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 675, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 680, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 680, - "kind": "local-variable", - "name": "seconds" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 683, - "kind": "local-variable", - "name": "d" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 683, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 689, - "kind": "function", - "name": "settingInt" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 693, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 693, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 697, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 697, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 704, - "kind": "function", - "name": "newBatchID" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 705, - "kind": "var", - "name": "b" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 706, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 712, - "kind": "function", - "name": "sleepCtx" - }, - { - "file": "internal/renewal/scheduler.go", - "line": 716, - "kind": "local-variable", - "name": "timer" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 22, - "kind": "type", - "name": "schedulerRoundTripperFunc" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 24, - "kind": "function", - "name": "RoundTrip" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 28, - "kind": "function", - "name": "newSchedulerTestStore" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 30, - "kind": "local-variable", - "name": "d" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 30, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 37, - "kind": "type", - "name": "schedulerFakeStarter" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 42, - "kind": "function", - "name": "Start" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 47, - "kind": "function", - "name": "Restart" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 52, - "kind": "type", - "name": "schedulerContextStarter" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 58, - "kind": "function", - "name": "Start" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 60, - "kind": "function", - "name": "Restart" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 69, - "kind": "type", - "name": "schedulerFakePasswordRefresher" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 73, - "kind": "type", - "name": "schedulerFakeNotifier" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 79, - "kind": "function", - "name": "NotifyAccountEvent" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 85, - "kind": "function", - "name": "OnPasswordLoginRefresh" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 90, - "kind": "type", - "name": "apiRenewLogSnapshot" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 102, - "kind": "function", - "name": "createSchedulerAccount" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 104, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 105, - "kind": "local-variable", - "name": "username" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 106, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 106, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 109, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 109, - "kind": "local-variable", - "name": "user" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 113, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 119, - "kind": "function", - "name": "lastAPIRenewLog" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 121, - "kind": "var", - "name": "log" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 122, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 137, - "kind": "function", - "name": "schedulerRenewServiceFromServer" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 147, - "kind": "function", - "name": "TestSchedulerIntervalsAligned" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 159, - "kind": "function", - "name": "TestPendingAPIRenewLogsPendingAndRestartsAfterLateCookie" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 160, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 160, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 162, - "kind": "local-variable", - "name": "account" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 163, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 169, - "kind": "local-variable", - "name": "starter" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 170, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 175, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 178, - "kind": "local-variable", - "name": "deadline" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 182, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 185, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 185, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 192, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 197, - "kind": "function", - "name": "TestAPICookieRenewSuccessWithoutCredentialChangeDoesNotRestart" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 198, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 198, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 200, - "kind": "local-variable", - "name": "expire" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 201, - "kind": "local-variable", - "name": "account" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 202, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 206, - "kind": "local-variable", - "name": "starter" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 207, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 210, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 213, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 218, - "kind": "function", - "name": "TestPendingAPIRenewUsesFreshContextForRestart" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 219, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 219, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 221, - "kind": "local-variable", - "name": "expire" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 222, - "kind": "local-variable", - "name": "account" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 223, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 229, - "kind": "local-variable", - "name": "starter" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 230, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 233, - "kind": "local-variable", - "name": "deadline" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 242, - "kind": "function", - "name": "TestPendingAPIRenewStopsWithSchedulerContext" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 243, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 243, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 245, - "kind": "local-variable", - "name": "account" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 246, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 252, - "kind": "local-variable", - "name": "starter" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 253, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 255, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 255, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 259, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 262, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 262, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 271, - "kind": "function", - "name": "TestPendingAPIRenewRestartFailureIsFinalFailure" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 272, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 272, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 274, - "kind": "local-variable", - "name": "account" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 275, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 281, - "kind": "local-variable", - "name": "starter" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 282, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 285, - "kind": "local-variable", - "name": "deadline" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 287, - "kind": "local-variable", - "name": "log" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 299, - "kind": "function", - "name": "futureSchedulerMillis" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 303, - "kind": "function", - "name": "TestAPIRenewCompatibilitySettingsUseSingleRunner" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 304, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 304, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 306, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 306, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 308, - "kind": "local-variable", - "name": "expire" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 310, - "kind": "range-variable", - "name": "key" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 311, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 315, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 318, - "kind": "var", - "name": "requests" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 319, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 324, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 327, - "kind": "local-variable", - "name": "deadline" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 332, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 337, - "kind": "function", - "name": "TestSchedulerDefaultsMatchUpstreamConfig" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 338, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 338, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 340, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 341, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 354, - "kind": "function", - "name": "TestAPICookieRenewFailureNotifiesOnlyAtThirdConsecutiveFailure" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 355, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 355, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 357, - "kind": "local-variable", - "name": "notifier" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 358, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 359, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 360, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 375, - "kind": "function", - "name": "TestLoginRenewPreservesValidTokenCache" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 376, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 376, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 378, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 379, - "kind": "local-variable", - "name": "account" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 380, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 383, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 389, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 393, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 393, - "kind": "local-variable", - "name": "token" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 397, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 397, - "kind": "local-variable", - "name": "updated" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 403, - "kind": "function", - "name": "TestLoginRenewSessionExpiredStartsImmediateRecovery" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 404, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 404, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 406, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 407, - "kind": "local-variable", - "name": "account" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 408, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 412, - "kind": "local-variable", - "name": "refresher" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 413, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 418, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 423, - "kind": "function", - "name": "TestLoginRenewPersistsAuthoritativeSessionBeforeParseError" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 424, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 424, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 426, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 427, - "kind": "local-variable", - "name": "account" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 429, - "kind": "local-variable", - "name": "snapshot" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 435, - "kind": "local-variable", - "name": "metadata" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 436, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 440, - "kind": "var", - "name": "requestCookie" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 441, - "kind": "local-variable", - "name": "client" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 453, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 457, - "kind": "range-variable", - "name": "want" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 462, - "kind": "range-variable", - "name": "unwanted" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 468, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 468, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 478, - "kind": "local-variable", - "name": "gotSnapshot" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 478, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 482, - "kind": "local-variable", - "name": "values" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 483, - "kind": "range-variable", - "name": "cookie" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 493, - "kind": "function", - "name": "TestSchedulerSettingEnabledOverrides" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 494, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 494, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 496, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 497, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 499, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 505, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 513, - "kind": "function", - "name": "TestSchedulerSettingIntervalOverrides" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 514, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 514, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 516, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 517, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 519, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 522, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 525, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 528, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 531, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 534, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 537, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 542, - "kind": "function", - "name": "TestSchedulerSettingIntOverrides" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 543, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 543, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 545, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 546, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 548, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 551, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 554, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 557, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 560, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 565, - "kind": "function", - "name": "TestRenewalCleanupLogsUsesRetentionDays" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 566, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 566, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 568, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 569, - "kind": "local-variable", - "name": "cookie" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 572, - "kind": "range-variable", - "name": "table" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 577, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 581, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 586, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 589, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 591, - "kind": "range-variable", - "name": "table" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 596, - "kind": "var", - "name": "newRows" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 596, - "kind": "var", - "name": "oldRows" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 597, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 600, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 609, - "kind": "function", - "name": "TestAPICookieRenewOneSkipsExpiredLongLoginWithoutEscalation" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 610, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 610, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 612, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 613, - "kind": "local-variable", - "name": "account" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 614, - "kind": "local-variable", - "name": "refresher" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 615, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 621, - "kind": "local-variable", - "name": "log" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 627, - "kind": "function", - "name": "TestAPICookieRenewOneUsesSingleSilentRequestAndSavesCookies" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 628, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 628, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 630, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 631, - "kind": "local-variable", - "name": "expire" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 632, - "kind": "local-variable", - "name": "account" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 633, - "kind": "local-variable", - "name": "refresher" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 634, - "kind": "local-variable", - "name": "starter" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 635, - "kind": "var", - "name": "requests" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 636, - "kind": "local-variable", - "name": "srv" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 643, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 653, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 653, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/renewal/scheduler_test.go", - "line": 657, - "kind": "local-variable", - "name": "log" - }, { "file": "internal/version/version.go", "line": 7, diff --git a/docs/architecture/refactoring-master-plan.md b/docs/architecture/refactoring-master-plan.md index 5d0a5b7..eafa402 100644 --- a/docs/architecture/refactoring-master-plan.md +++ b/docs/architecture/refactoring-master-plan.md @@ -634,3 +634,4 @@ npm --prefix frontend run build | 2026-08-15 | 完成阶段 10 第八个 PR 切片“Go internal/automation 注释基线按领域清零” | 为自动化中心、账号任务、动作执行器、事件流水线、运行协调器、调度器、通知器及其测试补齐函数、变量、字段和常量中文注释;`internal/automation` 注释基线清零;Automation 定向测试、`go test -race ./internal/automation`、全量 Go/React 门禁通过,合并为一个可回滚提交 | 阶段 10:继续清理 Go internal/account、internal/adapter、internal/renewal、internal/notify、internal/chat 等领域注释基线 | | 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 等领域注释基线 | diff --git a/internal/renewal/cooldown.go b/internal/renewal/cooldown.go index dee28db..bfeecb9 100644 --- a/internal/renewal/cooldown.go +++ b/internal/renewal/cooldown.go @@ -7,6 +7,7 @@ import ( // CooldownManager 保存登录恢复相关冷却状态。 // Scheduler 和运行时 Adapter 共用同一实例,避免同一账号被重复触发密码登录。 +// CooldownManager 保存CooldownManager,供当前处理流程使用 type CooldownManager struct { mu sync.Mutex @@ -18,6 +19,7 @@ type CooldownManager struct { // GlobalCooldown 是服务进程内的统一续期冷却状态。 var GlobalCooldown = NewCooldownManager() +// NewCooldownManager 负责NewCooldownManager相关处理。 func NewCooldownManager() *CooldownManager { return &CooldownManager{ sessionExpiredByCookie: make(map[string]time.Time), @@ -26,6 +28,7 @@ func NewCooldownManager() *CooldownManager { } } +// MarkSessionExpired 负责Mark会话Expired相关处理。 func (m *CooldownManager) MarkSessionExpired(cookieID string) { if m == nil { return @@ -35,21 +38,26 @@ func (m *CooldownManager) MarkSessionExpired(cookieID string) { m.sessionExpiredByCookie[cookieID] = time.Now() } +// IsSessionCooled 负责Is会话Cooled相关处理。 func (m *CooldownManager) IsSessionCooled(cookieID string) (bool, time.Duration) { if m == nil { return false, 0 } m.mu.Lock() defer m.mu.Unlock() + // last 保存last,供当前处理流程使用 last := m.sessionExpiredByCookie[cookieID] if last.IsZero() { return false, 0 } + // remain 保存remain,供当前处理流程使用 remain := sessionExpiredCooldown - time.Since(last) return remain > 0, remain } +// TryPasswordLogin 负责Try密码登录相关处理。 func (m *CooldownManager) TryPasswordLogin(cookieID string) (bool, time.Duration) { + // ok、remain 保存ok、remain,供当前处理流程使用 ok, remain, _ := m.PasswordLoginAllowed(cookieID, passwordLoginCooldown) if !ok { return false, remain @@ -61,22 +69,28 @@ func (m *CooldownManager) TryPasswordLogin(cookieID string) (bool, time.Duration // PasswordLoginAllowed 只检查冷却而不写入时间。参考运行时只在真实密码 // 登录拿到 Cookie 后记录登录时间,接口/浏览器轻量续期和失败尝试都不能启动 // 登录冷却。reason 为 login_cooldown 或 password_error_cooldown。 +// PasswordLoginAllowed 负责密码登录Allowed相关处理。 func (m *CooldownManager) PasswordLoginAllowed(cookieID string, loginCooldown time.Duration) (bool, time.Duration, string) { if m == nil { return true, 0, "" } m.mu.Lock() defer m.mu.Unlock() + // now 保存now,供当前处理流程使用 now := time.Now() + // last 保存last,供当前处理流程使用 last := m.passwordLoginByCookie[cookieID] if !last.IsZero() { + // remain 保存remain,供当前处理流程使用 remain := loginCooldown - now.Sub(last) if remain > 0 { return false, remain, "login_cooldown" } } + // lastErr 保存lastErr,供当前处理流程使用 lastErr := m.passwordErrorByCookie[cookieID] if !lastErr.IsZero() { + // remain 保存remain,供当前处理流程使用 remain := passwordErrorCooldown - now.Sub(lastErr) if remain > 0 { return false, remain, "password_error_cooldown" @@ -85,16 +99,19 @@ func (m *CooldownManager) PasswordLoginAllowed(cookieID string, loginCooldown ti return true, 0, "" } +// MarkPasswordLogin 负责Mark密码登录相关处理。 func (m *CooldownManager) MarkPasswordLogin(cookieID string) { if m == nil { return } m.mu.Lock() defer m.mu.Unlock() + // now 保存now,供当前处理流程使用 now := time.Now() m.passwordLoginByCookie[cookieID] = now } +// MarkPasswordError 负责Mark密码错误相关处理。 func (m *CooldownManager) MarkPasswordError(cookieID string) { if m == nil { return @@ -104,6 +121,7 @@ func (m *CooldownManager) MarkPasswordError(cookieID string) { m.passwordErrorByCookie[cookieID] = time.Now() } +// Reset 负责Reset相关处理。 func (m *CooldownManager) Reset(cookieID string) { if m == nil { return diff --git a/internal/renewal/cooldown_test.go b/internal/renewal/cooldown_test.go index fe6616e..fac32dd 100644 --- a/internal/renewal/cooldown_test.go +++ b/internal/renewal/cooldown_test.go @@ -5,9 +5,13 @@ import ( "time" ) +// TestPasswordLoginAllowedDoesNotStartCooldown 负责Test密码登录AllowedDoesNot开始Cooldown相关处理。 func TestPasswordLoginAllowedDoesNotStartCooldown(t *testing.T) { + // m 保存m,供当前处理流程使用 m := NewCooldownManager() - for i := 0; i < 2; i++ { + for // i 保存i,供当前处理流程使用 + i := 0; i < 2; i++ { + // ok、remain、reason 保存ok、remain、reason,供当前处理流程使用 ok, remain, reason := m.PasswordLoginAllowed("cid", 60*time.Second) if !ok || remain != 0 || reason != "" { t.Fatalf("check %d: ok=%v remain=%s reason=%q", i, ok, remain, reason) @@ -15,24 +19,31 @@ func TestPasswordLoginAllowedDoesNotStartCooldown(t *testing.T) { } } +// TestPasswordLoginCooldownStartsOnlyWhenMarked 负责Test密码登录CooldownStartsOnlyWhenMarked相关处理。 func TestPasswordLoginCooldownStartsOnlyWhenMarked(t *testing.T) { + // m 保存m,供当前处理流程使用 m := NewCooldownManager() m.MarkPasswordLogin("cid") + // ok、remain、reason 保存ok、remain、reason,供当前处理流程使用 ok, remain, reason := m.PasswordLoginAllowed("cid", 60*time.Second) if ok || remain <= 0 || remain > 60*time.Second || reason != "login_cooldown" { t.Fatalf("ok=%v remain=%s reason=%q", ok, remain, reason) } } +// TestPasswordErrorCooldownReason 负责Test密码错误Cooldown原因相关处理。 func TestPasswordErrorCooldownReason(t *testing.T) { + // m 保存m,供当前处理流程使用 m := NewCooldownManager() m.MarkPasswordError("cid") + // ok、remain、reason 保存ok、remain、reason,供当前处理流程使用 ok, remain, reason := m.PasswordLoginAllowed("cid", 60*time.Second) if ok || remain <= 0 || reason != "password_error_cooldown" { t.Fatalf("ok=%v remain=%s reason=%q", ok, remain, reason) } m.Reset("cid") - if ok, _, _ := m.PasswordLoginAllowed("cid", 60*time.Second); !ok { + if // ok 保存ok,供当前处理流程使用 + ok, _, _ := m.PasswordLoginAllowed("cid", 60*time.Second); !ok { t.Fatal("Reset 后应解除冷却") } } diff --git a/internal/renewal/scheduler.go b/internal/renewal/scheduler.go index 4ef638c..0f6649f 100644 --- a/internal/renewal/scheduler.go +++ b/internal/renewal/scheduler.go @@ -18,6 +18,7 @@ import ( apirenew "xianyu-go/internal/xianyu/renew" ) +// loginRenewInterval 保存登录RenewInterval,供当前处理流程使用 const ( loginRenewInterval = 600 * time.Second cookiesRefreshInterval = 600 * time.Second @@ -28,6 +29,7 @@ const ( passwordErrorCooldown = 5 * time.Hour ) +// loginRenewEnabledSetting 保存登录Renew启用状态设置,供当前处理流程使用 const ( loginRenewEnabledSetting = "renewal.login_renew.enabled" loginRenewIntervalSetting = "renewal.login_renew.interval_seconds" @@ -37,18 +39,22 @@ const ( cookiesRefreshIntervalSetting = "renewal.cookies_refresh.interval_seconds" ) +// AccountStarter 保存账号Starter,供当前处理流程使用 type AccountStarter interface { Start(ctx context.Context, cookieID, cookieValue string) error } +// accountRestarter 保存账号Restarter,供当前处理流程使用 type accountRestarter interface { Restart(ctx context.Context, cookieID string) error } +// PasswordRefresher 保存密码Refresher,供当前处理流程使用 type PasswordRefresher interface { OnPasswordLoginRefresh(ctx context.Context, cookieID string) bool } +// Scheduler 保存Scheduler,供当前处理流程使用 type Scheduler struct { store *db.Store starter AccountStarter @@ -64,6 +70,7 @@ type Scheduler struct { watchers sync.WaitGroup } +// RenewalNotifier 保存RenewalNotifier,供当前处理流程使用 type RenewalNotifier interface { NotifyAccountEvent(cookieID, eventType, level, title, body string) } @@ -73,6 +80,7 @@ func NewScheduler(store *db.Store, starter AccountStarter, refresher PasswordRef if logger == nil { logger = slog.Default() } + // notifier 保存notifier,供当前处理流程使用 var notifier RenewalNotifier if len(notifiers) > 0 { notifier = notifiers[0] @@ -90,6 +98,7 @@ func NewScheduler(store *db.Store, starter AccountStarter, refresher PasswordRef } } +// Run 执行当前值。 func (s *Scheduler) Run(ctx context.Context) { if s == nil || s.store == nil { return @@ -124,11 +133,13 @@ func (s *Scheduler) Wait() { <-s.done } +// runAPICookieRenewFixed 负责运行API登录凭证RenewFixed相关处理。 func (s *Scheduler) runAPICookieRenewFixed(ctx context.Context) { if s.apiRenewEnabled(ctx) { s.executeAPICookieRenew(ctx) } for { + // timer 保存定时器,供当前处理流程使用 timer := time.NewTimer(s.apiRenewInterval(ctx)) select { case <-ctx.Done(): @@ -144,12 +155,15 @@ func (s *Scheduler) runAPICookieRenewFixed(ctx context.Context) { } } +// runFixed 负责运行Fixed相关处理。 func (s *Scheduler) runFixed(ctx context.Context, name, settingKey, intervalKey string, defaultEnabled bool, defaultInterval time.Duration, fn func(context.Context)) { if s.settingEnabled(ctx, settingKey, defaultEnabled) { fn(ctx) } for { + // interval 保存interval,供当前处理流程使用 interval := s.settingInterval(ctx, intervalKey, defaultInterval) + // timer 保存定时器,供当前处理流程使用 timer := time.NewTimer(interval) select { case <-ctx.Done(): @@ -165,14 +179,18 @@ func (s *Scheduler) runFixed(ctx context.Context, name, settingKey, intervalKey } } +// executeLoginRenew 负责execute登录Renew相关处理。 func (s *Scheduler) executeLoginRenew(ctx context.Context) { s.cleanupExpiredLogs(ctx) + // batchID 保存批次ID,供当前处理流程使用 batchID := newBatchID() + // accounts、err 保存accounts、err,供当前处理流程使用 accounts, err := s.store.Cookies.ActiveRenewalRuntimeAccounts(ctx) if err != nil { s.logger.Warn("login_renew 加载账号失败", "err", err) return } + // i、account 表示当前遍历过程中的i、account for i, account := range accounts { if s.isSessionCooled(account.ID) { s.logger.Info("login_renew session 冷却中,跳过", "account", account.ID) @@ -185,9 +203,13 @@ func (s *Scheduler) executeLoginRenew(ctx context.Context) { } } +// loginRenewOne 负责登录RenewOne相关处理。 func (s *Scheduler) loginRenewOne(ctx context.Context, batchID string, account db.RenewalRuntimeAccount) { + // credentialUnlock 保存credentialUnlock,供当前处理流程使用 credentialUnlock := s.store.LockAccountCredentials(account.ID) + // credentialUpdated 保存credentialUpdated,供当前处理流程使用 credentialUpdated := false + // sessionExpired 保存会话Expired,供当前处理流程使用 sessionExpired := false defer func() { credentialUnlock() @@ -204,7 +226,9 @@ func (s *Scheduler) loginRenewOne(ctx context.Context, batchID string, account d s.restartAfterCredentialUpdate(ctx, account.ID, account.Enabled, "登录态续期") } }() + // started 保存started,供当前处理流程使用 started := time.Now() + // latest、err 保存latest、err,供当前处理流程使用 latest, err := s.reloadRenewalAccount(ctx, account) if err != nil { s.addLoginLog(ctx, batchID, account.ID, "failed", "重读账号凭证失败: "+err.Error(), nil, time.Since(started)) @@ -214,32 +238,42 @@ func (s *Scheduler) loginRenewOne(ctx context.Context, batchID string, account d if !account.Enabled { return } + // runCtx、cancel 保存运行Ctx、cancel,供当前处理流程使用 runCtx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() + // mtopCtx 保存mtopCtx,供当前处理流程使用 var mtopCtx context.Context + // cookieSession 保存登录凭证会话,供当前处理流程使用 var cookieSession *mtop.CookieSession - if snapshot, ok := cookierefresh.SnapshotFromMetadataOK(account.MetadataJSON); ok { + if // snapshot、ok 保存snapshot、ok,供当前处理流程使用 + snapshot, ok := cookierefresh.SnapshotFromMetadataOK(account.MetadataJSON); ok { mtopCtx, cookieSession = mtop.WithCookieSnapshot(runCtx, snapshot) } else { mtopCtx, cookieSession = mtop.WithFlatCookieSession(runCtx, account.Value) } + // res、callErr 保存res、callErr,供当前处理流程使用 res, callErr := s.mtop.CheckLoginStatusContext(mtopCtx, account.Value) // 对齐浏览器在响应头到达时立即应用 Set-Cookie 的时序。权威 session // 因此必须在处理请求或解析错误之前持久化,否则下次请求会 // 从数据库回滚到旧 Jar。 + // updated 保存updated,供当前处理流程使用 updated := []string(nil) + // value、snapshot、changed 保存value、snapshot、changed,供当前处理流程使用 value, snapshot, changed := cookieSession.State() // 完整 Jar 即使本轮没有变化也已经权威接管请求;不能因扁平 Cookie // 的顺序或尾分号不同回退写入并清掉快照。 + // sessionHandled 保存会话Handled,供当前处理流程使用 sessionHandled := snapshot != nil if changed { updated = cookierefresh.ChangedCookieNames(account.Value, value) + // metadata 保存metadata,供当前处理流程使用 metadata := cookierefresh.MetadataWithoutSnapshot(account.MetadataJSON) if snapshot != nil { metadata = cookierefresh.MetadataWithSnapshot(account.MetadataJSON, snapshot) } - if persistErr := s.store.Cookies.UpdateRenewalCookie(ctx, account.ID, value, metadata, time.Now().Unix()); persistErr != nil { + if // persistErr 保存persistErr,供当前处理流程使用 + persistErr := s.store.Cookies.UpdateRenewalCookie(ctx, account.ID, value, metadata, time.Now().Unix()); persistErr != nil { if callErr != nil { persistErr = errors.Join(callErr, fmt.Errorf("保存 loginuser.get 响应 Cookie Jar: %w", persistErr)) } @@ -264,8 +298,10 @@ func (s *Scheduler) loginRenewOne(ctx context.Context, batchID string, account d // 注入 mock 或没有权威快照的历史账号仍走扁平 // Cookie 兼容路径。扁平值无法证明旧 snapshot 的 // Domain/Path/expiry 仍有效,因此必须清除旧快照。 + // metadata 保存metadata,供当前处理流程使用 metadata := cookierefresh.MetadataWithoutSnapshot(account.MetadataJSON) - if err := s.store.Cookies.UpdateRenewalCookie(ctx, account.ID, res.UpdatedCookies, metadata, time.Now().Unix()); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.store.Cookies.UpdateRenewalCookie(ctx, account.ID, res.UpdatedCookies, metadata, time.Now().Unix()); err != nil { s.addLoginLog(ctx, batchID, account.ID, "failed", "保存 Cookie 失败: "+err.Error(), updated, time.Since(started)) return } @@ -281,14 +317,18 @@ func (s *Scheduler) loginRenewOne(ctx context.Context, batchID string, account d } } +// executeAPICookieRenew 负责executeAPI登录凭证Renew相关处理。 func (s *Scheduler) executeAPICookieRenew(ctx context.Context) { s.cleanupExpiredLogs(ctx) + // batchID 保存批次ID,供当前处理流程使用 batchID := newBatchID() + // accounts、err 保存accounts、err,供当前处理流程使用 accounts, err := s.store.Cookies.ActiveRenewalRuntimeAccounts(ctx) if err != nil { s.logger.Warn("api_cookie_renew 加载账号失败", "err", err) return } + // i、account 表示当前遍历过程中的i、account for i, account := range accounts { s.apiCookieRenewOne(ctx, batchID, account) if i < len(accounts)-1 { @@ -297,11 +337,17 @@ func (s *Scheduler) executeAPICookieRenew(ctx context.Context) { } } +// apiCookieRenewOne 负责api登录凭证RenewOne相关处理。 func (s *Scheduler) apiCookieRenewOne(ctx context.Context, batchID string, account db.RenewalRuntimeAccount) { + // credentialUnlock 保存credentialUnlock,供当前处理流程使用 credentialUnlock := s.store.LockAccountCredentials(account.ID) + // credentialLocked 保存credentialLocked,供当前处理流程使用 credentialLocked := true + // credentialChanged 保存credentialChanged,供当前处理流程使用 credentialChanged := false + // credentialPersisted 保存credentialPersisted,供当前处理流程使用 credentialPersisted := false + // restartHandled 保存restartHandled,供当前处理流程使用 restartHandled := false defer func() { if credentialLocked { @@ -314,7 +360,9 @@ func (s *Scheduler) apiCookieRenewOne(ctx context.Context, batchID string, accou } } }() + // started 保存started,供当前处理流程使用 started := time.Now() + // latest、err 保存latest、err,供当前处理流程使用 latest, err := s.reloadRenewalAccount(ctx, account) if err != nil { s.addAPILog(ctx, db.RenewalLog{BatchID: batchID, CookieID: account.ID, Status: "failed", ErrorMessage: "重读账号凭证失败: " + err.Error(), RenewMethod: "auto_login_plugin"}) @@ -325,8 +373,10 @@ func (s *Scheduler) apiCookieRenewOne(ctx context.Context, batchID string, accou if !account.Enabled { return } + // res、callErr 保存res、callErr,供当前处理流程使用 res, callErr := s.renewAPI(ctx, account.Value, cookierefresh.SnapshotFromMetadata(account.MetadataJSON)) if res == nil { + // message 保存消息,供当前处理流程使用 message := "接口续期未返回结果" if callErr != nil { message = callErr.Error() @@ -338,13 +388,17 @@ func (s *Scheduler) apiCookieRenewOne(ctx context.Context, batchID string, accou if res.HasPending() { s.watchPendingAPIRenew(ctx, batchID, account.ID, res) } + // stepDetails 保存stepDetails,供当前处理流程使用 stepDetails := make([]string, 0, len(res.StepDetails)+1) + // step 表示当前遍历过程中的step for _, step := range res.StepDetails { stepDetails = append(stepDetails, fmt.Sprintf("%s: http=%d business_ok=%v set_cookie=%d", step.Name, step.HTTPStatus, step.BusinessOK, step.SetCookieCount)) } stepDetails = append(stepDetails, fmt.Sprintf("result: success=%v skipped=%v reason=%s", res.Success, res.Skipped, res.SkipReason)) + // updated 保存updated,供当前处理流程使用 updated := cookierefresh.ChangedCookieNames(account.Value, res.NewCookies) if res.CookieSnapshotComplete || len(res.SetCookies) > 0 || res.NewCookies != account.Value { + // metadata 保存metadata,供当前处理流程使用 metadata := cookierefresh.MetadataWithoutSnapshot(account.MetadataJSON) if res.CookieSnapshotComplete { metadata = cookierefresh.MetadataWithSnapshot(account.MetadataJSON, res.CookieSnapshot) @@ -372,10 +426,12 @@ func (s *Scheduler) apiCookieRenewOne(ctx context.Context, batchID string, accou s.logger.Info("接口续期任务成功", "account", account.ID, "method", res.RenewMethod, "updated", strings.Join(updated, ","), "message", res.Message) credentialUnlock() credentialLocked = false - if restarter, ok := s.starter.(accountRestarter); ok { + if // restarter、ok 保存restarter、ok,供当前处理流程使用 + restarter, ok := s.starter.(accountRestarter); ok { restartHandled = true s.logger.Info("接口续期成功,正在重启账号以应用最新登录凭证", "account", account.ID) - if err := restarter.Restart(ctx, account.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := restarter.Restart(ctx, account.ID); err != nil { s.addAPILog(ctx, db.RenewalLog{BatchID: batchID, CookieID: account.ID, Status: "failed", ErrorMessage: "重建消息连接失败: " + err.Error(), UpdatedCookieNames: updated, StepDetails: strings.Join(stepDetails, " | "), RenewMethod: res.RenewMethod, DurationMS: time.Since(started).Milliseconds(), RequestCount: res.RequestCount}) s.logger.Warn("接口续期成功,但重启账号失败", "account", account.ID, "err", err) return @@ -383,6 +439,7 @@ func (s *Scheduler) apiCookieRenewOne(ctx context.Context, batchID string, accou s.logger.Info("接口续期后的账号重启已完成", "account", account.ID) } } + // status 保存状态,供当前处理流程使用 status := "failed" if res.HasPending() { status = "pending" @@ -414,26 +471,32 @@ func (s *Scheduler) apiCookieRenewOne(ctx context.Context, batchID string, accou } } +// restartAfterCredentialUpdate 负责restartAfterCredentialUpdate相关处理。 func (s *Scheduler) restartAfterCredentialUpdate(ctx context.Context, accountID string, enabled bool, source string) { if !enabled || ctx.Err() != nil { return } + // restarter、ok 保存restarter、ok,供当前处理流程使用 restarter, ok := s.starter.(accountRestarter) if !ok { return } s.logger.Info("认证 Cookie 已更新,正在重启账号以刷新 WS Token", "account", accountID, "source", source) - if err := restarter.Restart(ctx, accountID); err != nil { + if // err 保存err,供当前处理流程使用 + err := restarter.Restart(ctx, accountID); err != nil { s.logger.Warn("认证 Cookie 已更新,但重启账号刷新 WS Token 失败", "account", accountID, "source", source, "err", err) } } +// renewAPI 负责renewAPI相关处理。 func (s *Scheduler) renewAPI(ctx context.Context, cookieStr string, snapshot []cookierefresh.BrowserCookie) (*apirenew.Result, error) { + // runCtx、cancel 保存运行Ctx、cancel,供当前处理流程使用 runCtx, cancel := context.WithTimeout(ctx, 90*time.Second) defer cancel() return s.api.RenewAPIFirst(runCtx, cookieStr, snapshot) } +// watchPendingAPIRenew 负责watchPendingAPIRenew相关处理。 func (s *Scheduler) watchPendingAPIRenew(ctx context.Context, batchID, cookieID string, result *apirenew.Result) { if result == nil || !result.HasPending() || s.store == nil || s.store.Cookies == nil { return @@ -441,7 +504,9 @@ func (s *Scheduler) watchPendingAPIRenew(ctx context.Context, batchID, cookieID s.watchers.Add(1) go func() { defer s.watchers.Done() + // waitCtx、waitCancel 保存waitCtx、wait取消,供当前处理流程使用 waitCtx, waitCancel := context.WithTimeout(ctx, 35*time.Second) + // late、waitErr 保存late、waitErr,供当前处理流程使用 late, waitErr := result.AwaitPending(waitCtx) waitCancel() if late == nil { @@ -451,10 +516,14 @@ func (s *Scheduler) watchPendingAPIRenew(ctx context.Context, batchID, cookieID } return } + // opCtx、opCancel 保存opCtx、op取消,供当前处理流程使用 opCtx, opCancel := context.WithTimeout(ctx, 30*time.Second) defer opCancel() + // finalErr 保存finalErr,供当前处理流程使用 var finalErr error + // changed 保存changed,供当前处理流程使用 changed := func() bool { + // unlock 保存unlock,供当前处理流程使用 unlock := s.store.LockAccountCredentials(cookieID) defer unlock() detail, getErr := s.store.Cookies.GetCookiePlatformRuntimeData(opCtx, cookieID) // detail 只包含迟到 Cookie 合并所需的 Cookie 与 metadata。 @@ -466,11 +535,13 @@ func (s *Scheduler) watchPendingAPIRenew(ctx context.Context, batchID, cookieID finalErr = getErr return false } + // newCookies、metadata、changed 保存newCookies、metadata、changed,供当前处理流程使用 newCookies, metadata, changed := apirenew.RebaseResponseCookies(detail.Value, detail.MetadataJSON, late) if !changed { return false } - if saveErr := s.store.Cookies.UpdateRenewalCookie(opCtx, cookieID, newCookies, metadata, time.Now().Unix()); saveErr != nil { + if // saveErr 保存saveErr,供当前处理流程使用 + saveErr := s.store.Cookies.UpdateRenewalCookie(opCtx, cookieID, newCookies, metadata, time.Now().Unix()); saveErr != nil { s.logger.Warn("保存定时静默续期迟到 Cookie 失败", "account", cookieID, "err", saveErr) finalErr = saveErr return false @@ -482,7 +553,9 @@ func (s *Scheduler) watchPendingAPIRenew(ctx context.Context, batchID, cookieID }() if changed { s.logger.Info("已异步接收定时静默续期迟到 Cookie", "account", cookieID) - if restarter, ok := s.starter.(accountRestarter); ok { + if // restarter、ok 保存restarter、ok,供当前处理流程使用 + restarter, ok := s.starter.(accountRestarter); ok { + // enabled、statusErr 保存enabled、statusErr,供当前处理流程使用 enabled, _, statusErr := s.store.Cookies.StatusWithReason(opCtx, cookieID) if statusErr != nil { s.logger.Warn("迟到续期 Cookie 已保存,但读取账号状态失败", "account", cookieID, "err", statusErr) @@ -491,7 +564,8 @@ func (s *Scheduler) watchPendingAPIRenew(ctx context.Context, batchID, cookieID s.logger.Info("迟到续期 Cookie 已保存,账号已停用,不执行重启", "account", cookieID) } else { s.logger.Info("迟到续期 Cookie 已更新,正在重启账号以应用最新登录凭证", "account", cookieID) - if restartErr := restarter.Restart(opCtx, cookieID); restartErr != nil { + if // restartErr 保存restartErr,供当前处理流程使用 + restartErr := restarter.Restart(opCtx, cookieID); restartErr != nil { s.logger.Warn("迟到续期 Cookie 已保存,但重启账号失败", "account", cookieID, "err", restartErr) finalErr = restartErr } else { @@ -505,7 +579,9 @@ func (s *Scheduler) watchPendingAPIRenew(ctx context.Context, batchID, cookieID s.logger.Warn("定时静默续期底层响应失败,已保存响应 Cookie", "account", cookieID, "err", waitErr) finalErr = errors.Join(finalErr, waitErr) } + // status 保存状态,供当前处理流程使用 status := "failed" + // errorMessage 保存错误消息,供当前处理流程使用 errorMessage := "" if finalErr != nil { errorMessage = finalErr.Error() @@ -527,17 +603,20 @@ func (s *Scheduler) watchPendingAPIRenew(ctx context.Context, batchID, cookieID }() } +// wakeCredentialBlockedAutomation 负责wakeCredentialBlocked自动化相关处理。 func (s *Scheduler) wakeCredentialBlockedAutomation(ctx context.Context, cookieID string) { if s == nil || s.store == nil || s.store.Automation == nil { return } - if err := s.store.Automation.WakeCredentialBlocked(ctx, cookieID); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.store.Automation.WakeCredentialBlocked(ctx, cookieID); err != nil { s.logger.Warn("Cookie 更新后唤醒自动化任务失败", "account", cookieID, "err", err) return } s.logger.Info("Cookie 更新后已唤醒待恢复自动化任务", "account", cookieID) } +// apiRenewEnabled 负责apiRenew启用状态相关处理。 func (s *Scheduler) apiRenewEnabled(ctx context.Context) bool { if s.settingConfigured(ctx, apiCookieRenewEnabledSetting) { return s.settingEnabled(ctx, apiCookieRenewEnabledSetting, true) @@ -545,6 +624,7 @@ func (s *Scheduler) apiRenewEnabled(ctx context.Context) bool { return s.settingEnabled(ctx, cookiesRefreshEnabledSetting, true) } +// apiRenewInterval 负责apiRenewInterval相关处理。 func (s *Scheduler) apiRenewInterval(ctx context.Context) time.Duration { if s.settingConfigured(ctx, apiCookieRenewIntervalSetting) { return s.settingInterval(ctx, apiCookieRenewIntervalSetting, apiCookieRenewInterval) @@ -552,14 +632,17 @@ func (s *Scheduler) apiRenewInterval(ctx context.Context) time.Duration { return s.settingInterval(ctx, cookiesRefreshIntervalSetting, apiCookieRenewInterval) } +// settingConfigured 负责设置Configured相关处理。 func (s *Scheduler) settingConfigured(ctx context.Context, key string) bool { if s.store == nil || s.store.Settings == nil { return false } + // value、err 保存value、err,供当前处理流程使用 value, err := s.store.Settings.Get(ctx, key) return err == nil && strings.TrimSpace(value) != "" } +// reloadRenewalAccount 负责reloadRenewal账号相关处理。 func (s *Scheduler) reloadRenewalAccount(ctx context.Context, account db.RenewalRuntimeAccount) (db.RenewalRuntimeAccount, error) { // latest 是锁内重新读取的续期窄模型,用于避免批次列表中的旧 Cookie 覆盖新状态。 latest, err := s.store.Cookies.GetRenewalRuntimeAccount(ctx, account.ID) @@ -584,14 +667,17 @@ Cookie 更新后的重启和自动化唤醒逻辑保持原有顺序。 Cookie 明文只在本次调用链中短暂存在。 */ +// saveRenewedCookies 负责saveRenewedCookies相关处理。 func (s *Scheduler) saveRenewedCookies(ctx context.Context, cookieID, cookieStr, metadata string) bool { - if err := s.store.Cookies.UpdateRenewalCookie(ctx, cookieID, cookieStr, metadata, time.Now().Unix()); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.store.Cookies.UpdateRenewalCookie(ctx, cookieID, cookieStr, metadata, time.Now().Unix()); err != nil { s.logger.Warn("保存续期 Cookie 失败", "account", cookieID, "err", err) return false } return true } +// addLoginLog 负责add登录Log相关处理。 func (s *Scheduler) addLoginLog(ctx context.Context, batchID, cookieID, status, message string, updated []string, duration time.Duration) { _ = s.store.Renewal.AddLoginRenewLog(ctx, db.RenewalLog{ BatchID: batchID, @@ -606,14 +692,17 @@ func (s *Scheduler) addLoginLog(ctx context.Context, batchID, cookieID, status, }) } +// addAPILog 负责addAPILog相关处理。 func (s *Scheduler) addAPILog(ctx context.Context, log db.RenewalLog) { - if err := s.store.Renewal.AddAPICookieRenewLog(ctx, log); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.store.Renewal.AddAPICookieRenewLog(ctx, log); err != nil { s.logger.Warn("记录 API Cookie 续期日志失败", "account", log.CookieID, "status", log.Status, "err", err) return } if s.notifier == nil || log.Status != "failed" || s.store == nil || s.store.Renewal == nil { return } + // statuses、err 保存statuses、err,供当前处理流程使用 statuses, err := s.store.Renewal.RecentAPICookieRenewStatuses(ctx, log.CookieID, 4) if err != nil || len(statuses) < 3 || statuses[0] != "failed" || statuses[1] != "failed" || statuses[2] != "failed" { return @@ -621,6 +710,7 @@ func (s *Scheduler) addAPILog(ctx context.Context, log db.RenewalLog) { if len(statuses) >= 4 && statuses[3] == "failed" { return } + // reason 保存原因,供当前处理流程使用 reason := strings.TrimSpace(log.ErrorMessage) if reason == "" { reason = strings.TrimSpace(log.Message) @@ -631,29 +721,37 @@ func (s *Scheduler) addAPILog(ctx context.Context, log db.RenewalLog) { s.notifier.NotifyAccountEvent(log.CookieID, "token_renewal", "warn", "闲鱼 Cookie 自动续期连续失败", fmt.Sprintf("账号 %s 的 API 自动续期已连续失败 3 次,最近错误:%s", log.CookieID, reason)) } +// cleanupExpiredLogs 负责cleanupExpiredLogs相关处理。 func (s *Scheduler) cleanupExpiredLogs(ctx context.Context) { if s.store == nil || s.store.Renewal == nil { return } + // days 保存days,供当前处理流程使用 days := s.settingInt(ctx, "renewal_log_retention_days", 10) - if err := s.store.Renewal.CleanupLogs(ctx, days); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.store.Renewal.CleanupLogs(ctx, days); err != nil { s.logger.Warn("清理续期日志失败", "err", err) } } +// markSessionExpired 负责mark会话Expired相关处理。 func (s *Scheduler) markSessionExpired(cookieID string) { s.cooldown.MarkSessionExpired(cookieID) } +// isSessionCooled 负责is会话Cooled相关处理。 func (s *Scheduler) isSessionCooled(cookieID string) bool { + // ok 保存ok,供当前处理流程使用 ok, _ := s.cooldown.IsSessionCooled(cookieID) return ok } +// settingEnabled 负责设置启用状态相关处理。 func (s *Scheduler) settingEnabled(ctx context.Context, key string, defaultEnabled bool) bool { if s.store == nil || s.store.Settings == nil { return defaultEnabled } + // value、err 保存value、err,供当前处理流程使用 value, err := s.store.Settings.Get(ctx, key) if err != nil || strings.TrimSpace(value) == "" { return defaultEnabled @@ -668,32 +766,39 @@ func (s *Scheduler) settingEnabled(ctx context.Context, key string, defaultEnabl } } +// settingInterval 负责设置Interval相关处理。 func (s *Scheduler) settingInterval(ctx context.Context, key string, defaultInterval time.Duration) time.Duration { if s.store == nil || s.store.Settings == nil { return defaultInterval } + // value、err 保存value、err,供当前处理流程使用 value, err := s.store.Settings.Get(ctx, key) if err != nil || strings.TrimSpace(value) == "" { return defaultInterval } value = strings.TrimSpace(value) - if seconds, err := strconv.ParseFloat(value, 64); err == nil && seconds > 0 { + if // seconds、err 保存seconds、err,供当前处理流程使用 + seconds, err := strconv.ParseFloat(value, 64); err == nil && seconds > 0 { return time.Duration(seconds * float64(time.Second)) } - if d, err := time.ParseDuration(value); err == nil && d > 0 { + if // d、err 保存d、err,供当前处理流程使用 + d, err := time.ParseDuration(value); err == nil && d > 0 { return d } return defaultInterval } +// settingInt 负责设置Int相关处理。 func (s *Scheduler) settingInt(ctx context.Context, key string, defaultValue int) int { if s.store == nil || s.store.Settings == nil { return defaultValue } + // value、err 保存value、err,供当前处理流程使用 value, err := s.store.Settings.Get(ctx, key) if err != nil || strings.TrimSpace(value) == "" { return defaultValue } + // n、err 保存n、err,供当前处理流程使用 n, err := strconv.Atoi(strings.TrimSpace(value)) if err != nil || n < 0 { return defaultValue @@ -701,18 +806,23 @@ func (s *Scheduler) settingInt(ctx context.Context, key string, defaultValue int return n } +// newBatchID 负责new批次ID相关处理。 func newBatchID() string { + // b 保存b,供当前处理流程使用 var b [16]byte - if _, err := crand.Read(b[:]); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := crand.Read(b[:]); err != nil { return fmt.Sprintf("%d", time.Now().UnixNano()) } return hex.EncodeToString(b[:]) } +// sleepCtx 负责sleepCtx相关处理。 func sleepCtx(ctx context.Context, d time.Duration) error { if d <= 0 { return nil } + // timer 保存定时器,供当前处理流程使用 timer := time.NewTimer(d) defer timer.Stop() select { diff --git a/internal/renewal/scheduler_test.go b/internal/renewal/scheduler_test.go index 55589c1..5575bb4 100644 --- a/internal/renewal/scheduler_test.go +++ b/internal/renewal/scheduler_test.go @@ -19,14 +19,18 @@ import ( apirenew "xianyu-go/internal/xianyu/renew" ) +// schedulerRoundTripperFunc 保存schedulerRoundTripperFunc,供当前处理流程使用 type schedulerRoundTripperFunc func(*http.Request) (*http.Response, error) +// RoundTrip 负责RoundTrip相关处理。 func (f schedulerRoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error) { return f(req) } +// newSchedulerTestStore 负责newSchedulerTestStore相关处理。 func newSchedulerTestStore(t *testing.T) (*db.Store, func()) { t.Helper() + // d、err 保存d、err,供当前处理流程使用 d, _, err := db.Open(context.Background(), filepath.Join(t.TempDir(), "renewal.db")) if err != nil { t.Fatalf("Open: %v", err) @@ -34,29 +38,35 @@ func newSchedulerTestStore(t *testing.T) (*db.Store, func()) { return db.NewStore(d, db.DialectSQLite), func() { d.Close() } } +// schedulerFakeStarter 保存schedulerFakeStarter,供当前处理流程使用 type schedulerFakeStarter struct { starts atomic.Int32 restarts atomic.Int32 } +// Start 启动当前值。 func (f *schedulerFakeStarter) Start(context.Context, string, string) error { f.starts.Add(1) return nil } +// Restart 负责Restart相关处理。 func (f *schedulerFakeStarter) Restart(context.Context, string) error { f.restarts.Add(1) return nil } +// schedulerContextStarter 保存scheduler上下文Starter,供当前处理流程使用 type schedulerContextStarter struct { restarts atomic.Int32 ctxAlive atomic.Bool err error } +// Start 启动当前值。 func (f *schedulerContextStarter) Start(context.Context, string, string) error { return nil } +// Restart 负责Restart相关处理。 func (f *schedulerContextStarter) Restart(ctx context.Context, _ string) error { f.restarts.Add(1) f.ctxAlive.Store(ctx.Err() == nil) @@ -66,27 +76,32 @@ func (f *schedulerContextStarter) Restart(ctx context.Context, _ string) error { return ctx.Err() } +// schedulerFakePasswordRefresher 保存schedulerFake密码Refresher,供当前处理流程使用 type schedulerFakePasswordRefresher struct { calls atomic.Int32 } +// schedulerFakeNotifier 保存schedulerFakeNotifier,供当前处理流程使用 type schedulerFakeNotifier struct { calls atomic.Int32 title string message string } +// NotifyAccountEvent 负责Notify账号Event相关处理。 func (f *schedulerFakeNotifier) NotifyAccountEvent(_ string, _ string, _ string, title, body string) { f.calls.Add(1) f.title = title f.message = body } +// OnPasswordLoginRefresh 负责On密码登录Refresh相关处理。 func (f *schedulerFakePasswordRefresher) OnPasswordLoginRefresh(_ context.Context, _ string) bool { f.calls.Add(1) return true } +// apiRenewLogSnapshot 保存apiRenewLogSnapshot,供当前处理流程使用 type apiRenewLogSnapshot struct { status string message string @@ -99,26 +114,35 @@ type apiRenewLogSnapshot struct { requestCount int } +// createSchedulerAccount 负责createScheduler账号相关处理。 func createSchedulerAccount(t *testing.T, store *db.Store, cookieID, cookieValue string) db.RenewalRuntimeAccount { t.Helper() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // username 保存username,供当前处理流程使用 username := "user_" + strings.ReplaceAll(cookieID, "-", "_") - if ok, err := store.Users.Create(ctx, username, username+"@example.com", "pw"); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := store.Users.Create(ctx, username, username+"@example.com", "pw"); err != nil || !ok { t.Fatalf("Create user: ok=%v err=%v", ok, err) } + // user、err 保存user、err,供当前处理流程使用 user, err := store.Users.GetByUsername(ctx, username) if err != nil { t.Fatalf("GetByUsername: %v", err) } - if err := store.Cookies.Save(ctx, cookieID, cookieValue, user.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.Save(ctx, cookieID, cookieValue, user.ID); err != nil { t.Fatalf("Save cookie: %v", err) } return db.RenewalRuntimeAccount{ID: cookieID, Value: cookieValue, Enabled: true} } +// lastAPIRenewLog 负责lastAPIRenewLog相关处理。 func lastAPIRenewLog(t *testing.T, store *db.Store, cookieID string) apiRenewLogSnapshot { t.Helper() + // log 保存log,供当前处理流程使用 var log apiRenewLogSnapshot + // err 保存err,供当前处理流程使用 err := store.DB.QueryRowContext(context.Background(), `SELECT status, COALESCE(message,''), COALESCE(error_message,''), COALESCE(updated_cookie_names,''), COALESCE(response_content,''), COALESCE(step_details,''), COALESCE(renew_method,''), @@ -134,6 +158,7 @@ func lastAPIRenewLog(t *testing.T, store *db.Store, cookieID string) apiRenewLog return log } +// schedulerRenewServiceFromServer 负责schedulerRenewServiceFromServer相关处理。 func schedulerRenewServiceFromServer(srv *httptest.Server) apirenew.Service { return apirenew.Service{ HTTPClient: srv.Client(), @@ -144,6 +169,7 @@ func schedulerRenewServiceFromServer(srv *httptest.Server) apirenew.Service { } } +// TestSchedulerIntervalsAligned 负责TestSchedulerIntervalsAligned相关处理。 func TestSchedulerIntervalsAligned(t *testing.T) { if loginRenewInterval != 10*time.Minute { t.Fatalf("loginRenewInterval=%s want 10m", loginRenewInterval) @@ -156,32 +182,42 @@ func TestSchedulerIntervalsAligned(t *testing.T) { } } +// TestPendingAPIRenewLogsPendingAndRestartsAfterLateCookie 负责TestPendingAPIRenewLogsPendingAndRestartsAfterLate登录凭证相关处理。 func TestPendingAPIRenewLogsPendingAndRestartsAfterLateCookie(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // account 保存账号,供当前处理流程使用 account := createSchedulerAccount(t, store, "cid-pending", "unb=1; havana_lgc_exp="+strconv.FormatInt(time.Now().Add(time.Hour).UnixMilli(), 10)) + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { time.Sleep(60 * time.Millisecond) http.SetCookie(w, &http.Cookie{Name: "sdkSilent", Value: strconv.FormatInt(time.Now().Add(time.Hour).UnixMilli(), 10), Path: "/"}) _, _ = w.Write([]byte(`{"content":{"data":{"processFinished":true,"resultCode":100}}}`)) })) defer srv.Close() + // starter 保存starter,供当前处理流程使用 starter := &schedulerFakeStarter{} + // s 保存s,供当前处理流程使用 s := NewScheduler(store, starter, nil, nil) s.api = apirenew.Service{ HTTPClient: srv.Client(), SilentHasLoginURL: srv.URL, RetryDelay: -1, PromiseTimeout: 10 * time.Millisecond, } s.apiCookieRenewOne(context.Background(), "batch-pending", account) - if got := lastAPIRenewLog(t, store, account.ID).status; got != "pending" { + if // got 保存got,供当前处理流程使用 + got := lastAPIRenewLog(t, store, account.ID).status; got != "pending" { t.Fatalf("Promise 未完成时 status=%q want pending", got) } + // deadline 保存deadline,供当前处理流程使用 deadline := time.Now().Add(time.Second) for starter.restarts.Load() == 0 && time.Now().Before(deadline) { time.Sleep(10 * time.Millisecond) } - if got := starter.restarts.Load(); got != 1 { + if // got 保存got,供当前处理流程使用 + got := starter.restarts.Load(); got != 1 { t.Fatalf("迟到 Cookie 保存后 restarts=%d want 1", got) } + // detail、err 保存detail、err,供当前处理流程使用 detail, err := store.Cookies.GetDetails(context.Background(), account.ID) if err != nil { t.Fatal(err) @@ -189,47 +225,65 @@ func TestPendingAPIRenewLogsPendingAndRestartsAfterLateCookie(t *testing.T) { if !strings.Contains(detail.Value, "sdkSilent=") { t.Fatalf("迟到 Cookie 未保存: %q", detail.Value) } - if got := lastAPIRenewLog(t, store, account.ID).status; got != "cookie_updated" { + if // got 保存got,供当前处理流程使用 + got := lastAPIRenewLog(t, store, account.ID).status; got != "cookie_updated" { t.Fatalf("迟到响应最终状态=%q want cookie_updated", got) } } +// TestAPICookieRenewSuccessWithoutCredentialChangeDoesNotRestart 负责TestAPI登录凭证RenewSuccessWithoutCredentialChangeDoesNotRestart相关处理。 func TestAPICookieRenewSuccessWithoutCredentialChangeDoesNotRestart(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // expire 保存expire,供当前处理流程使用 expire := strconv.FormatInt(time.Now().Add(time.Hour).UnixMilli(), 10) + // account 保存账号,供当前处理流程使用 account := createSchedulerAccount(t, store, "cid-no-change", "unb=1; havana_lgc_exp="+expire) + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte(`{"content":{"data":{"processFinished":true,"resultCode":100}}}`)) })) defer srv.Close() + // starter 保存starter,供当前处理流程使用 starter := &schedulerFakeStarter{} + // s 保存s,供当前处理流程使用 s := NewScheduler(store, starter, nil, nil) s.api = apirenew.Service{HTTPClient: srv.Client(), SilentHasLoginURL: srv.URL, RetryDelay: -1} s.apiCookieRenewOne(context.Background(), "batch-no-change", account) - if got := starter.restarts.Load(); got != 0 { + if // got 保存got,供当前处理流程使用 + got := starter.restarts.Load(); got != 0 { t.Fatalf("Cookie 未变化时不应重启账号,restarts=%d", got) } - if got := lastAPIRenewLog(t, store, account.ID).status; got != "success" { + if // got 保存got,供当前处理流程使用 + got := lastAPIRenewLog(t, store, account.ID).status; got != "success" { t.Fatalf("无变化成功状态=%q want success", got) } } +// TestPendingAPIRenewUsesFreshContextForRestart 负责TestPendingAPIRenewUsesFresh上下文ForRestart相关处理。 func TestPendingAPIRenewUsesFreshContextForRestart(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // expire 保存expire,供当前处理流程使用 expire := strconv.FormatInt(time.Now().Add(time.Hour).UnixMilli(), 10) + // account 保存账号,供当前处理流程使用 account := createSchedulerAccount(t, store, "cid-fresh-context", "unb=1; havana_lgc_exp="+expire) + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { time.Sleep(40 * time.Millisecond) http.SetCookie(w, &http.Cookie{Name: "sdkSilent", Value: futureSchedulerMillis(), Path: "/"}) _, _ = w.Write([]byte(`{"content":{"data":{"processFinished":true,"resultCode":100}}}`)) })) defer srv.Close() + // starter 保存starter,供当前处理流程使用 starter := &schedulerContextStarter{} + // s 保存s,供当前处理流程使用 s := NewScheduler(store, starter, nil, nil) s.api = apirenew.Service{HTTPClient: srv.Client(), SilentHasLoginURL: srv.URL, RetryDelay: -1, PromiseTimeout: 5 * time.Millisecond} s.apiCookieRenewOne(context.Background(), "batch-context", account) + // deadline 保存deadline,供当前处理流程使用 deadline := time.Now().Add(time.Second) for starter.restarts.Load() == 0 && time.Now().Before(deadline) { time.Sleep(5 * time.Millisecond) @@ -239,26 +293,35 @@ func TestPendingAPIRenewUsesFreshContextForRestart(t *testing.T) { } } +// TestPendingAPIRenewStopsWithSchedulerContext 负责TestPendingAPIRenewStopsWithScheduler上下文相关处理。 func TestPendingAPIRenewStopsWithSchedulerContext(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // account 保存账号,供当前处理流程使用 account := createSchedulerAccount(t, store, "cid-canceled-pending", "unb=1; havana_lgc_exp="+futureSchedulerMillis()) + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { time.Sleep(80 * time.Millisecond) http.SetCookie(w, &http.Cookie{Name: "sdkSilent", Value: futureSchedulerMillis(), Path: "/"}) _, _ = w.Write([]byte(`{"content":{"data":{"processFinished":true,"resultCode":100}}}`)) })) defer srv.Close() + // starter 保存starter,供当前处理流程使用 starter := &schedulerFakeStarter{} + // s 保存s,供当前处理流程使用 s := NewScheduler(store, starter, nil, nil) s.api = apirenew.Service{HTTPClient: srv.Client(), SilentHasLoginURL: srv.URL, RetryDelay: -1, PromiseTimeout: 5 * time.Millisecond} + // ctx、cancel 保存ctx、cancel,供当前处理流程使用 ctx, cancel := context.WithCancel(context.Background()) s.apiCookieRenewOne(ctx, "batch-canceled-pending", account) cancel() s.watchers.Wait() - if got := starter.restarts.Load(); got != 0 { + if // got 保存got,供当前处理流程使用 + got := starter.restarts.Load(); got != 0 { t.Fatalf("调度器关闭后迟到响应不得重启账号,restarts=%d", got) } + // detail、err 保存detail、err,供当前处理流程使用 detail, err := store.Cookies.GetDetails(context.Background(), account.ID) if err != nil { t.Fatal(err) @@ -268,22 +331,30 @@ func TestPendingAPIRenewStopsWithSchedulerContext(t *testing.T) { } } +// TestPendingAPIRenewRestartFailureIsFinalFailure 负责TestPendingAPIRenewRestartFailureIsFinalFailure相关处理。 func TestPendingAPIRenewRestartFailureIsFinalFailure(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // account 保存账号,供当前处理流程使用 account := createSchedulerAccount(t, store, "cid-restart-failure", "unb=1; havana_lgc_exp="+futureSchedulerMillis()) + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { time.Sleep(30 * time.Millisecond) http.SetCookie(w, &http.Cookie{Name: "sdkSilent", Value: futureSchedulerMillis(), Path: "/"}) _, _ = w.Write([]byte(`{"content":{"data":{"processFinished":true,"resultCode":100}}}`)) })) defer srv.Close() + // starter 保存starter,供当前处理流程使用 starter := &schedulerContextStarter{err: errors.New("restart failed")} + // s 保存s,供当前处理流程使用 s := NewScheduler(store, starter, nil, nil) s.api = apirenew.Service{HTTPClient: srv.Client(), SilentHasLoginURL: srv.URL, RetryDelay: -1, PromiseTimeout: 5 * time.Millisecond} s.apiCookieRenewOne(context.Background(), "batch-restart-failure", account) + // deadline 保存deadline,供当前处理流程使用 deadline := time.Now().Add(time.Second) for time.Now().Before(deadline) { + // log 保存log,供当前处理流程使用 log := lastAPIRenewLog(t, store, account.ID) if log.status != "pending" { if log.status != "failed" || !strings.Contains(log.errorMessage, "restart failed") { @@ -296,48 +367,65 @@ func TestPendingAPIRenewRestartFailureIsFinalFailure(t *testing.T) { t.Fatal("迟到续期没有写入重启失败终态") } +// futureSchedulerMillis 负责futureSchedulerMillis相关处理。 func futureSchedulerMillis() string { return strconv.FormatInt(time.Now().Add(time.Hour).UnixMilli(), 10) } +// TestAPIRenewCompatibilitySettingsUseSingleRunner 负责TestAPIRenewCompatibility设置UseSingleRunner相关处理。 func TestAPIRenewCompatibilitySettingsUseSingleRunner(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // ctx、cancel 保存ctx、cancel,供当前处理流程使用 ctx, cancel := context.WithCancel(context.Background()) defer cancel() + // expire 保存expire,供当前处理流程使用 expire := futureSchedulerMillis() createSchedulerAccount(t, store, "cid-single-runner", "unb=1; havana_lgc_exp="+expire) + // key 表示当前遍历过程中的key for _, key := range []string{apiCookieRenewEnabledSetting, cookiesRefreshEnabledSetting} { - if err := store.Settings.Set(ctx, key, "true"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, key, "true"); err != nil { t.Fatal(err) } } - if err := store.Settings.Set(ctx, apiCookieRenewIntervalSetting, "10s"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, apiCookieRenewIntervalSetting, "10s"); err != nil { t.Fatal(err) } + // requests 保存请求列表,供当前处理流程使用 var requests atomic.Int32 + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { requests.Add(1) _, _ = w.Write([]byte(`{"content":{"data":{"processFinished":true,"resultCode":100}}}`)) })) defer srv.Close() + // s 保存s,供当前处理流程使用 s := NewScheduler(store, nil, nil, nil) s.api = apirenew.Service{HTTPClient: srv.Client(), SilentHasLoginURL: srv.URL, RetryDelay: -1} s.Run(ctx) + // deadline 保存deadline,供当前处理流程使用 deadline := time.Now().Add(time.Second) for requests.Load() == 0 && time.Now().Before(deadline) { time.Sleep(5 * time.Millisecond) } time.Sleep(30 * time.Millisecond) - if got := requests.Load(); got != 1 { + if // got 保存got,供当前处理流程使用 + got := requests.Load(); got != 1 { t.Fatalf("新旧配置同时开启只能启动一个续期任务,请求数=%d", got) } } +// TestSchedulerDefaultsMatchUpstreamConfig 负责TestSchedulerDefaultsMatchUpstream配置相关处理。 func TestSchedulerDefaultsMatchUpstreamConfig(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := NewScheduler(store, nil, nil, nil) if s.settingEnabled(ctx, loginRenewEnabledSetting, false) { @@ -351,13 +439,19 @@ func TestSchedulerDefaultsMatchUpstreamConfig(t *testing.T) { } } +// TestAPICookieRenewFailureNotifiesOnlyAtThirdConsecutiveFailure 负责TestAPI登录凭证RenewFailureNotifiesOnlyAtThirdConsecutiveFailure相关处理。 func TestAPICookieRenewFailureNotifiesOnlyAtThirdConsecutiveFailure(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // notifier 保存notifier,供当前处理流程使用 notifier := &schedulerFakeNotifier{} + // s 保存s,供当前处理流程使用 s := NewScheduler(store, nil, nil, nil, notifier) + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - for i := 0; i < 3; i++ { + for // i 保存i,供当前处理流程使用 + i := 0; i < 3; i++ { s.addAPILog(ctx, db.RenewalLog{BatchID: "batch", CookieID: "cid-failure", Status: "failed", ErrorMessage: "接口超时"}) } if notifier.calls.Load() != 1 { @@ -372,72 +466,98 @@ func TestAPICookieRenewFailureNotifiesOnlyAtThirdConsecutiveFailure(t *testing.T } } +// TestLoginRenewPreservesValidTokenCache 负责Test登录RenewPreserves有效令牌Cache相关处理。 func TestLoginRenewPreservesValidTokenCache(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // account 保存账号,供当前处理流程使用 account := createSchedulerAccount(t, store, "cid-login-renew", "unb=1; _m_h5_tk=old_1") - if err := store.Tokens.Save(ctx, account.ID, "did-stable", "cached-token", time.Now().Add(time.Hour).Unix()); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Tokens.Save(ctx, account.ID, "did-stable", "cached-token", time.Now().Add(time.Hour).Unix()); err != nil { t.Fatal(err) } + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { http.SetCookie(w, &http.Cookie{Name: "_m_h5_tk", Value: "new_1"}) _, _ = w.Write([]byte(`{"ret":["FAIL_SYS_TOKEN_EXOIRED::令牌过期"],"data":{}}`)) })) defer srv.Close() + // s 保存s,供当前处理流程使用 s := NewScheduler(store, nil, nil, nil) s.mtop = &mtop.ClientImpl{HTTPClient: srv.Client(), LoginUserURL: srv.URL} s.loginRenewOne(ctx, "batch-login-renew", account) + // token、err 保存token、err,供当前处理流程使用 token, err := store.Tokens.Get(ctx, account.ID) if err != nil || token.AccessToken != "cached-token" { t.Fatalf("login_renew 不得删除有效 token 缓存: token=%+v err=%v", token, err) } + // updated、err 保存updated、err,供当前处理流程使用 updated, err := store.Cookies.GetValue(ctx, account.ID) if err != nil || !strings.Contains(updated, "_m_h5_tk=new_1") { t.Fatalf("login_renew Cookie 未保存: %q err=%v", updated, err) } } +// TestLoginRenewSessionExpiredStartsImmediateRecovery 负责Test登录Renew会话ExpiredStartsImmediateRecovery相关处理。 func TestLoginRenewSessionExpiredStartsImmediateRecovery(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // account 保存账号,供当前处理流程使用 account := createSchedulerAccount(t, store, "cid-login-session-expired", "unb=1; _m_h5_tk=old_1") + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte(`{"ret":["FAIL_SYS_SESSION_EXPIRED::Session过期"],"data":{}}`)) })) defer srv.Close() + // refresher 保存refresher,供当前处理流程使用 refresher := &schedulerFakePasswordRefresher{} + // s 保存s,供当前处理流程使用 s := NewScheduler(store, nil, refresher, nil) s.mtop = &mtop.ClientImpl{HTTPClient: srv.Client(), LoginUserURL: srv.URL} s.loginRenewOne(ctx, "batch-login-session-expired", account) - if got := refresher.calls.Load(); got != 1 { + if // got 保存got,供当前处理流程使用 + got := refresher.calls.Load(); got != 1 { t.Fatalf("session 过期应在登录态检查返回后立即触发一次续期,calls=%d", got) } } +// TestLoginRenewPersistsAuthoritativeSessionBeforeParseError 负责Test登录RenewPersistsAuthoritative会话BeforeParse错误相关处理。 func TestLoginRenewPersistsAuthoritativeSessionBeforeParseError(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // account 保存账号,供当前处理流程使用 account := createSchedulerAccount(t, store, "cid-login-session-error", "flat_leak=must-not-send; unb=1; _m_h5_tk=flat_old_1") + // snapshot 保存snapshot,供当前处理流程使用 snapshot := []cookierefresh.BrowserCookie{ {Name: "unb", Value: "1", Domain: ".goofish.com", Path: "/", Secure: true}, {Name: "_m_h5_tk", Value: "snapshot_old_1", Domain: ".goofish.com", Path: "/", Secure: true}, {Name: "document_only", Value: "doc", Domain: "www.goofish.com", Path: "/im", Secure: true}, {Name: "api_only", Value: "api", Domain: "h5api.m.goofish.com", Path: "/h5", Secure: true, HTTPOnly: true}, } + // metadata 保存metadata,供当前处理流程使用 metadata := cookierefresh.MetadataWithSnapshot(`{"preserved":"yes"}`, snapshot) - if err := store.Cookies.UpdateRenewalCookie(ctx, account.ID, account.Value, metadata, 1); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.UpdateRenewalCookie(ctx, account.ID, account.Value, metadata, 1); err != nil { t.Fatal(err) } + // requestCookie 保存请求登录凭证,供当前处理流程使用 var requestCookie string + // client 保存client,供当前处理流程使用 client := &http.Client{Transport: schedulerRoundTripperFunc(func(req *http.Request) (*http.Response, error) { requestCookie = req.Header.Get("Cookie") return &http.Response{ @@ -450,21 +570,25 @@ func TestLoginRenewPersistsAuthoritativeSessionBeforeParseError(t *testing.T) { Request: req, }, nil })} + // s 保存s,供当前处理流程使用 s := NewScheduler(store, nil, nil, nil) s.mtop = &mtop.ClientImpl{HTTPClient: client, LoginUserURL: mtop.LoginUserAPI} s.loginRenewOne(ctx, "batch-login-session-error", account) + // want 表示当前遍历过程中的want for _, want := range []string{"unb=1", "_m_h5_tk=snapshot_old_1", "api_only=api"} { if !strings.Contains(requestCookie, want) { t.Fatalf("请求 Cookie %q 未使用加锁后重读的权威 Jar,缺少 %q", requestCookie, want) } } + // unwanted 表示当前遍历过程中的unwanted for _, unwanted := range []string{"flat_leak=", "document_only="} { if strings.Contains(requestCookie, unwanted) { t.Fatalf("请求 Cookie %q 泄漏了错误作用域 %q", requestCookie, unwanted) } } + // detail、err 保存detail、err,供当前处理流程使用 detail, err := store.Cookies.GetDetails(ctx, account.ID) if err != nil { t.Fatal(err) @@ -475,11 +599,14 @@ func TestLoginRenewPersistsAuthoritativeSessionBeforeParseError(t *testing.T) { if !strings.Contains(detail.MetadataJSON, `"preserved":"yes"`) { t.Fatalf("持久化 Jar 时丢失原 metadata: %s", detail.MetadataJSON) } + // gotSnapshot、ok 保存gotSnapshot、ok,供当前处理流程使用 gotSnapshot, ok := cookierefresh.SnapshotFromMetadataOK(detail.MetadataJSON) if !ok { t.Fatalf("响应后权威 snapshot 丢失: %s", detail.MetadataJSON) } + // values 保存values,供当前处理流程使用 values := make(map[string]string, len(gotSnapshot)) + // cookie 表示当前遍历过程中的登录凭证 for _, cookie := range gotSnapshot { values[cookie.Name+"|"+cookie.Domain+"|"+cookie.Path] = cookie.Value } @@ -490,19 +617,25 @@ func TestLoginRenewPersistsAuthoritativeSessionBeforeParseError(t *testing.T) { } } +// TestSchedulerSettingEnabledOverrides 负责TestScheduler设置启用状态Overrides相关处理。 func TestSchedulerSettingEnabledOverrides(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := NewScheduler(store, nil, nil, nil) - if err := store.Settings.Set(ctx, loginRenewEnabledSetting, "enabled"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, loginRenewEnabledSetting, "enabled"); err != nil { t.Fatalf("Set enabled: %v", err) } if !s.settingEnabled(ctx, loginRenewEnabledSetting, false) { t.Fatal("enabled 应开启任务") } - if err := store.Settings.Set(ctx, loginRenewEnabledSetting, "off"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, loginRenewEnabledSetting, "off"); err != nil { t.Fatalf("Set off: %v", err) } if s.settingEnabled(ctx, loginRenewEnabledSetting, true) { @@ -510,94 +643,127 @@ func TestSchedulerSettingEnabledOverrides(t *testing.T) { } } +// TestSchedulerSettingIntervalOverrides 负责TestScheduler设置IntervalOverrides相关处理。 func TestSchedulerSettingIntervalOverrides(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := NewScheduler(store, nil, nil, nil) - if got := s.settingInterval(ctx, loginRenewIntervalSetting, loginRenewInterval); got != loginRenewInterval { + if // got 保存got,供当前处理流程使用 + got := s.settingInterval(ctx, loginRenewIntervalSetting, loginRenewInterval); got != loginRenewInterval { t.Fatalf("未配置间隔应返回默认值: %s", got) } - if err := store.Settings.Set(ctx, loginRenewIntervalSetting, "30"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, loginRenewIntervalSetting, "30"); err != nil { t.Fatalf("Set seconds: %v", err) } - if got := s.settingInterval(ctx, loginRenewIntervalSetting, loginRenewInterval); got != 30*time.Second { + if // got 保存got,供当前处理流程使用 + got := s.settingInterval(ctx, loginRenewIntervalSetting, loginRenewInterval); got != 30*time.Second { t.Fatalf("秒数间隔=%s want 30s", got) } - if err := store.Settings.Set(ctx, loginRenewIntervalSetting, "2m"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, loginRenewIntervalSetting, "2m"); err != nil { t.Fatalf("Set duration: %v", err) } - if got := s.settingInterval(ctx, loginRenewIntervalSetting, loginRenewInterval); got != 2*time.Minute { + if // got 保存got,供当前处理流程使用 + got := s.settingInterval(ctx, loginRenewIntervalSetting, loginRenewInterval); got != 2*time.Minute { t.Fatalf("duration 间隔=%s want 2m", got) } - if err := store.Settings.Set(ctx, loginRenewIntervalSetting, "-1"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, loginRenewIntervalSetting, "-1"); err != nil { t.Fatalf("Set invalid: %v", err) } - if got := s.settingInterval(ctx, loginRenewIntervalSetting, loginRenewInterval); got != loginRenewInterval { + if // got 保存got,供当前处理流程使用 + got := s.settingInterval(ctx, loginRenewIntervalSetting, loginRenewInterval); got != loginRenewInterval { t.Fatalf("非法间隔应回退默认值: %s", got) } } +// TestSchedulerSettingIntOverrides 负责TestScheduler设置IntOverrides相关处理。 func TestSchedulerSettingIntOverrides(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // s 保存s,供当前处理流程使用 s := NewScheduler(store, nil, nil, nil) - if got := s.settingInt(ctx, "missing_int", 10); got != 10 { + if // got 保存got,供当前处理流程使用 + got := s.settingInt(ctx, "missing_int", 10); got != 10 { t.Fatalf("missing setting=%d want 10", got) } - if err := store.Settings.Set(ctx, "renewal_log_retention_days", "20"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, "renewal_log_retention_days", "20"); err != nil { t.Fatalf("Set int: %v", err) } - if got := s.settingInt(ctx, "renewal_log_retention_days", 10); got != 20 { + if // got 保存got,供当前处理流程使用 + got := s.settingInt(ctx, "renewal_log_retention_days", 10); got != 20 { t.Fatalf("setting int=%d want 20", got) } - if err := store.Settings.Set(ctx, "renewal_log_retention_days", "-1"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, "renewal_log_retention_days", "-1"); err != nil { t.Fatalf("Set invalid: %v", err) } - if got := s.settingInt(ctx, "renewal_log_retention_days", 10); got != 10 { + if // got 保存got,供当前处理流程使用 + got := s.settingInt(ctx, "renewal_log_retention_days", 10); got != 10 { t.Fatalf("invalid setting int=%d want 10", got) } } +// TestRenewalCleanupLogsUsesRetentionDays 负责TestRenewalCleanupLogsUsesRetentionDays相关处理。 func TestRenewalCleanupLogsUsesRetentionDays(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // cookie 保存登录凭证,供当前处理流程使用 cookie := createSchedulerAccount(t, store, "cid-cleanup", "unb=1") _ = cookie + // table 表示当前遍历过程中的table for _, table := range []string{ "scheduled_cookies_refresh_log", "scheduled_login_renew_log", "scheduled_api_cookie_renew_log", } { - if _, err := store.DB.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `INSERT INTO `+table+` (batch_id, cookie_id, status, created_at) VALUES ('old', 'cid-cleanup', 'failed', datetime('now','-20 days'))`); err != nil { t.Fatalf("insert old %s: %v", table, err) } - if _, err := store.DB.ExecContext(ctx, + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `INSERT INTO `+table+` (batch_id, cookie_id, status, created_at) VALUES ('new', 'cid-cleanup', 'success', CURRENT_TIMESTAMP)`); err != nil { t.Fatalf("insert new %s: %v", table, err) } } - if err := store.Settings.Set(ctx, "renewal_log_retention_days", "10"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Settings.Set(ctx, "renewal_log_retention_days", "10"); err != nil { t.Fatalf("set retention: %v", err) } + // s 保存s,供当前处理流程使用 s := NewScheduler(store, nil, nil, nil) s.cleanupExpiredLogs(ctx) + // table 表示当前遍历过程中的table for _, table := range []string{ "scheduled_cookies_refresh_log", "scheduled_login_renew_log", "scheduled_api_cookie_renew_log", } { + // oldRows、newRows 保存oldRows、newRows,供当前处理流程使用 var oldRows, newRows int - if err := store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM `+table+` WHERE batch_id='old'`).Scan(&oldRows); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM `+table+` WHERE batch_id='old'`).Scan(&oldRows); err != nil { t.Fatalf("count old %s: %v", table, err) } - if err := store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM `+table+` WHERE batch_id='new'`).Scan(&newRows); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM `+table+` WHERE batch_id='new'`).Scan(&newRows); err != nil { t.Fatalf("count new %s: %v", table, err) } if oldRows != 0 || newRows != 1 { @@ -606,33 +772,49 @@ func TestRenewalCleanupLogsUsesRetentionDays(t *testing.T) { } } +// TestAPICookieRenewOneSkipsExpiredLongLoginWithoutEscalation 负责TestAPI登录凭证RenewOneSkipsExpiredLong登录WithoutEscalation相关处理。 func TestAPICookieRenewOneSkipsExpiredLongLoginWithoutEscalation(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // account 保存账号,供当前处理流程使用 account := createSchedulerAccount(t, store, "cid-expired", "unb=1; cookie2=c2") + // refresher 保存refresher,供当前处理流程使用 refresher := &schedulerFakePasswordRefresher{} + // s 保存s,供当前处理流程使用 s := NewScheduler(store, nil, refresher, nil) s.apiCookieRenewOne(ctx, "batch-expired", account) if refresher.calls.Load() != 0 { t.Fatalf("proactive renewal escalated to account recovery: %d", refresher.calls.Load()) } + // log 保存log,供当前处理流程使用 log := lastAPIRenewLog(t, store, account.ID) if log.status != "skipped" || !strings.Contains(log.stepDetails, "long_login_expired") { t.Fatalf("expired long login log=%+v", log) } } +// TestAPICookieRenewOneUsesSingleSilentRequestAndSavesCookies 负责TestAPI登录凭证RenewOneUsesSingleSilent请求AndSavesCookies相关处理。 func TestAPICookieRenewOneUsesSingleSilentRequestAndSavesCookies(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newSchedulerTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // expire 保存expire,供当前处理流程使用 expire := strconv.FormatInt(time.Now().Add(time.Hour).UnixMilli(), 10) + // account 保存账号,供当前处理流程使用 account := createSchedulerAccount(t, store, "cid-silent", "unb=1; cookie2=c2; havana_lgc_exp="+expire) + // refresher 保存refresher,供当前处理流程使用 refresher := &schedulerFakePasswordRefresher{} + // starter 保存starter,供当前处理流程使用 starter := &schedulerFakeStarter{} + // requests 保存请求列表,供当前处理流程使用 var requests atomic.Int32 + // srv 保存srv,供当前处理流程使用 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { requests.Add(1) http.SetCookie(w, &http.Cookie{Name: "sdkSilent", Value: strconv.FormatInt(time.Now().Add(time.Hour).UnixMilli(), 10)}) @@ -640,6 +822,7 @@ func TestAPICookieRenewOneUsesSingleSilentRequestAndSavesCookies(t *testing.T) { })) defer srv.Close() + // s 保存s,供当前处理流程使用 s := NewScheduler(store, starter, refresher, nil) s.api = schedulerRenewServiceFromServer(srv) s.apiCookieRenewOne(ctx, "batch-silent", account) @@ -650,10 +833,12 @@ func TestAPICookieRenewOneUsesSingleSilentRequestAndSavesCookies(t *testing.T) { if starter.restarts.Load() != 1 || starter.starts.Load() != 0 { t.Fatalf("官网静默续期成功应模拟 reload 重建运行时: starts=%d restarts=%d", starter.starts.Load(), starter.restarts.Load()) } + // got、err 保存got、err,供当前处理流程使用 got, err := store.Cookies.GetValue(ctx, account.ID) if err != nil || !strings.Contains(got, "sdkSilent=") { t.Fatalf("silent Cookie not saved: value=%q err=%v", got, err) } + // log 保存log,供当前处理流程使用 log := lastAPIRenewLog(t, store, account.ID) if log.status != "cookie_updated" || log.requestCount != 1 || !strings.Contains(log.responseContent, "single-silent") { t.Fatalf("silent renewal log=%+v", log)