feat(backthink): 主动推送每次只发一个平台——决策渠道/最近活跃优先,平台含微信
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

主动推送目标不再取第一个白名单渠道(kook),也不再双目标 web+kook;改为每次只发一个平台,范围=全部已连接白名单渠道(含微信 weixin-ilink)。

backthink/push.go: pusher 单目标路由——web hint 一次 pushActive;im/auto/实体平台 hint 一次性 pushIM (msgs 置哨兵/实体平台),无 IM sink 时诚实降级 pushActive;保留 PushGate 降频与成功 RecordPush。
channelbridge/proactive.go: proactiveTarget 三级选择——①决策 [渠道:xxx] 实体平台且白名单+已连接优先;②最近活跃(主会话最近20条 newest-first 找白名单+已连接平台,web 会话自动跳过);③回退 NextConnectedAccount 用旋转游标避免永远 kook。微信不再排除、可被选中;决策 hint 指定非白名单渠道回退(不报错)。Bridge 新增 proactiveCursor 字段(mu 保护)。
context.go: guidancePrompt 描述改为每次挑一个合适渠道(含微信)。
测试: 决策优先/最近活跃/微信可选中/无信号回退旋转/单目标 等,go build/vet/test 全绿 + windows/darwin 交叉编译。stash@{0} 保留被取代的'web+kook双目标'WIP以备回滚。
This commit is contained in:
Aska committed 2026-09-08 13:34:22 +08:00
1 parent 12031bd13c
commit 3e4efa0e41
8 files changed
+419 -114

No files matched your search

+48 -14
View File
@@ -9,14 +9,39 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/channel/session"
)
func TestPusher_ActiveFirst(t *testing.T) {
func TestPusher_AutoRoutesIM(t *testing.T) {
t.Parallel()
active := &mockActive{n: 2}
// The owner mandate: a default (auto) push reaches ONE channel over the IM
// bridge (the bridge picks her [渠道:...] choice, then her most recent platform,
// then the whitelist default) — not the active web client by default.
active := &mockActive{n: 2} // a web client is online but is NOT the default target
im := &mockIMAdapter{}
p := newPusher(active, im, &mockGate{allow: true}, discardLog())
res := p.Push(context.Background(), PushRequest{Message: adapter.UnifiedMessage{}})
if !res.Pushed {
t.Fatalf("Pushed = false, want true")
}
if res.Route != RouteIMBridge {
t.Fatalf("Route = %q, want %q", res.Route, RouteIMBridge)
}
if im.count() != 1 {
t.Fatalf("im calls = %d, want 1 (single IM target)", im.count())
}
if active.calls != 0 {
t.Fatalf("active calls = %d, want 0 (web is not the default target)", active.calls)
}
}
func TestPusher_WebHintRoutesActive(t *testing.T) {
t.Parallel()
active := &mockActive{n: 1}
im := &mockIMAdapter{}
p := newPusher(active, im, &mockGate{allow: true}, discardLog())
res := p.Push(context.Background(), PushRequest{ChannelHint: channelWeb, Message: adapter.UnifiedMessage{}})
if !res.Pushed {
t.Fatalf("Pushed = false, want true")
}
@@ -27,17 +52,19 @@ func TestPusher_ActiveFirst(t *testing.T) {
t.Fatalf("active calls = %d, want 1", active.calls)
}
if im.count() != 0 {
t.Fatalf("im calls = %d, want 0 (active should be preferred)", im.count())
t.Fatalf("im calls = %d, want 0 (web hint targets only the active client)", im.count())
}
}
func TestPusher_IMFallback_NoActive(t *testing.T) {
func TestPusher_ConcreteHintRoutesIM_SingleTarget(t *testing.T) {
t.Parallel()
active := &mockActive{n: 0} // no active client online
// A concrete decision channel is honored over the IM bridge, and exactly ONE
// target is used (the IM bridge carries it; the active client is not touched).
active := &mockActive{n: 2}
im := &mockIMAdapter{}
p := newPusher(active, im, &mockGate{allow: true}, discardLog())
res := p.Push(context.Background(), PushRequest{Message: adapter.UnifiedMessage{}})
res := p.Push(context.Background(), PushRequest{ChannelHint: "kook", Message: adapter.UnifiedMessage{}})
if !res.Pushed {
t.Fatalf("Pushed = false, want true")
@@ -48,24 +75,31 @@ func TestPusher_IMFallback_NoActive(t *testing.T) {
if im.count() != 1 {
t.Fatalf("im calls = %d, want 1", im.count())
}
if active.calls != 0 {
t.Fatalf("active calls = %d, want 0 (a concrete hint targets only the IM bridge)", active.calls)
}
if im.last.Platform != "kook" {
t.Fatalf("im platform = %q, want kook", im.last.Platform)
}
}
func TestPusher_IMFallback_ActiveError(t *testing.T) {
func TestPusher_NoIMSink_DegradesToActive(t *testing.T) {
t.Parallel()
active := &mockActive{err: context.DeadlineExceeded}
im := &mockIMAdapter{}
p := newPusher(active, im, &mockGate{allow: true}, discardLog())
// With no IM sink wired (backthink IM seam absent) the push degrades to the
// active web client so the owner is still reached rather than dropped.
active := &mockActive{n: 1}
p := newPusher(active, nil, &mockGate{allow: true}, discardLog())
res := p.Push(context.Background(), PushRequest{Message: adapter.UnifiedMessage{}})
if !res.Pushed {
t.Fatalf("Pushed = false, want true")
}
if res.Route != RouteIMBridge {
t.Fatalf("Route = %q, want %q", res.Route, RouteIMBridge)
if res.Route != RouteActiveClient {
t.Fatalf("Route = %q, want %q", res.Route, RouteActiveClient)
}
if im.count() != 1 {
t.Fatalf("im calls = %d, want 1", im.count())
if active.calls != 1 {
t.Fatalf("active calls = %d, want 1", active.calls)
}
}