package gateway import ( "context" "testing" capreg "git.yeij.top/AskaEth/Cyrene_v2/internal/capability/registry" ) // testChannel is a bare sdk.Channel used to exercise findChannel resolution. type testChannel struct{ name string } func (t testChannel) Name() string { return t.name } func (t testChannel) Connect(context.Context) error { return nil } func (t testChannel) Disconnect(context.Context) error { return nil } func (t testChannel) IsConnected() bool { return false } func (t testChannel) HealthCheck(context.Context) error { return nil } // TestFindChannelExactMatch prefers an exact adapter name over a bare-name match. func TestFindChannelExactMatch(t *testing.T) { reg := capreg.New() _ = reg.Register(capreg.Capability{Name: "kook:conf0", Kind: capreg.KindChannel, Value: testChannel{name: "kook:conf0"}}) _ = reg.Register(capreg.Capability{Name: "telegram:conf0", Kind: capreg.KindChannel, Value: testChannel{name: "telegram:conf0"}}) ch, ok := findChannel(reg, "kook:conf0") if !ok || ch.Name() != "kook:conf0" { t.Fatalf("exact kook:conf0 not found, got %v/%v", ch, ok) } ch, ok = findChannel(reg, "telegram:conf0") if !ok || ch.Name() != "telegram:conf0" { t.Fatalf("exact telegram:conf0 not found, got %v/%v", ch, ok) } } // TestFindChannelBarePlatformResolvesToTokenAccount verifies a bare platform name // ("kook") that is not an exact adapter name resolves to that platform's first // registered account (the token-bearing one, since the empty-token bare account // is never registered). func TestFindChannelBarePlatformResolvesToTokenAccount(t *testing.T) { reg := capreg.New() _ = reg.Register(capreg.Capability{Name: "kook:3fc8", Kind: capreg.KindChannel, Value: testChannel{name: "kook:3fc8"}}) ch, ok := findChannel(reg, "kook") if !ok || ch.Name() != "kook:3fc8" { t.Fatalf("bare kook should resolve to kook:3fc8, got %v/%v", ch, ok) } } // TestFindChannelUnknownOrBlank rejects a name that matches no channel. func TestFindChannelUnknownOrBlank(t *testing.T) { reg := capreg.New() _ = reg.Register(capreg.Capability{Name: "kook:conf0", Kind: capreg.KindChannel, Value: testChannel{name: "kook:conf0"}}) if _, ok := findChannel(reg, "unknown"); ok { t.Fatal("unknown name should not be found") } if _, ok := findChannel(reg, ""); ok { t.Fatal("blank name should not be found") } // Skipped: non-channel capabilities must not match. _ = reg.Register(capreg.Capability{Name: "some-tool", Kind: capreg.KindTool, Value: testChannel{name: "some-tool"}}) if _, ok := findChannel(reg, "some-tool"); ok { t.Fatal("non-channel capability must not match findChannel") } }