refactor: remove dead BasePlatformAdapter code
This commit is contained in:
1 parent
29fba1740f
commit
d998c33b0d
5 files changed
+5
-240
No files matched your search
@@ -1,80 +0,0 @@
|
||||
package gateway
|
||||
|
||||
import "context"
|
||||
|
||||
// SendResult captures the outcome of a Send operation through a platform
|
||||
// adapter. It classifies errors so callers can implement retry policies
|
||||
// without inspecting platform-specific error types.
|
||||
type SendResult struct {
|
||||
// MessageID is the platform-assigned identifier of the sent message.
|
||||
// Empty when the send failed before the platform acknowledged it.
|
||||
MessageID string
|
||||
|
||||
// Success is true when the platform accepted the message.
|
||||
Success bool
|
||||
|
||||
// Retryable is true when the error is transient -- rate limits, network
|
||||
// timeouts, temporary platform outages -- and the caller should retry
|
||||
// with backoff.
|
||||
Retryable bool
|
||||
|
||||
// Error is the underlying error when Success is false.
|
||||
Error error
|
||||
|
||||
// ErrorCode classifies the failure for observability and retry-policy
|
||||
// decisions. Values:
|
||||
//
|
||||
// "" -- no error (Success == true)
|
||||
// "rate_limited" -- platform rejected due to rate limiting
|
||||
// "network" -- connection lost or timeout
|
||||
// "auth" -- token expired or credentials invalid
|
||||
// "invalid_message" -- message content rejected by platform
|
||||
// "internal" -- unexpected adapter or platform error
|
||||
ErrorCode string
|
||||
}
|
||||
|
||||
// ChatInfo is static metadata about the conversation a platform adapter is
|
||||
// connected to. Adapters return this from ChatInfo() so callers can display
|
||||
// context without knowing platform internals.
|
||||
type ChatInfo struct {
|
||||
// ID is the platform-specific chat identifier.
|
||||
ID string
|
||||
|
||||
// Title is the human-readable chat name (group title, DM username,
|
||||
// channel name).
|
||||
Title string
|
||||
|
||||
// Type is the chat kind: "private", "group", "channel", "supergroup".
|
||||
Type string
|
||||
|
||||
// Platform names the adapter ("telegram", "discord", "web").
|
||||
Platform string
|
||||
}
|
||||
|
||||
// BasePlatformAdapter is the interface every platform adapter must implement.
|
||||
// Each implementation owns its connection lifecycle and translates
|
||||
// platform-specific events into the shared MessageEvent model.
|
||||
//
|
||||
// The daemon instantiates one adapter per active bot identity × platform and
|
||||
// calls Connect to start the event loop. Inbound messages are delivered to a
|
||||
// shared handler; outbound messages flow through Send.
|
||||
type BasePlatformAdapter interface {
|
||||
// Connect establishes the persistent connection and starts the inbound
|
||||
// message loop. It blocks until ctx is cancelled or the connection
|
||||
// fails irrecoverably. Implementations should reconnect transient
|
||||
// failures internally.
|
||||
Connect(ctx context.Context) error
|
||||
|
||||
// Disconnect gracefully tears down the connection. After Disconnect
|
||||
// returns the adapter may be reused by calling Connect again.
|
||||
Disconnect(ctx context.Context) error
|
||||
|
||||
// Send delivers a message event to the platform. The returned
|
||||
// SendResult classifies the outcome so callers can decide whether
|
||||
// to retry.
|
||||
Send(ctx context.Context, event MessageEvent) (SendResult, error)
|
||||
|
||||
// ChatInfo returns static metadata about the connected conversation.
|
||||
// Useful for logging, status displays, and multi-bot dashboards.
|
||||
ChatInfo(ctx context.Context) (ChatInfo, error)
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// stubAdapter is a minimal BasePlatformAdapter for testing.
|
||||
type stubAdapter struct {
|
||||
info ChatInfo
|
||||
}
|
||||
|
||||
func (s *stubAdapter) Connect(ctx context.Context) error { return nil }
|
||||
func (s *stubAdapter) Disconnect(ctx context.Context) error { return nil }
|
||||
func (s *stubAdapter) Send(ctx context.Context, e MessageEvent) (SendResult, error) {
|
||||
return SendResult{Success: true, MessageID: "msg-1"}, nil
|
||||
}
|
||||
|
||||
func (s *stubAdapter) ChatInfo(ctx context.Context) (ChatInfo, error) {
|
||||
return s.info, nil
|
||||
}
|
||||
|
||||
var _ BasePlatformAdapter = (*stubAdapter)(nil)
|
||||
|
||||
func TestSendResult_Success(t *testing.T) {
|
||||
sr := SendResult{
|
||||
MessageID: "abc123",
|
||||
Success: true,
|
||||
}
|
||||
if !sr.Success {
|
||||
t.Error("expected Success to be true")
|
||||
}
|
||||
if sr.MessageID != "abc123" {
|
||||
t.Errorf("expected MessageID abc123, got %s", sr.MessageID)
|
||||
}
|
||||
if sr.ErrorCode != "" {
|
||||
t.Error("expected empty ErrorCode for success")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendResult_RateLimited(t *testing.T) {
|
||||
sr := SendResult{
|
||||
Success: false,
|
||||
Retryable: true,
|
||||
Error: errors.New("rate limited: retry after 30s"),
|
||||
ErrorCode: "rate_limited",
|
||||
}
|
||||
if sr.Success {
|
||||
t.Error("expected Success to be false")
|
||||
}
|
||||
if !sr.Retryable {
|
||||
t.Error("expected Retryable to be true for rate_limited")
|
||||
}
|
||||
if sr.ErrorCode != "rate_limited" {
|
||||
t.Errorf("expected ErrorCode rate_limited, got %s", sr.ErrorCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendResult_NetworkError(t *testing.T) {
|
||||
sr := SendResult{
|
||||
Success: false,
|
||||
Retryable: true,
|
||||
Error: errors.New("connection refused"),
|
||||
ErrorCode: "network",
|
||||
}
|
||||
if sr.ErrorCode != "network" {
|
||||
t.Errorf("expected ErrorCode network, got %s", sr.ErrorCode)
|
||||
}
|
||||
if !sr.Retryable {
|
||||
t.Error("expected network errors to be retryable")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendResult_AuthError(t *testing.T) {
|
||||
sr := SendResult{
|
||||
Success: false,
|
||||
Retryable: false,
|
||||
Error: errors.New("token expired"),
|
||||
ErrorCode: "auth",
|
||||
}
|
||||
if sr.Retryable {
|
||||
t.Error("expected auth errors to be non-retryable")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendResult_InvalidMessage(t *testing.T) {
|
||||
sr := SendResult{
|
||||
Success: false,
|
||||
Retryable: false,
|
||||
Error: errors.New("message too long"),
|
||||
ErrorCode: "invalid_message",
|
||||
}
|
||||
if sr.Retryable {
|
||||
t.Error("expected invalid_message to be non-retryable")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatInfo_Fields(t *testing.T) {
|
||||
ci := ChatInfo{
|
||||
ID: "chat-42",
|
||||
Title: "Engineering",
|
||||
Type: "group",
|
||||
Platform: "telegram",
|
||||
}
|
||||
if ci.ID != "chat-42" {
|
||||
t.Errorf("expected ID chat-42, got %s", ci.ID)
|
||||
}
|
||||
if ci.Title != "Engineering" {
|
||||
t.Errorf("expected Title Engineering, got %s", ci.Title)
|
||||
}
|
||||
if ci.Type != "group" {
|
||||
t.Errorf("expected Type group, got %s", ci.Type)
|
||||
}
|
||||
if ci.Platform != "telegram" {
|
||||
t.Errorf("expected Platform telegram, got %s", ci.Platform)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBasePlatformAdapter_Stub(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
a := &stubAdapter{info: ChatInfo{
|
||||
ID: "ch-1",
|
||||
Title: "test-chat",
|
||||
Type: "private",
|
||||
Platform: "web",
|
||||
}}
|
||||
|
||||
if err := a.Connect(ctx); err != nil {
|
||||
t.Errorf("Connect: %v", err)
|
||||
}
|
||||
|
||||
ci, err := a.ChatInfo(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("ChatInfo: %v", err)
|
||||
}
|
||||
if ci.Title != "test-chat" {
|
||||
t.Errorf("expected Title test-chat, got %s", ci.Title)
|
||||
}
|
||||
|
||||
sr, err := a.Send(ctx, MessageEvent{Type: MsgText, Text: "hi"})
|
||||
if err != nil {
|
||||
t.Fatalf("Send: %v", err)
|
||||
}
|
||||
if !sr.Success {
|
||||
t.Error("expected Send to succeed")
|
||||
}
|
||||
|
||||
if err := a.Disconnect(ctx); err != nil {
|
||||
t.Errorf("Disconnect: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -211,12 +212,7 @@ func repositoryUsesURL(dir, want string) bool {
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
for _, got := range remote.URLs {
|
||||
if got == want {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(remote.URLs, want)
|
||||
}
|
||||
|
||||
// refresh brings an already-prepared worktree back in line with the
|
||||
|
||||
Reference in new issue
Block a user