- 适配器只描述平台身份:qq_obv11 的 owner/admin 一律上报 RoleMember,不再上报 RoleOwner - session 层唯一判主点只认白名单(owner.yaml Accounts ∪ 每渠道 adminIds),nil 档案 fail-closed 拒绝 - 新增「每渠道管理员层」:channels.json ChannelAccount.adminIds[] → runtimeconfig.AdminIDs → OwnerProfile.SetPlatformAdmins(整体替换语义,热重载后移除的 id 立即失效) - 组合根接线:启动即播种、面板保存先灌白名单再重载适配器(cmd/cyrene/wire_channels.go + 4 条端到端单测) - 06.4.3 节流与参与度状态按会话独立计数(ConversationKey 三处统一,空会话 GC);06.4.4 未知平台主动发言保守默认 1 条/分钟
82 lines
2.5 KiB
Go
82 lines
2.5 KiB
Go
package runtimeconfig
|
|
|
|
// 本文件覆盖裁决 06.4.2 的配置侧形状:channels.json / CHANNELS_JSON 的账号级
|
|
// `adminIds[]`(现有 allowUsers 之外)能被解析,并被 AdminIDs 汇总成
|
|
// platform → 管理员 id 列表。
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/config"
|
|
)
|
|
|
|
// TestAdminIDsAggregatesPerPlatform 覆盖多账号、重复与空白条目的合并去重。
|
|
func TestAdminIDsAggregatesPerPlatform(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
accounts := map[string][]config.ChannelAccount{
|
|
"qq-obv11": {
|
|
{ID: "conf0", AdminIDs: []string{" 10001 ", "10002"}},
|
|
{ID: "conf1", AdminIDs: []string{"10002", "", "10003"}},
|
|
},
|
|
"telegram": {{ID: "conf0"}},
|
|
}
|
|
got := AdminIDs(accounts)
|
|
|
|
ids := got["qq-obv11"]
|
|
if len(ids) != 3 {
|
|
t.Fatalf("qq-obv11 admin ids = %v, want 3 个去重后的 id", ids)
|
|
}
|
|
for i, want := range []string{"10001", "10002", "10003"} {
|
|
if ids[i] != want {
|
|
t.Errorf("ids[%d] = %q, want %q", i, ids[i], want)
|
|
}
|
|
}
|
|
// 未声明 adminIds 的平台仍出现在结果里(空切片),这样调用方的一次循环就是整体替换:
|
|
// 该平台上一轮的管理员层会被 SetPlatformAdmins(p, nil) 清掉,热重载不留悬挂管理员。
|
|
tg, ok := got["telegram"]
|
|
if !ok {
|
|
t.Error("未声明 adminIds 的平台也应出现在结果里(空切片),否则热重载无法清掉旧管理员层")
|
|
}
|
|
if len(tg) != 0 {
|
|
t.Errorf("telegram admin ids = %v, want 空", tg)
|
|
}
|
|
if len(AdminIDs(nil)) != 0 {
|
|
t.Error("nil accounts 应返回空映射")
|
|
}
|
|
}
|
|
|
|
// TestLoadChannelsParsesAdminIDs 覆盖 channels.json 的账号级 adminIds[] 形状:文件优先
|
|
// 加载后能被 AdminIDs 读到(证明 schema 真的落到了配置结构上,而不是被静默丢弃)。
|
|
func TestLoadChannelsParsesAdminIDs(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
path := filepath.Join(t.TempDir(), "channels.json")
|
|
raw := map[string][]config.ChannelAccount{
|
|
"qq-obv11": {{
|
|
ID: "conf0",
|
|
Config: map[string]any{"remote_url": "ws://127.0.0.1:3001"},
|
|
AdminIDs: []string{"10001", "10002"},
|
|
}},
|
|
}
|
|
data, err := json.Marshal(raw)
|
|
if err != nil {
|
|
t.Fatalf("marshal: %v", err)
|
|
}
|
|
if err := os.WriteFile(path, data, 0o600); err != nil {
|
|
t.Fatalf("write: %v", err)
|
|
}
|
|
|
|
accounts, warn := LoadChannels(path, nil)
|
|
if warn != nil {
|
|
t.Fatalf("LoadChannels warn = %v, want nil", warn)
|
|
}
|
|
ids := AdminIDs(accounts)["qq-obv11"]
|
|
if len(ids) != 2 || ids[0] != "10001" || ids[1] != "10002" {
|
|
t.Fatalf("channels.json 的 adminIds[] 未落到配置结构: %v", ids)
|
|
}
|
|
}
|