feat(contract,gateway): B4 枚举权威表 — GET /api/v1/meta/enums + 未知值回落约定
- 新增 internal/contract/enums 叶子包:platform/mood/mode 三表 + UnknownFallback="display-raw";每次调用返回新切片,无包级可变全局 - GET /api/v1/meta/enums(anyAuth 只读、纯投影、无 store/无错误路径) - 反漂移 4 处:真构造内置适配器断言 Name() 与表双向相等、真工厂 buildAccountAdapter 逐项可建、mood 对齐 emotion 常量 + 默认转移表、mode 对齐前端 MODES(跨语言,文件缺失则 skip) - Docs/api-client §1.1 枚举权威表 + 行15 + v0.38;api-reference §3.7 + 行12
This commit is contained in:
1 parent
a828edacc5
commit
22e8398110
8 files changed
+617
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
// Wiring-level anti-drift test for the shared client enum table (design/07 §6).
|
||||
// The enums package test pins the platform table to the adapters' Name() values;
|
||||
// this one pins it to the composition root's factory — every platform the table
|
||||
// publishes must be one buildAccountAdapter actually knows how to build, so a
|
||||
// phantom entry (a platform listed for clients but never wired up) fails here.
|
||||
|
||||
import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/config"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/contract/enums"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/logger"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/history"
|
||||
)
|
||||
|
||||
// TestChannelFactoryBuildsEnumeratedPlatforms builds every adapter the published
|
||||
// platform table lists (other than the Web main-session source, which is not an
|
||||
// adapter) through the real factory and asserts the built adapter's Name()
|
||||
// resolves back to that platform. Adapter construction never dials out, so the
|
||||
// minimal configs below are enough.
|
||||
func TestChannelFactoryBuildsEnumeratedPlatforms(t *testing.T) {
|
||||
t.Parallel()
|
||||
log := logger.New(logger.Options{Out: io.Discard})
|
||||
minimalConfig := map[string]map[string]any{
|
||||
"kook": {"bot_token": "test"},
|
||||
"telegram": {"bot_token": "test"},
|
||||
}
|
||||
|
||||
for _, p := range enums.Platforms() {
|
||||
if p.ID == history.PlatformWeb {
|
||||
continue
|
||||
}
|
||||
acct := config.ChannelAccount{Config: minimalConfig[p.ID]}
|
||||
built, err := buildAccountAdapter(p.ID, acct, log)
|
||||
if err != nil {
|
||||
t.Errorf("platform %q is published to clients but the factory cannot build it: %v", p.ID, err)
|
||||
continue
|
||||
}
|
||||
if got := barePlatform(built.Name()); got != p.ID {
|
||||
t.Errorf("buildAccountAdapter(%q).Name() = %q, want %q", p.ID, got, p.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user