feat(channel): KOOK 渠道适配器 + 框架兼容增强(wsutil/httpclient)
- plugins/channels/kook: config/adapter/gateway/websocket/send/message/errors — 实现 PlatformAdapter 13方法 - WS 有状态网关: 取gateway地址→连WS→信令0/1/2/3/4/6 + 30s心跳/6s超时 + resume(拼接sn/session_id) + 指数退避重连 - 收事件: 信令0 → UnifiedMessage(word注 channel_type/type/target_id/extra.author→字段) - 发消息: /message/create(频道) + /direct-message/create(私聊,修正正确端点,非user-chat) + Bearer鉴权 - 注册 channels.go + CHANNELS_JSON 多账号 + channelbridge.configured 加 kook(bot_token非空才连) - 框架增强: internal/channel/adapter/wsutil(连接管理/心跳/重连/resume骨架,复用gorilla,KOOK用上) + httpclient(Bearer+envelope归一,KOOK用) - 全仓 go build/vet/test 绿, 零新依赖(复用餐gorilla), 未动telegram/qq/weixin/webhook契约 - §4.6 隔离/黑白名单/第三方边界未破坏 注: KOOK WS/WH 双模式待补(ReceiveMode), 实测需主人提供 CHANNEL_KOOK_TOKEN
This commit is contained in:
1 parent
eab6b63eb0
commit
764d592859
24 files changed
+2800
-2
No files matched your search
@@ -0,0 +1,56 @@
|
||||
package wsutil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestBackoffSequence(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := NewBackoff(2*time.Second, 60*time.Second)
|
||||
want := []time.Duration{2, 4, 8, 16, 32, 60, 60, 60}
|
||||
for i, exp := range want {
|
||||
if got := b.Next(); got != exp*time.Second {
|
||||
t.Fatalf("Next[%d] = %v, want %v", i, got, exp*time.Second)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackoffReset(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := NewBackoff(time.Second, time.Minute)
|
||||
_ = b.Next()
|
||||
_ = b.Next()
|
||||
b.Reset()
|
||||
if got := b.Next(); got != time.Second {
|
||||
t.Errorf("after Reset, Next = %v, want 1s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackoffDefaults(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := NewBackoff(0, 0)
|
||||
if got := b.Next(); got != time.Second {
|
||||
t.Errorf("default base Next = %v, want 1s", got)
|
||||
}
|
||||
if got := b.Next(); got != 2*time.Second {
|
||||
t.Errorf("default Next2 = %v, want 2s", got)
|
||||
}
|
||||
// cap of 60s by default: 1,2,4,8,16,32,60...
|
||||
for i := 0; i < 7; i++ {
|
||||
_ = b.Next()
|
||||
}
|
||||
if got := b.Next(); got != 60*time.Second {
|
||||
t.Errorf("default cap Next = %v, want 60s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackoffNoOverflow(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := NewBackoff(time.Second, time.Second)
|
||||
for i := 0; i < 200; i++ {
|
||||
if got := b.Next(); got != time.Second {
|
||||
t.Fatalf("Next[%d] = %v, want 1s (cap)", i, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user