feat(capability): 转码能力包(vendor 纯 Go AMR-NB 解码器 + 黄金向量逐样本对照 + 8 哨兵 + 注册面)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

This commit is contained in:
AskaEth committed 2026-10-05 13:02:28 +08:00
1 parent 89715d1813
commit 4a2d276881
100 files changed
+11319

No files matched your search

@@ -0,0 +1,48 @@
package transcode
import "testing"
// designPublishedRoutes 是 design/25 §3.1「格式矩阵」里**已发布**的路数:
// 本期只有一条 —— `amr → wav`。
//
// 这条常量刻意写在测试里:谁加了实现却忘了在 DefaultCodecs 注册(或反过来),
// 这条断言就会红,逼他回设计里对一次账。这就是 design/25 §6.3 要的「把值钉死在
// 设计上」,与只测边界逻辑互补。
const designPublishedRoutes = 1
// TestDefaultCodecsMatchesPublishedMatrix 断言注册点与设计矩阵一致。
func TestDefaultCodecsMatchesPublishedMatrix(t *testing.T) {
codecs := DefaultCodecs()
if len(codecs) != designPublishedRoutes {
t.Fatalf("DefaultCodecs() registers %d routes, design/25 §3.1 publishes %d: "+
"加了实现要在此处同步注册(并回设计对账)", len(codecs), designPublishedRoutes)
}
route := codecs[0]
if route.From() != FormatAMR || route.To() != FormatWAV {
t.Fatalf("DefaultCodecs()[0] = %s -> %s, want amr -> wav", route.From(), route.To())
}
}
// TestEnginePublishesOnlyTheDesignRoute 断言引擎对外报告的路也是那一条:
// Supports 只认 amr→wav,Formats 只报 amr/wav。
func TestEnginePublishesOnlyTheDesignRoute(t *testing.T) {
eng := NewEngine(DefaultLimits(), WithCodecs(DefaultCodecs()...))
if err := eng.RegistrationError(); err != nil {
t.Fatalf("registration: %v", err)
}
if !eng.Supports(FormatAMR, FormatWAV) {
t.Fatalf("amr -> wav must be supported")
}
for _, pair := range [][2]Format{
{FormatWAV, FormatAMR}, {FormatAMR, FormatAMR}, {FormatWAV, FormatWAV},
{FormatAMRWB, FormatWAV}, {FormatAMR, FormatAMRWB},
} {
if eng.Supports(pair[0], pair[1]) {
t.Errorf("Supports(%q, %q) = true, want false(本期只发 amr -> wav)", pair[0], pair[1])
}
}
formats := eng.Formats()
if len(formats) != 2 || formats[0] != FormatAMR || formats[1] != FormatWAV {
t.Fatalf("Formats = %v, want [amr wav]", formats)
}
}