refactor: automation 中心落地 + 清理 delivery_rules/SystemMessage 死代码
把卡密自动发货从 engine.DeliveryService 收敛到统一的 automation.Center: WS 事件/计划任务/手动触发统一为 Task,trigger_key 持久化防重,付款发货、 评价赠品、超时求评价共用一套规则+动作编排。新增 internal/automation 包、 db.AutomationRules repository、00007 迁移。 同步删除被取代的并行死系统: - engine.DeliveryService + delivery_test.go(已无引用) - db.DeliveryRules/DeliveryRule + 3 个 Match 方法(生产零调用) - card_handlers 的 /delivery-rules CRUD(前端早已只走 automation-rules) - engine.SystemMessage + extractSystemMessage(dispatch 不再单独路由 message["3"]) - store.DeliveryRules 字段、Cards.IncrementDeliveryTimes - 00008 迁移 DROP delivery_rules/delivery_rule_variants + email_verifications/ captcha_codes/ai_item_cache/risk_control_logs + publish 批次 3 个死列 - isAPIPath 清理 ~15 个未挂载的前缀,stub_handlers.go 内联删除 - vite.config 删 /delivery-rules proxy 其它:orders.Upsert 注释改为诚实描述(version 列不参与并发控制); dispatch.cleanupDedupLocked 用 sort.Slice 取代 O(n²) 选择排序; 删自定义 min 用内置;deliveryRuleItemOwned 改名 itemOwnedByUser。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
5546494577
commit
57f9090dd2
29 files changed
+2469
-2382
No files matched your search
@@ -9,14 +9,14 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"xianyu-go/internal/automation"
|
||||
"xianyu-go/internal/db"
|
||||
)
|
||||
|
||||
// recordingHandler 记录收到的聊天/系统消息,用于断言防抖与去重行为。
|
||||
// recordingHandler 记录收到的聊天消息,用于断言防抖与去重行为。
|
||||
type recordingHandler struct {
|
||||
mu sync.Mutex
|
||||
chats []ChatMessage
|
||||
systems []SystemMessage
|
||||
refresh int
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ func (h *recordingHandler) HandleChatMessage(_ context.Context, m ChatMessage) e
|
||||
h.chats = append(h.chats, m)
|
||||
return nil
|
||||
}
|
||||
func (h *recordingHandler) HandleSystemMessage(_ context.Context, m SystemMessage) error {
|
||||
func (h *recordingHandler) HandleSystemEvent(_ context.Context, task automation.Task) error {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
h.systems = append(h.systems, m)
|
||||
_ = task
|
||||
return nil
|
||||
}
|
||||
func (h *recordingHandler) OnPasswordLoginRefresh(_ context.Context, _ string) bool {
|
||||
@@ -94,26 +94,14 @@ func TestExtractChatMessage_FiltersRefundTradeCard(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractChatMessage_KeepsPaidDeliveryCard(t *testing.T) {
|
||||
func TestExtractChatMessage_FiltersPaidDeliveryCardFromChat(t *testing.T) {
|
||||
decrypted := mustPaidDeliveryCard(t)
|
||||
chat := extractChatMessage(decrypted, "cid", "cookie")
|
||||
if chat == nil {
|
||||
t.Fatal("付款待发货卡片应保留用于自动发货")
|
||||
if chat := extractChatMessage(decrypted, "cid", "cookie"); chat != nil {
|
||||
t.Fatalf("付款待发货系统卡片不应进入聊天回复链: %+v", chat)
|
||||
}
|
||||
if chat.Text != "[我已付款,等待你发货]" {
|
||||
t.Fatalf("Text=%q", chat.Text)
|
||||
}
|
||||
if chat.ItemID != "1063177864132" {
|
||||
t.Fatalf("ItemID=%q", chat.ItemID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsAutoDeliveryTriggerPaidCard(t *testing.T) {
|
||||
if !IsAutoDeliveryTrigger("[我已付款,等待你发货]") {
|
||||
t.Fatal("付款待发货卡片应触发自动发货")
|
||||
}
|
||||
if IsAutoDeliveryTrigger("[我已拍下,待付款]") {
|
||||
t.Fatal("仅拍下未付款不应触发自动发货")
|
||||
task := automation.ExtractTaskFromWS("cid", "cookie", decrypted)
|
||||
if task == nil || task.TriggerType != automation.TriggerOrderPaid {
|
||||
t.Fatalf("付款待发货卡片应进入自动化中心: %+v", task)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,18 +273,6 @@ func mustPaidDeliveryCard(t *testing.T) map[string]any {
|
||||
return m
|
||||
}
|
||||
|
||||
// TestExtractSystemMessage 系统消息提取。
|
||||
func TestExtractSystemMessage(t *testing.T) {
|
||||
m := mustDecryptGoldenSample(t)
|
||||
sys := extractSystemMessage(m, "cid", "cookie")
|
||||
if sys == nil {
|
||||
t.Fatal("应为系统消息")
|
||||
}
|
||||
if sys.RedReminder != "等待买家付款" {
|
||||
t.Errorf("RedReminder=%q", sys.RedReminder)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRetryDelay 复刻 _calculate_retry_delay 的分段逻辑。
|
||||
func TestRetryDelay(t *testing.T) {
|
||||
acc, _, _, cleanup := newAccountForTest(t)
|
||||
|
||||
Reference in new issue
Block a user