Merge pull request #873 from samcharles93/fix/restart-command-wiring
fix(chat): remove unreachable Telegram-router restart wiring
This commit is contained in:
4 files changed
+100
-10
No files matched your search
@@ -125,9 +125,8 @@ type boot struct {
|
||||
catalog modelcatalog.Snapshot
|
||||
catalogModels []string
|
||||
|
||||
bus *events.Bus
|
||||
restartTelegram func() error
|
||||
channelManager *status.Manager
|
||||
bus *events.Bus
|
||||
channelManager *status.Manager
|
||||
// rateLimiter is the shared per-(channel, sender) inbound budget every
|
||||
// chat Router is given. Nil when [chat.rate_limit] is not configured,
|
||||
// which leaves rate limiting off.
|
||||
@@ -685,9 +684,9 @@ func (b *boot) setupGateways(ctx context.Context, cfgPath, overlayPath string) b
|
||||
},
|
||||
ChatPRReviewer: b.prReviewer(),
|
||||
DefaultChatIdentity: b.defaultChatIdentity, SessionStore: b.chatSessionStore, Updates: b.updateService,
|
||||
Secrets: b.secrets,
|
||||
Bus: b.bus,
|
||||
RegisterRestart: func(request func() error) { b.restartTelegram = request }, Log: log,
|
||||
Secrets: b.secrets,
|
||||
Bus: b.bus,
|
||||
Log: log,
|
||||
ChannelManager: b.channelManager, AgentStatus: b.agentStatus,
|
||||
RateLimiter: b.rateLimiter,
|
||||
})
|
||||
|
||||
@@ -54,7 +54,6 @@ type telegramSetup struct {
|
||||
SessionStore gateway.SessionStore
|
||||
Updates telegram.UpdateService
|
||||
Dangerous gateway.DangerousCommandAuthority
|
||||
RegisterRestart func(func() error)
|
||||
// Bus carries primary-input events (archie-core-035): a completed
|
||||
// chat turn is published here so input-driven curators can wake. Nil
|
||||
// disables turn events (tests, minimal setups).
|
||||
@@ -118,9 +117,6 @@ func setupTelegramGateway(ctx context.Context, s telegramSetup) (start func(), o
|
||||
s.Log.Error("chat.telegram config invalid", "err", err)
|
||||
return nil, false
|
||||
}
|
||||
if s.RegisterRestart != nil {
|
||||
s.RegisterRestart(tg.RequestRestart)
|
||||
}
|
||||
tg.Version = func() string {
|
||||
return fmt.Sprintf("Archie\nGateway: %s\nRuntime: %s", gatewayVersion, runtimeVersion)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package archied
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/channels/telegram"
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
)
|
||||
|
||||
// TestBuildTelegramRouterLeavesRestartUnwired pins that the Telegram router
|
||||
// never wires Router.Restart, regardless of whether a Telegram adapter is in
|
||||
// scope. Telegram's /restart is served by a dedicated exact-match handler
|
||||
// (registerCommandHandlers → restartHandler), which is the only path that
|
||||
// reaches RequestRestart; the router's own handleRestartAdapter is never
|
||||
// reached on Telegram, so wiring Router.Restart here would be unreachable in
|
||||
// production. It must stay nil and the router's /restart reply must keep
|
||||
// reporting not-configured.
|
||||
func TestBuildTelegramRouterLeavesRestartUnwired(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
tg *telegram.Gateway
|
||||
}{
|
||||
{name: "telegram adapter present", tg: telegram.New("test-token", nil, slog.Default())},
|
||||
{name: "no telegram adapter", tg: nil},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
sessions := gateway.NewSessionStoreMemory()
|
||||
t.Cleanup(func() { _ = sessions.Close() })
|
||||
|
||||
router := buildTelegramRouter(ctx, tt.tg, telegramSetup{
|
||||
Cfg: config.NewHolder(config.Config{}),
|
||||
SessionStore: sessions,
|
||||
Log: slog.Default(),
|
||||
}, sessions)
|
||||
|
||||
if router.Restart != nil {
|
||||
t.Fatalf("router.Restart = %T, want nil: Telegram /restart is served by restartHandler, not this router", router.Restart)
|
||||
}
|
||||
|
||||
reply, err := router.Route(ctx, gateway.Inbound{Message: messaging.Message{
|
||||
Role: messaging.RoleUser,
|
||||
Text: "/restart",
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatalf("Route(/restart) error = %v", err)
|
||||
}
|
||||
if reply != "Chat adapter restart is not configured." {
|
||||
t.Fatalf("Route(/restart) = %q, want %q", reply, "Chat adapter restart is not configured.")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,44 @@ func TestRequestRestartQueuesScopedReload(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestRequestRestartRejectsDuplicate pins RequestRestart's dedupe contract:
|
||||
// the restart channel is buffered to one, so a second request while one is
|
||||
// still queued is rejected rather than silently dropped or blocking a caller
|
||||
// outside Telegram. restartHandler (restart.go) is the production driver of
|
||||
// this path; the error surface is what callers observe.
|
||||
func TestRequestRestartRejectsDuplicate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
prefill bool
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "first request queues", wantErr: false},
|
||||
{name: "second request rejected while queued", prefill: true, wantErr: true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
g := New("tok", []int64{1}, slog.Default())
|
||||
if tt.prefill {
|
||||
g.restartCh <- restartRequest{}
|
||||
}
|
||||
|
||||
err := g.RequestRestart()
|
||||
if tt.wantErr {
|
||||
if err == nil || err.Error() != "telegram gateway restart already in progress" {
|
||||
t.Fatalf("RequestRestart error = %v, want %q", err, "telegram gateway restart already in progress")
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("RequestRestart error = %v, want nil", err)
|
||||
}
|
||||
if got := len(g.restartCh); got != 1 {
|
||||
t.Fatalf("restart queue length = %d, want 1", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A failing Reload must not be fatal: a bad config edit should leave the
|
||||
// gateway running on its previous settings, not take chat down for good.
|
||||
func TestReloadFailureKeepsPreviousSettings(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user