From 8c16e7810c2899865377ac7e6e4da81e4928ba28 Mon Sep 17 00:00:00 2001 From: Christ Date: Sat, 15 Aug 2026 05:17:25 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B6=E6=AE=B5=E5=8D=81=EF=BC=9A=E5=AE=8C?= =?UTF-8?q?=E6=88=90=20Go=20Automation=20=E6=B3=A8=E9=87=8A=E5=9F=BA?= =?UTF-8?q?=E7=BA=BF=E6=B8=85=E9=9B=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .commentlint/go-baseline.json | 5952 ------------------ docs/architecture/refactoring-master-plan.md | 1 + internal/automation/account_tasks.go | 74 +- internal/automation/account_tasks_test.go | 86 +- internal/automation/action_executor.go | 13 +- internal/automation/center.go | 96 +- internal/automation/center_mock_mtop_test.go | 103 +- internal/automation/center_test.go | 496 +- internal/automation/event_pipeline.go | 25 +- internal/automation/event_pipeline_test.go | 6 +- internal/automation/events.go | 81 +- internal/automation/events_test.go | 29 +- internal/automation/run_coordinator.go | 6 +- internal/automation/scheduler.go | 86 +- internal/automation/scheduler_test.go | 86 +- 15 files changed, 1023 insertions(+), 6117 deletions(-) diff --git a/.commentlint/go-baseline.json b/.commentlint/go-baseline.json index 9d9273b..bdd8b1f 100644 --- a/.commentlint/go-baseline.json +++ b/.commentlint/go-baseline.json @@ -8027,5958 +8027,6 @@ "kind": "local-variable", "name": "admin" }, - { - "file": "internal/automation/account_tasks.go", - "line": 16, - "kind": "const", - "name": "TaskAutoRate" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 17, - "kind": "const", - "name": "TaskAutoPolish" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 18, - "kind": "const", - "name": "polishItemPageSize" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 19, - "kind": "const", - "name": "polishItemMaxPages" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 22, - "kind": "type", - "name": "AccountTaskClient" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 29, - "kind": "type", - "name": "AccountTaskSummary" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 79, - "kind": "local-variable", - "name": "allowed" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 79, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 86, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 86, - "kind": "local-variable", - "name": "settings" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 93, - "kind": "function", - "name": "runConfiguredAccountTask" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 94, - "kind": "local-variable", - "name": "blocked" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 94, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 101, - "kind": "var", - "name": "summary" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 102, - "kind": "var", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 118, - "kind": "function", - "name": "scanAccountTasks" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 122, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 122, - "kind": "local-variable", - "name": "settings" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 127, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 128, - "kind": "range-variable", - "name": "setting" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 129, - "kind": "local-variable", - "name": "allowed" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 129, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 133, - "kind": "local-variable", - "name": "blockErr" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 133, - "kind": "local-variable", - "name": "blocked" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 137, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 142, - "kind": "local-variable", - "name": "blocked" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 145, - "kind": "local-variable", - "name": "taskErr" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 156, - "kind": "function", - "name": "recoverAccountTaskSession" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 157, - "kind": "local-variable", - "name": "fingerprint" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 157, - "kind": "local-variable", - "name": "fingerprintErr" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 162, - "kind": "local-variable", - "name": "recoverer" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 169, - "kind": "function", - "name": "accountTaskSessionBlocked" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 170, - "kind": "local-variable", - "name": "blockedFingerprint" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 170, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 174, - "kind": "local-variable", - "name": "current" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 174, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 185, - "kind": "function", - "name": "accountCredentialFingerprint" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 198, - "kind": "local-variable", - "name": "summary" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 202, - "kind": "local-variable", - "name": "cookies" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 202, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 206, - "kind": "local-variable", - "name": "current" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 207, - "kind": "var", - "name": "orders" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 208, - "kind": "local-variable", - "name": "page" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 209, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 209, - "kind": "local-variable", - "name": "pending" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 220, - "kind": "range-variable", - "name": "order" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 221, - "kind": "local-variable", - "name": "runKey" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 222, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 222, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 231, - "kind": "local-variable", - "name": "rateErr" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 231, - "kind": "local-variable", - "name": "result" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 233, - "kind": "local-variable", - "name": "message" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 252, - "kind": "function", - "name": "runAutoPolish" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 253, - "kind": "local-variable", - "name": "summary" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 257, - "kind": "local-variable", - "name": "date" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 258, - "kind": "local-variable", - "name": "runKey" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 259, - "kind": "local-variable", - "name": "run" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 260, - "kind": "var", - "name": "claimed" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 261, - "kind": "var", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 274, - "kind": "local-variable", - "name": "cookies" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 274, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 279, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 279, - "kind": "local-variable", - "name": "items" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 284, - "kind": "local-variable", - "name": "current" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 286, - "kind": "var", - "name": "lastError" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 287, - "kind": "range-variable", - "name": "item" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 288, - "kind": "local-variable", - "name": "polishErr" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 288, - "kind": "local-variable", - "name": "result" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 304, - "kind": "local-variable", - "name": "retryAt" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 304, - "kind": "local-variable", - "name": "status" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 317, - "kind": "function", - "name": "persistTaskCookies" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 322, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 327, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 327, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 334, - "kind": "function", - "name": "beijingNow" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 338, - "kind": "function", - "name": "polishDue" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 342, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks.go", - "line": 342, - "kind": "local-variable", - "name": "target" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 14, - "kind": "type", - "name": "fakeAccountTaskClient" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 28, - "kind": "function", - "name": "FetchPendingRateOrders" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 36, - "kind": "function", - "name": "RateBuyer" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 44, - "kind": "function", - "name": "FetchAllItems" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 52, - "kind": "function", - "name": "PolishItem" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 60, - "kind": "function", - "name": "TestAccountTaskRateIsOrderIdempotent" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 61, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 61, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 63, - "kind": "local-variable", - "name": "client" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 64, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 66, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 67, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 71, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 71, - "kind": "local-variable", - "name": "first" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 75, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 75, - "kind": "local-variable", - "name": "second" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 81, - "kind": "function", - "name": "TestAccountTaskSessionExpiredRecoversOnceAndBlocksFurtherAPIRequests" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 82, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 82, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 84, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 85, - "kind": "local-variable", - "name": "sessionErr" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 86, - "kind": "local-variable", - "name": "client" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 87, - "kind": "local-variable", - "name": "recoverer" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 88, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 91, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 96, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 102, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 109, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 113, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 121, - "kind": "function", - "name": "TestAccountTaskStopsRemainingOrdersOnSessionExpired" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 122, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 122, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 124, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 125, - "kind": "local-variable", - "name": "sessionErr" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 126, - "kind": "local-variable", - "name": "client" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 130, - "kind": "local-variable", - "name": "recoverer" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 131, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 134, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 139, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 147, - "kind": "function", - "name": "TestAccountTaskPolishRunsOncePerBeijingDay" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 148, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 148, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 150, - "kind": "local-variable", - "name": "client" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 151, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 153, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 154, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 158, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 158, - "kind": "local-variable", - "name": "first" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 165, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 165, - "kind": "local-variable", - "name": "second" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 169, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 169, - "kind": "local-variable", - "name": "settings" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 175, - "kind": "function", - "name": "TestManualPolishReportsItemFailures" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 176, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 176, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 178, - "kind": "local-variable", - "name": "client" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 179, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 181, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 182, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 186, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 186, - "kind": "local-variable", - "name": "summary" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 192, - "kind": "function", - "name": "TestManualPolishCanRetryImmediatelyAfterFailure" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 193, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 193, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 195, - "kind": "local-variable", - "name": "client" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 196, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 198, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 199, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 203, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 207, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 207, - "kind": "local-variable", - "name": "second" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 211, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 211, - "kind": "local-variable", - "name": "third" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 217, - "kind": "function", - "name": "TestPolishDueHonorsConfiguredTimeAndDate" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 218, - "kind": "local-variable", - "name": "now" - }, - { - "file": "internal/automation/account_tasks_test.go", - "line": 219, - "kind": "local-variable", - "name": "settings" - }, - { - "file": "internal/automation/center.go", - "line": 18, - "kind": "var", - "name": "errAutomationDeferred" - }, - { - "file": "internal/automation/center.go", - "line": 19, - "kind": "var", - "name": "errAutomationNeedsReview" - }, - { - "file": "internal/automation/center.go", - "line": 20, - "kind": "var", - "name": "errAutomationQuarantine" - }, - { - "file": "internal/automation/center.go", - "line": 21, - "kind": "var", - "name": "errActionNotPerformed" - }, - { - "file": "internal/automation/center.go", - "line": 28, - "kind": "type", - "name": "preparationError" - }, - { - "file": "internal/automation/center.go", - "line": 30, - "kind": "function", - "name": "Error" - }, - { - "file": "internal/automation/center.go", - "line": 31, - "kind": "function", - "name": "Unwrap" - }, - { - "file": "internal/automation/center.go", - "line": 33, - "kind": "type", - "name": "uncertainActionError" - }, - { - "file": "internal/automation/center.go", - "line": 35, - "kind": "function", - "name": "Error" - }, - { - "file": "internal/automation/center.go", - "line": 36, - "kind": "function", - "name": "Unwrap" - }, - { - "file": "internal/automation/center.go", - "line": 38, - "kind": "function", - "name": "uncertainAction" - }, - { - "file": "internal/automation/center.go", - "line": 42, - "kind": "var", - "name": "existing" - }, - { - "file": "internal/automation/center.go", - "line": 117, - "kind": "local-variable", - "name": "client" - }, - { - "file": "internal/automation/center.go", - "line": 118, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center.go", - "line": 195, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/automation/center.go", - "line": 195, - "kind": "local-variable", - "name": "recoverer" - }, - { - "file": "internal/automation/center.go", - "line": 212, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 216, - "kind": "function", - "name": "handleTask" - }, - { - "file": "internal/automation/center.go", - "line": 224, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 228, - "kind": "local-variable", - "name": "order" - }, - { - "file": "internal/automation/center.go", - "line": 228, - "kind": "local-variable", - "name": "orderErr" - }, - { - "file": "internal/automation/center.go", - "line": 234, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 234, - "kind": "local-variable", - "name": "paused" - }, - { - "file": "internal/automation/center.go", - "line": 234, - "kind": "local-variable", - "name": "until" - }, - { - "file": "internal/automation/center.go", - "line": 239, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 245, - "kind": "local-variable", - "name": "enabled" - }, - { - "file": "internal/automation/center.go", - "line": 245, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 253, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 253, - "kind": "local-variable", - "name": "rules" - }, - { - "file": "internal/automation/center.go", - "line": 261, - "kind": "var", - "name": "firstErr" - }, - { - "file": "internal/automation/center.go", - "line": 262, - "kind": "range-variable", - "name": "rule" - }, - { - "file": "internal/automation/center.go", - "line": 263, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 264, - "kind": "var", - "name": "prepErr" - }, - { - "file": "internal/automation/center.go", - "line": 266, - "kind": "local-variable", - "name": "dueAt" - }, - { - "file": "internal/automation/center.go", - "line": 267, - "kind": "local-variable", - "name": "deferErr" - }, - { - "file": "internal/automation/center.go", - "line": 286, - "kind": "function", - "name": "taskAutomationRunID" - }, - { - "file": "internal/automation/center.go", - "line": 290, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/automation/center.go", - "line": 291, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/automation/center.go", - "line": 295, - "kind": "function", - "name": "taskDelayCursor" - }, - { - "file": "internal/automation/center.go", - "line": 299, - "kind": "local-variable", - "name": "value" - }, - { - "file": "internal/automation/center.go", - "line": 300, - "kind": "local-variable", - "name": "cursor" - }, - { - "file": "internal/automation/center.go", - "line": 300, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 307, - "kind": "function", - "name": "isDeferredReplay" - }, - { - "file": "internal/automation/center.go", - "line": 311, - "kind": "function", - "name": "deferTask" - }, - { - "file": "internal/automation/center.go", - "line": 315, - "kind": "function", - "name": "deferTaskWithError" - }, - { - "file": "internal/automation/center.go", - "line": 316, - "kind": "local-variable", - "name": "key" - }, - { - "file": "internal/automation/center.go", - "line": 321, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 321, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/automation/center.go", - "line": 340, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 340, - "kind": "local-variable", - "name": "paused" - }, - { - "file": "internal/automation/center.go", - "line": 340, - "kind": "local-variable", - "name": "until" - }, - { - "file": "internal/automation/center.go", - "line": 347, - "kind": "local-variable", - "name": "enabled" - }, - { - "file": "internal/automation/center.go", - "line": 347, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 363, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/center.go", - "line": 383, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 383, - "kind": "local-variable", - "name": "rules" - }, - { - "file": "internal/automation/center.go", - "line": 390, - "kind": "local-variable", - "name": "sent" - }, - { - "file": "internal/automation/center.go", - "line": 391, - "kind": "range-variable", - "name": "rule" - }, - { - "file": "internal/automation/center.go", - "line": 396, - "kind": "local-variable", - "name": "rawTask" - }, - { - "file": "internal/automation/center.go", - "line": 398, - "kind": "local-variable", - "name": "rawJSON" - }, - { - "file": "internal/automation/center.go", - "line": 399, - "kind": "local-variable", - "name": "runID" - }, - { - "file": "internal/automation/center.go", - "line": 399, - "kind": "local-variable", - "name": "startErr" - }, - { - "file": "internal/automation/center.go", - "line": 399, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/automation/center.go", - "line": 417, - "kind": "local-variable", - "name": "getErr" - }, - { - "file": "internal/automation/center.go", - "line": 417, - "kind": "local-variable", - "name": "run" - }, - { - "file": "internal/automation/center.go", - "line": 421, - "kind": "local-variable", - "name": "deferred" - }, - { - "file": "internal/automation/center.go", - "line": 421, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 421, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/automation/center.go", - "line": 429, - "kind": "local-variable", - "name": "errMsg" - }, - { - "file": "internal/automation/center.go", - "line": 429, - "kind": "local-variable", - "name": "status" - }, - { - "file": "internal/automation/center.go", - "line": 433, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "internal/automation/center.go", - "line": 433, - "kind": "local-variable", - "name": "finishCtx" - }, - { - "file": "internal/automation/center.go", - "line": 434, - "kind": "local-variable", - "name": "finishErr" - }, - { - "file": "internal/automation/center.go", - "line": 468, - "kind": "function", - "name": "notifyRunNeedsReview" - }, - { - "file": "internal/automation/center.go", - "line": 481, - "kind": "var", - "name": "cfg" - }, - { - "file": "internal/automation/center.go", - "line": 485, - "kind": "local-variable", - "name": "card" - }, - { - "file": "internal/automation/center.go", - "line": 485, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 498, - "kind": "function", - "name": "prepareTask" - }, - { - "file": "internal/automation/center.go", - "line": 508, - "kind": "local-variable", - "name": "needsDetail" - }, - { - "file": "internal/automation/center.go", - "line": 509, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 509, - "kind": "local-variable", - "name": "existing" - }, - { - "file": "internal/automation/center.go", - "line": 523, - "kind": "local-variable", - "name": "cookieStr" - }, - { - "file": "internal/automation/center.go", - "line": 525, - "kind": "var", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 531, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/automation/center.go", - "line": 531, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 567, - "kind": "function", - "name": "mergeOrderIntoTask" - }, - { - "file": "internal/automation/center.go", - "line": 610, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center.go", - "line": 630, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/automation/center.go", - "line": 630, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center.go", - "line": 634, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/automation/center.go", - "line": 634, - "kind": "local-variable", - "name": "ready" - }, - { - "file": "internal/automation/center.go", - "line": 655, - "kind": "function", - "name": "buildTriggerKey" - }, - { - "file": "internal/automation/center.go", - "line": 657, - "kind": "local-variable", - "name": "attempt" - }, - { - "file": "internal/automation/center.go", - "line": 657, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 28, - "kind": "type", - "name": "fakeConsignResult" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 35, - "kind": "function", - "name": "FetchUserProfile" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 38, - "kind": "function", - "name": "ConsignContext" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 44, - "kind": "local-variable", - "name": "result" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 50, - "kind": "function", - "name": "FetchItemsPage" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 53, - "kind": "function", - "name": "FetchAllItems" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 56, - "kind": "function", - "name": "PublishItem" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 59, - "kind": "function", - "name": "RefreshTokenWithDeviceIDContext" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 63, - "kind": "type", - "name": "fakeCredentialRecoverer" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 69, - "kind": "function", - "name": "FetchOrderDetail" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 73, - "kind": "function", - "name": "RecoverExpiredCredential" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 78, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 78, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 85, - "kind": "function", - "name": "TestConfirmShipmentRetriesFromCheckpointWithoutResendingCard" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 86, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 86, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 88, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 89, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 90, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 90, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 94, - "kind": "local-variable", - "name": "cardID" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 95, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 105, - "kind": "local-variable", - "name": "mtopMock" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 109, - "kind": "local-variable", - "name": "recoverer" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 110, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 111, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 114, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 116, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 119, - "kind": "var", - "name": "errMsg" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 119, - "kind": "var", - "name": "status" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 120, - "kind": "var", - "name": "cursor" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 120, - "kind": "var", - "name": "sent" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 121, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 129, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 141, - "kind": "function", - "name": "TestConfirmShipmentRecoversExpiredSessionAndRetriesOnlyConsign" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 142, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 142, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 144, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 145, - "kind": "local-variable", - "name": "mtopMock" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 149, - "kind": "local-variable", - "name": "recoverer" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 150, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 153, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 162, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 162, - "kind": "local-variable", - "name": "order" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 172, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 172, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 174, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 175, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 191, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 223, - "kind": "local-variable", - "name": "center2" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 236, - "kind": "function", - "name": "TestConfirmShipmentQuarantinesKnownRemoteSuccessWhenLocalPersistenceFails" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 237, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 237, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 239, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 240, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 243, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 249, - "kind": "local-variable", - "name": "mtopMock" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 250, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 252, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 255, - "kind": "var", - "name": "uncertain" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 262, - "kind": "local-variable", - "name": "getErr" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 262, - "kind": "local-variable", - "name": "order" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 271, - "kind": "function", - "name": "TestConfirmShipmentKeepsAuthoritativeSnapshotWhenSessionUnchanged" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 272, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 272, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 274, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 275, - "kind": "local-variable", - "name": "initial" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 276, - "kind": "local-variable", - "name": "metadata" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 280, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 283, - "kind": "local-variable", - "name": "updated" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 284, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 285, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 287, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 293, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 293, - "kind": "local-variable", - "name": "getErr" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 300, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 300, - "kind": "local-variable", - "name": "snapshot" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 311, - "kind": "function", - "name": "TestConfirmShipmentKeepsFlatMockFallbackWithoutSnapshot" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 312, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 312, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 314, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 315, - "kind": "local-variable", - "name": "initial" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 316, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 319, - "kind": "local-variable", - "name": "updated" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 320, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 321, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 323, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 329, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 329, - "kind": "local-variable", - "name": "getErr" - }, - { - "file": "internal/automation/center_mock_mtop_test.go", - "line": 336, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/automation/center_test.go", - "line": 22, - "kind": "type", - "name": "automationRoundTripperFunc" - }, - { - "file": "internal/automation/center_test.go", - "line": 24, - "kind": "function", - "name": "RoundTrip" - }, - { - "file": "internal/automation/center_test.go", - "line": 28, - "kind": "type", - "name": "testSenderProvider" - }, - { - "file": "internal/automation/center_test.go", - "line": 30, - "kind": "function", - "name": "Sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 32, - "kind": "type", - "name": "testSender" - }, - { - "file": "internal/automation/center_test.go", - "line": 41, - "kind": "function", - "name": "SendText" - }, - { - "file": "internal/automation/center_test.go", - "line": 52, - "kind": "function", - "name": "TestPartialAutomationRunIsQuarantined" - }, - { - "file": "internal/automation/center_test.go", - "line": 53, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 53, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 55, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 56, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 57, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 66, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 67, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 68, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 71, - "kind": "var", - "name": "status" - }, - { - "file": "internal/automation/center_test.go", - "line": 72, - "kind": "var", - "name": "sent" - }, - { - "file": "internal/automation/center_test.go", - "line": 73, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 81, - "kind": "function", - "name": "TestMessageDefinitelyNotSentIsRetried" - }, - { - "file": "internal/automation/center_test.go", - "line": 82, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 82, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 84, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 85, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 86, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 92, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 93, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 94, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/center_test.go", - "line": 95, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 98, - "kind": "var", - "name": "status" - }, - { - "file": "internal/automation/center_test.go", - "line": 99, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 106, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 113, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 121, - "kind": "function", - "name": "TestAbortRunActionFailureQuarantinesRun" - }, - { - "file": "internal/automation/center_test.go", - "line": 122, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 122, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 124, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 125, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 126, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 132, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 138, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 139, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/center_test.go", - "line": 140, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 143, - "kind": "var", - "name": "status" - }, - { - "file": "internal/automation/center_test.go", - "line": 144, - "kind": "var", - "name": "actionStarted" - }, - { - "file": "internal/automation/center_test.go", - "line": 145, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 153, - "kind": "function", - "name": "TestCardDefinitelyNotSentIsRetriedAndDataInventoryRestored" - }, - { - "file": "internal/automation/center_test.go", - "line": 154, - "kind": "range-variable", - "name": "tc" - }, - { - "file": "internal/automation/center_test.go", - "line": 163, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 163, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 165, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 166, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 167, - "kind": "local-variable", - "name": "query" - }, - { - "file": "internal/automation/center_test.go", - "line": 168, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 168, - "kind": "local-variable", - "name": "res" - }, - { - "file": "internal/automation/center_test.go", - "line": 172, - "kind": "local-variable", - "name": "cardID" - }, - { - "file": "internal/automation/center_test.go", - "line": 173, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 180, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 181, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 182, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/center_test.go", - "line": 184, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 187, - "kind": "var", - "name": "status" - }, - { - "file": "internal/automation/center_test.go", - "line": 188, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 195, - "kind": "var", - "name": "inventory" - }, - { - "file": "internal/automation/center_test.go", - "line": 196, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 201, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 212, - "kind": "function", - "name": "TestRuleMatchingUsesStoredOrderItemWhenEventOmitsItemID" - }, - { - "file": "internal/automation/center_test.go", - "line": 213, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 213, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 215, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 216, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 217, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 222, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 229, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 230, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 231, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 241, - "kind": "function", - "name": "TestImageCardMissingSenderIsDefinitelyNotSent" - }, - { - "file": "internal/automation/center_test.go", - "line": 242, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 242, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 244, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 245, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 251, - "kind": "function", - "name": "SendImage" - }, - { - "file": "internal/automation/center_test.go", - "line": 252, - "kind": "function", - "name": "UpdateCookie" - }, - { - "file": "internal/automation/center_test.go", - "line": 259, - "kind": "type", - "name": "testFetcher" - }, - { - "file": "internal/automation/center_test.go", - "line": 265, - "kind": "function", - "name": "FetchOrderDetail" - }, - { - "file": "internal/automation/center_test.go", - "line": 272, - "kind": "function", - "name": "TestReviewAutomationsDoNotRequireOrderDetail" - }, - { - "file": "internal/automation/center_test.go", - "line": 273, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 273, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 275, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 276, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 277, - "kind": "range-variable", - "name": "trigger" - }, - { - "file": "internal/automation/center_test.go", - "line": 278, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 285, - "kind": "local-variable", - "name": "calls" - }, - { - "file": "internal/automation/center_test.go", - "line": 286, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 287, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 289, - "kind": "range-variable", - "name": "i" - }, - { - "file": "internal/automation/center_test.go", - "line": 289, - "kind": "range-variable", - "name": "trigger" - }, - { - "file": "internal/automation/center_test.go", - "line": 290, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/center_test.go", - "line": 291, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 300, - "kind": "function", - "name": "TestOrderPaidPreparationFailureIsPersistedAndRecovered" - }, - { - "file": "internal/automation/center_test.go", - "line": 301, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 301, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 303, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 304, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 307, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 313, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 314, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 316, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/center_test.go", - "line": 317, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 320, - "kind": "var", - "name": "pending" - }, - { - "file": "internal/automation/center_test.go", - "line": 320, - "kind": "var", - "name": "runs" - }, - { - "file": "internal/automation/center_test.go", - "line": 333, - "kind": "var", - "name": "status" - }, - { - "file": "internal/automation/center_test.go", - "line": 340, - "kind": "function", - "name": "newAutomationTestStore" - }, - { - "file": "internal/automation/center_test.go", - "line": 342, - "kind": "local-variable", - "name": "database" - }, - { - "file": "internal/automation/center_test.go", - "line": 342, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 346, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 347, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 350, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 351, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 357, - "kind": "function", - "name": "TestActionDelayUsesCardDefaultUnlessOverridden" - }, - { - "file": "internal/automation/center_test.go", - "line": 358, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 358, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 360, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 361, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 362, - "kind": "local-variable", - "name": "cardID" - }, - { - "file": "internal/automation/center_test.go", - "line": 362, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 368, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 370, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 370, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/automation/center_test.go", - "line": 384, - "kind": "function", - "name": "TestActionDelayRejectsDisabledCardAndEmptyTextCard" - }, - { - "file": "internal/automation/center_test.go", - "line": 385, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 385, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 387, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 388, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 389, - "kind": "local-variable", - "name": "disabledID" - }, - { - "file": "internal/automation/center_test.go", - "line": 389, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 393, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 394, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 397, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 402, - "kind": "function", - "name": "TestSendDataCardKeepsConsumedInventoryWhenDeliveryResultIsUncertain" - }, - { - "file": "internal/automation/center_test.go", - "line": 403, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 403, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 405, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 406, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 407, - "kind": "local-variable", - "name": "cardID" - }, - { - "file": "internal/automation/center_test.go", - "line": 407, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 413, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 414, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 421, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 421, - "kind": "local-variable", - "name": "reserved" - }, - { - "file": "internal/automation/center_test.go", - "line": 427, - "kind": "function", - "name": "TestCenterSkipsPausedAccountTasks" - }, - { - "file": "internal/automation/center_test.go", - "line": 428, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 428, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 430, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 431, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 432, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 438, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 441, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 442, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 443, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 449, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 452, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 455, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 466, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 469, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 475, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 480, - "kind": "function", - "name": "TestDelayedAutomationIsPersistedAndReplayedWithoutSleeping" - }, - { - "file": "internal/automation/center_test.go", - "line": 481, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 481, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 483, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 484, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 485, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 491, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 492, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 493, - "kind": "local-variable", - "name": "start" - }, - { - "file": "internal/automation/center_test.go", - "line": 494, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 500, - "kind": "var", - "name": "pending" - }, - { - "file": "internal/automation/center_test.go", - "line": 501, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 511, - "kind": "function", - "name": "TestMultipleActionDelaysPreserveSequentialSemantics" - }, - { - "file": "internal/automation/center_test.go", - "line": 512, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 512, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 514, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 515, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 516, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 516, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/automation/center_test.go", - "line": 526, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 527, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 528, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 534, - "kind": "var", - "name": "cursor" - }, - { - "file": "internal/automation/center_test.go", - "line": 535, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 538, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 554, - "kind": "function", - "name": "TestExpiredRunDuringExternalActionIsQuarantined" - }, - { - "file": "internal/automation/center_test.go", - "line": 555, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 555, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 557, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 558, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 559, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/automation/center_test.go", - "line": 561, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/center_test.go", - "line": 562, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/automation/center_test.go", - "line": 563, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 563, - "kind": "local-variable", - "name": "runID" - }, - { - "file": "internal/automation/center_test.go", - "line": 563, - "kind": "local-variable", - "name": "started" - }, - { - "file": "internal/automation/center_test.go", - "line": 568, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 568, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/automation/center_test.go", - "line": 572, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 574, - "kind": "local-variable", - "name": "run" - }, - { - "file": "internal/automation/center_test.go", - "line": 580, - "kind": "function", - "name": "TestInvalidDeferredTaskMovesToDeadLetter" - }, - { - "file": "internal/automation/center_test.go", - "line": 581, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 581, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 583, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 584, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 589, - "kind": "local-variable", - "name": "scheduler" - }, - { - "file": "internal/automation/center_test.go", - "line": 590, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/automation/center_test.go", - "line": 594, - "kind": "var", - "name": "status" - }, - { - "file": "internal/automation/center_test.go", - "line": 595, - "kind": "var", - "name": "attempts" - }, - { - "file": "internal/automation/center_test.go", - "line": 596, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 604, - "kind": "function", - "name": "TestUnknownExternalAutomationRunCannotBeRetried" - }, - { - "file": "internal/automation/center_test.go", - "line": 605, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 605, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 607, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 608, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 609, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 615, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 616, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 617, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 620, - "kind": "var", - "name": "runID" - }, - { - "file": "internal/automation/center_test.go", - "line": 621, - "kind": "var", - "name": "initialStatus" - }, - { - "file": "internal/automation/center_test.go", - "line": 622, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 628, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 631, - "kind": "var", - "name": "status" - }, - { - "file": "internal/automation/center_test.go", - "line": 632, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 640, - "kind": "function", - "name": "TestFailedDeferredTaskRemainsPending" - }, - { - "file": "internal/automation/center_test.go", - "line": 641, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 641, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 643, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 644, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 645, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 651, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/center_test.go", - "line": 652, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/automation/center_test.go", - "line": 653, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 656, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 658, - "kind": "var", - "name": "status" - }, - { - "file": "internal/automation/center_test.go", - "line": 659, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 667, - "kind": "function", - "name": "TestCenterOrderPaidFetchesOrderDetailMatchesSpecAndQuantity" - }, - { - "file": "internal/automation/center_test.go", - "line": 668, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 668, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 670, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 672, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 673, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 676, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 681, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 681, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/automation/center_test.go", - "line": 693, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 694, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 707, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/automation/center_test.go", - "line": 707, - "kind": "local-variable", - "name": "want" - }, - { - "file": "internal/automation/center_test.go", - "line": 710, - "kind": "range-variable", - "name": "i" - }, - { - "file": "internal/automation/center_test.go", - "line": 710, - "kind": "range-variable", - "name": "want" - }, - { - "file": "internal/automation/center_test.go", - "line": 715, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 715, - "kind": "local-variable", - "name": "order" - }, - { - "file": "internal/automation/center_test.go", - "line": 727, - "kind": "function", - "name": "TestCenterBuyerReviewedFirstEventRecordsReviewTime" - }, - { - "file": "internal/automation/center_test.go", - "line": 728, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 728, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 730, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 731, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 733, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 744, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 745, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 746, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 756, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 756, - "kind": "local-variable", - "name": "order" - }, - { - "file": "internal/automation/center_test.go", - "line": 763, - "kind": "local-variable", - "name": "sysShipped" - }, - { - "file": "internal/automation/center_test.go", - "line": 764, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 769, - "kind": "local-variable", - "name": "due" - }, - { - "file": "internal/automation/center_test.go", - "line": 769, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 778, - "kind": "function", - "name": "TestCenterOrderPaidSendsAllCardActionsForSameSpec" - }, - { - "file": "internal/automation/center_test.go", - "line": 779, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 779, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 781, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 782, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 788, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 800, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 801, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 806, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 813, - "kind": "local-variable", - "name": "want" - }, - { - "file": "internal/automation/center_test.go", - "line": 817, - "kind": "range-variable", - "name": "i" - }, - { - "file": "internal/automation/center_test.go", - "line": 824, - "kind": "function", - "name": "TestCenterOrderPaidDoesNotConfirmWhenNoCardSpecMatches" - }, - { - "file": "internal/automation/center_test.go", - "line": 825, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 825, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 827, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 828, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 832, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 844, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 845, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 858, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 858, - "kind": "local-variable", - "name": "order" - }, - { - "file": "internal/automation/center_test.go", - "line": 867, - "kind": "function", - "name": "TestCenterOrderPaidSendsCardBeforeConfirmShipment" - }, - { - "file": "internal/automation/center_test.go", - "line": 868, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 868, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 870, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 871, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 875, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 888, - "kind": "local-variable", - "name": "events" - }, - { - "file": "internal/automation/center_test.go", - "line": 889, - "kind": "local-variable", - "name": "server" - }, - { - "file": "internal/automation/center_test.go", - "line": 895, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 896, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 900, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 907, - "kind": "local-variable", - "name": "want" - }, - { - "file": "internal/automation/center_test.go", - "line": 911, - "kind": "range-variable", - "name": "i" - }, - { - "file": "internal/automation/center_test.go", - "line": 918, - "kind": "function", - "name": "TestConfirmShipmentPersistsAuthoritativeSessionBeforeParseError" - }, - { - "file": "internal/automation/center_test.go", - "line": 919, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 919, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 921, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 922, - "kind": "local-variable", - "name": "initialValue" - }, - { - "file": "internal/automation/center_test.go", - "line": 923, - "kind": "local-variable", - "name": "snapshot" - }, - { - "file": "internal/automation/center_test.go", - "line": 929, - "kind": "local-variable", - "name": "metadata" - }, - { - "file": "internal/automation/center_test.go", - "line": 930, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 934, - "kind": "var", - "name": "requestCookie" - }, - { - "file": "internal/automation/center_test.go", - "line": 935, - "kind": "local-variable", - "name": "client" - }, - { - "file": "internal/automation/center_test.go", - "line": 947, - "kind": "local-variable", - "name": "lockReleasedBeforeRuntimeUpdate" - }, - { - "file": "internal/automation/center_test.go", - "line": 948, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 949, - "kind": "local-variable", - "name": "acquired" - }, - { - "file": "internal/automation/center_test.go", - "line": 951, - "kind": "local-variable", - "name": "unlock" - }, - { - "file": "internal/automation/center_test.go", - "line": 961, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 963, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 966, - "kind": "var", - "name": "uncertain" - }, - { - "file": "internal/automation/center_test.go", - "line": 970, - "kind": "range-variable", - "name": "want" - }, - { - "file": "internal/automation/center_test.go", - "line": 975, - "kind": "range-variable", - "name": "unwanted" - }, - { - "file": "internal/automation/center_test.go", - "line": 981, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/automation/center_test.go", - "line": 981, - "kind": "local-variable", - "name": "getErr" - }, - { - "file": "internal/automation/center_test.go", - "line": 991, - "kind": "local-variable", - "name": "gotSnapshot" - }, - { - "file": "internal/automation/center_test.go", - "line": 991, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/automation/center_test.go", - "line": 995, - "kind": "local-variable", - "name": "values" - }, - { - "file": "internal/automation/center_test.go", - "line": 996, - "kind": "range-variable", - "name": "cookie" - }, - { - "file": "internal/automation/center_test.go", - "line": 1012, - "kind": "function", - "name": "TestConfirmShipmentPropagatesAuthoritativeEmptySession" - }, - { - "file": "internal/automation/center_test.go", - "line": 1013, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 1013, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 1015, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 1016, - "kind": "local-variable", - "name": "initialValue" - }, - { - "file": "internal/automation/center_test.go", - "line": 1017, - "kind": "local-variable", - "name": "metadata" - }, - { - "file": "internal/automation/center_test.go", - "line": 1021, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1024, - "kind": "local-variable", - "name": "client" - }, - { - "file": "internal/automation/center_test.go", - "line": 1035, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 1036, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 1038, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1041, - "kind": "var", - "name": "uncertain" - }, - { - "file": "internal/automation/center_test.go", - "line": 1045, - "kind": "local-variable", - "name": "detail" - }, - { - "file": "internal/automation/center_test.go", - "line": 1045, - "kind": "local-variable", - "name": "getErr" - }, - { - "file": "internal/automation/center_test.go", - "line": 1052, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/automation/center_test.go", - "line": 1052, - "kind": "local-variable", - "name": "snapshot" - }, - { - "file": "internal/automation/center_test.go", - "line": 1061, - "kind": "function", - "name": "TestManualFullDeliveryIsImmediateIdempotentAndForcesConfirmation" - }, - { - "file": "internal/automation/center_test.go", - "line": 1062, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 1062, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 1064, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 1065, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 1068, - "kind": "local-variable", - "name": "cardID" - }, - { - "file": "internal/automation/center_test.go", - "line": 1068, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1084, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 1085, - "kind": "local-variable", - "name": "mtopMock" - }, - { - "file": "internal/automation/center_test.go", - "line": 1086, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 1089, - "kind": "local-variable", - "name": "order" - }, - { - "file": "internal/automation/center_test.go", - "line": 1091, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1091, - "kind": "local-variable", - "name": "sent" - }, - { - "file": "internal/automation/center_test.go", - "line": 1095, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1111, - "kind": "function", - "name": "NotifyDelivery" - }, - { - "file": "internal/automation/center_test.go", - "line": 1119, - "kind": "function", - "name": "messages" - }, - { - "file": "internal/automation/center_test.go", - "line": 1122, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/automation/center_test.go", - "line": 1123, - "kind": "range-variable", - "name": "c" - }, - { - "file": "internal/automation/center_test.go", - "line": 1123, - "kind": "range-variable", - "name": "i" - }, - { - "file": "internal/automation/center_test.go", - "line": 1131, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 1131, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 1133, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 1134, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 1138, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1149, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 1150, - "kind": "local-variable", - "name": "notifier" - }, - { - "file": "internal/automation/center_test.go", - "line": 1151, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 1157, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1164, - "kind": "local-variable", - "name": "msgs" - }, - { - "file": "internal/automation/center_test.go", - "line": 1175, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 1175, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 1177, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 1178, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 1182, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1194, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 1195, - "kind": "local-variable", - "name": "notifier" - }, - { - "file": "internal/automation/center_test.go", - "line": 1196, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 1208, - "kind": "local-variable", - "name": "msgs" - }, - { - "file": "internal/automation/center_test.go", - "line": 1219, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 1219, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 1221, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 1223, - "kind": "local-variable", - "name": "notifier" - }, - { - "file": "internal/automation/center_test.go", - "line": 1224, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 1240, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 1240, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 1242, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 1243, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 1244, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1258, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1258, - "kind": "local-variable", - "name": "orders" - }, - { - "file": "internal/automation/center_test.go", - "line": 1270, - "kind": "function", - "name": "TestReviewRequestCounterFailureMovesCompletedActionToNeedsReview" - }, - { - "file": "internal/automation/center_test.go", - "line": 1271, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/center_test.go", - "line": 1271, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/center_test.go", - "line": 1273, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/center_test.go", - "line": 1274, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/center_test.go", - "line": 1275, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1275, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/automation/center_test.go", - "line": 1282, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1285, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1291, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1291, - "kind": "local-variable", - "name": "rule" - }, - { - "file": "internal/automation/center_test.go", - "line": 1295, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/center_test.go", - "line": 1296, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/center_test.go", - "line": 1308, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/center_test.go", - "line": 1308, - "kind": "local-variable", - "name": "order" - }, - { - "file": "internal/automation/center_test.go", - "line": 1312, - "kind": "var", - "name": "message" - }, - { - "file": "internal/automation/center_test.go", - "line": 1312, - "kind": "var", - "name": "status" - }, - { - "file": "internal/automation/center_test.go", - "line": 1313, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 28, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 43, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 47, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 70, - "kind": "local-variable", - "name": "runID" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 71, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 71, - "kind": "local-variable", - "name": "run" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 78, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 78, - "kind": "local-variable", - "name": "rule" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 96, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 98, - "kind": "range-variable", - "name": "action" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 103, - "kind": "range-variable", - "name": "action" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 110, - "kind": "range-variable", - "name": "action" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 120, - "kind": "range-variable", - "name": "action" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 130, - "kind": "local-variable", - "name": "out" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 132, - "kind": "range-variable", - "name": "i" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 137, - "kind": "local-variable", - "name": "config" - }, - { - "file": "internal/automation/event_pipeline.go", - "line": 140, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/automation/event_pipeline_test.go", - "line": 27, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/automation/event_pipeline_test.go", - "line": 39, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/events.go", - "line": 19, - "kind": "const", - "name": "TriggerOrderPaid" - }, - { - "file": "internal/automation/events.go", - "line": 20, - "kind": "const", - "name": "TriggerBuyerReviewed" - }, - { - "file": "internal/automation/events.go", - "line": 21, - "kind": "const", - "name": "TriggerReviewMissingTimeout" - }, - { - "file": "internal/automation/events.go", - "line": 23, - "kind": "const", - "name": "ActionConfirmShipment" - }, - { - "file": "internal/automation/events.go", - "line": 24, - "kind": "const", - "name": "ActionSendCard" - }, - { - "file": "internal/automation/events.go", - "line": 25, - "kind": "const", - "name": "ActionSendText" - }, - { - "file": "internal/automation/events.go", - "line": 69, - "kind": "local-variable", - "name": "f" - }, - { - "file": "internal/automation/events.go", - "line": 73, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/events.go", - "line": 96, - "kind": "type", - "name": "rawFields" - }, - { - "file": "internal/automation/events.go", - "line": 111, - "kind": "function", - "name": "fieldsFromRaw" - }, - { - "file": "internal/automation/events.go", - "line": 112, - "kind": "var", - "name": "f" - }, - { - "file": "internal/automation/events.go", - "line": 113, - "kind": "local-variable", - "name": "m1" - }, - { - "file": "internal/automation/events.go", - "line": 114, - "kind": "local-variable", - "name": "s" - }, - { - "file": "internal/automation/events.go", - "line": 117, - "kind": "local-variable", - "name": "m10" - }, - { - "file": "internal/automation/events.go", - "line": 127, - "kind": "local-variable", - "name": "contentJSON" - }, - { - "file": "internal/automation/events.go", - "line": 128, - "kind": "local-variable", - "name": "role" - }, - { - "file": "internal/automation/events.go", - "line": 131, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/automation/events.go", - "line": 136, - "kind": "local-variable", - "name": "m3" - }, - { - "file": "internal/automation/events.go", - "line": 141, - "kind": "local-variable", - "name": "m4" - }, - { - "file": "internal/automation/events.go", - "line": 162, - "kind": "local-variable", - "name": "chatID" - }, - { - "file": "internal/automation/events.go", - "line": 162, - "kind": "local-variable", - "name": "orderID" - }, - { - "file": "internal/automation/events.go", - "line": 187, - "kind": "function", - "name": "isOrderPaidEvent" - }, - { - "file": "internal/automation/events.go", - "line": 197, - "kind": "function", - "name": "isBuyerReviewedEvent" - }, - { - "file": "internal/automation/events.go", - "line": 208, - "kind": "function", - "name": "extFields" - }, - { - "file": "internal/automation/events.go", - "line": 212, - "kind": "var", - "name": "m" - }, - { - "file": "internal/automation/events.go", - "line": 219, - "kind": "function", - "name": "parseUpdateKey" - }, - { - "file": "internal/automation/events.go", - "line": 220, - "kind": "local-variable", - "name": "parts" - }, - { - "file": "internal/automation/events.go", - "line": 227, - "kind": "function", - "name": "queryValue" - }, - { - "file": "internal/automation/events.go", - "line": 231, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/events.go", - "line": 231, - "kind": "local-variable", - "name": "u" - }, - { - "file": "internal/automation/events.go", - "line": 238, - "kind": "function", - "name": "mapAt" - }, - { - "file": "internal/automation/events.go", - "line": 239, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/automation/events.go", - "line": 243, - "kind": "function", - "name": "nestedString" - }, - { - "file": "internal/automation/events.go", - "line": 244, - "kind": "var", - "name": "cur" - }, - { - "file": "internal/automation/events.go", - "line": 245, - "kind": "range-variable", - "name": "p" - }, - { - "file": "internal/automation/events.go", - "line": 246, - "kind": "local-variable", - "name": "cm" - }, - { - "file": "internal/automation/events.go", - "line": 246, - "kind": "local-variable", - "name": "ok" - }, - { - "file": "internal/automation/events.go", - "line": 255, - "kind": "function", - "name": "strAny" - }, - { - "file": "internal/automation/events.go", - "line": 256, - "kind": "local-variable", - "name": "x" - }, - { - "file": "internal/automation/events.go", - "line": 262, - "kind": "local-variable", - "name": "b" - }, - { - "file": "internal/automation/events.go", - "line": 267, - "kind": "function", - "name": "firstNonEmpty" - }, - { - "file": "internal/automation/events.go", - "line": 268, - "kind": "range-variable", - "name": "v" - }, - { - "file": "internal/automation/events.go", - "line": 276, - "kind": "function", - "name": "trimGoofishSID" - }, - { - "file": "internal/automation/events.go", - "line": 277, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/automation/events.go", - "line": 283, - "kind": "var", - "name": "orderIDPatterns" - }, - { - "file": "internal/automation/events.go", - "line": 290, - "kind": "function", - "name": "extractOrderRoleFromContent" - }, - { - "file": "internal/automation/events.go", - "line": 291, - "kind": "var", - "name": "c" - }, - { - "file": "internal/automation/events.go", - "line": 295, - "kind": "range-variable", - "name": "path" - }, - { - "file": "internal/automation/events.go", - "line": 300, - "kind": "local-variable", - "name": "role" - }, - { - "file": "internal/automation/events.go", - "line": 307, - "kind": "function", - "name": "orderRoleFromURL" - }, - { - "file": "internal/automation/events.go", - "line": 314, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/events.go", - "line": 314, - "kind": "local-variable", - "name": "u" - }, - { - "file": "internal/automation/events.go", - "line": 326, - "kind": "function", - "name": "bizTaskName" - }, - { - "file": "internal/automation/events.go", - "line": 327, - "kind": "var", - "name": "tag" - }, - { - "file": "internal/automation/events.go", - "line": 334, - "kind": "function", - "name": "orderRoleFromTaskName" - }, - { - "file": "internal/automation/events.go", - "line": 345, - "kind": "function", - "name": "matchOrderID" - }, - { - "file": "internal/automation/events.go", - "line": 346, - "kind": "range-variable", - "name": "re" - }, - { - "file": "internal/automation/events.go", - "line": 347, - "kind": "local-variable", - "name": "m" - }, - { - "file": "internal/automation/events.go", - "line": 354, - "kind": "function", - "name": "extractOrderIDFromContent" - }, - { - "file": "internal/automation/events.go", - "line": 355, - "kind": "var", - "name": "c" - }, - { - "file": "internal/automation/events.go", - "line": 359, - "kind": "range-variable", - "name": "path" - }, - { - "file": "internal/automation/events.go", - "line": 364, - "kind": "local-variable", - "name": "id" - }, - { - "file": "internal/automation/events_test.go", - "line": 8, - "kind": "function", - "name": "TestExtractTaskFromWS_BuyerReviewed" - }, - { - "file": "internal/automation/events_test.go", - "line": 9, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/automation/events_test.go", - "line": 22, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/events_test.go", - "line": 32, - "kind": "function", - "name": "TestExtractTaskFromWS_BuyerReviewedUsesBusinessKeyAcrossCopyVariants" - }, - { - "file": "internal/automation/events_test.go", - "line": 33, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/automation/events_test.go", - "line": 41, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/events_test.go", - "line": 47, - "kind": "function", - "name": "TestExtractTaskFromWS_ServiceReviewInvitationIgnored" - }, - { - "file": "internal/automation/events_test.go", - "line": 48, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/automation/events_test.go", - "line": 59, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/events_test.go", - "line": 64, - "kind": "function", - "name": "TestExtractTaskFromWS_OrderPaid" - }, - { - "file": "internal/automation/events_test.go", - "line": 65, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/automation/events_test.go", - "line": 77, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/events_test.go", - "line": 83, - "kind": "function", - "name": "TestExtractTaskFromWS_BuyerOrderPaidIgnored" - }, - { - "file": "internal/automation/events_test.go", - "line": 84, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/automation/events_test.go", - "line": 96, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/events_test.go", - "line": 101, - "kind": "function", - "name": "TestExtractTaskFromWS_BuyerOrderPaidTaskNameIgnored" - }, - { - "file": "internal/automation/events_test.go", - "line": 102, - "kind": "local-variable", - "name": "raw" - }, - { - "file": "internal/automation/events_test.go", - "line": 109, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/events_test.go", - "line": 114, - "kind": "function", - "name": "mustMap" - }, - { - "file": "internal/automation/events_test.go", - "line": 116, - "kind": "var", - "name": "m" - }, - { - "file": "internal/automation/events_test.go", - "line": 117, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/run_coordinator.go", - "line": 164, - "kind": "local-variable", - "name": "reason" - }, - { - "file": "internal/automation/run_coordinator.go", - "line": 241, - "kind": "local-variable", - "name": "reason" - }, - { - "file": "internal/automation/run_coordinator.go", - "line": 250, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 15, - "kind": "const", - "name": "defaultReviewRequestScanInterval" - }, - { - "file": "internal/automation/scheduler.go", - "line": 41, - "kind": "local-variable", - "name": "ticker" - }, - { - "file": "internal/automation/scheduler.go", - "line": 55, - "kind": "function", - "name": "Wait" - }, - { - "file": "internal/automation/scheduler.go", - "line": 61, - "kind": "function", - "name": "scan" - }, - { - "file": "internal/automation/scheduler.go", - "line": 64, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 64, - "kind": "local-variable", - "name": "recovered" - }, - { - "file": "internal/automation/scheduler.go", - "line": 72, - "kind": "local-variable", - "name": "waitingForWS" - }, - { - "file": "internal/automation/scheduler.go", - "line": 74, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 74, - "kind": "local-variable", - "name": "orders" - }, - { - "file": "internal/automation/scheduler.go", - "line": 79, - "kind": "range-variable", - "name": "order" - }, - { - "file": "internal/automation/scheduler.go", - "line": 80, - "kind": "local-variable", - "name": "allowErr" - }, - { - "file": "internal/automation/scheduler.go", - "line": 80, - "kind": "local-variable", - "name": "allowed" - }, - { - "file": "internal/automation/scheduler.go", - "line": 92, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 92, - "kind": "local-variable", - "name": "rules" - }, - { - "file": "internal/automation/scheduler.go", - "line": 100, - "kind": "range-variable", - "name": "rule" - }, - { - "file": "internal/automation/scheduler.go", - "line": 104, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/scheduler.go", - "line": 108, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 118, - "kind": "range-variable", - "name": "accountID" - }, - { - "file": "internal/automation/scheduler.go", - "line": 118, - "kind": "range-variable", - "name": "count" - }, - { - "file": "internal/automation/scheduler.go", - "line": 123, - "kind": "function", - "name": "runRecoveryTasks" - }, - { - "file": "internal/automation/scheduler.go", - "line": 124, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 124, - "kind": "local-variable", - "name": "runs" - }, - { - "file": "internal/automation/scheduler.go", - "line": 129, - "kind": "range-variable", - "name": "run" - }, - { - "file": "internal/automation/scheduler.go", - "line": 131, - "kind": "local-variable", - "name": "reason" - }, - { - "file": "internal/automation/scheduler.go", - "line": 136, - "kind": "var", - "name": "task" - }, - { - "file": "internal/automation/scheduler.go", - "line": 137, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 138, - "kind": "local-variable", - "name": "reason" - }, - { - "file": "internal/automation/scheduler.go", - "line": 143, - "kind": "local-variable", - "name": "allowed" - }, - { - "file": "internal/automation/scheduler.go", - "line": 143, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 145, - "kind": "local-variable", - "name": "postponeErr" - }, - { - "file": "internal/automation/scheduler.go", - "line": 150, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 150, - "kind": "local-variable", - "name": "rule" - }, - { - "file": "internal/automation/scheduler.go", - "line": 159, - "kind": "local-variable", - "name": "reason" - }, - { - "file": "internal/automation/scheduler.go", - "line": 165, - "kind": "local-variable", - "name": "postponeErr" - }, - { - "file": "internal/automation/scheduler.go", - "line": 170, - "kind": "local-variable", - "name": "claimErr" - }, - { - "file": "internal/automation/scheduler.go", - "line": 170, - "kind": "local-variable", - "name": "claimed" - }, - { - "file": "internal/automation/scheduler.go", - "line": 179, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 185, - "kind": "function", - "name": "recoveryNeedsSender" - }, - { - "file": "internal/automation/scheduler.go", - "line": 186, - "kind": "local-variable", - "name": "actions" - }, - { - "file": "internal/automation/scheduler.go", - "line": 201, - "kind": "function", - "name": "runDeferredTasks" - }, - { - "file": "internal/automation/scheduler.go", - "line": 202, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 202, - "kind": "local-variable", - "name": "tasks" - }, - { - "file": "internal/automation/scheduler.go", - "line": 207, - "kind": "range-variable", - "name": "pending" - }, - { - "file": "internal/automation/scheduler.go", - "line": 208, - "kind": "var", - "name": "task" - }, - { - "file": "internal/automation/scheduler.go", - "line": 209, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 217, - "kind": "local-variable", - "name": "deferredAgain" - }, - { - "file": "internal/automation/scheduler.go", - "line": 217, - "kind": "local-variable", - "name": "runErr" - }, - { - "file": "internal/automation/scheduler.go", - "line": 222, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 228, - "kind": "function", - "name": "errorString" - }, - { - "file": "internal/automation/scheduler.go", - "line": 235, - "kind": "function", - "name": "reviewRequestRuleDue" - }, - { - "file": "internal/automation/scheduler.go", - "line": 236, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "internal/automation/scheduler.go", - "line": 240, - "kind": "local-variable", - "name": "baseRaw" - }, - { - "file": "internal/automation/scheduler.go", - "line": 241, - "kind": "local-variable", - "name": "waitHours" - }, - { - "file": "internal/automation/scheduler.go", - "line": 246, - "kind": "local-variable", - "name": "base" - }, - { - "file": "internal/automation/scheduler.go", - "line": 253, - "kind": "type", - "name": "reviewRuleConfig" - }, - { - "file": "internal/automation/scheduler.go", - "line": 259, - "kind": "function", - "name": "parseReviewRuleConfig" - }, - { - "file": "internal/automation/scheduler.go", - "line": 260, - "kind": "local-variable", - "name": "cfg" - }, - { - "file": "internal/automation/scheduler.go", - "line": 264, - "kind": "var", - "name": "m" - }, - { - "file": "internal/automation/scheduler.go", - "line": 268, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/automation/scheduler.go", - "line": 271, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/automation/scheduler.go", - "line": 274, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/automation/scheduler.go", - "line": 277, - "kind": "local-variable", - "name": "v" - }, - { - "file": "internal/automation/scheduler.go", - "line": 283, - "kind": "function", - "name": "intFromAny" - }, - { - "file": "internal/automation/scheduler.go", - "line": 284, - "kind": "local-variable", - "name": "x" - }, - { - "file": "internal/automation/scheduler.go", - "line": 290, - "kind": "local-variable", - "name": "n" - }, - { - "file": "internal/automation/scheduler.go", - "line": 297, - "kind": "function", - "name": "parseDBTime" - }, - { - "file": "internal/automation/scheduler.go", - "line": 298, - "kind": "range-variable", - "name": "layout" - }, - { - "file": "internal/automation/scheduler.go", - "line": 306, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler.go", - "line": 306, - "kind": "local-variable", - "name": "t" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 13, - "kind": "type", - "name": "readinessTestSender" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 18, - "kind": "function", - "name": "AutomationReady" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 20, - "kind": "type", - "name": "readinessTestProvider" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 22, - "kind": "function", - "name": "Sender" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 50, - "kind": "local-variable", - "name": "cases" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 62, - "kind": "range-variable", - "name": "c" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 63, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 71, - "kind": "local-variable", - "name": "t1" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 74, - "kind": "local-variable", - "name": "t1" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 77, - "kind": "local-variable", - "name": "t1" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 80, - "kind": "local-variable", - "name": "t1" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 87, - "kind": "local-variable", - "name": "rule" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 129, - "kind": "function", - "name": "TestReviewRequestRuleDueUsesRepeatIntervalAfterFirstAttempt" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 130, - "kind": "local-variable", - "name": "rule" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 131, - "kind": "local-variable", - "name": "order" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 147, - "kind": "function", - "name": "TestParseDBTimeAcceptsPostgresTimestampText" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 148, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 152, - "kind": "local-variable", - "name": "want" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 160, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 163, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 166, - "kind": "local-variable", - "name": "got" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 175, - "kind": "local-variable", - "name": "database" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 175, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 180, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 181, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 183, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 208, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 214, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 215, - "kind": "local-variable", - "name": "center" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 216, - "kind": "local-variable", - "name": "sched" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 239, - "kind": "function", - "name": "TestSchedulerWaitsForWebSocketBeforeCreatingRun" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 240, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 240, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 242, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 243, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 244, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 244, - "kind": "local-variable", - "name": "ruleID" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 253, - "kind": "local-variable", - "name": "shipped" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 254, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 259, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 260, - "kind": "local-variable", - "name": "scheduler" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 262, - "kind": "var", - "name": "count" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 263, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 276, - "kind": "function", - "name": "TestSchedulerScansMoreThanOneReviewPage" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 277, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 277, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 279, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 280, - "kind": "local-variable", - "name": "admin" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 281, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 288, - "kind": "local-variable", - "name": "shipped" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 289, - "kind": "local-variable", - "name": "i" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 290, - "kind": "local-variable", - "name": "err" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 296, - "kind": "local-variable", - "name": "sender" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 303, - "kind": "function", - "name": "TestRecoveryNeedsSenderUsesNextActionType" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 304, - "kind": "local-variable", - "name": "rule" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 308, - "kind": "local-variable", - "name": "task" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 317, - "kind": "function", - "name": "TestAutomationSchedulerWaitsForShutdown" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 318, - "kind": "local-variable", - "name": "cleanup" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 318, - "kind": "local-variable", - "name": "store" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 320, - "kind": "local-variable", - "name": "scheduler" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 321, - "kind": "local-variable", - "name": "cancel" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 321, - "kind": "local-variable", - "name": "ctx" - }, - { - "file": "internal/automation/scheduler_test.go", - "line": 322, - "kind": "local-variable", - "name": "done" - }, { "file": "internal/browser/cookierenew.go", "line": 19, diff --git a/docs/architecture/refactoring-master-plan.md b/docs/architecture/refactoring-master-plan.md index a6a3f25..30f5e22 100644 --- a/docs/architecture/refactoring-master-plan.md +++ b/docs/architecture/refactoring-master-plan.md @@ -631,3 +631,4 @@ npm --prefix frontend run build | 2026-08-15 | 完成阶段 10 第五个 PR 切片“Go internal/db 注释基线按领域清零” | 为数据库 Store、repository、迁移/方言、多数据库适配、凭证与订单数据访问及其测试补齐函数、变量、字段和常量中文注释;`internal/db` 注释基线清零;数据库定向测试、SQLite 迁移与 CRUD 验证、Go 注释门禁通过,合并为一个可回滚提交 | 阶段 10:继续清理 Go internal/xianyu 领域注释基线 | | 2026-08-15 | 完成阶段 10 第六个 PR 切片“Go internal/xianyu 注释基线按领域清零” | 为 MTOP 请求、协议编解码与签名、二维码登录、续期、WebSocket、Cookie 刷新和用户代理代码及其测试补齐函数、变量、字段和常量中文注释;`internal/xianyu` 及子包注释基线清零;平台协议定向测试和 Go 注释门禁通过,合并为一个可回滚提交 | 阶段 10:继续清理 Go internal/engine、internal/automation 与其他领域注释基线 | | 2026-08-15 | 完成阶段 10 第七个 PR 切片“Go internal/engine 注释基线按领域清零” | 为账号运行时、连接循环、凭证作用域、消息分发、回复策略、AI、令牌缓存和生命周期测试补齐函数、变量、字段及常量中文注释;`internal/engine` 注释基线清零;Engine 定向测试、`go test -race ./internal/engine`、全量 Go/React 门禁通过,合并为一个可回滚提交 | 阶段 10:继续清理 Go internal/automation、internal/account、internal/adapter、internal/renewal、internal/notify、internal/chat 等领域注释基线 | +| 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 等领域注释基线 | diff --git a/internal/automation/account_tasks.go b/internal/automation/account_tasks.go index fc0a453..f5b419f 100644 --- a/internal/automation/account_tasks.go +++ b/internal/automation/account_tasks.go @@ -12,6 +12,7 @@ import ( "xianyu-go/internal/xianyu/mtop" ) +// TaskAutoRate 保存任务AutoRate,供当前处理流程使用 const ( TaskAutoRate = "auto_rate" TaskAutoPolish = "auto_polish" @@ -19,6 +20,7 @@ const ( polishItemMaxPages = 20 ) +// AccountTaskClient 保存账号任务Client,供当前处理流程使用 type AccountTaskClient interface { FetchPendingRateOrders(ctx context.Context, cookiesStr string, page, pageSize int) (*mtop.PendingRateResult, error) RateBuyer(ctx context.Context, cookiesStr, tradeID, feedback string) (*mtop.AccountTaskResult, error) @@ -26,6 +28,7 @@ type AccountTaskClient interface { PolishItem(ctx context.Context, cookiesStr, itemID string) (*mtop.AccountTaskResult, error) } +// AccountTaskSummary 保存账号任务Summary,供当前处理流程使用 type AccountTaskSummary struct { TaskType string `json:"task_type"` Found int `json:"found"` @@ -37,6 +40,7 @@ type AccountTaskSummary struct { // accountTaskCoordinator 负责账号自动评价、商品擦亮和凭证阻断状态。 // 它拥有账号任务专用的 Session 指纹状态,Center 只保留兼容调用入口和依赖装配。 +// accountTaskCoordinator 保存账号任务Coordinator,供当前处理流程使用 type accountTaskCoordinator struct { // repository 提供账号任务所需的最小持久化能力。 repository AccountTaskRepository @@ -61,12 +65,14 @@ func (c *accountTaskCoordinator) accountAutomationAllowed(ctx context.Context, a } // paused 表示账号是否被用户临时暂停。 // err 保存读取账号暂停状态的错误。 + // paused、err 保存paused、err,供当前处理流程使用 paused, _, err := c.repository.IsPaused(ctx, accountID) if err != nil { return false, fmt.Errorf("读取账号暂停状态: %w", err) } // enabled 表示账号是否处于启用状态。 // statusErr 保存读取账号启用状态的错误。 + // enabled、statusErr 保存enabled、statusErr,供当前处理流程使用 enabled, statusErr := c.repository.Status(ctx, accountID) if statusErr != nil { return false, fmt.Errorf("读取账号启用状态: %w", statusErr) @@ -76,6 +82,7 @@ func (c *accountTaskCoordinator) accountAutomationAllowed(ctx context.Context, a // runAccountTask 执行指定账号任务,并在执行前检查账号状态门禁。 func (c *accountTaskCoordinator) runAccountTask(ctx context.Context, accountID, taskType string) (AccountTaskSummary, error) { + // allowed、err 保存allowed、err,供当前处理流程使用 allowed, err := c.accountAutomationAllowed(ctx, accountID) if err != nil { return AccountTaskSummary{TaskType: taskType}, err @@ -83,6 +90,7 @@ func (c *accountTaskCoordinator) runAccountTask(ctx context.Context, accountID, if !allowed { return AccountTaskSummary{TaskType: taskType}, fmt.Errorf("账号已停用或暂停,无法执行任务") } + // settings、err 保存settings、err,供当前处理流程使用 settings, err := c.repository.Get(ctx, accountID) if err != nil { return AccountTaskSummary{TaskType: taskType}, err @@ -90,13 +98,16 @@ func (c *accountTaskCoordinator) runAccountTask(ctx context.Context, accountID, return c.runConfiguredAccountTask(ctx, settings, taskType) } +// runConfiguredAccountTask 负责运行Configured账号任务相关处理。 func (c *accountTaskCoordinator) runConfiguredAccountTask(ctx context.Context, settings db.AccountTaskSettings, taskType string) (AccountTaskSummary, error) { - if blocked, err := c.accountTaskSessionBlocked(ctx, settings.CookieID); err != nil { + if // blocked、err 保存blocked、err,供当前处理流程使用 + blocked, err := c.accountTaskSessionBlocked(ctx, settings.CookieID); err != nil { return AccountTaskSummary{TaskType: taskType}, err } else if blocked { return AccountTaskSummary{TaskType: taskType, Skipped: 1, Message: "Session 已失效,等待续期或重新登录"}, fmt.Errorf("账号 Session 已失效,已停止自动化 API 请求,等待续期或重新登录") } + // summary 保存summary,供当前处理流程使用 var ( summary AccountTaskSummary err error @@ -115,33 +126,42 @@ func (c *accountTaskCoordinator) runConfiguredAccountTask(ctx context.Context, s return summary, err } +// scanAccountTasks 负责scan账号任务列表相关处理。 func (c *accountTaskCoordinator) scanAccountTasks(ctx context.Context) { if c.client() == nil || c.repository == nil { return } + // settings、err 保存settings、err,供当前处理流程使用 settings, err := c.repository.Enabled(ctx) if err != nil { c.logger.Warn("扫描账号任务配置失败", "err", err) return } + // now 保存now,供当前处理流程使用 now := beijingNow() + // setting 表示当前遍历过程中的设置 for _, setting := range settings { + // allowed、err 保存allowed、err,供当前处理流程使用 allowed, err := c.accountAutomationAllowed(ctx, setting.CookieID) if err != nil || !allowed { continue } - if blocked, blockErr := c.accountTaskSessionBlocked(ctx, setting.CookieID); blockErr != nil || blocked { + if // blocked、blockErr 保存blocked、blockErr,供当前处理流程使用 + blocked, blockErr := c.accountTaskSessionBlocked(ctx, setting.CookieID); blockErr != nil || blocked { continue } if setting.AutoRateEnabled { - if _, err := c.runConfiguredAccountTask(ctx, setting, TaskAutoRate); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := c.runConfiguredAccountTask(ctx, setting, TaskAutoRate); err != nil { c.logger.Warn("自动评价扫描失败", "account", setting.CookieID, "err", err) } } if setting.AutoPolishEnabled && polishDue(setting, now) { - if blocked, _ := c.accountTaskSessionBlocked(ctx, setting.CookieID); blocked { + if // blocked 保存blocked,供当前处理流程使用 + blocked, _ := c.accountTaskSessionBlocked(ctx, setting.CookieID); blocked { continue } + // taskErr 保存任务Err,供当前处理流程使用 _, taskErr := c.runAutoPolish(ctx, setting, now, false) if taskErr != nil && mtop.IsSessionExpiredErr(taskErr) { taskErr = c.recoverAccountTaskSession(ctx, setting.CookieID, taskErr) @@ -153,24 +173,30 @@ func (c *accountTaskCoordinator) scanAccountTasks(ctx context.Context) { } } +// recoverAccountTaskSession 负责recover账号任务会话相关处理。 func (c *accountTaskCoordinator) recoverAccountTaskSession(ctx context.Context, accountID string, sessionErr error) error { + // fingerprint、fingerprintErr 保存fingerprint、fingerprintErr,供当前处理流程使用 fingerprint, fingerprintErr := c.accountCredentialFingerprint(ctx, accountID) if fingerprintErr == nil { c.sessionExpired.Store(accountID, fingerprint) } c.logger.Warn("自动化 API 检测到 Session 过期,停止后续请求并开始即时续期", "account", accountID, "err", sessionErr) - if recoverer := c.recoverer(); recoverer != nil && recoverer.RecoverExpiredCredential(ctx, accountID) { + if // recoverer 保存recoverer,供当前处理流程使用 + recoverer := c.recoverer(); recoverer != nil && recoverer.RecoverExpiredCredential(ctx, accountID) { c.sessionExpired.Delete(accountID) return fmt.Errorf("%w;Session 续期成功,本次自动化已停止,下一轮将使用新凭证", sessionErr) } return fmt.Errorf("%w;已停止该账号自动化 API 请求,等待续期或重新登录", sessionErr) } +// accountTaskSessionBlocked 负责账号任务会话Blocked相关处理。 func (c *accountTaskCoordinator) accountTaskSessionBlocked(ctx context.Context, accountID string) (bool, error) { + // blockedFingerprint、ok 保存blockedFingerprint、ok,供当前处理流程使用 blockedFingerprint, ok := c.sessionExpired.Load(accountID) if !ok { return false, nil } + // current、err 保存current、err,供当前处理流程使用 current, err := c.accountCredentialFingerprint(ctx, accountID) if err != nil { return true, err @@ -182,6 +208,7 @@ func (c *accountTaskCoordinator) accountTaskSessionBlocked(ctx context.Context, return true, nil } +// accountCredentialFingerprint 负责账号CredentialFingerprint相关处理。 func (c *accountTaskCoordinator) accountCredentialFingerprint(ctx context.Context, accountID string) (string, error) { // data 是生成自动化 Session 阻断指纹所需的最小 Cookie 与 metadata 输入。 data, err := c.repository.GetCookieRuntimeData(ctx, accountID) @@ -195,17 +222,23 @@ func (c *accountTaskCoordinator) accountCredentialFingerprint(ctx context.Contex // runAutoRate 执行自动评价任务,并在明确的单值 Cookie 查询边界内调用平台 API。 func (c *accountTaskCoordinator) runAutoRate(ctx context.Context, settings db.AccountTaskSettings) (AccountTaskSummary, error) { + // summary 保存summary,供当前处理流程使用 summary := AccountTaskSummary{TaskType: TaskAutoRate} if c.client() == nil { return summary, fmt.Errorf("自动评价客户端未初始化") } + // cookies、err 保存cookies、err,供当前处理流程使用 cookies, err := c.repository.GetValue(ctx, settings.CookieID) if err != nil { return summary, err } + // current 保存current,供当前处理流程使用 current := cookies + // orders 保存订单列表,供当前处理流程使用 var orders []mtop.PendingRateOrder - for page := 1; page <= 20; page++ { + for // page 保存页码,供当前处理流程使用 + page := 1; page <= 20; page++ { + // pending、err 保存pending、err,供当前处理流程使用 pending, err := c.client().FetchPendingRateOrders(ctx, current, page, 50) if err != nil { return summary, err @@ -217,8 +250,11 @@ func (c *accountTaskCoordinator) runAutoRate(ctx context.Context, settings db.Ac } } summary.Found = len(orders) + // order 表示当前遍历过程中的订单 for _, order := range orders { + // runKey 保存运行Key,供当前处理流程使用 runKey := "rate:" + settings.CookieID + ":" + order.TradeID + // claimed、err 保存claimed、err,供当前处理流程使用 claimed, err := c.repository.ClaimRun(ctx, db.AccountTaskRun{RunKey: runKey, CookieID: settings.CookieID, TaskType: TaskAutoRate, TargetID: order.TradeID}, time.Now().UTC().Unix()) if err != nil { @@ -228,8 +264,10 @@ func (c *accountTaskCoordinator) runAutoRate(ctx context.Context, settings db.Ac summary.Skipped++ continue } + // result、rateErr 保存result、rateErr,供当前处理流程使用 result, rateErr := c.client().RateBuyer(ctx, current, order.TradeID, settings.RateContent) if rateErr != nil || result == nil || !result.Success { + // message 保存消息,供当前处理流程使用 message := errorString(rateErr) if result != nil && result.Message != "" { message = result.Message @@ -249,15 +287,22 @@ func (c *accountTaskCoordinator) runAutoRate(ctx context.Context, settings db.Ac return summary, nil } +// runAutoPolish 负责运行AutoPolish相关处理。 func (c *accountTaskCoordinator) runAutoPolish(ctx context.Context, settings db.AccountTaskSettings, now time.Time, manual bool) (AccountTaskSummary, error) { + // summary 保存summary,供当前处理流程使用 summary := AccountTaskSummary{TaskType: TaskAutoPolish} if c.client() == nil { return summary, fmt.Errorf("擦亮客户端未初始化") } + // date 保存日期,供当前处理流程使用 date := now.Format("2006-01-02") + // runKey 保存运行Key,供当前处理流程使用 runKey := "polish:" + settings.CookieID + ":" + date + // run 保存运行,供当前处理流程使用 run := db.AccountTaskRun{RunKey: runKey, CookieID: settings.CookieID, TaskType: TaskAutoPolish, RunDate: date} + // claimed 保存claimed,供当前处理流程使用 var claimed bool + // err 保存err,供当前处理流程使用 var err error if manual { claimed, err = c.repository.ClaimRunImmediately(ctx, run, time.Now().UTC().Unix()) @@ -271,20 +316,26 @@ func (c *accountTaskCoordinator) runAutoPolish(ctx context.Context, settings db. } return summary, err } + // cookies、err 保存cookies、err,供当前处理流程使用 cookies, err := c.repository.GetValue(ctx, settings.CookieID) if err != nil { _ = c.repository.FinishRun(ctx, runKey, "failed", 0, 1, err.Error(), time.Now().UTC().Add(10*time.Minute).Unix()) return summary, err } + // items、err 保存items、err,供当前处理流程使用 items, err := c.client().FetchAllItems(ctx, cookies, polishItemPageSize, polishItemMaxPages) if err != nil { _ = c.repository.FinishRun(ctx, runKey, "failed", 0, 1, err.Error(), time.Now().UTC().Add(10*time.Minute).Unix()) return summary, err } + // current 保存current,供当前处理流程使用 current := c.persistTaskCookies(ctx, settings.CookieID, cookies, items.UpdatedCookies) summary.Found = len(items.Items) + // lastError 保存last错误,供当前处理流程使用 var lastError string + // item 表示当前遍历过程中的商品 for _, item := range items.Items { + // result、polishErr 保存result、polishErr,供当前处理流程使用 result, polishErr := c.client().PolishItem(ctx, current, item.ID) if polishErr != nil || result == nil || !result.Success { summary.Failed++ @@ -301,6 +352,7 @@ func (c *accountTaskCoordinator) runAutoPolish(ctx context.Context, settings db. current = c.persistTaskCookies(ctx, settings.CookieID, current, result.UpdatedCookies) summary.Success++ } + // status、retryAt 保存status、retryAt,供当前处理流程使用 status, retryAt := "success", int64(0) if summary.Failed > 0 { status, retryAt = "failed", time.Now().UTC().Add(10*time.Minute).Unix() @@ -314,31 +366,37 @@ func (c *accountTaskCoordinator) runAutoPolish(ctx context.Context, settings db. return summary, nil } +// persistTaskCookies 负责persist任务Cookies相关处理。 func (c *accountTaskCoordinator) persistTaskCookies(ctx context.Context, accountID, oldValue, newValue string) string { newValue = strings.TrimSpace(newValue) if newValue == "" || newValue == oldValue { return oldValue } - if err := c.repository.UpdateValueExisting(ctx, accountID, newValue); err != nil { + if // err 保存err,供当前处理流程使用 + err := c.repository.UpdateValueExisting(ctx, accountID, newValue); err != nil { c.logger.Warn("保存账号任务响应 Cookie 失败", "account", accountID, "err", err) return oldValue } if c.senders != nil { - if sender, ok := c.senders.Sender(accountID); ok && sender != nil { + if // sender、ok 保存sender、ok,供当前处理流程使用 + sender, ok := c.senders.Sender(accountID); ok && sender != nil { sender.UpdateCookie(newValue) } } return newValue } +// beijingNow 负责beijingNow相关处理。 func beijingNow() time.Time { return time.Now().In(time.FixedZone("Asia/Shanghai", 8*60*60)) } +// polishDue 负责polishDue相关处理。 func polishDue(settings db.AccountTaskSettings, now time.Time) bool { if settings.LastPolishDate == now.Format("2006-01-02") { return false } + // target、err 保存target、err,供当前处理流程使用 target, err := time.Parse("15:04", settings.PolishTime) if err != nil { target, _ = time.Parse("15:04", "03:00") diff --git a/internal/automation/account_tasks_test.go b/internal/automation/account_tasks_test.go index 8742d7a..f0de8af 100644 --- a/internal/automation/account_tasks_test.go +++ b/internal/automation/account_tasks_test.go @@ -11,6 +11,7 @@ import ( "xianyu-go/internal/xianyu/mtop" ) +// fakeAccountTaskClient 保存fake账号任务Client,供当前处理流程使用 type fakeAccountTaskClient struct { pendingCalls int rateCalls int @@ -25,6 +26,7 @@ type fakeAccountTaskClient struct { polishErr error } +// FetchPendingRateOrders 负责FetchPendingRate订单列表相关处理。 func (f *fakeAccountTaskClient) FetchPendingRateOrders(context.Context, string, int, int) (*mtop.PendingRateResult, error) { f.pendingCalls++ if f.pendingErr != nil { @@ -33,6 +35,7 @@ func (f *fakeAccountTaskClient) FetchPendingRateOrders(context.Context, string, return &mtop.PendingRateResult{Orders: f.pending}, nil } +// RateBuyer 负责Rate买家相关处理。 func (f *fakeAccountTaskClient) RateBuyer(context.Context, string, string, string) (*mtop.AccountTaskResult, error) { f.rateCalls++ if f.rateErr != nil { @@ -41,6 +44,7 @@ func (f *fakeAccountTaskClient) RateBuyer(context.Context, string, string, strin return &mtop.AccountTaskResult{Success: true, Message: "ok"}, nil } +// FetchAllItems 负责FetchAll商品列表相关处理。 func (f *fakeAccountTaskClient) FetchAllItems(_ context.Context, _ string, pageSize, maxPages int) (*mtop.ItemListResult, error) { f.fetchPageSize, f.fetchMaxPages = pageSize, maxPages if f.fetchItemsErr != nil { @@ -49,6 +53,7 @@ func (f *fakeAccountTaskClient) FetchAllItems(_ context.Context, _ string, pageS return &mtop.ItemListResult{Items: f.items}, nil } +// PolishItem 负责Polish商品相关处理。 func (f *fakeAccountTaskClient) PolishItem(context.Context, string, string) (*mtop.AccountTaskResult, error) { f.polishCalls++ if f.polishErr != nil { @@ -57,60 +62,80 @@ func (f *fakeAccountTaskClient) PolishItem(context.Context, string, string) (*mt return &mtop.AccountTaskResult{Success: true, Message: "ok"}, nil } +// TestAccountTaskRateIsOrderIdempotent 负责Test账号任务RateIs订单Idempotent相关处理。 func TestAccountTaskRateIsOrderIdempotent(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // client 保存client,供当前处理流程使用 client := &fakeAccountTaskClient{pending: []mtop.PendingRateOrder{{TradeID: "order-1"}, {TradeID: "order-2"}}} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: &testSender{}}, nil) center.SetAccountTaskClient(client) + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if err := store.AccountTasks.Upsert(ctx, db.AccountTaskSettings{CookieID: "cid", AutoRateEnabled: true, + if // err 保存err,供当前处理流程使用 + err := store.AccountTasks.Upsert(ctx, db.AccountTaskSettings{CookieID: "cid", AutoRateEnabled: true, RateContent: "交易愉快", PolishTime: "03:00"}); err != nil { t.Fatal(err) } + // first、err 保存first、err,供当前处理流程使用 first, err := center.RunAccountTask(ctx, "cid", TaskAutoRate) if err != nil || first.Success != 2 || client.rateCalls != 2 { t.Fatalf("first=%+v calls=%d err=%v", first, client.rateCalls, err) } + // second、err 保存second、err,供当前处理流程使用 second, err := center.RunAccountTask(ctx, "cid", TaskAutoRate) if err != nil || second.Skipped != 2 || client.rateCalls != 2 { t.Fatalf("second=%+v calls=%d err=%v", second, client.rateCalls, err) } } +// TestAccountTaskSessionExpiredRecoversOnceAndBlocksFurtherAPIRequests 负责Test账号任务会话ExpiredRecoversOnceAndBlocksFurtherAPI请求列表相关处理。 func TestAccountTaskSessionExpiredRecoversOnceAndBlocksFurtherAPIRequests(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // sessionErr 保存会话Err,供当前处理流程使用 sessionErr := &mtop.SessionExpiredError{API: "自动评价接口", Ret: []string{"FAIL_SYS_SESSION_EXPIRED::Session过期"}} + // client 保存client,供当前处理流程使用 client := &fakeAccountTaskClient{pendingErr: sessionErr} + // recoverer 保存recoverer,供当前处理流程使用 recoverer := &fakeCredentialRecoverer{store: store, fail: true} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: &testSender{}}, nil) center.SetAccountTaskClient(client) center.SetOrderDetailFetcher(recoverer) - if err := store.AccountTasks.Upsert(ctx, db.AccountTaskSettings{CookieID: "cid", AutoRateEnabled: true, + if // err 保存err,供当前处理流程使用 + err := store.AccountTasks.Upsert(ctx, db.AccountTaskSettings{CookieID: "cid", AutoRateEnabled: true, RateContent: "交易愉快", PolishTime: "03:00"}); err != nil { t.Fatal(err) } - if _, err := center.RunAccountTask(ctx, "cid", TaskAutoRate); err == nil || !mtop.IsSessionExpiredErr(err) { + if // err 保存err,供当前处理流程使用 + _, err := center.RunAccountTask(ctx, "cid", TaskAutoRate); err == nil || !mtop.IsSessionExpiredErr(err) { t.Fatalf("首次 session 失效应触发续期并返回原始分类错误: %v", err) } if client.pendingCalls != 1 || recoverer.calls != 1 { t.Fatalf("first calls: api=%d recover=%d want 1/1", client.pendingCalls, recoverer.calls) } - if _, err := center.RunAccountTask(ctx, "cid", TaskAutoRate); err == nil || !strings.Contains(err.Error(), "已停止自动化 API 请求") { + if // err 保存err,供当前处理流程使用 + _, err := center.RunAccountTask(ctx, "cid", TaskAutoRate); err == nil || !strings.Contains(err.Error(), "已停止自动化 API 请求") { t.Fatalf("未更新凭证时应保持阻断: %v", err) } if client.pendingCalls != 1 || recoverer.calls != 1 { t.Fatalf("blocked run must not call API/recovery again: api=%d recover=%d", client.pendingCalls, recoverer.calls) } - if err := store.Cookies.UpdateValueExisting(ctx, "cid", "unb=1; _m_h5_tk=fresh_1; renewed=1"); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.UpdateValueExisting(ctx, "cid", "unb=1; _m_h5_tk=fresh_1; renewed=1"); err != nil { t.Fatal(err) } client.pendingErr = nil - if _, err := center.RunAccountTask(ctx, "cid", TaskAutoRate); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := center.RunAccountTask(ctx, "cid", TaskAutoRate); err != nil { t.Fatalf("凭证变化后应自动解除阻断: %v", err) } if client.pendingCalls != 2 { @@ -118,25 +143,34 @@ func TestAccountTaskSessionExpiredRecoversOnceAndBlocksFurtherAPIRequests(t *tes } } +// TestAccountTaskStopsRemainingOrdersOnSessionExpired 负责Test账号任务StopsRemaining订单列表On会话Expired相关处理。 func TestAccountTaskStopsRemainingOrdersOnSessionExpired(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // sessionErr 保存会话Err,供当前处理流程使用 sessionErr := &mtop.SessionExpiredError{API: "评价接口", Ret: []string{"FAIL_SYS_SESSION_EXPIRED::Session过期"}} + // client 保存client,供当前处理流程使用 client := &fakeAccountTaskClient{ pending: []mtop.PendingRateOrder{{TradeID: "order-1"}, {TradeID: "order-2"}}, rateErr: sessionErr, } + // recoverer 保存recoverer,供当前处理流程使用 recoverer := &fakeCredentialRecoverer{store: store, fail: true} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: &testSender{}}, nil) center.SetAccountTaskClient(client) center.SetOrderDetailFetcher(recoverer) - if err := store.AccountTasks.Upsert(ctx, db.AccountTaskSettings{CookieID: "cid", AutoRateEnabled: true, + if // err 保存err,供当前处理流程使用 + err := store.AccountTasks.Upsert(ctx, db.AccountTaskSettings{CookieID: "cid", AutoRateEnabled: true, RateContent: "交易愉快", PolishTime: "03:00"}); err != nil { t.Fatal(err) } - if _, err := center.RunAccountTask(ctx, "cid", TaskAutoRate); err == nil { + if // err 保存err,供当前处理流程使用 + _, err := center.RunAccountTask(ctx, "cid", TaskAutoRate); err == nil { t.Fatal("session expiry must be returned") } if client.rateCalls != 1 || recoverer.calls != 1 { @@ -144,17 +178,24 @@ func TestAccountTaskStopsRemainingOrdersOnSessionExpired(t *testing.T) { } } +// TestAccountTaskPolishRunsOncePerBeijingDay 负责Test账号任务Polish运行记录OncePerBeijingDay相关处理。 func TestAccountTaskPolishRunsOncePerBeijingDay(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // client 保存client,供当前处理流程使用 client := &fakeAccountTaskClient{items: []mtop.ItemListItem{{ID: "item-1"}, {ID: "item-2"}}} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: &testSender{}}, nil) center.SetAccountTaskClient(client) + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if err := store.AccountTasks.Upsert(ctx, db.AccountTaskSettings{CookieID: "cid", AutoPolishEnabled: true, + if // err 保存err,供当前处理流程使用 + err := store.AccountTasks.Upsert(ctx, db.AccountTaskSettings{CookieID: "cid", AutoPolishEnabled: true, RateContent: "交易愉快", PolishTime: "00:00"}); err != nil { t.Fatal(err) } + // first、err 保存first、err,供当前处理流程使用 first, err := center.RunAccountTask(ctx, "cid", TaskAutoPolish) if err != nil || first.Success != 2 || client.polishCalls != 2 { t.Fatalf("first=%+v calls=%d err=%v", first, client.polishCalls, err) @@ -162,60 +203,81 @@ func TestAccountTaskPolishRunsOncePerBeijingDay(t *testing.T) { if client.fetchPageSize != 20 || client.fetchMaxPages != 20 { t.Fatalf("unexpected item pagination: pageSize=%d maxPages=%d", client.fetchPageSize, client.fetchMaxPages) } + // second、err 保存second、err,供当前处理流程使用 second, err := center.RunAccountTask(ctx, "cid", TaskAutoPolish) if err != nil || second.Skipped != 1 || client.polishCalls != 2 { t.Fatalf("second=%+v calls=%d err=%v", second, client.polishCalls, err) } + // settings、err 保存settings、err,供当前处理流程使用 settings, err := store.AccountTasks.Get(ctx, "cid") if err != nil || settings.LastPolishDate != beijingNow().Format("2006-01-02") { t.Fatalf("settings=%+v err=%v", settings, err) } } +// TestManualPolishReportsItemFailures 负责TestManualPolishReports商品Failures相关处理。 func TestManualPolishReportsItemFailures(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // client 保存client,供当前处理流程使用 client := &fakeAccountTaskClient{items: []mtop.ItemListItem{{ID: "item-1"}}, polishErr: errors.New("both polish APIs failed")} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: &testSender{}}, nil) center.SetAccountTaskClient(client) + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if err := store.AccountTasks.Upsert(ctx, db.AccountTaskSettings{CookieID: "cid", AutoPolishEnabled: true, + if // err 保存err,供当前处理流程使用 + err := store.AccountTasks.Upsert(ctx, db.AccountTaskSettings{CookieID: "cid", AutoPolishEnabled: true, RateContent: "交易愉快", PolishTime: "00:00"}); err != nil { t.Fatal(err) } + // summary、err 保存summary、err,供当前处理流程使用 summary, err := center.RunAccountTask(ctx, "cid", TaskAutoPolish) if err == nil || summary.Failed != 1 || summary.Success != 0 { t.Fatalf("summary=%+v err=%v", summary, err) } } +// TestManualPolishCanRetryImmediatelyAfterFailure 负责TestManualPolishCan重试ImmediatelyAfterFailure相关处理。 func TestManualPolishCanRetryImmediatelyAfterFailure(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // client 保存client,供当前处理流程使用 client := &fakeAccountTaskClient{items: []mtop.ItemListItem{{ID: "item-1"}}, fetchItemsErr: errors.New("upstream 502")} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: &testSender{}}, nil) center.SetAccountTaskClient(client) + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if err := store.AccountTasks.Upsert(ctx, db.AccountTaskSettings{CookieID: "cid", AutoPolishEnabled: true, + if // err 保存err,供当前处理流程使用 + err := store.AccountTasks.Upsert(ctx, db.AccountTaskSettings{CookieID: "cid", AutoPolishEnabled: true, RateContent: "交易愉快", PolishTime: "00:00"}); err != nil { t.Fatal(err) } - if _, err := center.RunAccountTask(ctx, "cid", TaskAutoPolish); err == nil { + if // err 保存err,供当前处理流程使用 + _, err := center.RunAccountTask(ctx, "cid", TaskAutoPolish); err == nil { t.Fatal("first polish should expose the upstream failure") } client.fetchItemsErr = nil + // second、err 保存second、err,供当前处理流程使用 second, err := center.RunAccountTask(ctx, "cid", TaskAutoPolish) if err != nil || second.Success != 1 || second.Skipped != 0 || client.polishCalls != 1 { t.Fatalf("manual retry=%+v calls=%d err=%v", second, client.polishCalls, err) } + // third、err 保存third、err,供当前处理流程使用 third, err := center.RunAccountTask(ctx, "cid", TaskAutoPolish) if err != nil || third.Skipped != 1 || client.polishCalls != 1 { t.Fatalf("successful day must remain idempotent: summary=%+v calls=%d err=%v", third, client.polishCalls, err) } } +// TestPolishDueHonorsConfiguredTimeAndDate 负责TestPolishDueHonorsConfigured时间And日期相关处理。 func TestPolishDueHonorsConfiguredTimeAndDate(t *testing.T) { + // now 保存now,供当前处理流程使用 now := beijingNow() + // settings 保存设置,供当前处理流程使用 settings := db.AccountTaskSettings{PolishTime: now.Add(2 * time.Hour).Format("15:04")} if polishDue(settings, now) && now.Hour() < 22 { t.Fatal("task must not run before configured time") diff --git a/internal/automation/action_executor.go b/internal/automation/action_executor.go index 4563d18..dbc9e3d 100644 --- a/internal/automation/action_executor.go +++ b/internal/automation/action_executor.go @@ -69,6 +69,7 @@ func (e *automationActionExecutor) confirmShipment(ctx context.Context, task Tas } // enabled 表示账号是否打开自动确认发货设置。 // readErr 保存读取自动确认发货设置的错误。 + // enabled、readErr 保存enabled、readErr,供当前处理流程使用 enabled, readErr := e.store.Cookies.GetAutoConfirm(ctx, task.AccountID) if readErr != nil { return fmt.Errorf("读取自动确认发货设置: %w", readErr) @@ -108,7 +109,8 @@ func (e *automationActionExecutor) confirmShipmentAttempt(ctx context.Context, t var cookieSession *mtop.CookieSession // snapshot 是 metadata 中恢复出的完整 Cookie Jar。 // snapshotOK 表示完整 Cookie Jar 是否存在。 - if snapshot, snapshotOK := cookierefresh.SnapshotFromMetadataOK(runtimeData.MetadataJSON); snapshotOK { + if // snapshot、snapshotOK 保存snapshot、snapshotOK,供当前处理流程使用 + snapshot, snapshotOK := cookierefresh.SnapshotFromMetadataOK(runtimeData.MetadataJSON); snapshotOK { mtopCtx, cookieSession = mtop.WithCookieSnapshot(ctx, snapshot) } else { mtopCtx, cookieSession = mtop.WithFlatCookieSession(ctx, cookieStr) @@ -121,6 +123,7 @@ func (e *automationActionExecutor) confirmShipmentAttempt(ctx context.Context, t // ret 保存远端返回的业务错误文本。 // updated 保存无权威 Cookie Jar 时的扁平 Cookie 更新结果。 // callErr 保存 MTOP 请求层错误。 + // consignOK、ret、updated、callErr 保存consignOK、ret、updated、callErr,供当前处理流程使用 consignOK, ret, updated, callErr := e.mtop().ConsignContext(mtopCtx, cookieStr, task.OrderID) // persistenceErrs 收集远端动作完成后本地状态写入失败。 var persistenceErrs []error @@ -131,6 +134,7 @@ func (e *automationActionExecutor) confirmShipmentAttempt(ctx context.Context, t // value 是 Cookie 会话合并后的扁平值。 // snapshot 是 Cookie 会话合并后的完整快照。 // changed 表示 Cookie 会话是否产生变化。 + // value、snapshot、changed 保存value、snapshot、changed,供当前处理流程使用 value, snapshot, changed := cookieSession.State() // sessionHandled 表示本次请求是否由完整 Cookie Jar 接管。 sessionHandled := snapshot != nil @@ -164,7 +168,8 @@ func (e *automationActionExecutor) confirmShipmentAttempt(ctx context.Context, t if runtimeCookieChanged && e.senders != nil { // sender 是当前账号的在线消息发送器。 // running 表示账号是否仍处于运行状态。 - if sender, running := e.senders.Sender(task.AccountID); running { + if // sender、running 保存sender、running,供当前处理流程使用 + sender, running := e.senders.Sender(task.AccountID); running { sender.UpdateCookie(runtimeCookie) } } @@ -255,6 +260,7 @@ func (e *automationActionExecutor) sendCard(ctx context.Context, task Task, acti for i := 0; i < count; i++ { // content 是当前卡密文本内容。 // imageURL 是当前卡密图片地址。 + // content、imageURL、readErr 保存content、imageURL、readErr,供当前处理流程使用 content, imageURL, readErr := e.cardContent(ctx, card) if readErr != nil { return sent, readErr @@ -322,6 +328,7 @@ func (e *automationActionExecutor) sendText(ctx context.Context, task Task, text } // sender 是当前账号的在线消息发送器。 // senderOK 表示是否找到在线发送器。 + // sender、senderOK 保存sender、senderOK,供当前处理流程使用 sender, senderOK := e.senders.Sender(task.AccountID) if !senderOK { return fmt.Errorf("%w: 账号未在线,无法发送自动化消息", ErrMessageNotSent) @@ -339,6 +346,7 @@ func (e *automationActionExecutor) sendImage(ctx context.Context, task Task, ima } // sender 是当前账号的在线图片发送器。 // senderOK 表示是否找到在线发送器。 + // sender、senderOK 保存sender、senderOK,供当前处理流程使用 sender, senderOK := e.senders.Sender(task.AccountID) if !senderOK { return fmt.Errorf("%w: 账号未在线,无法发送自动化图片", ErrMessageNotSent) @@ -425,6 +433,7 @@ func parsePositiveInt(raw string) int { // err 是数量文本解析错误。 // n 是解析后的数量值。 // parseErr 是数量文本解析错误。 + // n、parseErr 保存n、parseErr,供当前处理流程使用 n, parseErr := strconv.Atoi(raw) if parseErr != nil || n < 0 { return 0 diff --git a/internal/automation/center.go b/internal/automation/center.go index 82a0f0d..18b5ba7 100644 --- a/internal/automation/center.go +++ b/internal/automation/center.go @@ -14,6 +14,7 @@ import ( "xianyu-go/internal/xianyu/mtop" ) +// errAutomationDeferred 保存err自动化Deferred,供当前处理流程使用 var ( errAutomationDeferred = errors.New("自动化动作已持久化等待执行") errAutomationNeedsReview = errors.New("自动化动作结果需要人工核对") @@ -25,20 +26,30 @@ var ( ErrMessageNotSent = errors.New("自动化消息确定未发送") ) +// preparationError 保存preparation错误,供当前处理流程使用 type preparationError struct{ err error } +// Error 负责错误相关处理。 func (e *preparationError) Error() string { return e.err.Error() } + +// Unwrap 负责Unwrap相关处理。 func (e *preparationError) Unwrap() error { return e.err } +// uncertainActionError 保存uncertain动作错误,供当前处理流程使用 type uncertainActionError struct{ err error } +// Error 负责错误相关处理。 func (e *uncertainActionError) Error() string { return e.err.Error() } + +// Unwrap 负责Unwrap相关处理。 func (e *uncertainActionError) Unwrap() error { return e.err } +// uncertainAction 负责uncertain动作相关处理。 func uncertainAction(err error) error { if err == nil { return nil } + // existing 保存existing,供当前处理流程使用 var existing *uncertainActionError if errors.As(err, &existing) { return err @@ -48,6 +59,7 @@ func uncertainAction(err error) error { // SenderProvider 根据账号 ID 提供当前在线账号的发送能力。 // 计划任务和 WS 事件都复用这个抽象,避免自动化中心直接依赖 account.Manager。 +// SenderProvider 保存SenderProvider,供当前处理流程使用 type SenderProvider interface { Sender(cookieID string) (MessageSender, bool) } @@ -61,12 +73,14 @@ type MessageSender interface { // automationReadySender 由能够报告实时连接状态的发送器选择性实现。 // 未实现的测试或外部发送器保持向后兼容,视为已经就绪。 +// automationReadySender 保存自动化ReadySender,供当前处理流程使用 type automationReadySender interface { AutomationReady() bool } // OrderDetailFetcher 查询闲鱼订单详情。自动发货必须先拿到订单规格和购买数量, // 再按规则里的规格映射发货。 +// OrderDetailFetcher 保存订单DetailFetcher,供当前处理流程使用 type OrderDetailFetcher interface { FetchOrderDetail(ctx context.Context, cookieID, orderID, itemID, buyerID, cookieStr string) (*OrderDetail, error) } @@ -83,6 +97,7 @@ type Notifier interface { // Center 是统一自动化处理中心。 // 它只接收已经分类好的系统事件或计划任务,不处理用户消息;用户消息由 engine 的回复链处理。 +// Center 保存Center,供当前处理流程使用 type Center struct { // facts 记录已解析的自动化事件事实,不执行规则动作。 facts eventFactRecorder @@ -114,7 +129,9 @@ func New(store *db.Store, senders SenderProvider, logger *slog.Logger) *Center { if logger == nil { logger = slog.Default() } + // client 保存client,供当前处理流程使用 client := mtop.NewClient() + // center 保存center,供当前处理流程使用 center := &Center{ facts: newEventFactRecorder(store), rules: newRuleMatcher(store), @@ -177,6 +194,7 @@ func (c *Center) SetMTop(m mtop.Client) { c.mtop = m } // SetAccountTaskClient overrides automatic rating/polish transport for tests. // SetAccountTaskClient 注入自动评价和商品擦亮的任务客户端。 +// SetAccountTaskClient 设置账号任务Client。 func (c *Center) SetAccountTaskClient(client AccountTaskClient) { c.accountTaskClient = client } // RunAccountTask 执行指定账号任务,并保持 Center 的公开兼容入口。 @@ -192,7 +210,8 @@ func (c *Center) scanAccountTasks(ctx context.Context) { // SetOrderDetailFetcher 注入订单详情查询能力。 func (c *Center) SetOrderDetailFetcher(fetcher OrderDetailFetcher) { c.fetcher = fetcher - if recoverer, ok := fetcher.(CredentialRecoverer); ok { + if // recoverer、ok 保存recoverer、ok,供当前处理流程使用 + recoverer, ok := fetcher.(CredentialRecoverer); ok { c.recoverer = recoverer } } @@ -209,10 +228,12 @@ func (c *Center) SetCookieSource(fn func(context.Context, string) (string, error // HandleTask 处理一条自动化任务。无匹配规则时安全忽略。 func (c *Center) HandleTask(ctx context.Context, task Task) error { + // err 保存err,供当前处理流程使用 _, err := c.handleTask(ctx, task) return err } +// handleTask 负责handle任务相关处理。 func (c *Center) handleTask(ctx context.Context, task Task) (bool, error) { if c == nil || c.store == nil || c.store.Automation == nil { return false, nil @@ -221,27 +242,32 @@ func (c *Center) handleTask(ctx context.Context, task Task) (bool, error) { if task.TriggerType == "" || task.AccountID == "" { return false, nil } - if err := c.facts.record(ctx, task); err != nil { + if // err 保存err,供当前处理流程使用 + err := c.facts.record(ctx, task); err != nil { return false, err } if task.OrderID != "" { - if order, orderErr := c.store.Orders.Get(ctx, task.OrderID); orderErr == nil && order != nil { + if // order、orderErr 保存order、orderErr,供当前处理流程使用 + order, orderErr := c.store.Orders.Get(ctx, task.OrderID); orderErr == nil && order != nil { task = mergeOrderIntoTask(task, order) } else if orderErr != nil && !errors.Is(orderErr, db.ErrNotFound) { return false, fmt.Errorf("读取自动化事件订单事实: %w", orderErr) } } + // paused、until、err 保存paused、until、err,供当前处理流程使用 paused, until, err := c.store.Cookies.IsPaused(ctx, task.AccountID) if err != nil { return false, err } if paused { - if err := c.deferTask(ctx, task, until); err != nil { + if // err 保存err,供当前处理流程使用 + err := c.deferTask(ctx, task, until); err != nil { return false, err } c.logger.Info("账号已暂停,自动化事件已持久化等待恢复", "account", task.AccountID, "trigger", task.TriggerType, "due_at", until) return true, nil } + // enabled、err 保存enabled、err,供当前处理流程使用 enabled, err := c.store.Cookies.Status(ctx, task.AccountID) if err != nil { return false, err @@ -250,6 +276,7 @@ func (c *Center) handleTask(ctx context.Context, task Task) (bool, error) { c.logger.Info("账号已停用,记录事件事实但不执行自动化", "account", task.AccountID, "trigger", task.TriggerType) return false, nil } + // rules、err 保存rules、err,供当前处理流程使用 rules, err := c.rules.match(ctx, task) if err != nil { return false, err @@ -258,13 +285,19 @@ func (c *Center) handleTask(ctx context.Context, task Task) (bool, error) { c.logger.Info("无匹配自动化规则,忽略事件", "trigger", task.TriggerType, "order_id", task.OrderID, "item_id", task.ItemID) return false, nil } + // firstErr 保存firstErr,供当前处理流程使用 var firstErr error + // rule 表示当前遍历过程中的规则 for _, rule := range rules { - if err := c.executeRule(ctx, task, rule); err != nil { + if // err 保存err,供当前处理流程使用 + err := c.executeRule(ctx, task, rule); err != nil { + // prepErr 保存prepErr,供当前处理流程使用 var prepErr *preparationError if errors.As(err, &prepErr) && !isDeferredReplay(task) { + // dueAt 保存dueAt,供当前处理流程使用 dueAt := time.Now().UTC().Add(time.Minute).Unix() - if deferErr := c.deferTaskWithError(ctx, task, dueAt, prepErr.Error()); deferErr != nil { + if // deferErr 保存deferErr,供当前处理流程使用 + deferErr := c.deferTaskWithError(ctx, task, dueAt, prepErr.Error()); deferErr != nil { return false, errors.Join(err, fmt.Errorf("持久化前置失败任务: %w", deferErr)) } c.logger.Warn("自动化前置处理失败,任务已持久化等待恢复", "account", task.AccountID, @@ -283,20 +316,26 @@ func (c *Center) handleTask(ctx context.Context, task Task) (bool, error) { return false, firstErr } +// taskAutomationRunID 负责任务自动化运行ID相关处理。 func taskAutomationRunID(task Task) int64 { if task.Raw == nil { return 0 } + // value 保存值,供当前处理流程使用 value := fmt.Sprint(task.Raw["automation_run_id"]) + // id 保存标识,供当前处理流程使用 id, _ := strconv.ParseInt(value, 10, 64) return id } +// taskDelayCursor 负责任务延迟游标相关处理。 func taskDelayCursor(task Task) int { if task.Raw == nil { return -1 } + // value 保存值,供当前处理流程使用 value := fmt.Sprint(task.Raw["automation_delay_cursor"]) + // cursor、err 保存cursor、err,供当前处理流程使用 cursor, err := strconv.Atoi(value) if err != nil { return -1 @@ -304,20 +343,25 @@ func taskDelayCursor(task Task) int { return cursor } +// isDeferredReplay 负责isDeferredReplay相关处理。 func isDeferredReplay(task Task) bool { return task.Raw != nil && task.Raw["automation_deferred_replay"] == true } +// deferTask 负责defer任务相关处理。 func (c *Center) deferTask(ctx context.Context, task Task, dueAt int64) error { return c.deferTaskWithError(ctx, task, dueAt, "") } +// deferTaskWithError 负责defer任务With错误相关处理。 func (c *Center) deferTaskWithError(ctx context.Context, task Task, dueAt int64, errMsg string) error { + // key 保存key,供当前处理流程使用 key := buildTriggerKey(task) if key == "" { return fmt.Errorf("暂停期间的自动化事件缺少可持久化防重键") } task.CookieStr = "" + // raw、err 保存raw、err,供当前处理流程使用 raw, err := json.Marshal(task) if err != nil { return err @@ -330,6 +374,7 @@ func (c *Center) deferTaskWithError(ctx context.Context, task Task, dueAt int64, // ManualFullDelivery 对已存在订单执行完整发货,和付款系统事件共用同一套 // 订单详情补全、规格匹配、按购买数量发卡、确认发货逻辑。 +// ManualFullDelivery 负责ManualFull发货相关处理。 func (c *Center) ManualFullDelivery(ctx context.Context, order *db.Order) (int, error) { if c == nil || c.store == nil || order == nil { return 0, fmt.Errorf("自动化中心未初始化或订单为空") @@ -337,6 +382,7 @@ func (c *Center) ManualFullDelivery(ctx context.Context, order *db.Order) (int, if strings.TrimSpace(order.OrderID) == "" { return 0, fmt.Errorf("订单缺少订单ID") } + // paused、until、err 保存paused、until、err,供当前处理流程使用 paused, until, err := c.store.Cookies.IsPaused(ctx, order.CookieID) if err != nil { return 0, fmt.Errorf("读取账号暂停状态: %w", err) @@ -344,6 +390,7 @@ func (c *Center) ManualFullDelivery(ctx context.Context, order *db.Order) (int, if paused { return 0, fmt.Errorf("账号暂停处理中,恢复时间 %d", until) } + // enabled、err 保存enabled、err,供当前处理流程使用 enabled, err := c.store.Cookies.Status(ctx, order.CookieID) if err != nil { return 0, fmt.Errorf("读取账号启用状态: %w", err) @@ -360,6 +407,7 @@ func (c *Center) ManualFullDelivery(ctx context.Context, order *db.Order) (int, if strings.TrimSpace(order.ChatID) == "" || strings.TrimSpace(order.BuyerID) == "" { return 0, fmt.Errorf("订单缺少 chat_id 或 buyer_id,无法发送卡券") } + // task 保存任务,供当前处理流程使用 task := Task{ Source: "manual", AccountID: order.CookieID, @@ -380,6 +428,7 @@ func (c *Center) ManualFullDelivery(ctx context.Context, order *db.Order) (int, if err != nil { return 0, err } + // rules、err 保存rules、err,供当前处理流程使用 rules, err := c.rules.match(ctx, task) if err != nil { return 0, err @@ -387,15 +436,20 @@ func (c *Center) ManualFullDelivery(ctx context.Context, order *db.Order) (int, if len(rules) == 0 { return 0, fmt.Errorf("未匹配到付款后自动发货规则") } + // sent 保存sent,供当前处理流程使用 sent := 0 + // rule 表示当前遍历过程中的规则 for _, rule := range rules { if !c.planner.hasMatchingSendCard(task, rule.Actions) { continue } task.ActionPlan = c.planner.plan(task, c.planner.immediateManualActions(rule.Actions)) + // rawTask 保存原始任务,供当前处理流程使用 rawTask := task rawTask.CookieStr = "" + // rawJSON 保存原始JSON,供当前处理流程使用 rawJSON, _ := json.Marshal(rawTask) + // runID、started、startErr 保存运行ID、started、startErr,供当前处理流程使用 runID, started, startErr := c.store.Automation.TryStartRun(ctx, db.AutomationRun{ RuleID: rule.ID, CookieID: task.AccountID, @@ -414,10 +468,12 @@ func (c *Center) ManualFullDelivery(ctx context.Context, order *db.Order) (int, if !started { return 0, fmt.Errorf("该订单已自动或手动执行过完整发货;如仅需补记状态,请选择仅修改发货状态") } + // run、getErr 保存run、getErr,供当前处理流程使用 run, getErr := c.store.Automation.GetRun(ctx, runID) if getErr != nil { return 0, getErr } + // n、deferred、err 保存n、deferred、err,供当前处理流程使用 n, deferred, err := c.executeRunActions(ctx, task, rule.ID, run, task.ActionPlan, true) if deferred { return n, errors.New("手动完整发货不应进入延迟队列") @@ -426,11 +482,14 @@ func (c *Center) ManualFullDelivery(ctx context.Context, order *db.Order) (int, if errors.Is(err, errAutomationNeedsReview) { return sent, err } + // status、errMsg 保存status、errMsg,供当前处理流程使用 status, errMsg := "success", "" if err != nil { status, errMsg = "failed", err.Error() } + // finishCtx、cancel 保存finishCtx、cancel,供当前处理流程使用 finishCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + // finishErr 保存finishErr,供当前处理流程使用 finishErr := c.store.Automation.FinishRun(finishCtx, runID, run.AttemptCount, status, sent, errMsg) cancel() if finishErr != nil { @@ -461,10 +520,12 @@ func (c *Center) executeRunActions(ctx context.Context, task Task, ruleID int64, // notifyResult 根据规则执行结果发送通知。成功且实际发出了内容才通知, // 避免无匹配动作的空跑刷屏;失败时发失败通知。 +// notifyResult 负责notify结果相关处理。 func (c *Center) notifyResult(task Task, status string, sent int, errMsg string) { c.notifications.notifyResult(task, status, sent, errMsg) } +// notifyRunNeedsReview 负责notify运行NeedsReview相关处理。 func (c *Center) notifyRunNeedsReview(run db.AutomationRun, reason string) { if c == nil { return @@ -474,14 +535,17 @@ func (c *Center) notifyRunNeedsReview(run db.AutomationRun, reason string) { // actionDelaySeconds 统一卡密默认延时和动作覆盖语义。旧动作没有 // delay_override 字段时自动使用卡密上的默认延时。 +// actionDelaySeconds 负责动作延迟秒数相关处理。 func (c *Center) actionDelaySeconds(ctx context.Context, action db.AutomationAction) (int, error) { if action.ActionType != ActionSendCard || action.CardID <= 0 { return action.DelaySeconds, nil } + // cfg 保存cfg,供当前处理流程使用 var cfg struct { DelayOverride bool `json:"delay_override"` } _ = json.Unmarshal([]byte(action.ConfigJSON), &cfg) + // card、err 保存card、err,供当前处理流程使用 card, err := c.store.Cards.Get(ctx, action.CardID) if err != nil { return 0, err @@ -495,6 +559,7 @@ func (c *Center) actionDelaySeconds(ctx context.Context, action db.AutomationAct return card.DelaySeconds, nil } +// prepareTask 负责prepare任务相关处理。 func (c *Center) prepareTask(ctx context.Context, task Task) (Task, error) { if task.OrderID == "" { return task, nil @@ -505,8 +570,10 @@ func (c *Center) prepareTask(ctx context.Context, task Task) (Task, error) { BuyerID: task.BuyerID, ChatID: task.ChatID, }) + // needsDetail 保存needsDetail,供当前处理流程使用 needsDetail := task.TriggerType == TriggerOrderPaid - if existing, err := c.store.Orders.Get(ctx, task.OrderID); err == nil && existing != nil { + if // existing、err 保存existing、err,供当前处理流程使用 + existing, err := c.store.Orders.Get(ctx, task.OrderID); err == nil && existing != nil { task = mergeOrderIntoTask(task, existing) if needsDetail && (existing.Quantity == "" || existing.Amount == "") { needsDetail = true @@ -520,14 +587,17 @@ func (c *Center) prepareTask(ctx context.Context, task Task) (Task, error) { if !needsDetail || c.fetcher == nil { return task, nil } + // cookieStr 保存登录凭证Str,供当前处理流程使用 cookieStr := task.CookieStr if strings.TrimSpace(cookieStr) == "" { + // err 保存err,供当前处理流程使用 var err error cookieStr, err = c.cookieValue(ctx, task.AccountID) if err != nil { return task, err } } + // detail、err 保存detail、err,供当前处理流程使用 detail, err := c.fetcher.FetchOrderDetail(ctx, task.AccountID, task.OrderID, task.ItemID, task.BuyerID, cookieStr) if err != nil { return task, err @@ -564,6 +634,7 @@ func (c *Center) prepareTask(ctx context.Context, task Task) (Task, error) { return task, nil } +// mergeOrderIntoTask 负责merge订单Into任务相关处理。 func mergeOrderIntoTask(task Task, order *db.Order) Task { if task.ItemID == "" { task.ItemID = order.ItemID @@ -607,7 +678,8 @@ func (c *Center) wakeCredentialBlockedAutomation(ctx context.Context, accountID if c == nil || c.store == nil || c.store.Automation == nil { return } - if err := c.store.Automation.WakeCredentialBlocked(ctx, accountID); err != nil { + if // err 保存err,供当前处理流程使用 + err := c.store.Automation.WakeCredentialBlocked(ctx, accountID); err != nil { c.logger.Warn("Cookie 更新后唤醒自动化任务失败", "account", accountID, "err", err) } } @@ -627,11 +699,13 @@ func (c *Center) accountSenderReady(accountID string) bool { if c == nil || c.senders == nil { return false } + // sender、ok 保存sender、ok,供当前处理流程使用 sender, ok := c.senders.Sender(accountID) if !ok { return false } - if ready, ok := sender.(automationReadySender); ok { + if // ready、ok 保存ready、ok,供当前处理流程使用 + ready, ok := sender.(automationReadySender); ok { return ready.AutomationReady() } return true @@ -652,9 +726,11 @@ func (c *Center) cookieValue(ctx context.Context, cookieID string) (string, erro return c.actions.cookieValue(ctx, cookieID) } +// buildTriggerKey 负责buildTriggerKey相关处理。 func buildTriggerKey(task Task) string { if task.TriggerType == TriggerReviewMissingTimeout && task.OrderID != "" { - if attempt, ok := task.Raw["attempt"]; ok { + if // attempt、ok 保存attempt、ok,供当前处理流程使用 + attempt, ok := task.Raw["attempt"]; ok { return fmt.Sprintf("%s:%s:%v", task.TriggerType, task.OrderID, attempt) } } diff --git a/internal/automation/center_mock_mtop_test.go b/internal/automation/center_mock_mtop_test.go index 8d1b461..485c741 100644 --- a/internal/automation/center_mock_mtop_test.go +++ b/internal/automation/center_mock_mtop_test.go @@ -25,6 +25,7 @@ type fakeMTop struct { consignResults []fakeConsignResult } +// fakeConsignResult 保存fakeConsign结果,供当前处理流程使用 type fakeConsignResult struct { ok bool ret []string @@ -32,49 +33,65 @@ type fakeConsignResult struct { err error } +// FetchUserProfile 负责Fetch用户Profile相关处理。 func (f *fakeMTop) FetchUserProfile(context.Context, string) (*mtop.UserProfileResult, error) { return nil, nil } + +// ConsignContext 负责Consign上下文相关处理。 func (f *fakeMTop) ConsignContext(_ context.Context, cookiesStr, orderID string) (bool, []string, string, error) { f.consignCalls++ f.consignCookieIn = cookiesStr f.consignOrderIn = orderID f.consignCookies = append(f.consignCookies, cookiesStr) if len(f.consignResults) > 0 { + // result 保存结果,供当前处理流程使用 result := f.consignResults[0] f.consignResults = f.consignResults[1:] return result.ok, result.ret, result.updated, result.err } return f.consignOk, f.consignRet, f.consignUpdated, f.consignErr } + +// FetchItemsPage 负责Fetch商品列表页码相关处理。 func (f *fakeMTop) FetchItemsPage(context.Context, string, int, int) (*mtop.ItemListResult, error) { return nil, nil } + +// FetchAllItems 负责FetchAll商品列表相关处理。 func (f *fakeMTop) FetchAllItems(context.Context, string, int, int) (*mtop.ItemListResult, error) { return nil, nil } + +// PublishItem 负责发布商品相关处理。 func (f *fakeMTop) PublishItem(context.Context, string, mtop.PublishItemRequest) (*mtop.PublishItemResult, error) { return nil, nil } + +// RefreshTokenWithDeviceIDContext 刷新令牌WithDeviceID上下文。 func (f *fakeMTop) RefreshTokenWithDeviceIDContext(context.Context, string, string) (*mtop.RefreshResult, error) { return nil, nil } +// fakeCredentialRecoverer 保存fakeCredentialRecoverer,供当前处理流程使用 type fakeCredentialRecoverer struct { store *db.Store calls int fail bool } +// FetchOrderDetail 负责Fetch订单Detail相关处理。 func (f *fakeCredentialRecoverer) FetchOrderDetail(context.Context, string, string, string, string, string) (*OrderDetail, error) { return &OrderDetail{Quantity: "1", Amount: "9.9"}, nil } +// RecoverExpiredCredential 负责RecoverExpiredCredential相关处理。 func (f *fakeCredentialRecoverer) RecoverExpiredCredential(ctx context.Context, cookieID string) bool { f.calls++ if f.fail { return false } + // detail、err 保存detail、err,供当前处理流程使用 detail, err := f.store.Cookies.GetDetails(ctx, cookieID) if err != nil { return false @@ -82,17 +99,24 @@ func (f *fakeCredentialRecoverer) RecoverExpiredCredential(ctx context.Context, return f.store.Cookies.UpdateRenewalCookie(ctx, cookieID, "unb=123; _m_h5_tk=fresh_1;", detail.MetadataJSON, time.Now().Unix()) == nil } +// TestConfirmShipmentRetriesFromCheckpointWithoutResendingCard 负责TestConfirmShipmentRetriesFromCheckpointWithoutResending卡密相关处理。 func TestConfirmShipmentRetriesFromCheckpointWithoutResendingCard(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") + // res、err 保存res、err,供当前处理流程使用 res, err := store.DB.ExecContext(ctx, `INSERT INTO cards (name,type,text_content,enabled,user_id) VALUES ('gift','text','ONLY-ONCE',1,?)`, admin.ID) if err != nil { t.Fatal(err) } + // cardID 保存卡密ID,供当前处理流程使用 cardID, _ := res.LastInsertId() - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", ItemID: "checkpoint-item", Name: "checkpoint", TriggerType: TriggerOrderPaid, Enabled: true, Actions: []db.AutomationActionInput{ @@ -102,23 +126,32 @@ func TestConfirmShipmentRetriesFromCheckpointWithoutResendingCard(t *testing.T) }); err != nil { t.Fatal(err) } + // mtopMock 保存mtopMock,供当前处理流程使用 mtopMock := &fakeMTop{consignResults: []fakeConsignResult{ {ret: []string{"FAIL_SYS_SESSION_EXPIRED::Session过期"}}, {ok: true, ret: []string{"SUCCESS::调用成功"}}, }} + // recoverer 保存recoverer,供当前处理流程使用 recoverer := &fakeCredentialRecoverer{store: store, fail: true} + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetMTop(mtopMock) center.SetOrderDetailFetcher(recoverer) + // task 保存任务,供当前处理流程使用 task := Task{AccountID: "cid", TriggerType: TriggerOrderPaid, OrderID: "checkpoint-order", ItemID: "checkpoint-item", BuyerID: "buyer", ChatID: "chat", Quantity: "1", Amount: "9.9"} - if err := center.HandleTask(ctx, task); err == nil { + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, task); err == nil { t.Fatal("首次确认发货应因 Session 恢复失败而返回错误") } + // status、errMsg 保存status、errMsg,供当前处理流程使用 var status, errMsg string + // sent、cursor 保存sent、cursor,供当前处理流程使用 var sent, cursor int - if err := store.DB.QueryRowContext(ctx, `SELECT status,error_message,sent_count,action_cursor FROM automation_runs WHERE order_id=?`, task.OrderID). + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT status,error_message,sent_count,action_cursor FROM automation_runs WHERE order_id=?`, task.OrderID). Scan(&status, &errMsg, &sent, &cursor); err != nil { t.Fatal(err) } @@ -126,7 +159,8 @@ func TestConfirmShipmentRetriesFromCheckpointWithoutResendingCard(t *testing.T) t.Fatalf("status=%q err=%q sent=%d cursor=%d", status, errMsg, sent, cursor) } recoverer.fail = false - if _, err := store.DB.ExecContext(ctx, `UPDATE automation_runs SET next_retry_at=0 WHERE order_id=?`, task.OrderID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `UPDATE automation_runs SET next_retry_at=0 WHERE order_id=?`, task.OrderID); err != nil { t.Fatal(err) } NewScheduler(center).runRecoveryTasks(ctx) @@ -138,19 +172,26 @@ func TestConfirmShipmentRetriesFromCheckpointWithoutResendingCard(t *testing.T) } } +// TestConfirmShipmentRecoversExpiredSessionAndRetriesOnlyConsign 负责TestConfirmShipmentRecoversExpired会话AndRetriesOnlyConsign相关处理。 func TestConfirmShipmentRecoversExpiredSessionAndRetriesOnlyConsign(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // mtopMock 保存mtopMock,供当前处理流程使用 mtopMock := &fakeMTop{consignResults: []fakeConsignResult{ {ret: []string{"FAIL_SYS_SESSION_EXPIRED::Session过期"}}, {ok: true, ret: []string{"SUCCESS::调用成功"}}, }} + // recoverer 保存recoverer,供当前处理流程使用 recoverer := &fakeCredentialRecoverer{store: store} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: &testSender{}}, nil) center.SetMTop(mtopMock) center.SetOrderDetailFetcher(recoverer) - if err := center.confirmShipment(ctx, Task{AccountID: "cid", OrderID: "session-order", ItemID: "item", BuyerID: "buyer", ChatID: "chat"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := center.confirmShipment(ctx, Task{AccountID: "cid", OrderID: "session-order", ItemID: "item", BuyerID: "buyer", ChatID: "chat"}); err != nil { t.Fatal(err) } if recoverer.calls != 1 || mtopMock.consignCalls != 2 { @@ -159,6 +200,7 @@ func TestConfirmShipmentRecoversExpiredSessionAndRetriesOnlyConsign(t *testing.T if len(mtopMock.consignCookies) != 2 || !strings.Contains(mtopMock.consignCookies[1], "fresh_1") { t.Fatalf("确认发货重试未使用续期 Cookie: %v", mtopMock.consignCookies) } + // order、err 保存order、err,供当前处理流程使用 order, err := store.Orders.Get(ctx, "session-order") if err != nil || !order.SystemShipped { t.Fatalf("恢复后应记录系统发货: order=%+v err=%v", order, err) @@ -168,10 +210,14 @@ func TestConfirmShipmentRecoversExpiredSessionAndRetriesOnlyConsign(t *testing.T // TestCenterConfirmShipment_MockMTopConsigError 用 mock mtop 验证: // ConsignContext 返回错误时 confirmShipment 透传错误,不写 system_shipped; // ok=false 但无错误时返回"确认发货失败"错误。 +// TestCenterConfirmShipment_MockMTopConsigError 负责TestCenterConfirmShipmentMockMTopConsig错误相关处理。 func TestCenterConfirmShipment_MockMTopConsigError(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") // 插入卡密 + 多规格商品 + 付款发货规则(含 confirm_shipment 动作)。 @@ -188,6 +234,7 @@ func TestCenterConfirmShipment_MockMTopConsigError(t *testing.T) { // ConsignContext 报错。 mtopMock := &fakeMTop{consignErr: errors.New("network down")} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: &testSender{}}, nil) center.SetMTop(mtopMock) center.SetOrderDetailFetcher(testFetcher{detail: &OrderDetail{Quantity: "1", Amount: "9.9"}}) @@ -220,6 +267,7 @@ func TestCenterConfirmShipment_MockMTopConsigError(t *testing.T) { // 第二轮:ConsignContext 返回 ok=false(业务失败),run 同样记 failed。 _ = store.Orders.Upsert(ctx, "order-mock2", db.OrderUpsertOpts{CookieID: "cid", ItemID: "item-1", BuyerID: "buyer-1"}) + // center2 保存center2,供当前处理流程使用 center2 := New(store, testSenderProvider{sender: &testSender{}}, nil) center2.SetMTop(&fakeMTop{consignOk: false, consignRet: []string{"FAIL_SHIP"}}) center2.SetOrderDetailFetcher(testFetcher{detail: &OrderDetail{Quantity: "1", Amount: "9.9"}}) @@ -233,25 +281,34 @@ func TestCenterConfirmShipment_MockMTopConsigError(t *testing.T) { } } +// TestConfirmShipmentQuarantinesKnownRemoteSuccessWhenLocalPersistenceFails 负责TestConfirmShipmentQuarantinesKnownRemoteSuccessWhenLocalPersistenceFails相关处理。 func TestConfirmShipmentQuarantinesKnownRemoteSuccessWhenLocalPersistenceFails(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if err := store.Orders.Upsert(ctx, "persist-failure", db.OrderUpsertOpts{CookieID: "cid", ItemID: "item-1", BuyerID: "buyer"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Orders.Upsert(ctx, "persist-failure", db.OrderUpsertOpts{CookieID: "cid", ItemID: "item-1", BuyerID: "buyer"}); err != nil { t.Fatal(err) } - if _, err := store.DB.ExecContext(ctx, `CREATE TRIGGER reject_shipped_state + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `CREATE TRIGGER reject_shipped_state BEFORE UPDATE OF system_shipped ON orders WHEN NEW.system_shipped=1 BEGIN SELECT RAISE(FAIL, 'forced shipment persistence failure'); END`); err != nil { t.Fatal(err) } + // mtopMock 保存mtopMock,供当前处理流程使用 mtopMock := &fakeMTop{consignOk: true, consignUpdated: "unb=123; _m_h5_tk=updated_1;"} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: &testSender{}}, nil) center.SetMTop(mtopMock) + // err 保存err,供当前处理流程使用 err := center.confirmShipment(ctx, Task{ AccountID: "cid", OrderID: "persist-failure", ItemID: "item-1", BuyerID: "buyer", ChatID: "chat", }) + // uncertain 保存uncertain,供当前处理流程使用 var uncertain *uncertainActionError if !errors.As(err, &uncertain) { t.Fatalf("known remote success with local failure must be quarantined, got %v", err) @@ -259,6 +316,7 @@ func TestConfirmShipmentQuarantinesKnownRemoteSuccessWhenLocalPersistenceFails(t if !strings.Contains(err.Error(), "闲鱼已确认发货") || !strings.Contains(err.Error(), "本地状态保存失败") { t.Fatalf("unexpected error: %v", err) } + // order、getErr 保存order、getErr,供当前处理流程使用 order, getErr := store.Orders.Get(ctx, "persist-failure") if getErr != nil { t.Fatal(getErr) @@ -268,28 +326,39 @@ func TestConfirmShipmentQuarantinesKnownRemoteSuccessWhenLocalPersistenceFails(t } } +// TestConfirmShipmentKeepsAuthoritativeSnapshotWhenSessionUnchanged 负责TestConfirmShipmentKeepsAuthoritativeSnapshotWhen会话Unchanged相关处理。 func TestConfirmShipmentKeepsAuthoritativeSnapshotWhenSessionUnchanged(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // initial 保存initial,供当前处理流程使用 initial := "unb=123; _m_h5_tk=old_1;" + // metadata 保存metadata,供当前处理流程使用 metadata := cookierefresh.MetadataWithSnapshot(`{"preserved":true}`, []cookierefresh.BrowserCookie{ {Name: "unb", Value: "123", Domain: ".goofish.com", Path: "/", Secure: true}, {Name: "_m_h5_tk", Value: "old_1", Domain: ".goofish.com", Path: "/", Secure: true}, }) - if err := store.Cookies.UpdateRenewalCookie(ctx, "cid", initial, metadata, 1); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.UpdateRenewalCookie(ctx, "cid", initial, metadata, 1); err != nil { t.Fatal(err) } + // updated 保存updated,供当前处理流程使用 updated := "unb=123; _m_h5_tk=mock_new_2;" + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetMTop(&fakeMTop{consignOk: false, consignRet: []string{"FAIL_SHIP"}, consignUpdated: updated}) + // err 保存err,供当前处理流程使用 err := center.confirmShipment(ctx, Task{ AccountID: "cid", OrderID: "flat-mock-fallback", ForceConfirmShipment: true, }) if err == nil || !strings.Contains(err.Error(), "FAIL_SHIP") { t.Fatalf("mock 业务失败应保留原返回语义: %v", err) } + // detail、getErr 保存detail、getErr,供当前处理流程使用 detail, getErr := store.Cookies.GetDetails(ctx, "cid") if getErr != nil { t.Fatal(getErr) @@ -297,7 +366,8 @@ func TestConfirmShipmentKeepsAuthoritativeSnapshotWhenSessionUnchanged(t *testin if detail.Value != initial { t.Fatalf("完整 Jar 未变化时不得被扁平/mock 返回覆盖: %q", detail.Value) } - if snapshot, ok := cookierefresh.SnapshotFromMetadataOK(detail.MetadataJSON); !ok || len(snapshot) != 2 { + if // snapshot、ok 保存snapshot、ok,供当前处理流程使用 + snapshot, ok := cookierefresh.SnapshotFromMetadataOK(detail.MetadataJSON); !ok || len(snapshot) != 2 { t.Fatalf("完整 Jar 未变化时必须继续保留: ok=%v snapshot=%+v metadata=%s", ok, snapshot, detail.MetadataJSON) } if !strings.Contains(detail.MetadataJSON, `"preserved":true`) { @@ -308,24 +378,34 @@ func TestConfirmShipmentKeepsAuthoritativeSnapshotWhenSessionUnchanged(t *testin } } +// TestConfirmShipmentKeepsFlatMockFallbackWithoutSnapshot 负责TestConfirmShipmentKeepsFlatMockFallbackWithoutSnapshot相关处理。 func TestConfirmShipmentKeepsFlatMockFallbackWithoutSnapshot(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // initial 保存initial,供当前处理流程使用 initial := "unb=123; _m_h5_tk=old_1;" - if err := store.Cookies.UpdateRenewalCookie(ctx, "cid", initial, `{"preserved":true}`, 1); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.UpdateRenewalCookie(ctx, "cid", initial, `{"preserved":true}`, 1); err != nil { t.Fatal(err) } + // updated 保存updated,供当前处理流程使用 updated := "unb=123; _m_h5_tk=mock_new_2;" + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetMTop(&fakeMTop{consignOk: false, consignRet: []string{"FAIL_SHIP"}, consignUpdated: updated}) + // err 保存err,供当前处理流程使用 err := center.confirmShipment(ctx, Task{ AccountID: "cid", OrderID: "flat-mock-fallback", ForceConfirmShipment: true, }) if err == nil || !strings.Contains(err.Error(), "FAIL_SHIP") { t.Fatalf("mock 业务失败应保留原返回语义: %v", err) } + // detail、getErr 保存detail、getErr,供当前处理流程使用 detail, getErr := store.Cookies.GetDetails(ctx, "cid") if getErr != nil { t.Fatal(getErr) @@ -333,7 +413,8 @@ func TestConfirmShipmentKeepsFlatMockFallbackWithoutSnapshot(t *testing.T) { if detail.Value != updated { t.Fatalf("无完整 Jar 时未保留扁平/mock 写回路径: %q", detail.Value) } - if _, ok := cookierefresh.SnapshotFromMetadataOK(detail.MetadataJSON); ok { + if // ok 保存ok,供当前处理流程使用 + _, ok := cookierefresh.SnapshotFromMetadataOK(detail.MetadataJSON); ok { t.Fatalf("扁平 mock 结果不得伪装成权威 Jar: %s", detail.MetadataJSON) } if !strings.Contains(detail.MetadataJSON, `"preserved":true`) { diff --git a/internal/automation/center_test.go b/internal/automation/center_test.go index 207d666..d168f94 100644 --- a/internal/automation/center_test.go +++ b/internal/automation/center_test.go @@ -19,16 +19,21 @@ import ( "xianyu-go/internal/xianyu/mtop" ) +// automationRoundTripperFunc 保存自动化RoundTripperFunc,供当前处理流程使用 type automationRoundTripperFunc func(*http.Request) (*http.Response, error) +// RoundTrip 负责RoundTrip相关处理。 func (f automationRoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error) { return f(req) } +// testSenderProvider 保存testSenderProvider,供当前处理流程使用 type testSenderProvider struct{ sender *testSender } +// Sender 负责Sender相关处理。 func (p testSenderProvider) Sender(string) (MessageSender, bool) { return p.sender, true } +// testSender 保存testSender,供当前处理流程使用 type testSender struct { texts []string cookieUpdates []string @@ -38,6 +43,7 @@ type testSender struct { failAfter int } +// SendText 负责Send文本相关处理。 func (s *testSender) SendText(_ context.Context, _, _, text string) error { if s.err != nil && (s.failAfter == 0 || len(s.texts) >= s.failAfter) { return s.err @@ -49,12 +55,17 @@ func (s *testSender) SendText(_ context.Context, _, _, text string) error { return nil } +// TestPartialAutomationRunIsQuarantined 负责TestPartial自动化运行IsQuarantined相关处理。 func TestPartialAutomationRunIsQuarantined(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", Name: "partial", TriggerType: TriggerBuyerReviewed, Enabled: true, Actions: []db.AutomationActionInput{ {ActionType: ActionSendText, MessageTemplate: "first", Enabled: true, SortOrder: 1}, @@ -63,14 +74,20 @@ func TestPartialAutomationRunIsQuarantined(t *testing.T) { }); err != nil { t.Fatal(err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) - if err := center.HandleTask(ctx, Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "partial-order", ChatID: "chat", BuyerID: "buyer"}); err == nil { + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "partial-order", ChatID: "chat", BuyerID: "buyer"}); err == nil { t.Fatal("partial execution should return an error") } + // status 保存状态,供当前处理流程使用 var status string + // sent 保存sent,供当前处理流程使用 var sent int - if err := store.DB.QueryRowContext(ctx, `SELECT status,sent_count FROM automation_runs WHERE order_id='partial-order'`).Scan(&status, &sent); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT status,sent_count FROM automation_runs WHERE order_id='partial-order'`).Scan(&status, &sent); err != nil { t.Fatal(err) } if status != "needs_review" || sent != 1 || len(sender.texts) != 1 { @@ -78,39 +95,52 @@ func TestPartialAutomationRunIsQuarantined(t *testing.T) { } } +// TestMessageDefinitelyNotSentIsRetried 负责Test消息DefinitelyNotSentIsRetried相关处理。 func TestMessageDefinitelyNotSentIsRetried(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", Name: "retry-before-send", TriggerType: TriggerBuyerReviewed, Enabled: true, Actions: []db.AutomationActionInput{{ActionType: ActionSendText, MessageTemplate: "gift", Enabled: true}}, }); err != nil { t.Fatal(err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{err: fmt.Errorf("%w: websocket reconnecting", ErrMessageNotSent)} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) + // task 保存任务,供当前处理流程使用 task := Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "retry-order", ChatID: "chat", BuyerID: "buyer"} - if err := center.HandleTask(ctx, task); err == nil { + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, task); err == nil { t.Fatal("首次发送应返回连接未就绪错误") } + // status 保存状态,供当前处理流程使用 var status string - if err := store.DB.QueryRowContext(ctx, `SELECT status FROM automation_runs WHERE order_id=?`, task.OrderID).Scan(&status); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT status FROM automation_runs WHERE order_id=?`, task.OrderID).Scan(&status); err != nil { t.Fatal(err) } if status != "failed" { t.Fatalf("确定未发送应进入可重试 failed,got %q", status) } sender.err = nil - if _, err := store.DB.ExecContext(ctx, `UPDATE automation_runs SET next_retry_at=0 WHERE order_id=?`, task.OrderID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `UPDATE automation_runs SET next_retry_at=0 WHERE order_id=?`, task.OrderID); err != nil { t.Fatal(err) } NewScheduler(center).runRecoveryTasks(ctx) if len(sender.texts) != 1 || sender.texts[0] != "gift" { t.Fatalf("连接恢复后应安全重试,got %v", sender.texts) } - if err := store.DB.QueryRowContext(ctx, `SELECT status FROM automation_runs WHERE order_id=?`, task.OrderID).Scan(&status); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT status FROM automation_runs WHERE order_id=?`, task.OrderID).Scan(&status); err != nil { t.Fatal(err) } if status != "success" { @@ -118,31 +148,43 @@ func TestMessageDefinitelyNotSentIsRetried(t *testing.T) { } } +// TestAbortRunActionFailureQuarantinesRun 负责TestAbort运行动作FailureQuarantines运行相关处理。 func TestAbortRunActionFailureQuarantinesRun(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", Name: "abort-failure", TriggerType: TriggerBuyerReviewed, Enabled: true, Actions: []db.AutomationActionInput{{ActionType: ActionSendText, MessageTemplate: "gift", Enabled: true}}, }); err != nil { t.Fatal(err) } - if _, err := store.DB.ExecContext(ctx, `CREATE TRIGGER fail_abort_run_action + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `CREATE TRIGGER fail_abort_run_action BEFORE UPDATE OF action_started ON automation_runs WHEN OLD.action_started = 1 AND NEW.action_started = 0 BEGIN SELECT RAISE(ABORT, 'forced abort failure'); END`); err != nil { t.Fatal(err) } + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: &testSender{err: fmt.Errorf("%w: websocket unavailable", ErrMessageNotSent)}}, nil) + // task 保存任务,供当前处理流程使用 task := Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "abort-failure-order", ChatID: "chat", BuyerID: "buyer"} - if err := center.HandleTask(ctx, task); err == nil || !errors.Is(err, errAutomationNeedsReview) { + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, task); err == nil || !errors.Is(err, errAutomationNeedsReview) { t.Fatalf("回滚检查点失败后应要求人工核对,err=%v", err) } + // status 保存状态,供当前处理流程使用 var status string + // actionStarted 保存动作Started,供当前处理流程使用 var actionStarted int - if err := store.DB.QueryRowContext(ctx, `SELECT status,action_started FROM automation_runs WHERE order_id=?`, task.OrderID).Scan(&status, &actionStarted); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT status,action_started FROM automation_runs WHERE order_id=?`, task.OrderID).Scan(&status, &actionStarted); err != nil { t.Fatal(err) } if status != "needs_review" || actionStarted != 1 { @@ -150,7 +192,9 @@ func TestAbortRunActionFailureQuarantinesRun(t *testing.T) { } } +// TestCardDefinitelyNotSentIsRetriedAndDataInventoryRestored 负责Test卡密DefinitelyNotSentIsRetriedAnd数据InventoryRestored相关处理。 func TestCardDefinitelyNotSentIsRetriedAndDataInventoryRestored(t *testing.T) { + // tc 表示当前遍历过程中的tc for _, tc := range []struct { name string cardType string @@ -160,45 +204,61 @@ func TestCardDefinitelyNotSentIsRetriedAndDataInventoryRestored(t *testing.T) { {name: "data", cardType: "data", cardColumn: "data_content"}, } { t.Run(tc.name, func(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") + // query 保存查询,供当前处理流程使用 query := fmt.Sprintf(`INSERT INTO cards (name,type,%s,enabled,user_id) VALUES (?,?,?,?,?)`, tc.cardColumn) + // res、err 保存res、err,供当前处理流程使用 res, err := store.DB.ExecContext(ctx, query, "gift", tc.cardType, "GIFT-CODE", 1, admin.ID) if err != nil { t.Fatal(err) } + // cardID 保存卡密ID,供当前处理流程使用 cardID, _ := res.LastInsertId() - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", ItemID: "item-card", Name: "card-retry-" + tc.name, TriggerType: TriggerBuyerReviewed, Enabled: true, Actions: []db.AutomationActionInput{{ActionType: ActionSendCard, CardID: cardID, DeliveryCount: 1, Enabled: true}}, }); err != nil { t.Fatal(err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{err: fmt.Errorf("%w: websocket reconnecting", ErrMessageNotSent)} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) + // task 保存任务,供当前处理流程使用 task := Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "card-order-" + tc.name, ItemID: "item-card", ChatID: "chat", BuyerID: "buyer"} - if err := center.HandleTask(ctx, task); err == nil { + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, task); err == nil { t.Fatal("首次卡密发送应返回连接未就绪错误") } + // status 保存状态,供当前处理流程使用 var status string - if err := store.DB.QueryRowContext(ctx, `SELECT status FROM automation_runs WHERE order_id=?`, task.OrderID).Scan(&status); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT status FROM automation_runs WHERE order_id=?`, task.OrderID).Scan(&status); err != nil { t.Fatal(err) } if status != "failed" { t.Fatalf("确定未发送的卡密应进入可重试 failed,got %q", status) } if tc.cardType == "data" { + // inventory 保存inventory,供当前处理流程使用 var inventory string - if err := store.DB.QueryRowContext(ctx, `SELECT data_content FROM cards WHERE id=?`, cardID).Scan(&inventory); err != nil || inventory != "GIFT-CODE" { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT data_content FROM cards WHERE id=?`, cardID).Scan(&inventory); err != nil || inventory != "GIFT-CODE" { t.Fatalf("未发送 Data 卡密必须恢复库存: inventory=%q err=%v", inventory, err) } } sender.err = nil - if _, err := store.DB.ExecContext(ctx, `UPDATE automation_runs SET next_retry_at=0 WHERE order_id=?`, task.OrderID); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `UPDATE automation_runs SET next_retry_at=0 WHERE order_id=?`, task.OrderID); err != nil { t.Fatal(err) } NewScheduler(center).runRecoveryTasks(ctx) @@ -209,26 +269,35 @@ func TestCardDefinitelyNotSentIsRetriedAndDataInventoryRestored(t *testing.T) { } } +// TestRuleMatchingUsesStoredOrderItemWhenEventOmitsItemID 负责Test规则MatchingUsesStored订单商品WhenEventOmits商品ID相关处理。 func TestRuleMatchingUsesStoredOrderItemWhenEventOmitsItemID(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if err := store.Orders.Upsert(ctx, "known-order", db.OrderUpsertOpts{ + if // err 保存err,供当前处理流程使用 + err := store.Orders.Upsert(ctx, "known-order", db.OrderUpsertOpts{ CookieID: "cid", ItemID: "known-item", BuyerID: "buyer", ChatID: "chat", }); err != nil { t.Fatal(err) } - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", ItemID: "known-item", Name: "item-specific-review", TriggerType: TriggerBuyerReviewed, Enabled: true, Actions: []db.AutomationActionInput{{ActionType: ActionSendText, MessageTemplate: "review-gift", Enabled: true}}, }); err != nil { t.Fatal(err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) - if err := center.HandleTask(ctx, Task{ + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, Task{ AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "known-order", }); err != nil { t.Fatal(err) @@ -238,17 +307,24 @@ func TestRuleMatchingUsesStoredOrderItemWhenEventOmitsItemID(t *testing.T) { } } +// TestImageCardMissingSenderIsDefinitelyNotSent 负责Test图片卡密MissingSenderIsDefinitelyNotSent相关处理。 func TestImageCardMissingSenderIsDefinitelyNotSent(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // center 保存center,供当前处理流程使用 center := New(store, nil, nil) + // err 保存err,供当前处理流程使用 err := center.sendImage(context.Background(), Task{AccountID: "cid", ChatID: "chat", BuyerID: "buyer"}, "https://example.com/gift.png", 1) if !errors.Is(err, ErrMessageNotSent) { t.Fatalf("图片发送器缺失应标记为明确未发送,got %v", err) } } +// SendImage 负责Send图片相关处理。 func (s *testSender) SendImage(context.Context, string, string, string, int64) error { return nil } + +// UpdateCookie 更新登录凭证。 func (s *testSender) UpdateCookie(cookieStr string) { s.cookieUpdates = append(s.cookieUpdates, cookieStr) if s.onCookieUpdate != nil { @@ -256,12 +332,14 @@ func (s *testSender) UpdateCookie(cookieStr string) { } } +// testFetcher 保存testFetcher,供当前处理流程使用 type testFetcher struct { detail *OrderDetail err error calls *int } +// FetchOrderDetail 负责Fetch订单Detail相关处理。 func (f testFetcher) FetchOrderDetail(context.Context, string, string, string, string, string) (*OrderDetail, error) { if f.calls != nil { *f.calls++ @@ -269,26 +347,38 @@ func (f testFetcher) FetchOrderDetail(context.Context, string, string, string, s return f.detail, f.err } +// TestReviewAutomationsDoNotRequireOrderDetail 负责TestReviewAutomationsDoNotRequire订单Detail相关处理。 func TestReviewAutomationsDoNotRequireOrderDetail(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") + // trigger 表示当前遍历过程中的trigger for _, trigger := range []string{TriggerBuyerReviewed, TriggerReviewMissingTimeout} { - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", Name: trigger, TriggerType: trigger, Enabled: true, Actions: []db.AutomationActionInput{{ActionType: ActionSendText, MessageTemplate: trigger, Enabled: true}}, }); err != nil { t.Fatal(err) } } + // calls 保存calls,供当前处理流程使用 calls := 0 + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetOrderDetailFetcher(testFetcher{err: errors.New("must not fetch"), calls: &calls}) + // i、trigger 表示当前遍历过程中的i、trigger for i, trigger := range []string{TriggerBuyerReviewed, TriggerReviewMissingTimeout} { + // task 保存任务,供当前处理流程使用 task := Task{Source: "ws", AccountID: "cid", TriggerType: trigger, OrderID: fmt.Sprintf("review-no-detail-%d", i), ChatID: "chat", BuyerID: "buyer", Raw: map[string]any{"attempt": 1}} - if err := center.HandleTask(ctx, task); err != nil { + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, task); err != nil { t.Fatalf("%s should not fetch order detail: %v", trigger, err) } } @@ -297,26 +387,36 @@ func TestReviewAutomationsDoNotRequireOrderDetail(t *testing.T) { } } +// TestOrderPaidPreparationFailureIsPersistedAndRecovered 负责Test订单PaidPreparationFailureIsPersistedAndRecovered相关处理。 func TestOrderPaidPreparationFailureIsPersistedAndRecovered(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") _, _ = store.DB.ExecContext(ctx, `INSERT INTO item_info (cookie_id,item_id,item_title,is_multi_spec) VALUES ('cid','pending-item','商品',1)`) _, _ = store.DB.ExecContext(ctx, `INSERT INTO cards (id,name,type,text_content,enabled,user_id) VALUES (91,'库存','text','RECOVERED-CARD',1,?)`, admin.ID) - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", ItemID: "pending-item", Name: "付款恢复", TriggerType: TriggerOrderPaid, Enabled: true, Actions: []db.AutomationActionInput{{ActionType: ActionSendCard, CardID: 91, DeliveryCount: 1, ConfigJSON: `{"spec_name":"套餐","spec_value":"恢复版"}`, Enabled: true}}, }); err != nil { t.Fatal(err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetOrderDetailFetcher(testFetcher{err: errors.New("temporary order API failure")}) + // task 保存任务,供当前处理流程使用 task := Task{Source: "ws", AccountID: "cid", TriggerType: TriggerOrderPaid, OrderID: "pending-order", ItemID: "pending-item", ChatID: "chat", BuyerID: "buyer", Raw: map[string]any{"message_id": "paid-1"}} - if err := center.HandleTask(ctx, task); err != nil { + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, task); err != nil { t.Fatalf("preparation failure should be durably deferred: %v", err) } + // pending、runs 保存pending、runs,供当前处理流程使用 var pending, runs int _ = store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM automation_pending_tasks WHERE cookie_id='cid' AND trigger_type='order_paid'`).Scan(&pending) _ = store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM automation_runs WHERE order_id='pending-order'`).Scan(&runs) @@ -330,6 +430,7 @@ func TestOrderPaidPreparationFailureIsPersistedAndRecovered(t *testing.T) { t.Fatalf("recovered sends=%v", sender.texts) } _ = store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM automation_pending_tasks WHERE cookie_id='cid'`).Scan(&pending) + // status 保存状态,供当前处理流程使用 var status string _ = store.DB.QueryRowContext(ctx, `SELECT status FROM automation_runs WHERE order_id='pending-order'`).Scan(&status) if pending != 0 || status != "success" { @@ -337,36 +438,49 @@ func TestOrderPaidPreparationFailureIsPersistedAndRecovered(t *testing.T) { } } +// newAutomationTestStore 负责new自动化TestStore相关处理。 func newAutomationTestStore(t *testing.T) (*db.Store, func()) { t.Helper() + // database、err 保存database、err,供当前处理流程使用 database, _, err := db.Open(context.Background(), filepath.Join(t.TempDir(), "test.db")) if err != nil { t.Fatalf("Open: %v", err) } + // store 保存store,供当前处理流程使用 store := db.NewStore(database, db.DialectSQLite) - if _, err := store.Users.Create(context.Background(), "admin", "admin@example.com", "pw"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.Users.Create(context.Background(), "admin", "admin@example.com", "pw"); err != nil { t.Fatalf("create user: %v", err) } + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(context.Background(), "admin") - if err := store.Cookies.Save(context.Background(), "cid", "unb=123; _m_h5_tk=tk_1;", admin.ID); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.Save(context.Background(), "cid", "unb=123; _m_h5_tk=tk_1;", admin.ID); err != nil { t.Fatalf("save cookie: %v", err) } return store, func() { _ = database.Close() } } +// TestActionDelayUsesCardDefaultUnlessOverridden 负责Test动作延迟Uses卡密DefaultUnlessOverridden相关处理。 func TestActionDelayUsesCardDefaultUnlessOverridden(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") + // cardID、err 保存卡密ID、err,供当前处理流程使用 cardID, err := store.Cards.Create(ctx, &db.CardFull{ Name: "delayed", Type: "text", TextContent: "x", Enabled: true, DelaySeconds: 15, UserID: admin.ID, }) if err != nil { t.Fatal(err) } + // center 保存center,供当前处理流程使用 center := New(store, nil, nil) + // got、err 保存got、err,供当前处理流程使用 got, err := center.actionDelaySeconds(ctx, db.AutomationAction{ ActionType: ActionSendCard, CardID: cardID, DelaySeconds: 0, ConfigJSON: `{}`, }) @@ -381,36 +495,51 @@ func TestActionDelayUsesCardDefaultUnlessOverridden(t *testing.T) { } } +// TestActionDelayRejectsDisabledCardAndEmptyTextCard 负责Test动作延迟RejectsDisabled卡密AndEmpty文本卡密相关处理。 func TestActionDelayRejectsDisabledCardAndEmptyTextCard(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") + // disabledID、err 保存disabledID、err,供当前处理流程使用 disabledID, err := store.Cards.Create(ctx, &db.CardFull{Name: "disabled", Type: "text", TextContent: "x", Enabled: false, UserID: admin.ID}) if err != nil { t.Fatal(err) } + // center 保存center,供当前处理流程使用 center := New(store, nil, nil) - if _, err := center.actionDelaySeconds(ctx, db.AutomationAction{ActionType: ActionSendCard, CardID: disabledID}); err == nil { + if // err 保存err,供当前处理流程使用 + _, err := center.actionDelaySeconds(ctx, db.AutomationAction{ActionType: ActionSendCard, CardID: disabledID}); err == nil { t.Fatal("disabled card must not be executed") } - if _, _, err := center.cardContent(ctx, &db.CardFull{ID: 99, Type: "text", Enabled: true}); err == nil { + if // err 保存err,供当前处理流程使用 + _, _, err := center.cardContent(ctx, &db.CardFull{ID: 99, Type: "text", Enabled: true}); err == nil { t.Fatal("empty text card must not produce a successful send") } } +// TestSendDataCardKeepsConsumedInventoryWhenDeliveryResultIsUncertain 负责TestSend数据卡密KeepsConsumedInventoryWhen发货结果IsUncertain相关处理。 func TestSendDataCardKeepsConsumedInventoryWhenDeliveryResultIsUncertain(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") + // cardID、err 保存卡密ID、err,供当前处理流程使用 cardID, err := store.Cards.Create(ctx, &db.CardFull{ Name: "data", Type: "data", DataContent: "secret-1\nsecret-2", Enabled: true, UserID: admin.ID, }) if err != nil { t.Fatal(err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{err: errors.New("temporary send failure")} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) _, err = center.sendCard(ctx, Task{AccountID: "cid", ChatID: "chat", BuyerID: "buyer"}, db.AutomationAction{ ActionType: ActionSendCard, CardID: cardID, DeliveryCount: 1, ConfigJSON: `{}`, @@ -418,41 +547,54 @@ func TestSendDataCardKeepsConsumedInventoryWhenDeliveryResultIsUncertain(t *test if err == nil { t.Fatal("send failure must be returned") } + // reserved、err 保存reserved、err,供当前处理流程使用 reserved, err := store.Cards.ConsumeBatchData(ctx, cardID) if err != nil || reserved != "secret-2" { t.Fatalf("uncertain send must not expose the same secret again: got=%q err=%v", reserved, err) } } +// TestCenterSkipsPausedAccountTasks 负责TestCenterSkipsPaused账号任务列表相关处理。 func TestCenterSkipsPausedAccountTasks(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", Name: "paused", TriggerType: TriggerBuyerReviewed, Enabled: true, Actions: []db.AutomationActionInput{{ActionType: ActionSendText, MessageTemplate: "must-not-send", Enabled: true}}, }); err != nil { t.Fatal(err) } - if _, err := store.Cookies.SetPause(ctx, "cid", 10); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.Cookies.SetPause(ctx, "cid", 10); err != nil { t.Fatal(err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) - if err := center.HandleTask(ctx, Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "paused-order", ChatID: "chat", BuyerID: "buyer"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "paused-order", ChatID: "chat", BuyerID: "buyer"}); err != nil { t.Fatal(err) } if len(sender.texts) != 0 { t.Fatalf("paused account sent messages: %v", sender.texts) } - if _, err := store.Orders.Get(ctx, "paused-order"); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.Orders.Get(ctx, "paused-order"); err != nil { t.Fatalf("paused event facts must be persisted, got %v", err) } - if _, err := center.ManualFullDelivery(ctx, &db.Order{OrderID: "manual", CookieID: "cid"}); err == nil { + if // err 保存err,供当前处理流程使用 + _, err := center.ManualFullDelivery(ctx, &db.Order{OrderID: "manual", CookieID: "cid"}); err == nil { t.Fatal("manual full delivery must reject a paused account") } - if _, err := store.Cookies.SetPause(ctx, "cid", 0); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.Cookies.SetPause(ctx, "cid", 0); err != nil { t.Fatal(err) } (&Scheduler{center: center}).runDeferredTasks(ctx) @@ -463,42 +605,56 @@ func TestCenterSkipsPausedAccountTasks(t *testing.T) { if len(sender.texts) != 1 { t.Fatalf("deferred event replay was not idempotent: %v", sender.texts) } - if err := store.Cookies.SetStatus(ctx, "cid", false); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.SetStatus(ctx, "cid", false); err != nil { t.Fatal(err) } - if err := center.HandleTask(ctx, Task{AccountID: "cid", TriggerType: TriggerOrderPaid, OrderID: "disabled-order", ChatID: "chat"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, Task{AccountID: "cid", TriggerType: TriggerOrderPaid, OrderID: "disabled-order", ChatID: "chat"}); err != nil { t.Fatal(err) } if len(sender.texts) != 1 { t.Fatalf("disabled account sent messages: %v", sender.texts) } - if _, err := center.ManualFullDelivery(ctx, &db.Order{OrderID: "disabled-manual", CookieID: "cid"}); err == nil { + if // err 保存err,供当前处理流程使用 + _, err := center.ManualFullDelivery(ctx, &db.Order{OrderID: "disabled-manual", CookieID: "cid"}); err == nil { t.Fatal("manual full delivery must reject a disabled account") } } +// TestDelayedAutomationIsPersistedAndReplayedWithoutSleeping 负责TestDelayed自动化IsPersistedAndReplayedWithoutSleeping相关处理。 func TestDelayedAutomationIsPersistedAndReplayedWithoutSleeping(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", Name: "delayed", TriggerType: TriggerBuyerReviewed, Enabled: true, Actions: []db.AutomationActionInput{{ActionType: ActionSendText, MessageTemplate: "delayed-message", DelaySeconds: 30, Enabled: true}}, }); err != nil { t.Fatal(err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) + // start 保存开始,供当前处理流程使用 start := time.Now() - if err := center.HandleTask(ctx, Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "delay-order", ChatID: "chat", BuyerID: "buyer"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "delay-order", ChatID: "chat", BuyerID: "buyer"}); err != nil { t.Fatal(err) } if time.Since(start) > time.Second || len(sender.texts) != 0 { t.Fatalf("delayed task blocked or sent immediately: elapsed=%s texts=%v", time.Since(start), sender.texts) } + // pending 保存pending,供当前处理流程使用 var pending int - if err := store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM automation_pending_tasks WHERE status='pending'`).Scan(&pending); err != nil || pending != 1 { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM automation_pending_tasks WHERE status='pending'`).Scan(&pending); err != nil || pending != 1 { t.Fatalf("pending=%d err=%v", pending, err) } _, _ = store.DB.ExecContext(ctx, `UPDATE automation_pending_tasks SET due_at=0`) @@ -508,11 +664,16 @@ func TestDelayedAutomationIsPersistedAndReplayedWithoutSleeping(t *testing.T) { } } +// TestMultipleActionDelaysPreserveSequentialSemantics 负责TestMultiple动作DelaysPreserveSequentialSemantics相关处理。 func TestMultipleActionDelaysPreserveSequentialSemantics(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", Name: "sequential", TriggerType: TriggerBuyerReviewed, Enabled: true, Actions: []db.AutomationActionInput{ @@ -523,19 +684,25 @@ func TestMultipleActionDelaysPreserveSequentialSemantics(t *testing.T) { if err != nil { t.Fatal(err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) - if err := center.HandleTask(ctx, Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "seq-order", ChatID: "chat", BuyerID: "buyer"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "seq-order", ChatID: "chat", BuyerID: "buyer"}); err != nil { t.Fatal(err) } if len(sender.texts) != 1 || sender.texts[0] != "first" { t.Fatalf("first action was not immediate: %v", sender.texts) } + // cursor 保存游标,供当前处理流程使用 var cursor int - if err := store.DB.QueryRowContext(ctx, `SELECT action_cursor FROM automation_runs WHERE order_id='seq-order'`).Scan(&cursor); err != nil || cursor != 1 { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT action_cursor FROM automation_runs WHERE order_id='seq-order'`).Scan(&cursor); err != nil || cursor != 1 { t.Fatalf("cursor=%d err=%v", cursor, err) } - if err := store.Automation.Update(ctx, admin.ID, ruleID, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + err := store.Automation.Update(ctx, admin.ID, ruleID, db.AutomationRuleInput{ CookieID: "cid", Name: "changed", TriggerType: TriggerBuyerReviewed, Enabled: true, Actions: []db.AutomationActionInput{ {ActionType: ActionSendText, MessageTemplate: "inserted", Enabled: true, SortOrder: 1}, @@ -551,49 +718,69 @@ func TestMultipleActionDelaysPreserveSequentialSemantics(t *testing.T) { } } +// TestExpiredRunDuringExternalActionIsQuarantined 负责TestExpired运行DuringExternal动作IsQuarantined相关处理。 func TestExpiredRunDuringExternalActionIsQuarantined(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") + // ruleID 保存规则ID,供当前处理流程使用 ruleID, _ := store.Automation.Create(ctx, db.AutomationRuleInput{UserID: admin.ID, CookieID: "cid", Name: "crash", TriggerType: TriggerBuyerReviewed, Enabled: true, Actions: []db.AutomationActionInput{{ActionType: ActionSendText, MessageTemplate: "must-not-repeat", Enabled: true}}}) + // task 保存任务,供当前处理流程使用 task := Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "crash-order", ChatID: "chat", BuyerID: "buyer"} + // raw 保存原始,供当前处理流程使用 raw, _ := json.Marshal(task) + // runID、started、err 保存运行ID、started、err,供当前处理流程使用 runID, started, err := store.Automation.TryStartRun(ctx, db.AutomationRun{RuleID: ruleID, CookieID: "cid", OrderID: "crash-order", TriggerType: TriggerBuyerReviewed, TriggerKey: buildTriggerKey(task), RawEventJSON: string(raw), LeaseExpiresAt: time.Now().Add(time.Minute).Unix()}) if err != nil || !started { t.Fatalf("start=%v err=%v", started, err) } - if ok, err := store.Automation.StartRunAction(ctx, runID, 1, 0, time.Now().Add(-time.Minute).Unix()); err != nil || !ok { + if // ok、err 保存ok、err,供当前处理流程使用 + ok, err := store.Automation.StartRunAction(ctx, runID, 1, 0, time.Now().Add(-time.Minute).Unix()); err != nil || !ok { t.Fatalf("start action=%v err=%v", ok, err) } _, _ = store.DB.ExecContext(ctx, `UPDATE automation_runs SET lease_expires_at=0 WHERE id=?`, runID) + // sender 保存sender,供当前处理流程使用 sender := &testSender{} (&Scheduler{center: New(store, testSenderProvider{sender: sender}, nil)}).runRecoveryTasks(ctx) + // run 保存运行,供当前处理流程使用 run, _ := store.Automation.GetRun(ctx, runID) if run.Status != "needs_review" || len(sender.texts) != 0 { t.Fatalf("run=%+v texts=%v", run, sender.texts) } } +// TestInvalidDeferredTaskMovesToDeadLetter 负责TestInvalidDeferred任务MovesToDeadLetter相关处理。 func TestInvalidDeferredTaskMovesToDeadLetter(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() - if _, err := store.DB.ExecContext(ctx, `INSERT INTO automation_pending_tasks + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `INSERT INTO automation_pending_tasks (task_key,cookie_id,trigger_type,task_json,due_at,status,attempt_count,lease_expires_at,error_message) VALUES ('cid:bad','cid',?,'{"broken',0,'pending',0,0,'')`, TriggerBuyerReviewed); err != nil { t.Fatal(err) } + // scheduler 保存scheduler,供当前处理流程使用 scheduler := &Scheduler{center: New(store, testSenderProvider{sender: &testSender{}}, nil)} - for i := 0; i < 5; i++ { + for // i 保存i,供当前处理流程使用 + i := 0; i < 5; i++ { _, _ = store.DB.ExecContext(ctx, `UPDATE automation_pending_tasks SET due_at=0`) scheduler.runDeferredTasks(ctx) } + // status 保存状态,供当前处理流程使用 var status string + // attempts 保存尝试次数,供当前处理流程使用 var attempts int - if err := store.DB.QueryRowContext(ctx, `SELECT status,attempt_count FROM automation_pending_tasks WHERE task_key='cid:bad'`).Scan(&status, &attempts); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT status,attempt_count FROM automation_pending_tasks WHERE task_key='cid:bad'`).Scan(&status, &attempts); err != nil { t.Fatal(err) } if status != "dead_letter" || attempts != 5 { @@ -601,35 +788,49 @@ func TestInvalidDeferredTaskMovesToDeadLetter(t *testing.T) { } } +// TestUnknownExternalAutomationRunCannotBeRetried 负责TestUnknownExternal自动化运行CannotBeRetried相关处理。 func TestUnknownExternalAutomationRunCannotBeRetried(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", Name: "retry", TriggerType: TriggerBuyerReviewed, Enabled: true, Actions: []db.AutomationActionInput{{ActionType: ActionSendText, MessageTemplate: "retry-message", Enabled: true}}, }); err != nil { t.Fatal(err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{err: errors.New("temporary")} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) - if err := center.HandleTask(ctx, Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "retry-order", ChatID: "chat", BuyerID: "buyer"}); err == nil { + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "retry-order", ChatID: "chat", BuyerID: "buyer"}); err == nil { t.Fatal("first execution should fail") } + // runID 保存运行ID,供当前处理流程使用 var runID int64 + // initialStatus 保存initial状态,供当前处理流程使用 var initialStatus string - if err := store.DB.QueryRowContext(ctx, `SELECT id,status FROM automation_runs WHERE order_id='retry-order'`).Scan(&runID, &initialStatus); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT id,status FROM automation_runs WHERE order_id='retry-order'`).Scan(&runID, &initialStatus); err != nil { t.Fatal(err) } if initialStatus != "needs_review" { t.Fatalf("ambiguous failure status=%s", initialStatus) } - if err := store.Automation.ResolveRunIssue(ctx, admin.ID, runID, "retry"); err == nil { + if // err 保存err,供当前处理流程使用 + err := store.Automation.ResolveRunIssue(ctx, admin.ID, runID, "retry"); err == nil { t.Fatal("unknown external send result must reject retry") } + // status 保存状态,供当前处理流程使用 var status string - if err := store.DB.QueryRowContext(ctx, `SELECT status FROM automation_runs WHERE order_id='retry-order'`).Scan(&status); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT status FROM automation_runs WHERE order_id='retry-order'`).Scan(&status); err != nil { t.Fatal(err) } if status != "needs_review" { @@ -637,26 +838,37 @@ func TestUnknownExternalAutomationRunCannotBeRetried(t *testing.T) { } } +// TestFailedDeferredTaskRemainsPending 负责Test失败Deferred任务RemainsPending相关处理。 func TestFailedDeferredTaskRemainsPending(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", Name: "deferred-fail", TriggerType: TriggerBuyerReviewed, Enabled: true, Actions: []db.AutomationActionInput{{ActionType: ActionSendText, MessageTemplate: "x", Enabled: true}}, }); err != nil { t.Fatal(err) } + // task 保存任务,供当前处理流程使用 task := Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed, OrderID: "deferred-fail", ChatID: "chat", BuyerID: "buyer", Raw: map[string]any{"delays_elapsed": true}} + // raw 保存原始,供当前处理流程使用 raw, _ := json.Marshal(task) - if err := store.Automation.DeferTask(ctx, db.DeferredAutomationTask{TaskKey: "cid:buyer_reviewed:deferred-fail", CookieID: "cid", TriggerType: TriggerBuyerReviewed, TaskJSON: string(raw), DueAt: 0}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Automation.DeferTask(ctx, db.DeferredAutomationTask{TaskKey: "cid:buyer_reviewed:deferred-fail", CookieID: "cid", TriggerType: TriggerBuyerReviewed, TaskJSON: string(raw), DueAt: 0}); err != nil { t.Fatal(err) } + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: &testSender{err: errors.New("temporary")}}, nil) (&Scheduler{center: center}).runDeferredTasks(ctx) + // status 保存状态,供当前处理流程使用 var status string - if err := store.DB.QueryRowContext(ctx, `SELECT status FROM automation_pending_tasks WHERE task_key='cid:buyer_reviewed:deferred-fail'`).Scan(&status); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT status FROM automation_pending_tasks WHERE task_key='cid:buyer_reviewed:deferred-fail'`).Scan(&status); err != nil { t.Fatal(err) } if status != "pending" { @@ -664,20 +876,27 @@ func TestFailedDeferredTaskRemainsPending(t *testing.T) { } } +// TestCenterOrderPaidFetchesOrderDetailMatchesSpecAndQuantity 负责TestCenter订单PaidFetches订单DetailMatchesSpecAndQuantity相关处理。 func TestCenterOrderPaidFetchesOrderDetailMatchesSpecAndQuantity(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if _, err := store.DB.ExecContext(ctx, `INSERT INTO item_info (cookie_id,item_id,item_title,is_multi_spec) VALUES ('cid','item-1','会员',1)`); err != nil { + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `INSERT INTO item_info (cookie_id,item_id,item_title,is_multi_spec) VALUES ('cid','item-1','会员',1)`); err != nil { t.Fatal(err) } - if _, err := store.DB.ExecContext(ctx, `INSERT INTO cards (id,name,type,data_content,enabled,user_id) VALUES + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `INSERT INTO cards (id,name,type,data_content,enabled,user_id) VALUES (11,'30天库存','data','A1'||char(10)||'A2'||char(10)||'A3'||char(10)||'A4',1,?), (12,'90天库存','data','B1'||char(10)||'B2'||char(10)||'B3'||char(10)||'B4',1,?)`, admin.ID, admin.ID); err != nil { t.Fatal(err) } + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", ItemID: "item-1", Name: "付款后自动发货", TriggerType: TriggerOrderPaid, Enabled: true, Priority: 100, @@ -690,7 +909,9 @@ func TestCenterOrderPaidFetchesOrderDetailMatchesSpecAndQuantity(t *testing.T) { t.Fatalf("create automation rule: id=%d err=%v", ruleID, err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetOrderDetailFetcher(testFetcher{detail: &OrderDetail{ SpecName: "套餐", SpecValue: "90天", Quantity: "2", Amount: "19.8", OrderStatus: "pending_ship", @@ -704,14 +925,17 @@ func TestCenterOrderPaidFetchesOrderDetailMatchesSpecAndQuantity(t *testing.T) { t.Fatalf("HandleTask: %v", err) } - if got, want := len(sender.texts), 4; got != want { + if // got、want 保存got、want,供当前处理流程使用 + got, want := len(sender.texts), 4; got != want { t.Fatalf("发送条数=%d want %d texts=%v", got, want, sender.texts) } + // i、want 表示当前遍历过程中的i、want for i, want := range []string{"B1", "B2", "B3", "B4"} { if sender.texts[i] != want { t.Fatalf("texts[%d]=%q want %q", i, sender.texts[i], want) } } + // order、err 保存order、err,供当前处理流程使用 order, err := store.Orders.Get(ctx, "order-1") if err != nil { t.Fatal(err) @@ -724,12 +948,17 @@ func TestCenterOrderPaidFetchesOrderDetailMatchesSpecAndQuantity(t *testing.T) { } } +// TestCenterBuyerReviewedFirstEventRecordsReviewTime 负责TestCenter买家ReviewedFirstEventRecordsReview时间相关处理。 func TestCenterBuyerReviewedFirstEventRecordsReviewTime(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") + // err 保存err,供当前处理流程使用 _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", ItemID: "item-review", Name: "评价赠品", TriggerType: TriggerBuyerReviewed, Enabled: true, Priority: 100, @@ -741,9 +970,12 @@ func TestCenterBuyerReviewedFirstEventRecordsReviewTime(t *testing.T) { t.Fatalf("create review rule: %v", err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) - if err := center.HandleTask(ctx, Task{ + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, Task{ Source: "ws", AccountID: "cid", TriggerType: TriggerBuyerReviewed, ChatID: "chat-review", OrderID: "order-review", ItemID: "item-review", BuyerID: "buyer-review", Raw: map[string]any{"message_id": "review-1"}, @@ -753,6 +985,7 @@ func TestCenterBuyerReviewedFirstEventRecordsReviewTime(t *testing.T) { if len(sender.texts) != 1 || sender.texts[0] != "谢谢评价" { t.Fatalf("评价赠品发送异常: %v", sender.texts) } + // order、err 保存order、err,供当前处理流程使用 order, err := store.Orders.Get(ctx, "order-review") if err != nil { t.Fatalf("Get order-review: %v", err) @@ -760,12 +993,15 @@ func TestCenterBuyerReviewedFirstEventRecordsReviewTime(t *testing.T) { if order.BuyerReviewedAt == "" { t.Fatalf("首次评价事件创建订单时应记录 buyer_reviewed_at: %+v", order) } + // sysShipped 保存sysShipped,供当前处理流程使用 sysShipped := true - if err := store.Orders.Upsert(ctx, "order-review", db.OrderUpsertOpts{ + if // err 保存err,供当前处理流程使用 + err := store.Orders.Upsert(ctx, "order-review", db.OrderUpsertOpts{ CookieID: "cid", ItemID: "item-review", BuyerID: "buyer-review", ChatID: "chat-review", SystemShipped: &sysShipped, }); err != nil { t.Fatalf("mark shipped: %v", err) } + // due、err 保存due、err,供当前处理流程使用 due, err := store.Automation.DueReviewRequestOrders(ctx, 200) if err != nil { t.Fatalf("DueReviewRequestOrders: %v", err) @@ -775,16 +1011,21 @@ func TestCenterBuyerReviewedFirstEventRecordsReviewTime(t *testing.T) { } } +// TestCenterOrderPaidSendsAllCardActionsForSameSpec 负责TestCenter订单PaidSendsAll卡密动作列表ForSameSpec相关处理。 func TestCenterOrderPaidSendsAllCardActionsForSameSpec(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") _, _ = store.DB.ExecContext(ctx, `INSERT INTO item_info (cookie_id,item_id,item_title,is_multi_spec) VALUES ('cid','item-bundle','组合商品',1)`) _, _ = store.DB.ExecContext(ctx, `INSERT INTO cards (id,name,type,text_content,enabled,user_id) VALUES (41,'主卡库存','text','MAIN-CARD',1,?), (42,'附赠卡库存','text','GIFT-CARD',1,?)`, admin.ID, admin.ID) + // err 保存err,供当前处理流程使用 _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", ItemID: "item-bundle", Name: "组合商品自动发货", TriggerType: TriggerOrderPaid, Enabled: true, Priority: 100, @@ -797,23 +1038,28 @@ func TestCenterOrderPaidSendsAllCardActionsForSameSpec(t *testing.T) { t.Fatalf("create automation rule: %v", err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetOrderDetailFetcher(testFetcher{detail: &OrderDetail{ SpecName: "套餐", SpecValue: "组合版", Quantity: "1", Amount: "29.9", }}) - if err := center.HandleTask(ctx, Task{ + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, Task{ Source: "ws", AccountID: "cid", CookieStr: "unb=123; _m_h5_tk=tk_1;", TriggerType: TriggerOrderPaid, ChatID: "chat-bundle", OrderID: "order-bundle", ItemID: "item-bundle", BuyerID: "buyer-1", Raw: map[string]any{"message_id": "m-bundle"}, }); err != nil { t.Fatalf("HandleTask: %v", err) } + // want 保存want,供当前处理流程使用 want := []string{"MAIN-CARD", "GIFT-CARD"} if len(sender.texts) != len(want) { t.Fatalf("发送内容=%v want %v", sender.texts, want) } + // i 表示当前遍历过程中的i for i := range want { if sender.texts[i] != want[i] { t.Fatalf("发送内容=%v want %v", sender.texts, want) @@ -821,14 +1067,19 @@ func TestCenterOrderPaidSendsAllCardActionsForSameSpec(t *testing.T) { } } +// TestCenterOrderPaidDoesNotConfirmWhenNoCardSpecMatches 负责TestCenter订单PaidDoesNotConfirmWhenNo卡密SpecMatches相关处理。 func TestCenterOrderPaidDoesNotConfirmWhenNoCardSpecMatches(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") _, _ = store.DB.ExecContext(ctx, `INSERT INTO item_info (cookie_id,item_id,item_title,is_multi_spec) VALUES ('cid','item-1','会员',1)`) _, _ = store.DB.ExecContext(ctx, `INSERT INTO cards (id,name,type,text_content,enabled,user_id) VALUES (21,'30天库存','text','A',1,?)`, admin.ID) + // err 保存err,供当前处理流程使用 _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", ItemID: "item-1", Name: "付款后自动发货", TriggerType: TriggerOrderPaid, Enabled: true, Priority: 100, @@ -841,7 +1092,9 @@ func TestCenterOrderPaidDoesNotConfirmWhenNoCardSpecMatches(t *testing.T) { t.Fatalf("create automation rule: %v", err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetOrderDetailFetcher(testFetcher{detail: &OrderDetail{SpecName: "套餐", SpecValue: "90天", Quantity: "1"}}) @@ -855,6 +1108,7 @@ func TestCenterOrderPaidDoesNotConfirmWhenNoCardSpecMatches(t *testing.T) { if len(sender.texts) != 0 { t.Fatalf("规格不匹配时不应发送卡密: %v", sender.texts) } + // order、err 保存order、err,供当前处理流程使用 order, err := store.Orders.Get(ctx, "order-no-match") if err != nil { t.Fatal(err) @@ -864,14 +1118,19 @@ func TestCenterOrderPaidDoesNotConfirmWhenNoCardSpecMatches(t *testing.T) { } } +// TestCenterOrderPaidSendsCardBeforeConfirmShipment 负责TestCenter订单PaidSends卡密BeforeConfirmShipment相关处理。 func TestCenterOrderPaidSendsCardBeforeConfirmShipment(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") _, _ = store.DB.ExecContext(ctx, `INSERT INTO item_info (cookie_id,item_id,item_title) VALUES ('cid','item-1','会员')`) _, _ = store.DB.ExecContext(ctx, `INSERT INTO cards (id,name,type,text_content,enabled,user_id) VALUES (31,'默认库存','text','CARD-1',1,?)`, admin.ID) + // err 保存err,供当前处理流程使用 _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", ItemID: "item-1", Name: "付款后自动发货", TriggerType: TriggerOrderPaid, Enabled: true, Priority: 100, @@ -885,29 +1144,36 @@ func TestCenterOrderPaidSendsCardBeforeConfirmShipment(t *testing.T) { t.Fatalf("create automation rule: %v", err) } + // events 保存events,供当前处理流程使用 events := []string{} + // server 保存server,供当前处理流程使用 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { events = append(events, "confirm") fmt.Fprint(w, `{"ret":["SUCCESS::调用成功"]}`) })) defer server.Close() + // sender 保存sender,供当前处理流程使用 sender := &testSender{events: &events} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetMTop(&mtop.ClientImpl{HTTPClient: server.Client(), ConsignURL: server.URL + "/"}) center.SetOrderDetailFetcher(testFetcher{detail: &OrderDetail{Quantity: "1", Amount: "9.9"}}) - if err := center.HandleTask(ctx, Task{ + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, Task{ Source: "ws", AccountID: "cid", CookieStr: "unb=123; _m_h5_tk=tk_1;", TriggerType: TriggerOrderPaid, ChatID: "chat-1", OrderID: "order-seq", ItemID: "item-1", BuyerID: "buyer-1", Raw: map[string]any{"message_id": "m3"}, }); err != nil { t.Fatalf("HandleTask: %v", err) } + // want 保存want,供当前处理流程使用 want := []string{"send:CARD-1", "confirm"} if len(events) != len(want) { t.Fatalf("events=%v want %v", events, want) } + // i 表示当前遍历过程中的i for i := range want { if events[i] != want[i] { t.Fatalf("events=%v want %v", events, want) @@ -915,23 +1181,32 @@ func TestCenterOrderPaidSendsCardBeforeConfirmShipment(t *testing.T) { } } +// TestConfirmShipmentPersistsAuthoritativeSessionBeforeParseError 负责TestConfirmShipmentPersistsAuthoritative会话BeforeParse错误相关处理。 func TestConfirmShipmentPersistsAuthoritativeSessionBeforeParseError(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // initialValue 保存initial值,供当前处理流程使用 initialValue := "flat_leak=must-not-send; unb=123; _m_h5_tk=flat_old_1" + // snapshot 保存snapshot,供当前处理流程使用 snapshot := []cookierefresh.BrowserCookie{ {Name: "unb", Value: "123", 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, "cid", initialValue, metadata, 1); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.UpdateRenewalCookie(ctx, "cid", initialValue, metadata, 1); err != nil { t.Fatal(err) } + // requestCookie 保存请求登录凭证,供当前处理流程使用 var requestCookie string + // client 保存client,供当前处理流程使用 client := &http.Client{Transport: automationRoundTripperFunc(func(req *http.Request) (*http.Response, error) { requestCookie = req.Header.Get("Cookie") return &http.Response{ @@ -944,10 +1219,14 @@ func TestConfirmShipmentPersistsAuthoritativeSessionBeforeParseError(t *testing. Request: req, }, nil })} + // lockReleasedBeforeRuntimeUpdate 保存锁ReleasedBeforeRuntimeUpdate,供当前处理流程使用 lockReleasedBeforeRuntimeUpdate := false + // sender 保存sender,供当前处理流程使用 sender := &testSender{onCookieUpdate: func(string) { + // acquired 保存acquired,供当前处理流程使用 acquired := make(chan struct{}) go func() { + // unlock 保存unlock,供当前处理流程使用 unlock := store.LockAccountCredentials("cid") unlock() close(acquired) @@ -958,26 +1237,32 @@ func TestConfirmShipmentPersistsAuthoritativeSessionBeforeParseError(t *testing. case <-time.After(500 * time.Millisecond): } }} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetMTop(&mtop.ClientImpl{HTTPClient: client, ConsignURL: mtop.ConsignAPI}) + // err 保存err,供当前处理流程使用 err := center.confirmShipment(ctx, Task{ AccountID: "cid", OrderID: "session-parse-error", ForceConfirmShipment: true, }) + // uncertain 保存uncertain,供当前处理流程使用 var uncertain *uncertainActionError if !errors.As(err, &uncertain) { t.Fatalf("远程响应解析失败应进入人工核对: %v", err) } + // want 表示当前遍历过程中的want for _, want := range []string{"unb=123", "_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、getErr 保存detail、getErr,供当前处理流程使用 detail, getErr := store.Cookies.GetDetails(ctx, "cid") if getErr != nil { t.Fatal(getErr) @@ -988,11 +1273,14 @@ func TestConfirmShipmentPersistsAuthoritativeSessionBeforeParseError(t *testing. 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 } @@ -1009,18 +1297,25 @@ func TestConfirmShipmentPersistsAuthoritativeSessionBeforeParseError(t *testing. } } +// TestConfirmShipmentPropagatesAuthoritativeEmptySession 负责TestConfirmShipmentPropagatesAuthoritativeEmpty会话相关处理。 func TestConfirmShipmentPropagatesAuthoritativeEmptySession(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // initialValue 保存initial值,供当前处理流程使用 initialValue := "unb=123; _m_h5_tk=old_1" + // metadata 保存metadata,供当前处理流程使用 metadata := cookierefresh.MetadataWithSnapshot(`{"preserved":true}`, []cookierefresh.BrowserCookie{ {Name: "unb", Value: "123", Domain: ".goofish.com", Path: "/", Secure: true}, {Name: "_m_h5_tk", Value: "old_1", Domain: ".goofish.com", Path: "/", Secure: true}, }) - if err := store.Cookies.UpdateRenewalCookie(ctx, "cid", initialValue, metadata, 1); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Cookies.UpdateRenewalCookie(ctx, "cid", initialValue, metadata, 1); err != nil { t.Fatal(err) } + // client 保存client,供当前处理流程使用 client := &http.Client{Transport: automationRoundTripperFunc(func(req *http.Request) (*http.Response, error) { return &http.Response{ StatusCode: http.StatusOK, @@ -1032,16 +1327,21 @@ func TestConfirmShipmentPropagatesAuthoritativeEmptySession(t *testing.T) { Request: req, }, nil })} + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetMTop(&mtop.ClientImpl{HTTPClient: client, ConsignURL: mtop.ConsignAPI}) + // err 保存err,供当前处理流程使用 err := center.confirmShipment(ctx, Task{ AccountID: "cid", OrderID: "authoritative-empty-session", ForceConfirmShipment: true, }) + // uncertain 保存uncertain,供当前处理流程使用 var uncertain *uncertainActionError if !errors.As(err, &uncertain) { t.Fatalf("删除凭证后的解析失败应进入人工核对: %v", err) } + // detail、getErr 保存detail、getErr,供当前处理流程使用 detail, getErr := store.Cookies.GetDetails(ctx, "cid") if getErr != nil { t.Fatal(getErr) @@ -1049,6 +1349,7 @@ func TestConfirmShipmentPropagatesAuthoritativeEmptySession(t *testing.T) { if detail.Value != "" { t.Fatalf("权威空 Jar 未持久化: %q", detail.Value) } + // snapshot、ok 保存snapshot、ok,供当前处理流程使用 snapshot, ok := cookierefresh.SnapshotFromMetadataOK(detail.MetadataJSON) if !ok || snapshot == nil || len(snapshot) != 0 { t.Fatalf("权威空 snapshot 语义丢失: ok=%v snapshot=%#v metadata=%s", ok, snapshot, detail.MetadataJSON) @@ -1058,13 +1359,18 @@ func TestConfirmShipmentPropagatesAuthoritativeEmptySession(t *testing.T) { } } +// TestManualFullDeliveryIsImmediateIdempotentAndForcesConfirmation 负责TestManualFull发货IsImmediateIdempotentAndForcesConfirmation相关处理。 func TestManualFullDeliveryIsImmediateIdempotentAndForcesConfirmation(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") _, _ = store.DB.ExecContext(ctx, `UPDATE cookies SET auto_confirm=0 WHERE id='cid'`) _, _ = store.DB.ExecContext(ctx, `INSERT INTO item_info (cookie_id,item_id,item_title) VALUES ('cid','manual-item','会员')`) + // cardID、err 保存卡密ID、err,供当前处理流程使用 cardID, err := store.Cards.Create(ctx, &db.CardFull{ Name: "manual-card", Type: "text", TextContent: "MANUAL-CARD", Enabled: true, DelaySeconds: 86400, UserID: admin.ID, }) @@ -1081,18 +1387,24 @@ func TestManualFullDeliveryIsImmediateIdempotentAndForcesConfirmation(t *testing if err != nil { t.Fatal(err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // mtopMock 保存mtopMock,供当前处理流程使用 mtopMock := &fakeMTop{consignOk: true} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetMTop(mtopMock) center.SetOrderDetailFetcher(testFetcher{detail: &OrderDetail{Quantity: "1", OrderStatus: "pending_ship"}}) + // order 保存订单,供当前处理流程使用 order := &db.Order{OrderID: "manual-order", CookieID: "cid", ItemID: "manual-item", BuyerID: "buyer", ChatID: "chat"} + // sent、err 保存sent、err,供当前处理流程使用 sent, err := center.ManualFullDelivery(ctx, order) if err != nil || sent != 1 || len(sender.texts) != 1 || mtopMock.consignCalls != 1 { t.Fatalf("first manual delivery sent=%d texts=%v consign=%d err=%v", sent, sender.texts, mtopMock.consignCalls, err) } - if _, err := center.ManualFullDelivery(ctx, order); err == nil || !strings.Contains(err.Error(), "执行过") { + if // err 保存err,供当前处理流程使用 + _, err := center.ManualFullDelivery(ctx, order); err == nil || !strings.Contains(err.Error(), "执行过") { t.Fatalf("duplicate manual delivery should be rejected: %v", err) } if len(sender.texts) != 1 || mtopMock.consignCalls != 1 { @@ -1108,6 +1420,7 @@ type recordingNotifier struct { } } +// NotifyDelivery 负责Notify发货相关处理。 func (r *recordingNotifier) NotifyDelivery(accountID, buyerName, buyerID, itemID, message, chatID string) { r.mu.Lock() defer r.mu.Unlock() @@ -1116,10 +1429,13 @@ func (r *recordingNotifier) NotifyDelivery(accountID, buyerName, buyerID, itemID }{accountID, buyerID, itemID, message, chatID}) } +// messages 负责消息列表相关处理。 func (r *recordingNotifier) messages() []string { r.mu.Lock() defer r.mu.Unlock() + // out 保存out,供当前处理流程使用 out := make([]string, len(r.calls)) + // i、c 表示当前遍历过程中的i、c for i, c := range r.calls { out[i] = c.message } @@ -1128,13 +1444,17 @@ func (r *recordingNotifier) messages() []string { // TestCenterNotifiesOnDeliverySuccess 验证规则执行成功(实际发出卡券)时触发成功通知。 func TestCenterNotifiesOnDeliverySuccess(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") _, _ = store.DB.ExecContext(ctx, `INSERT INTO item_info (cookie_id,item_id,item_title,is_multi_spec) VALUES ('cid','item-n','N',1)`) _, _ = store.DB.ExecContext(ctx, `INSERT INTO cards (id,name,type,text_content,enabled,user_id) VALUES (61,'卡','text','CARD',1,?)`, admin.ID) + // err 保存err,供当前处理流程使用 _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", ItemID: "item-n", Name: "通知测试", TriggerType: TriggerOrderPaid, Enabled: true, Priority: 100, @@ -1146,21 +1466,26 @@ func TestCenterNotifiesOnDeliverySuccess(t *testing.T) { t.Fatalf("create rule: %v", err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // notifier 保存notifier,供当前处理流程使用 notifier := &recordingNotifier{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetOrderDetailFetcher(testFetcher{detail: &OrderDetail{ SpecName: "套餐", SpecValue: "标准", Quantity: "1", Amount: "9.9", OrderStatus: "pending_ship", }}) center.SetNotifier(notifier) - if err := center.HandleTask(ctx, Task{ + if // err 保存err,供当前处理流程使用 + err := center.HandleTask(ctx, Task{ Source: "ws", AccountID: "cid", TriggerType: TriggerOrderPaid, ChatID: "chat-n", OrderID: "order-n", ItemID: "item-n", BuyerID: "buyer-n", Raw: map[string]any{"mid": "m"}, }); err != nil { t.Fatalf("HandleTask: %v", err) } + // msgs 保存msgs,供当前处理流程使用 msgs := notifier.messages() if len(msgs) != 1 { t.Fatalf("应发 1 条成功通知,got %d: %v", len(msgs), msgs) @@ -1172,13 +1497,17 @@ func TestCenterNotifiesOnDeliverySuccess(t *testing.T) { // TestCenterNotifiesOnDeliveryFailure 验证无匹配规格动作导致失败时触发失败通知。 func TestCenterNotifiesOnDeliveryFailure(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") _, _ = store.DB.ExecContext(ctx, `INSERT INTO item_info (cookie_id,item_id,item_title,is_multi_spec) VALUES ('cid','item-f','F',1)`) _, _ = store.DB.ExecContext(ctx, `INSERT INTO cards (id,name,type,text_content,enabled,user_id) VALUES (71,'卡','text','CARD',1,?)`, admin.ID) + // err 保存err,供当前处理流程使用 _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", ItemID: "item-f", Name: "失败通知测试", TriggerType: TriggerOrderPaid, Enabled: true, Priority: 100, @@ -1191,8 +1520,11 @@ func TestCenterNotifiesOnDeliveryFailure(t *testing.T) { t.Fatalf("create rule: %v", err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // notifier 保存notifier,供当前处理流程使用 notifier := &recordingNotifier{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) center.SetOrderDetailFetcher(testFetcher{detail: &OrderDetail{ SpecName: "套餐", SpecValue: "90天", Quantity: "1", Amount: "9.9", OrderStatus: "pending_ship", @@ -1205,6 +1537,7 @@ func TestCenterNotifiesOnDeliveryFailure(t *testing.T) { ChatID: "chat-f", OrderID: "order-f", ItemID: "item-f", BuyerID: "buyer-f", Raw: map[string]any{"mid": "m"}, }) + // msgs 保存msgs,供当前处理流程使用 msgs := notifier.messages() if len(msgs) != 1 { t.Fatalf("应发 1 条失败通知,got %d: %v", len(msgs), msgs) @@ -1216,11 +1549,15 @@ func TestCenterNotifiesOnDeliveryFailure(t *testing.T) { // TestCenterNoNotifyWhenNoMatchingRule 验证无匹配规则时不发通知(空跑不刷屏)。 func TestCenterNoNotifyWhenNoMatchingRule(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // notifier 保存notifier,供当前处理流程使用 notifier := &recordingNotifier{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: &testSender{}}, nil) center.SetNotifier(notifier) @@ -1236,12 +1573,17 @@ func TestCenterNoNotifyWhenNoMatchingRule(t *testing.T) { // TestDueReviewRequestOrdersHandlesNullSpecColumns 验证订单 spec_name/spec_value 为 NULL // 时(旧库升级数据常见)DueReviewRequestOrders 不报扫描错误。 +// TestDueReviewRequestOrdersHandlesNullSpecColumns 负责TestDueReview请求订单列表HandlesNullSpecColumns相关处理。 func TestDueReviewRequestOrdersHandlesNullSpecColumns(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", Name: "review", TriggerType: TriggerReviewMissingTimeout, Enabled: true, Actions: []db.AutomationActionInput{{ActionType: ActionSendText, MessageTemplate: "review", Enabled: true}}, }); err != nil { @@ -1255,6 +1597,7 @@ func TestDueReviewRequestOrdersHandlesNullSpecColumns(t *testing.T) { t.Fatal(err) } + // orders、err 保存orders、err,供当前处理流程使用 orders, err := store.Automation.DueReviewRequestOrders(ctx, 200) if err != nil { t.Fatalf("DueReviewRequestOrders 扫描 NULL 列失败: %v", err) @@ -1267,11 +1610,16 @@ func TestDueReviewRequestOrdersHandlesNullSpecColumns(t *testing.T) { } } +// TestReviewRequestCounterFailureMovesCompletedActionToNeedsReview 负责TestReview请求CounterFailureMovesCompleted动作ToNeedsReview相关处理。 func TestReviewRequestCounterFailureMovesCompletedActionToNeedsReview(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", Name: "review-counter", TriggerType: TriggerReviewMissingTimeout, Enabled: true, Actions: []db.AutomationActionInput{{ActionType: ActionSendText, MessageTemplate: "请评价", Enabled: true}}, @@ -1279,20 +1627,25 @@ func TestReviewRequestCounterFailureMovesCompletedActionToNeedsReview(t *testing if err != nil { t.Fatal(err) } - if err := store.Orders.Upsert(ctx, "review-counter-order", db.OrderUpsertOpts{CookieID: "cid", ChatID: "chat", BuyerID: "buyer"}); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.Orders.Upsert(ctx, "review-counter-order", db.OrderUpsertOpts{CookieID: "cid", ChatID: "chat", BuyerID: "buyer"}); err != nil { t.Fatal(err) } - if _, err := store.DB.ExecContext(ctx, `CREATE TRIGGER reject_review_counter + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `CREATE TRIGGER reject_review_counter BEFORE UPDATE OF review_request_count ON orders WHEN NEW.review_request_count>OLD.review_request_count BEGIN SELECT RAISE(FAIL, 'forced review counter failure'); END`); err != nil { t.Fatal(err) } + // rule、err 保存rule、err,供当前处理流程使用 rule, err := store.Automation.Get(ctx, ruleID) if err != nil { t.Fatal(err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) err = center.executeRule(ctx, Task{ Source: "scheduler", AccountID: "cid", TriggerType: TriggerReviewMissingTimeout, @@ -1305,12 +1658,15 @@ func TestReviewRequestCounterFailureMovesCompletedActionToNeedsReview(t *testing if len(sender.texts) != 1 { t.Fatalf("message action should execute exactly once, got %v", sender.texts) } + // order、err 保存order、err,供当前处理流程使用 order, err := store.Orders.Get(ctx, "review-counter-order") if err != nil || order.ReviewRequestCount != 0 { t.Fatalf("counter=%d err=%v", order.ReviewRequestCount, err) } + // status、message 保存status、message,供当前处理流程使用 var status, message string - if err := store.DB.QueryRowContext(ctx, `SELECT status,error_message FROM automation_runs WHERE order_id=?`, "review-counter-order").Scan(&status, &message); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT status,error_message FROM automation_runs WHERE order_id=?`, "review-counter-order").Scan(&status, &message); err != nil { t.Fatal(err) } if status != "needs_review" || !strings.Contains(message, "保存提醒次数失败") { diff --git a/internal/automation/event_pipeline.go b/internal/automation/event_pipeline.go index 22b4c24..5c816fe 100644 --- a/internal/automation/event_pipeline.go +++ b/internal/automation/event_pipeline.go @@ -10,6 +10,7 @@ import ( // eventFactRecorder 只负责把已经解析出的事件事实写入持久化层。 // 它不读取规则、不创建运行记录,也不执行任何外部动作。 +// eventFactRecorder 保存eventFactRecorder,供当前处理流程使用 type eventFactRecorder struct { // store 提供订单事实和事件时间的持久化能力。 store *db.Store @@ -25,7 +26,8 @@ func (r eventFactRecorder) record(ctx context.Context, task Task) error { if r.store == nil || r.store.Orders == nil || r.store.Automation == nil || task.OrderID == "" { return nil } - if err := r.store.Orders.Upsert(ctx, task.OrderID, db.OrderUpsertOpts{ + if // err 保存err,供当前处理流程使用 + err := r.store.Orders.Upsert(ctx, task.OrderID, db.OrderUpsertOpts{ CookieID: task.AccountID, ItemID: task.ItemID, BuyerID: task.BuyerID, @@ -40,11 +42,13 @@ func (r eventFactRecorder) record(ctx context.Context, task Task) error { } switch task.TriggerType { case TriggerOrderPaid: - if err := r.store.Automation.MarkOrderEventTime(ctx, task.OrderID, "paid_at"); err != nil { + if // err 保存err,供当前处理流程使用 + err := r.store.Automation.MarkOrderEventTime(ctx, task.OrderID, "paid_at"); err != nil { return fmt.Errorf("记录订单付款时间: %w", err) } case TriggerBuyerReviewed: - if err := r.store.Automation.MarkOrderEventTime(ctx, task.OrderID, "buyer_reviewed_at"); err != nil { + if // err 保存err,供当前处理流程使用 + err := r.store.Automation.MarkOrderEventTime(ctx, task.OrderID, "buyer_reviewed_at"); err != nil { return fmt.Errorf("记录买家评价时间: %w", err) } } @@ -67,7 +71,9 @@ func (m ruleMatcher) match(ctx context.Context, task Task) ([]db.AutomationRule, if m.store == nil || m.store.Automation == nil { return nil, nil } - if runID := taskAutomationRunID(task); runID > 0 { + if // runID 保存运行ID,供当前处理流程使用 + runID := taskAutomationRunID(task); runID > 0 { + // run、err 保存run、err,供当前处理流程使用 run, err := m.store.Automation.GetRun(ctx, runID) if err != nil { return nil, err @@ -75,6 +81,7 @@ func (m ruleMatcher) match(ctx context.Context, task Task) ([]db.AutomationRule, if run.Status != "running" { return nil, nil } + // rule、err 保存rule、err,供当前处理流程使用 rule, err := m.store.Automation.Get(ctx, run.RuleID) if err != nil { return nil, err @@ -89,17 +96,21 @@ func (m ruleMatcher) match(ctx context.Context, task Task) ([]db.AutomationRule, // actionPlanner 只根据任务事实和规则动作生成不可变的动作计划。 // 计划过程不得访问数据库、发送网络请求或修改规则。 +// actionPlanner 保存动作Planner,供当前处理流程使用 type actionPlanner struct{} // plan 根据触发类型筛选可执行动作,并保留付款事件的发卡优先顺序。 func (actionPlanner) plan(task Task, actions []db.AutomationAction) []db.AutomationAction { + // out 保存out,供当前处理流程使用 out := make([]db.AutomationAction, 0, len(actions)) if task.TriggerType == TriggerOrderPaid { + // action 表示当前遍历过程中的动作 for _, action := range actions { if action.Enabled && action.ActionType == ActionSendCard && actionMatchesOrderSpec(task, action) { out = append(out, action) } } + // action 表示当前遍历过程中的动作 for _, action := range actions { if action.Enabled && action.ActionType == ActionConfirmShipment { out = append(out, action) @@ -107,6 +118,7 @@ func (actionPlanner) plan(task Task, actions []db.AutomationAction) []db.Automat } return out } + // action 表示当前遍历过程中的动作 for _, action := range actions { if action.Enabled { out = append(out, action) @@ -117,6 +129,7 @@ func (actionPlanner) plan(task Task, actions []db.AutomationAction) []db.Automat // hasMatchingSendCard 判断付款事件是否存在匹配当前规格的发卡动作。 func (actionPlanner) hasMatchingSendCard(task Task, actions []db.AutomationAction) bool { + // action 表示当前遍历过程中的动作 for _, action := range actions { if action.Enabled && action.ActionType == ActionSendCard && actionMatchesOrderSpec(task, action) { return true @@ -127,16 +140,20 @@ func (actionPlanner) hasMatchingSendCard(task Task, actions []db.AutomationActio // immediateManualActions 复制动作并清除延迟,供明确的人工完整发货使用。 func (actionPlanner) immediateManualActions(actions []db.AutomationAction) []db.AutomationAction { + // out 保存out,供当前处理流程使用 out := make([]db.AutomationAction, len(actions)) copy(out, actions) + // i 表示当前遍历过程中的i for i := range out { out[i].DelaySeconds = 0 if out[i].ActionType != ActionSendCard { continue } + // config 保存配置,供当前处理流程使用 config := map[string]any{} _ = json.Unmarshal([]byte(out[i].ConfigJSON), &config) config["delay_override"] = true + // raw 保存原始,供当前处理流程使用 raw, _ := json.Marshal(config) out[i].ConfigJSON = string(raw) } diff --git a/internal/automation/event_pipeline_test.go b/internal/automation/event_pipeline_test.go index 2e59238..8a522be 100644 --- a/internal/automation/event_pipeline_test.go +++ b/internal/automation/event_pipeline_test.go @@ -24,7 +24,8 @@ func TestActionPlannerPaidEventKeepsCardBeforeShipment(t *testing.T) { planner := actionPlanner{} // plan 是按发卡优先规则生成的不可变动作快照。 plan := planner.plan(task, actions) - if got := []int64{plan[0].ID, plan[1].ID}; !reflect.DeepEqual(got, []int64{2, 1}) { + if // got 保存got,供当前处理流程使用 + got := []int64{plan[0].ID, plan[1].ID}; !reflect.DeepEqual(got, []int64{2, 1}) { t.Fatalf("付款事件动作顺序=%v,want [2 1]", got) } if !reflect.DeepEqual(actions, original) { @@ -36,7 +37,8 @@ func TestActionPlannerPaidEventKeepsCardBeforeShipment(t *testing.T) { func TestEventFactRecorderWithoutOrderIsNoOp(t *testing.T) { // recorder 未注入数据库时应对无订单任务安全忽略。 recorder := newEventFactRecorder(nil) - if err := recorder.record(context.Background(), Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed}); err != nil { + if // err 保存err,供当前处理流程使用 + err := recorder.record(context.Background(), Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed}); err != nil { t.Fatalf("无订单事实应安全忽略,err=%v", err) } } diff --git a/internal/automation/events.go b/internal/automation/events.go index 99fb015..2e25465 100644 --- a/internal/automation/events.go +++ b/internal/automation/events.go @@ -15,6 +15,7 @@ import ( "xianyu-go/internal/db" ) +// TriggerOrderPaid 保存Trigger订单Paid,供当前处理流程使用 const ( TriggerOrderPaid = "order_paid" TriggerBuyerReviewed = "buyer_reviewed" @@ -52,6 +53,7 @@ type Task struct { // OrderDetail 是自动化中心执行交易类任务前需要补齐的订单事实。 // 规格和数量来自闲鱼订单,不由自动化规则修改商品属性。 +// OrderDetail 保存订单Detail,供当前处理流程使用 type OrderDetail struct { Quantity string SpecName string @@ -62,14 +64,17 @@ type OrderDetail struct { // ExtractTaskFromWS 从一条解密后的 WS 消息中提取系统事件。 // 这里只做事实解析:识别平台告诉了我们什么;是否执行自动化由 Center 根据规则决定。 +// ExtractTaskFromWS 负责Extract任务FromWS相关处理。 func ExtractTaskFromWS(accountID, cookieStr string, raw map[string]any) *Task { if raw == nil { return nil } + // f 保存f,供当前处理流程使用 f := fieldsFromRaw(raw) if f.text == "" && f.redReminder == "" && f.updateKey == "" { return nil } + // task 保存任务,供当前处理流程使用 task := &Task{ Source: "ws", AccountID: accountID, @@ -93,6 +98,7 @@ func ExtractTaskFromWS(accountID, cookieStr string, raw map[string]any) *Task { return task } +// rawFields 保存原始字段列表,供当前处理流程使用 type rawFields struct { text string redReminder string @@ -108,13 +114,18 @@ type rawFields struct { reminderURL string } +// fieldsFromRaw 负责字段列表From原始相关处理。 func fieldsFromRaw(raw map[string]any) rawFields { + // f 保存f,供当前处理流程使用 var f rawFields - if m1 := mapAt(raw, "1"); m1 != nil { - if s := strAny(m1["2"]); s != "" { + if // m1 保存m1,供当前处理流程使用 + m1 := mapAt(raw, "1"); m1 != nil { + if // s 保存s,供当前处理流程使用 + s := strAny(m1["2"]); s != "" { f.chatID = trimGoofishSID(s) } - if m10 := mapAt(m1, "10"); m10 != nil { + if // m10 保存m10,供当前处理流程使用 + m10 := mapAt(m1, "10"); m10 != nil { f.text = strAny(m10["reminderContent"]) f.redReminder = strAny(m10["redReminder"]) f.title = strAny(m10["reminderTitle"]) @@ -124,21 +135,26 @@ func fieldsFromRaw(raw map[string]any) rawFields { f.updateKey, f.contentType = extFields(strAny(m10["extJson"])) f.orderRole = orderRoleFromTaskName(bizTaskName(strAny(m10["bizTag"]))) } - if contentJSON := nestedString(raw, "1", "6", "3", "5"); contentJSON != "" { - if role := extractOrderRoleFromContent(contentJSON); role != "" { + if // contentJSON 保存内容JSON,供当前处理流程使用 + contentJSON := nestedString(raw, "1", "6", "3", "5"); contentJSON != "" { + if // role 保存role,供当前处理流程使用 + role := extractOrderRoleFromContent(contentJSON); role != "" { f.orderRole = role } - if id := extractOrderIDFromContent(contentJSON); id != "" { + if // id 保存标识,供当前处理流程使用 + id := extractOrderIDFromContent(contentJSON); id != "" { f.orderID = id } } } - if m3 := mapAt(raw, "3"); m3 != nil { + if // m3 保存m3,供当前处理流程使用 + m3 := mapAt(raw, "3"); m3 != nil { if f.redReminder == "" { f.redReminder = strAny(m3["redReminder"]) } } - if m4 := mapAt(raw, "4"); m4 != nil { + if // m4 保存m4,供当前处理流程使用 + m4 := mapAt(raw, "4"); m4 != nil { if f.text == "" { f.text = strAny(m4["reminderContent"]) } @@ -159,6 +175,7 @@ func fieldsFromRaw(raw map[string]any) rawFields { } } if f.updateKey != "" { + // chatID、orderID 保存聊天ID、orderID,供当前处理流程使用 chatID, orderID := parseUpdateKey(f.updateKey) if f.chatID == "" { f.chatID = chatID @@ -184,6 +201,7 @@ func fieldsFromRaw(raw map[string]any) rawFields { return f } +// isOrderPaidEvent 负责is订单PaidEvent相关处理。 func isOrderPaidEvent(f rawFields) bool { if f.orderRole == "buyer" { return false @@ -194,6 +212,7 @@ func isOrderPaidEvent(f rawFields) bool { strings.Contains(f.redReminder, "等待卖家发货") } +// isBuyerReviewedEvent 负责is买家ReviewedEvent相关处理。 func isBuyerReviewedEvent(f rawFields) bool { // 闲鱼评价样本: // redReminder=有新交易评价 @@ -205,10 +224,12 @@ func isBuyerReviewedEvent(f rawFields) bool { return strings.Contains(strings.ToUpper(f.updateKey), "BUYER_RATE_SELLER") } +// extFields 负责ext字段列表相关处理。 func extFields(ext string) (updateKey, contentType string) { if strings.TrimSpace(ext) == "" { return "", "" } + // m 保存m,供当前处理流程使用 var m map[string]any if json.Unmarshal([]byte(ext), &m) != nil { return "", "" @@ -216,7 +237,9 @@ func extFields(ext string) (updateKey, contentType string) { return strAny(m["updateKey"]), strAny(m["contentType"]) } +// parseUpdateKey 负责parseUpdateKey相关处理。 func parseUpdateKey(updateKey string) (chatID, orderID string) { + // parts 保存parts,供当前处理流程使用 parts := strings.Split(updateKey, ":") if len(parts) >= 2 { return parts[0], parts[1] @@ -224,10 +247,12 @@ func parseUpdateKey(updateKey string) (chatID, orderID string) { return "", "" } +// queryValue 负责查询值相关处理。 func queryValue(rawURL, key string) string { if strings.HasPrefix(rawURL, "fleamarket://") { rawURL = "https://local.invalid/" + strings.TrimPrefix(rawURL, "fleamarket://") } + // u、err 保存u、err,供当前处理流程使用 u, err := url.Parse(rawURL) if err != nil { return "" @@ -235,14 +260,20 @@ func queryValue(rawURL, key string) string { return u.Query().Get(key) } +// mapAt 负责mapAt相关处理。 func mapAt(m map[string]any, key string) map[string]any { + // v 保存v,供当前处理流程使用 v, _ := m[key].(map[string]any) return v } +// nestedString 负责nestedString相关处理。 func nestedString(m map[string]any, path ...string) string { + // cur 保存cur,供当前处理流程使用 var cur any = m + // p 表示当前遍历过程中的p for _, p := range path { + // cm、ok 保存cm、ok,供当前处理流程使用 cm, ok := cur.(map[string]any) if !ok { return "" @@ -252,19 +283,24 @@ func nestedString(m map[string]any, path ...string) string { return strAny(cur) } +// strAny 负责strAny相关处理。 func strAny(v any) string { - switch x := v.(type) { + switch // x 保存x,供当前处理流程使用 + x := v.(type) { case string: return x case nil: return "" default: + // b 保存b,供当前处理流程使用 b, _ := json.Marshal(x) return string(b) } } +// firstNonEmpty 负责firstNonEmpty相关处理。 func firstNonEmpty(values ...string) string { + // v 表示当前遍历过程中的v for _, v := range values { if strings.TrimSpace(v) != "" { return v @@ -273,13 +309,16 @@ func firstNonEmpty(values ...string) string { return "" } +// trimGoofishSID 负责trimGoofishSID相关处理。 func trimGoofishSID(s string) string { - if i := strings.Index(s, "@"); i >= 0 { + if // i 保存i,供当前处理流程使用 + i := strings.Index(s, "@"); i >= 0 { return s[:i] } return s } +// orderIDPatterns 保存订单IDPatterns,供当前处理流程使用 var orderIDPatterns = []*regexp.Regexp{ regexp.MustCompile(`orderId[=:](\d{10,})`), regexp.MustCompile(`order_detail\?id=(\d{10,})`), @@ -287,23 +326,28 @@ var orderIDPatterns = []*regexp.Regexp{ regexp.MustCompile(`id=(\d{10,})`), } +// extractOrderRoleFromContent 负责extract订单RoleFrom内容相关处理。 func extractOrderRoleFromContent(contentJSON string) string { + // c 保存c,供当前处理流程使用 var c map[string]any if json.Unmarshal([]byte(contentJSON), &c) != nil { return "" } + // path 表示当前遍历过程中的路径 for _, path := range [][]string{ {"dxCard", "item", "main", "exContent", "button", "targetUrl"}, {"dxCard", "item", "main", "targetUrl"}, {"dynamicOperation", "changeContent", "dxCard", "item", "main", "exContent", "button", "targetUrl"}, } { - if role := orderRoleFromURL(nestedString(c, path...)); role != "" { + if // role 保存role,供当前处理流程使用 + role := orderRoleFromURL(nestedString(c, path...)); role != "" { return role } } return "" } +// orderRoleFromURL 负责订单RoleFromURL相关处理。 func orderRoleFromURL(rawURL string) string { if strings.TrimSpace(rawURL) == "" { return "" @@ -311,6 +355,7 @@ func orderRoleFromURL(rawURL string) string { if strings.HasPrefix(rawURL, "fleamarket://") { rawURL = "https://local.invalid/" + strings.TrimPrefix(rawURL, "fleamarket://") } + // u、err 保存u、err,供当前处理流程使用 u, err := url.Parse(rawURL) if err != nil { return "" @@ -323,7 +368,9 @@ func orderRoleFromURL(rawURL string) string { } } +// bizTaskName 负责biz任务名称相关处理。 func bizTaskName(raw string) string { + // tag 保存tag,供当前处理流程使用 var tag map[string]any if json.Unmarshal([]byte(raw), &tag) != nil { return "" @@ -331,6 +378,7 @@ func bizTaskName(raw string) string { return strAny(tag["taskName"]) } +// orderRoleFromTaskName 负责订单RoleFrom任务名称相关处理。 func orderRoleFromTaskName(taskName string) string { switch { case strings.Contains(taskName, "买家"): @@ -342,26 +390,33 @@ func orderRoleFromTaskName(taskName string) string { } } +// matchOrderID 负责match订单ID相关处理。 func matchOrderID(s string) string { + // re 表示当前遍历过程中的re for _, re := range orderIDPatterns { - if m := re.FindStringSubmatch(s); len(m) == 2 { + if // m 保存m,供当前处理流程使用 + m := re.FindStringSubmatch(s); len(m) == 2 { return m[1] } } return "" } +// extractOrderIDFromContent 负责extract订单IDFrom内容相关处理。 func extractOrderIDFromContent(contentJSON string) string { + // c 保存c,供当前处理流程使用 var c map[string]any if json.Unmarshal([]byte(contentJSON), &c) != nil { return "" } + // path 表示当前遍历过程中的路径 for _, path := range [][]string{ {"dxCard", "item", "main", "exContent", "button", "targetUrl"}, {"dxCard", "item", "main", "targetUrl"}, {"dynamicOperation", "changeContent", "dxCard", "item", "main", "exContent", "button", "targetUrl"}, } { - if id := matchOrderID(nestedString(c, path...)); id != "" { + if // id 保存标识,供当前处理流程使用 + id := matchOrderID(nestedString(c, path...)); id != "" { return id } } diff --git a/internal/automation/events_test.go b/internal/automation/events_test.go index 4e916a0..53dc18e 100644 --- a/internal/automation/events_test.go +++ b/internal/automation/events_test.go @@ -5,7 +5,9 @@ import ( "testing" ) +// TestExtractTaskFromWS_BuyerReviewed 负责TestExtract任务FromWS买家Reviewed相关处理。 func TestExtractTaskFromWS_BuyerReviewed(t *testing.T) { + // raw 保存原始,供当前处理流程使用 raw := mustMap(t, `{ "1": { "2": "62904549781@goofish", @@ -19,6 +21,7 @@ func TestExtractTaskFromWS_BuyerReviewed(t *testing.T) { } } }`) + // task 保存任务,供当前处理流程使用 task := ExtractTaskFromWS("acc1", "cookie", raw) if task == nil { t.Fatal("评价卡片应解析为自动化事件") @@ -29,7 +32,9 @@ func TestExtractTaskFromWS_BuyerReviewed(t *testing.T) { } } +// TestExtractTaskFromWS_BuyerReviewedUsesBusinessKeyAcrossCopyVariants 负责TestExtract任务FromWS买家ReviewedUsesBusinessKeyAcrossCopyVariants相关处理。 func TestExtractTaskFromWS_BuyerReviewedUsesBusinessKeyAcrossCopyVariants(t *testing.T) { + // raw 保存原始,供当前处理流程使用 raw := mustMap(t, `{ "1":{"2":"62904549781@goofish","10":{ "reminderContent":"感谢您的再次购买,评价已经完成", @@ -38,13 +43,16 @@ func TestExtractTaskFromWS_BuyerReviewedUsesBusinessKeyAcrossCopyVariants(t *tes "extJson":"{\"updateKey\":\"62904549781:order-second:10:buyer_rate_seller:26\",\"contentType\":\"26\"}" }} }`) + // task 保存任务,供当前处理流程使用 task := ExtractTaskFromWS("acc1", "cookie", raw) if task == nil || task.TriggerType != TriggerBuyerReviewed || task.OrderID != "order-second" { t.Fatalf("second-purchase review task=%+v", task) } } +// TestExtractTaskFromWS_ServiceReviewInvitationIgnored 负责TestExtract任务FromWSServiceReviewInvitationIgnored相关处理。 func TestExtractTaskFromWS_ServiceReviewInvitationIgnored(t *testing.T) { + // raw 保存原始,供当前处理流程使用 raw := mustMap(t, `{ "1": { "2": "62854995941@goofish", @@ -56,12 +64,15 @@ func TestExtractTaskFromWS_ServiceReviewInvitationIgnored(t *testing.T) { } } }`) - if task := ExtractTaskFromWS("acc1", "cookie", raw); task != nil { + if // task 保存任务,供当前处理流程使用 + task := ExtractTaskFromWS("acc1", "cookie", raw); task != nil { t.Fatalf("服务评价邀请不能触发买家评价赠品: %+v", task) } } +// TestExtractTaskFromWS_OrderPaid 负责TestExtract任务FromWS订单Paid相关处理。 func TestExtractTaskFromWS_OrderPaid(t *testing.T) { + // raw 保存原始,供当前处理流程使用 raw := mustMap(t, `{ "1": { "2": "63107041124@goofish", @@ -74,13 +85,16 @@ func TestExtractTaskFromWS_OrderPaid(t *testing.T) { "6": {"3": {"5": "{\"dxCard\":{\"item\":{\"main\":{\"targetUrl\":\"fleamarket://order_detail?id=3310145690545023994&role=seller\"}}}}"}} } }`) + // task 保存任务,供当前处理流程使用 task := ExtractTaskFromWS("acc1", "cookie", raw) if task == nil || task.TriggerType != TriggerOrderPaid || task.OrderID != "3310145690545023994" { t.Fatalf("task=%+v", task) } } +// TestExtractTaskFromWS_BuyerOrderPaidIgnored 负责TestExtract任务FromWS买家订单PaidIgnored相关处理。 func TestExtractTaskFromWS_BuyerOrderPaidIgnored(t *testing.T) { + // raw 保存原始,供当前处理流程使用 raw := mustMap(t, `{ "1": { "2": "63107041124@goofish", @@ -93,12 +107,15 @@ func TestExtractTaskFromWS_BuyerOrderPaidIgnored(t *testing.T) { "6": {"3": {"5": "{\"dxCard\":{\"item\":{\"main\":{\"targetUrl\":\"fleamarket://order_detail?id=3310145690545023994&role=buyer\"}}}}"}} } }`) - if task := ExtractTaskFromWS("acc1", "cookie", raw); task != nil { + if // task 保存任务,供当前处理流程使用 + task := ExtractTaskFromWS("acc1", "cookie", raw); task != nil { t.Fatalf("买家订单不应进入卖家自动化和订单管理: %+v", task) } } +// TestExtractTaskFromWS_BuyerOrderPaidTaskNameIgnored 负责TestExtract任务FromWS买家订单Paid任务名称Ignored相关处理。 func TestExtractTaskFromWS_BuyerOrderPaidTaskNameIgnored(t *testing.T) { + // raw 保存原始,供当前处理流程使用 raw := mustMap(t, `{ "1": {"2": "63107041124@goofish", "10": { "bizTag": "{\"taskName\":\"付款完成待发货_买家\"}", @@ -106,15 +123,19 @@ func TestExtractTaskFromWS_BuyerOrderPaidTaskNameIgnored(t *testing.T) { "reminderContent": "[我已付款,等待你发货]" }} }`) - if task := ExtractTaskFromWS("acc1", "cookie", raw); task != nil { + if // task 保存任务,供当前处理流程使用 + task := ExtractTaskFromWS("acc1", "cookie", raw); task != nil { t.Fatalf("买家侧 taskName 不应进入卖家自动化和订单管理: %+v", task) } } +// mustMap 负责mustMap相关处理。 func mustMap(t *testing.T, s string) map[string]any { t.Helper() + // m 保存m,供当前处理流程使用 var m map[string]any - if err := json.Unmarshal([]byte(s), &m); err != nil { + if // err 保存err,供当前处理流程使用 + err := json.Unmarshal([]byte(s), &m); err != nil { t.Fatal(err) } return m diff --git a/internal/automation/run_coordinator.go b/internal/automation/run_coordinator.go index 9e8a1af..90b5ae8 100644 --- a/internal/automation/run_coordinator.go +++ b/internal/automation/run_coordinator.go @@ -161,6 +161,7 @@ func (r automationRunCoordinator) executeRule(ctx context.Context, task Task, ru if task.TriggerType == TriggerReviewMissingTimeout && task.OrderID != "" { // incrementErr 保存求评价消息成功后的提醒次数。 if incrementErr := r.store.Automation.IncrementReviewRequest(ctx, task.OrderID); incrementErr != nil { + // reason 保存原因,供当前处理流程使用 reason := "求评价消息已发送,但保存提醒次数失败,已停止自动重放: " + incrementErr.Error() // quarantineErr 保存提醒次数写入失败的人工核对状态。 if quarantineErr := r.store.Automation.QuarantineRunResult(ctx, run.ID, run.AttemptCount, sent, reason); quarantineErr != nil { @@ -201,6 +202,7 @@ func (r automationRunCoordinator) executeRunActions(ctx context.Context, task Ta task.Raw["automation_delay_cursor"] = cursor // dueAt 是动作重新进入可执行状态的时间点。 // dueAt 是动作重新进入可执行状态的时间点。 + // dueAt 保存dueAt,供当前处理流程使用 dueAt := time.Now().UTC().Add(time.Duration(delaySeconds) * time.Second) // leaseErr 保存延期运行续租失败的原因。 if leaseErr := r.store.Automation.RenewRunLease(ctx, run.ID, run.AttemptCount, dueAt.Add(5*time.Minute).Unix()); leaseErr != nil { @@ -238,6 +240,7 @@ func (r automationRunCoordinator) executeRunActions(ctx context.Context, task Ta } // abortErr 清理明确未执行动作的占用检查点。 if abortErr := r.store.Automation.AbortRunAction(ctx, run.ID, run.AttemptCount, cursor); abortErr != nil { + // reason 保存原因,供当前处理流程使用 reason := "外部动作明确未执行,但清除动作占用状态失败,已停止自动重放: " + abortErr.Error() // quarantineErr 保存动作检查点无法清理时的隔离结果。 if quarantineErr := r.store.Automation.QuarantineRun(ctx, run.ID, run.AttemptCount, reason); quarantineErr != nil { @@ -247,7 +250,8 @@ func (r automationRunCoordinator) executeRunActions(ctx context.Context, task Ta } return sent, false, actionErr } - if err := r.store.Automation.AdvanceRunAction(ctx, run.ID, run.AttemptCount, cursor, n); err != nil { + if // err 保存err,供当前处理流程使用 + err := r.store.Automation.AdvanceRunAction(ctx, run.ID, run.AttemptCount, cursor, n); err != nil { // quarantineErr 保存检查点失败后的人工核对状态。 if quarantineErr := r.store.Automation.QuarantineRun(ctx, run.ID, run.AttemptCount, "动作已执行但检查点保存失败,请人工核对,禁止自动重放: "+err.Error()); quarantineErr != nil { r.logger.Error("保存检查点异常的人工核对状态失败", "run_id", run.ID, "err", quarantineErr) diff --git a/internal/automation/scheduler.go b/internal/automation/scheduler.go index fa46756..0b8fb29 100644 --- a/internal/automation/scheduler.go +++ b/internal/automation/scheduler.go @@ -12,10 +12,12 @@ import ( "xianyu-go/internal/db" ) +// defaultReviewRequestScanInterval 保存defaultReview请求ScanInterval,供当前处理流程使用 const defaultReviewRequestScanInterval = time.Minute // Scheduler 执行计划任务类自动化。 // 计划任务只负责“发现应该触发的任务”,具体动作仍交给 Center,避免形成第二套执行链。 +// Scheduler 保存Scheduler,供当前处理流程使用 type Scheduler struct { center *Center interval time.Duration @@ -38,6 +40,7 @@ func (s *Scheduler) Run(ctx context.Context) { if ctx.Err() != nil { return } + // ticker 保存ticker,供当前处理流程使用 ticker := time.NewTicker(s.interval) defer ticker.Stop() s.scan(ctx) @@ -52,16 +55,19 @@ func (s *Scheduler) Run(ctx context.Context) { }) } +// Wait 负责Wait相关处理。 func (s *Scheduler) Wait() { if s != nil && s.done != nil { <-s.done } } +// scan 负责scan相关处理。 func (s *Scheduler) scan(ctx context.Context) { s.runDeferredTasks(ctx) s.center.scanAccountTasks(ctx) - if recovered, err := s.center.store.Automation.RecoverDefinitelyUnsentReviewRuns(ctx); err != nil { + if // recovered、err 保存recovered、err,供当前处理流程使用 + recovered, err := s.center.store.Automation.RecoverDefinitelyUnsentReviewRuns(ctx); err != nil { s.center.logger.Warn("恢复历史求评价未发送任务失败", "err", err) } else if recovered > 0 { s.center.logger.Info("已恢复历史求评价未发送任务,等待安全重试", "count", recovered) @@ -69,14 +75,18 @@ func (s *Scheduler) scan(ctx context.Context) { s.runRecoveryTasks(ctx) // 逐页执行,避免把所有到期订单一次性装入内存。稳定 ID 游标确保本轮有界。 afterOrderID := "" + // waitingForWS 保存waitingForWS,供当前处理流程使用 waitingForWS := map[string]int{} for { + // orders、err 保存orders、err,供当前处理流程使用 orders, err := s.center.store.Automation.DueReviewRequestOrdersAfter(ctx, afterOrderID, 200) if err != nil { s.center.logger.Warn("扫描求评价计划任务失败", "err", err) return } + // order 表示当前遍历过程中的订单 for _, order := range orders { + // allowed、allowErr 保存allowed、allowErr,供当前处理流程使用 allowed, allowErr := s.center.accountAutomationAllowed(ctx, order.CookieID) if allowErr != nil { s.center.logger.Warn("检查求评价账号状态失败", "account", order.CookieID, "err", allowErr) @@ -89,6 +99,7 @@ func (s *Scheduler) scan(ctx context.Context) { waitingForWS[order.CookieID]++ continue } + // rules、err 保存rules、err,供当前处理流程使用 rules, err := s.center.rules.match(ctx, Task{AccountID: order.CookieID, ItemID: order.ItemID, TriggerType: TriggerReviewMissingTimeout}) if err != nil { s.center.logger.Warn("查询求评价自动化规则失败", "account", order.CookieID, "order_id", order.OrderID, "item_id", order.ItemID, "err", err) @@ -97,15 +108,18 @@ func (s *Scheduler) scan(ctx context.Context) { if len(rules) == 0 { continue } + // rule 表示当前遍历过程中的规则 for _, rule := range rules { if !reviewRequestRuleDue(order, rule) { continue } + // task 保存任务,供当前处理流程使用 task := Task{Source: "scheduler", AccountID: order.CookieID, TriggerType: TriggerReviewMissingTimeout, ChatID: order.ChatID, OrderID: order.OrderID, ItemID: order.ItemID, BuyerID: order.BuyerID, Text: "发货后一段时间未评价", Raw: map[string]any{"source": "scheduler", "rule_id": rule.ID, "order_id": order.OrderID, "attempt": order.ReviewRequestCount + 1}} - if err := s.center.executeRule(ctx, task, rule); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.center.executeRule(ctx, task, rule); err != nil { s.center.logger.Warn("求评价计划任务执行失败", "account", order.CookieID, "order_id", order.OrderID, "rule_id", rule.ID, "err", err) } } @@ -115,38 +129,49 @@ func (s *Scheduler) scan(ctx context.Context) { } afterOrderID = orders[len(orders)-1].OrderID } + // accountID、count 表示当前遍历过程中的账号ID、count for accountID, count := range waitingForWS { s.center.logger.Info("账号 WebSocket 尚未就绪,求评价任务等待下次扫描", "account", accountID, "orders", count) } } +// runRecoveryTasks 负责运行Recovery任务列表相关处理。 func (s *Scheduler) runRecoveryTasks(ctx context.Context) { + // runs、err 保存runs、err,供当前处理流程使用 runs, err := s.center.store.Automation.DueRecoveryRuns(ctx, 100) if err != nil { s.center.logger.Warn("扫描失败自动化运行失败", "err", err) return } + // run 表示当前遍历过程中的运行 for _, run := range runs { if run.ActionStarted { + // reason 保存原因,供当前处理流程使用 reason := "进程在外部动作执行期间中断,发送结果未知,已禁止自动重放" _ = s.center.store.Automation.QuarantineRun(ctx, run.ID, run.AttemptCount, reason) s.center.notifyRunNeedsReview(run, reason) continue } + // task 保存任务,供当前处理流程使用 var task Task - if err := json.Unmarshal([]byte(run.RawEventJSON), &task); err != nil || task.AccountID == "" { + if // err 保存err,供当前处理流程使用 + err := json.Unmarshal([]byte(run.RawEventJSON), &task); err != nil || task.AccountID == "" { + // reason 保存原因,供当前处理流程使用 reason := "历史运行数据无法安全解析,已移入人工检查" _ = s.center.store.Automation.QuarantineRun(ctx, run.ID, run.AttemptCount, reason) s.center.notifyRunNeedsReview(run, reason) continue } + // allowed、err 保存allowed、err,供当前处理流程使用 allowed, err := s.center.accountAutomationAllowed(ctx, task.AccountID) if err != nil || !allowed { - if postponeErr := s.center.store.Automation.PostponeRecoveryRun(ctx, run.ID, run.AttemptCount, time.Now().UTC().Add(10*time.Minute).Unix()); postponeErr != nil { + if // postponeErr 保存postponeErr,供当前处理流程使用 + postponeErr := s.center.store.Automation.PostponeRecoveryRun(ctx, run.ID, run.AttemptCount, time.Now().UTC().Add(10*time.Minute).Unix()); postponeErr != nil { s.center.logger.Warn("延期自动化恢复任务失败", "run_id", run.ID, "err", postponeErr) } continue } + // rule、err 保存rule、err,供当前处理流程使用 rule, err := s.center.store.Automation.Get(ctx, run.RuleID) if err != nil && !errors.Is(err, db.ErrNotFound) { if ctx.Err() != nil { @@ -156,17 +181,20 @@ func (s *Scheduler) runRecoveryTasks(ctx context.Context) { continue } if errors.Is(err, db.ErrNotFound) || rule == nil || !rule.Enabled { + // reason 保存原因,供当前处理流程使用 reason := "自动化规则不存在或已停用,无法恢复" _ = s.center.store.Automation.QuarantineRun(ctx, run.ID, run.AttemptCount, reason) s.center.notifyRunNeedsReview(run, reason) continue } if recoveryNeedsSender(task, *rule, run.ActionCursor) && !s.center.accountSenderReady(task.AccountID) { - if postponeErr := s.center.store.Automation.PostponeRecoveryRun(ctx, run.ID, run.AttemptCount, time.Now().UTC().Add(defaultReviewRequestScanInterval).Unix()); postponeErr != nil { + if // postponeErr 保存postponeErr,供当前处理流程使用 + postponeErr := s.center.store.Automation.PostponeRecoveryRun(ctx, run.ID, run.AttemptCount, time.Now().UTC().Add(defaultReviewRequestScanInterval).Unix()); postponeErr != nil { s.center.logger.Warn("等待 WebSocket 时延期自动化任务失败", "run_id", run.ID, "err", postponeErr) } continue } + // claimed、claimErr 保存claimed、claimErr,供当前处理流程使用 claimed, claimErr := s.center.store.Automation.ClaimRecoveryRun(ctx, run.ID, time.Now().UTC().Add(5*time.Minute).Unix()) if claimErr != nil || !claimed { continue @@ -176,13 +204,16 @@ func (s *Scheduler) runRecoveryTasks(ctx context.Context) { } task.Raw["automation_run_id"] = run.ID task.Raw["automation_rule_id"] = run.RuleID - if err := s.center.executeRule(ctx, task, *rule); err != nil && !errors.Is(err, errAutomationDeferred) { + if // err 保存err,供当前处理流程使用 + err := s.center.executeRule(ctx, task, *rule); err != nil && !errors.Is(err, errAutomationDeferred) { s.center.logger.Warn("重试自动化运行失败", "run_id", run.ID, "err", err) } } } +// recoveryNeedsSender 负责recoveryNeedsSender相关处理。 func recoveryNeedsSender(task Task, rule db.AutomationRule, cursor int) bool { + // actions 保存动作列表,供当前处理流程使用 actions := task.ActionPlan if len(actions) == 0 { actions = (actionPlanner{}).plan(task, rule.Actions) @@ -198,15 +229,20 @@ func recoveryNeedsSender(task Task, rule db.AutomationRule, cursor int) bool { } } +// runDeferredTasks 负责运行Deferred任务列表相关处理。 func (s *Scheduler) runDeferredTasks(ctx context.Context) { + // tasks、err 保存tasks、err,供当前处理流程使用 tasks, err := s.center.store.Automation.ClaimDueDeferredTasks(ctx, 100) if err != nil { s.center.logger.Warn("扫描暂停期间自动化事件失败", "err", err) return } + // pending 表示当前遍历过程中的pending for _, pending := range tasks { + // task 保存任务,供当前处理流程使用 var task Task - if err := json.Unmarshal([]byte(pending.TaskJSON), &task); err != nil { + if // err 保存err,供当前处理流程使用 + err := json.Unmarshal([]byte(pending.TaskJSON), &task); err != nil { _ = s.center.store.Automation.FinishDeferredTask(ctx, pending.ID, pending.ClaimVersion, false, "解析任务失败: "+err.Error()) continue } @@ -214,17 +250,20 @@ func (s *Scheduler) runDeferredTasks(ctx context.Context) { task.Raw = map[string]any{} } task.Raw["automation_deferred_replay"] = true + // deferredAgain、runErr 保存deferredAgain、runErr,供当前处理流程使用 deferredAgain, runErr := s.center.handleTask(ctx, task) if deferredAgain { // handleTask 已按新的 paused_until 重置同一任务;当前 claim 不再删除。 continue } - if err := s.center.store.Automation.FinishDeferredTask(ctx, pending.ID, pending.ClaimVersion, runErr == nil, errorString(runErr)); err != nil { + if // err 保存err,供当前处理流程使用 + err := s.center.store.Automation.FinishDeferredTask(ctx, pending.ID, pending.ClaimVersion, runErr == nil, errorString(runErr)); err != nil { s.center.logger.Warn("保存暂停事件重放结果失败", "task_id", pending.ID, "err", err) } } } +// errorString 负责错误String相关处理。 func errorString(err error) string { if err == nil { return "" @@ -232,17 +271,22 @@ func errorString(err error) string { return err.Error() } +// reviewRequestRuleDue 负责review请求规则Due相关处理。 func reviewRequestRuleDue(order db.Order, rule db.AutomationRule) bool { + // cfg 保存cfg,供当前处理流程使用 cfg := parseReviewRuleConfig(rule.ConfigJSON) if cfg.MaxAttempts > 0 && order.ReviewRequestCount >= cfg.MaxAttempts { return false } + // baseRaw 保存base原始,供当前处理流程使用 baseRaw := firstNonEmpty(order.ShippedAt, order.UpdatedAt, order.CreatedAt) + // waitHours 保存waitHours,供当前处理流程使用 waitHours := cfg.AfterShippedHours if order.ReviewRequestCount > 0 && strings.TrimSpace(order.LastReviewRequestAt) != "" { baseRaw = order.LastReviewRequestAt waitHours = cfg.RepeatIntervalHours } + // base 保存base,供当前处理流程使用 base := parseDBTime(baseRaw) if base.IsZero() { return false @@ -250,43 +294,54 @@ func reviewRequestRuleDue(order db.Order, rule db.AutomationRule) bool { return time.Since(base) >= time.Duration(waitHours)*time.Hour } +// reviewRuleConfig 保存review规则配置,供当前处理流程使用 type reviewRuleConfig struct { AfterShippedHours int RepeatIntervalHours int MaxAttempts int } +// parseReviewRuleConfig 负责parseReview规则配置相关处理。 func parseReviewRuleConfig(raw string) reviewRuleConfig { + // cfg 保存cfg,供当前处理流程使用 cfg := reviewRuleConfig{AfterShippedHours: 72, RepeatIntervalHours: 24, MaxAttempts: 1} if strings.TrimSpace(raw) == "" { return cfg } + // m 保存m,供当前处理流程使用 var m map[string]any if json.Unmarshal([]byte(raw), &m) != nil { return cfg } - if v := intFromAny(m["after_shipped_hours"]); v > 0 { + if // v 保存v,供当前处理流程使用 + v := intFromAny(m["after_shipped_hours"]); v > 0 { cfg.AfterShippedHours = v } - if v := intFromAny(m["first_delay_hours"]); v > 0 { + if // v 保存v,供当前处理流程使用 + v := intFromAny(m["first_delay_hours"]); v > 0 { cfg.AfterShippedHours = v } - if v := intFromAny(m["repeat_interval_hours"]); v > 0 { + if // v 保存v,供当前处理流程使用 + v := intFromAny(m["repeat_interval_hours"]); v > 0 { cfg.RepeatIntervalHours = v } - if v := intFromAny(m["max_attempts"]); v > 0 { + if // v 保存v,供当前处理流程使用 + v := intFromAny(m["max_attempts"]); v > 0 { cfg.MaxAttempts = v } return cfg } +// intFromAny 负责intFromAny相关处理。 func intFromAny(v any) int { - switch x := v.(type) { + switch // x 保存x,供当前处理流程使用 + x := v.(type) { case float64: return int(x) case int: return x case string: + // n 保存n,供当前处理流程使用 n, _ := strconv.Atoi(strings.TrimSpace(x)) return n default: @@ -294,7 +349,9 @@ func intFromAny(v any) int { } } +// parseDBTime 负责parseDB时间相关处理。 func parseDBTime(s string) time.Time { + // layout 表示当前遍历过程中的layout for _, layout := range []string{ time.RFC3339Nano, "2006-01-02 15:04:05.999999999Z07:00", // Postgres TEXT(CURRENT_TIMESTAMP) @@ -303,7 +360,8 @@ func parseDBTime(s string) time.Time { "2006-01-02 15:04:05Z07", "2006-01-02 15:04:05", // SQLite/MySQL 历史值;按既有 UTC 约定解释 } { - if t, err := time.ParseInLocation(layout, strings.TrimSpace(s), time.UTC); err == nil { + if // t、err 保存t、err,供当前处理流程使用 + t, err := time.ParseInLocation(layout, strings.TrimSpace(s), time.UTC); err == nil { return t } } diff --git a/internal/automation/scheduler_test.go b/internal/automation/scheduler_test.go index dacce20..dc545ad 100644 --- a/internal/automation/scheduler_test.go +++ b/internal/automation/scheduler_test.go @@ -10,15 +10,19 @@ import ( "xianyu-go/internal/db" ) +// readinessTestSender 保存readinessTestSender,供当前处理流程使用 type readinessTestSender struct { *testSender ready bool } +// AutomationReady 负责自动化Ready相关处理。 func (s *readinessTestSender) AutomationReady() bool { return s.ready } +// readinessTestProvider 保存readinessTestProvider,供当前处理流程使用 type readinessTestProvider struct{ sender MessageSender } +// Sender 负责Sender相关处理。 func (p readinessTestProvider) Sender(string) (MessageSender, bool) { return p.sender, true } // TestParseReviewRuleConfig 默认值 + JSON 覆盖 + 非法输入兜底。 @@ -47,6 +51,7 @@ func TestParseReviewRuleConfig(t *testing.T) { // TestIntFromAny float64/int/string 三类来源 + 无效类型返回 0。 func TestIntFromAny(t *testing.T) { + // cases 保存cases,供当前处理流程使用 cases := []struct { in any want int @@ -59,8 +64,10 @@ func TestIntFromAny(t *testing.T) { {nil, 0}, {true, 0}, } + // c 表示当前遍历过程中的c for _, c := range cases { - if got := intFromAny(c.in); got != c.want { + if // got 保存got,供当前处理流程使用 + got := intFromAny(c.in); got != c.want { t.Errorf("intFromAny(%v)=%d want %d", c.in, got, c.want) } } @@ -68,22 +75,27 @@ func TestIntFromAny(t *testing.T) { // TestParseDBTime 支持的三种格式 + 无效返回零值。 func TestParseDBTime(t *testing.T) { - if t1 := parseDBTime("2026-01-02 15:04:05"); t1.IsZero() { + if // t1 保存t1,供当前处理流程使用 + t1 := parseDBTime("2026-01-02 15:04:05"); t1.IsZero() { t.Error("datetime 格式应解析成功") } - if t1 := parseDBTime("2026-01-02T15:04:05Z"); t1.IsZero() { + if // t1 保存t1,供当前处理流程使用 + t1 := parseDBTime("2026-01-02T15:04:05Z"); t1.IsZero() { t.Error("RFC3339 格式应解析成功") } - if t1 := parseDBTime(""); !t1.IsZero() { + if // t1 保存t1,供当前处理流程使用 + t1 := parseDBTime(""); !t1.IsZero() { t.Error("空串应返回零值") } - if t1 := parseDBTime("not a time"); !t1.IsZero() { + if // t1 保存t1,供当前处理流程使用 + t1 := parseDBTime("not a time"); !t1.IsZero() { t.Error("非法串应返回零值") } } // TestReviewRequestRuleDue 综合判定:达到时长且未超次数 → due;否则不 due。 func TestReviewRequestRuleDue(t *testing.T) { + // rule 保存规则,供当前处理流程使用 rule := db.AutomationRule{ConfigJSON: `{"after_shipped_hours":1,"max_attempts":2}`} // 已发货 2 小时、未请求过 → due。 @@ -126,8 +138,11 @@ func TestReviewRequestRuleDue(t *testing.T) { } } +// TestReviewRequestRuleDueUsesRepeatIntervalAfterFirstAttempt 负责TestReview请求规则DueUsesRepeatIntervalAfterFirst尝试次数相关处理。 func TestReviewRequestRuleDueUsesRepeatIntervalAfterFirstAttempt(t *testing.T) { + // rule 保存规则,供当前处理流程使用 rule := db.AutomationRule{ConfigJSON: `{"first_delay_hours":1,"repeat_interval_hours":24,"max_attempts":3}`} + // order 保存订单,供当前处理流程使用 order := db.Order{ OrderID: "repeat-review", SystemShipped: true, @@ -144,11 +159,14 @@ func TestReviewRequestRuleDueUsesRepeatIntervalAfterFirstAttempt(t *testing.T) { } } +// TestParseDBTimeAcceptsPostgresTimestampText 负责TestParseDB时间AcceptsPostgresTimestamp文本相关处理。 func TestParseDBTimeAcceptsPostgresTimestampText(t *testing.T) { + // got 保存got,供当前处理流程使用 got := parseDBTime("2026-07-27 03:36:29.123456+00") if got.IsZero() { t.Fatal("Postgres CURRENT_TIMESTAMP 文本不应解析为零值") } + // want 保存want,供当前处理流程使用 want := time.Date(2026, 7, 27, 3, 36, 29, 123456000, time.UTC) if !got.Equal(want) { t.Fatalf("parseDBTime=%s want %s", got, want) @@ -157,13 +175,16 @@ func TestParseDBTimeAcceptsPostgresTimestampText(t *testing.T) { // TestFirstNonEmpty 返回首个非空串。 func TestFirstNonEmpty(t *testing.T) { - if got := firstNonEmpty("", "", "x", "y"); got != "x" { + if // got 保存got,供当前处理流程使用 + got := firstNonEmpty("", "", "x", "y"); got != "x" { t.Errorf("firstNonEmpty=%q want x", got) } - if got := firstNonEmpty(); got != "" { + if // got 保存got,供当前处理流程使用 + got := firstNonEmpty(); got != "" { t.Errorf("无参应返回空,got %q", got) } - if got := firstNonEmpty("a"); got != "a" { + if // got 保存got,供当前处理流程使用 + got := firstNonEmpty("a"); got != "a" { t.Errorf("单参=%q want a", got) } } @@ -171,15 +192,20 @@ func TestFirstNonEmpty(t *testing.T) { // TestSchedulerScanExecutesDueThenSkipsOnMaxAttempts 端到端验证调度扫描: // 首次扫描命中到期订单 → 执行规则 → 发送文本 + 计数 +1; // 二次扫描因达到 max_attempts 跳过,不再发送。 +// TestSchedulerScanExecutesDueThenSkipsOnMaxAttempts 负责TestSchedulerScanExecutesDueThenSkipsOnMax尝试次数相关处理。 func TestSchedulerScanExecutesDueThenSkipsOnMaxAttempts(t *testing.T) { + // database、err 保存database、err,供当前处理流程使用 database, _, err := db.Open(context.Background(), filepath.Join(t.TempDir(), "sched.db")) if err != nil { t.Fatalf("Open: %v", err) } defer database.Close() + // store 保存store,供当前处理流程使用 store := db.NewStore(database, db.DialectSQLite) + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() store.Users.Create(ctx, "admin", "a@e.com", "pw") + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") store.Cookies.Save(ctx, "cid", "unb=1; _m_h5_tk=tk;", admin.ID) @@ -205,14 +231,18 @@ func TestSchedulerScanExecutesDueThenSkipsOnMaxAttempts(t *testing.T) { // 已发货、未评价、有 chat_id 的订单。 shipped := time.Now().UTC().Add(-2 * time.Hour).Format("2006-01-02 15:04:05") - if _, err := store.DB.ExecContext(ctx, `INSERT INTO orders + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `INSERT INTO orders (order_id, cookie_id, item_id, buyer_id, chat_id, system_shipped, shipped_at, review_request_count) VALUES ('o-sched', 'cid', 'item-1', 'buyer-1', 'chat-1', 1, ?, 0)`, shipped); err != nil { t.Fatalf("insert order: %v", err) } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} + // center 保存center,供当前处理流程使用 center := New(store, testSenderProvider{sender: sender}, nil) + // sched 保存sched,供当前处理流程使用 sched := NewScheduler(center) // 缩短间隔不影响单次 scan 调用,但避免 Run 阻塞。 _ = sched @@ -236,11 +266,16 @@ func TestSchedulerScanExecutesDueThenSkipsOnMaxAttempts(t *testing.T) { } } +// TestSchedulerWaitsForWebSocketBeforeCreatingRun 负责TestSchedulerWaitsForWebSocketBeforeCreating运行相关处理。 func TestSchedulerWaitsForWebSocketBeforeCreatingRun(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") + // ruleID、err 保存规则ID、err,供当前处理流程使用 ruleID, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", ItemID: "item-ready", Name: "wait-ws", TriggerType: TriggerReviewMissingTimeout, Enabled: true, @@ -250,17 +285,23 @@ func TestSchedulerWaitsForWebSocketBeforeCreatingRun(t *testing.T) { if err != nil { t.Fatal(err) } + // shipped 保存shipped,供当前处理流程使用 shipped := time.Now().UTC().Add(-2 * time.Hour).Format(time.RFC3339Nano) - if _, err := store.DB.ExecContext(ctx, `INSERT INTO orders + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `INSERT INTO orders (order_id,cookie_id,item_id,buyer_id,chat_id,system_shipped,shipped_at) VALUES ('wait-ws-order','cid','item-ready','buyer','chat',1,?)`, shipped); err != nil { t.Fatal(err) } + // sender 保存sender,供当前处理流程使用 sender := &readinessTestSender{testSender: &testSender{}, ready: false} + // scheduler 保存scheduler,供当前处理流程使用 scheduler := NewScheduler(New(store, readinessTestProvider{sender: sender}, nil)) scheduler.scan(ctx) + // count 保存数量,供当前处理流程使用 var count int - if err := store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM automation_runs WHERE rule_id=?`, ruleID).Scan(&count); err != nil { + if // err 保存err,供当前处理流程使用 + err := store.DB.QueryRowContext(ctx, `SELECT COUNT(*) FROM automation_runs WHERE rule_id=?`, ruleID).Scan(&count); err != nil { t.Fatal(err) } if count != 0 { @@ -273,26 +314,35 @@ func TestSchedulerWaitsForWebSocketBeforeCreatingRun(t *testing.T) { } } +// TestSchedulerScansMoreThanOneReviewPage 负责TestSchedulerScansMoreThanOneReview页码相关处理。 func TestSchedulerScansMoreThanOneReviewPage(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // ctx 保存ctx,供当前处理流程使用 ctx := context.Background() + // admin 保存admin,供当前处理流程使用 admin, _ := store.Users.GetByUsername(ctx, "admin") - if _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ + if // err 保存err,供当前处理流程使用 + _, err := store.Automation.Create(ctx, db.AutomationRuleInput{ UserID: admin.ID, CookieID: "cid", Name: "review-all", TriggerType: TriggerReviewMissingTimeout, Enabled: true, ConfigJSON: `{"after_shipped_hours":1,"max_attempts":1}`, Actions: []db.AutomationActionInput{{ActionType: ActionSendText, MessageTemplate: "review", Enabled: true}}, }); err != nil { t.Fatal(err) } + // shipped 保存shipped,供当前处理流程使用 shipped := time.Now().UTC().Add(-2 * time.Hour).Format("2006-01-02 15:04:05") - for i := 0; i < 205; i++ { - if _, err := store.DB.ExecContext(ctx, `INSERT INTO orders + for // i 保存i,供当前处理流程使用 + i := 0; i < 205; i++ { + if // err 保存err,供当前处理流程使用 + _, err := store.DB.ExecContext(ctx, `INSERT INTO orders (order_id,cookie_id,buyer_id,chat_id,system_shipped,shipped_at,review_request_count,updated_at) VALUES (?,?,?,?,1,?,0,?)`, fmt.Sprintf("review-%03d", i), "cid", "buyer", fmt.Sprintf("chat-%03d", i), shipped, shipped); err != nil { t.Fatal(err) } } + // sender 保存sender,供当前处理流程使用 sender := &testSender{} NewScheduler(New(store, testSenderProvider{sender: sender}, nil)).scan(ctx) if len(sender.texts) != 205 { @@ -300,11 +350,14 @@ func TestSchedulerScansMoreThanOneReviewPage(t *testing.T) { } } +// TestRecoveryNeedsSenderUsesNextActionType 负责TestRecoveryNeedsSenderUsesNext动作类型相关处理。 func TestRecoveryNeedsSenderUsesNextActionType(t *testing.T) { + // rule 保存规则,供当前处理流程使用 rule := db.AutomationRule{Actions: []db.AutomationAction{ {ActionType: ActionConfirmShipment, Enabled: true}, {ActionType: ActionSendText, Enabled: true}, }} + // task 保存任务,供当前处理流程使用 task := Task{TriggerType: TriggerBuyerReviewed} if recoveryNeedsSender(task, rule, 0) { t.Fatal("确认发货动作不应等待 WebSocket") @@ -314,11 +367,16 @@ func TestRecoveryNeedsSenderUsesNextActionType(t *testing.T) { } } +// TestAutomationSchedulerWaitsForShutdown 负责Test自动化SchedulerWaitsForShutdown相关处理。 func TestAutomationSchedulerWaitsForShutdown(t *testing.T) { + // store、cleanup 保存store、cleanup,供当前处理流程使用 store, cleanup := newAutomationTestStore(t) defer cleanup() + // scheduler 保存scheduler,供当前处理流程使用 scheduler := NewScheduler(New(store, testSenderProvider{sender: &testSender{}}, nil)) + // ctx、cancel 保存ctx、cancel,供当前处理流程使用 ctx, cancel := context.WithCancel(context.Background()) + // done 保存done,供当前处理流程使用 done := make(chan struct{}) go func() { scheduler.Run(ctx)