fix(channels): delete unreachable Telegram webhook delivery mode
telegram.New only ever constructed with empty webhookURL/webhookSecret (telegram_setup.go) and config.TelegramConfig has no field to set them, so the SetWebhook/StartWebhook branch, WebhookHandler, and webhook teardown in Stop were dead code exercised only by tests. Long-polling is the only reachable mode; delete the webhook path and its ConfigSchema properties so the schema no longer advertises unsupported config.
This commit is contained in:
10 files changed
+101
-184
No files matched your search
@@ -102,7 +102,7 @@ func setupTelegramGateway(ctx context.Context, s telegramSetup) (start func(), o
|
|||||||
s.Log.Warn("chat.telegram has no allowed_user_ids: every sender will be rejected. " +
|
s.Log.Warn("chat.telegram has no allowed_user_ids: every sender will be rejected. " +
|
||||||
"Add your Telegram user id to chat.telegram.allowed_user_ids to enable the bot.")
|
"Add your Telegram user id to chat.telegram.allowed_user_ids to enable the bot.")
|
||||||
}
|
}
|
||||||
tg := telegram.New(tgToken, "", "", cfg.Chat.Telegram.AllowedUserIDs, s.Log)
|
tg := telegram.New(tgToken, cfg.Chat.Telegram.AllowedUserIDs, s.Log)
|
||||||
if s.RegisterRestart != nil {
|
if s.RegisterRestart != nil {
|
||||||
s.RegisterRestart(tg.RequestRestart)
|
s.RegisterRestart(tg.RequestRestart)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const (
|
|||||||
|
|
||||||
func newApprovalTestGateway(t *testing.T) (*Gateway, *bot.Bot, *[]telegramRequest) {
|
func newApprovalTestGateway(t *testing.T) (*Gateway, *bot.Bot, *[]telegramRequest) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
g := New("1:test", "", "", []int64{approvalTestRecipient}, slog.Default())
|
g := New("1:test", []int64{approvalTestRecipient}, slog.Default())
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
return g, b, requests
|
return g, b, requests
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ func TestApprovalCallbackExpiredTokenRejected(t *testing.T) {
|
|||||||
|
|
||||||
func TestApprovalCallbackWrongRecipientRejected(t *testing.T) {
|
func TestApprovalCallbackWrongRecipientRejected(t *testing.T) {
|
||||||
const otherUserID = int64(43)
|
const otherUserID = int64(43)
|
||||||
g := New("1:test", "", "", []int64{approvalTestRecipient, otherUserID}, slog.Default())
|
g := New("1:test", []int64{approvalTestRecipient, otherUserID}, slog.Default())
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
token := makeDangerousToken()
|
token := makeDangerousToken()
|
||||||
@@ -369,7 +369,7 @@ func TestApprovalPromptText(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestApprovalKeyboardUsesApprovalPrefix(t *testing.T) {
|
func TestApprovalKeyboardUsesApprovalPrefix(t *testing.T) {
|
||||||
g := New("1:test", "", "", []int64{approvalTestRecipient}, slog.Default())
|
g := New("1:test", []int64{approvalTestRecipient}, slog.Default())
|
||||||
markup := g.approvalKeyboard("token123")
|
markup := g.approvalKeyboard("token123")
|
||||||
|
|
||||||
if len(markup.InlineKeyboard) != 3 {
|
if len(markup.InlineKeyboard) != 3 {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ func TestRollbackListsCheckpoints(t *testing.T) {
|
|||||||
{Number: 1, Timestamp: now.Add(-2 * time.Hour), Label: "Initial checkout", Size: "8 MB"},
|
{Number: 1, Timestamp: now.Add(-2 * time.Hour), Label: "Initial checkout", Size: "8 MB"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ func TestRollbackListsCheckpoints(t *testing.T) {
|
|||||||
func TestRollbackEmptyCheckpoints(t *testing.T) {
|
func TestRollbackEmptyCheckpoints(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{} // no checkpoints
|
stub := &dangerousStub{} // no checkpoints
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ func TestRollbackEmptyCheckpoints(t *testing.T) {
|
|||||||
func TestRollbackCheckpointError(t *testing.T) {
|
func TestRollbackCheckpointError(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{checkpointsErr: fmt.Errorf("storage offline")}
|
stub := &dangerousStub{checkpointsErr: fmt.Errorf("storage offline")}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ func TestRollbackWithNumberRequiresApproval(t *testing.T) {
|
|||||||
stub := &dangerousStub{
|
stub := &dangerousStub{
|
||||||
rollbackResult: "Restored to checkpoint 2: 15 files changed, 3 removed.",
|
rollbackResult: "Restored to checkpoint 2: 15 files changed, 3 removed.",
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ func TestRollbackApprovalExecutes(t *testing.T) {
|
|||||||
stub := &dangerousStub{
|
stub := &dangerousStub{
|
||||||
rollbackResult: "Restored to checkpoint 2: 15 files changed.",
|
rollbackResult: "Restored to checkpoint 2: 15 files changed.",
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -277,7 +277,7 @@ func TestRollbackApprovalExecutes(t *testing.T) {
|
|||||||
func TestRollbackWithBadNumber(t *testing.T) {
|
func TestRollbackWithBadNumber(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{}
|
stub := &dangerousStub{}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -301,7 +301,7 @@ func TestRollbackWithBadNumber(t *testing.T) {
|
|||||||
func TestStopRequiresApproval(t *testing.T) {
|
func TestStopRequiresApproval(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{}
|
stub := &dangerousStub{}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -330,7 +330,7 @@ func TestStopRequiresApproval(t *testing.T) {
|
|||||||
func TestStopApprovalExecutes(t *testing.T) {
|
func TestStopApprovalExecutes(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{}
|
stub := &dangerousStub{}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -376,7 +376,7 @@ func TestStopApprovalExecutes(t *testing.T) {
|
|||||||
func TestStopWithNoArgumentDoesNotRequireApproval(t *testing.T) {
|
func TestStopWithNoArgumentDoesNotRequireApproval(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{}
|
stub := &dangerousStub{}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -404,7 +404,7 @@ func TestStopWithNoArgumentDoesNotRequireApproval(t *testing.T) {
|
|||||||
// a turn in flight is cancelled, and the queue behind it is discarded.
|
// a turn in flight is cancelled, and the queue behind it is discarded.
|
||||||
func TestStopCancelsRunningChatTurn(t *testing.T) {
|
func TestStopCancelsRunningChatTurn(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
|
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
g.turns = gateway.NewTurns(slog.Default())
|
g.turns = gateway.NewTurns(slog.Default())
|
||||||
@@ -441,7 +441,7 @@ func TestDangerousCallbackRejectsUnauthorizedSender(t *testing.T) {
|
|||||||
stub := &dangerousStub{
|
stub := &dangerousStub{
|
||||||
rollbackResult: "ok",
|
rollbackResult: "ok",
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -483,7 +483,7 @@ func TestDangerousCallbackRejectsUnauthorizedSender(t *testing.T) {
|
|||||||
func TestDangerousCallbackExpiredToken(t *testing.T) {
|
func TestDangerousCallbackExpiredToken(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{rollbackResult: "ok"}
|
stub := &dangerousStub{rollbackResult: "ok"}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -521,7 +521,7 @@ func TestDangerousCallbackExpiredToken(t *testing.T) {
|
|||||||
func TestDangerousCallbackSingleUse(t *testing.T) {
|
func TestDangerousCallbackSingleUse(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{rollbackResult: "ok"}
|
stub := &dangerousStub{rollbackResult: "ok"}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -572,7 +572,7 @@ func TestDangerousCallbackSingleUse(t *testing.T) {
|
|||||||
func TestDangerousCallbackDeny(t *testing.T) {
|
func TestDangerousCallbackDeny(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{rollbackResult: "ok"}
|
stub := &dangerousStub{rollbackResult: "ok"}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -610,7 +610,7 @@ func TestDangerousCallbackDeny(t *testing.T) {
|
|||||||
func TestDangerousCallbackExecutionFailure(t *testing.T) {
|
func TestDangerousCallbackExecutionFailure(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{rollbackErr: fmt.Errorf("checkpoint corrupted")}
|
stub := &dangerousStub{rollbackErr: fmt.Errorf("checkpoint corrupted")}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -649,7 +649,7 @@ func TestPermanentApprovalSkipsInlineKeyboard(t *testing.T) {
|
|||||||
stub := &dangerousStub{
|
stub := &dangerousStub{
|
||||||
rollbackResult: "Restored (permanent approval).",
|
rollbackResult: "Restored (permanent approval).",
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
|
|
||||||
// Grant permanent approval for rollback.
|
// Grant permanent approval for rollback.
|
||||||
@@ -690,7 +690,7 @@ func TestPermanentApprovalSkipsInlineKeyboard(t *testing.T) {
|
|||||||
func TestPermanentApprovalExpired(t *testing.T) {
|
func TestPermanentApprovalExpired(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{rollbackResult: "ok"}
|
stub := &dangerousStub{rollbackResult: "ok"}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
|
|
||||||
// Grant expired permanent approval.
|
// Grant expired permanent approval.
|
||||||
@@ -729,7 +729,7 @@ func TestPermanentApprovalButtonGrantsApproval(t *testing.T) {
|
|||||||
stub := &dangerousStub{
|
stub := &dangerousStub{
|
||||||
rollbackResult: "Restored after permanent approval grant.",
|
rollbackResult: "Restored after permanent approval grant.",
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -790,7 +790,7 @@ func TestPermanentApprovalScopedToRecipient(t *testing.T) {
|
|||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
const otherUserID = int64(99)
|
const otherUserID = int64(99)
|
||||||
stub := &dangerousStub{rollbackResult: "ok"}
|
stub := &dangerousStub{rollbackResult: "ok"}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID, otherUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID, otherUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
|
|
||||||
// Grant permanent approval for user 42.
|
// Grant permanent approval for user 42.
|
||||||
@@ -824,7 +824,7 @@ func TestPermanentApprovalScopedToRecipient(t *testing.T) {
|
|||||||
func TestApproveHandlerShowsPendingCommands(t *testing.T) {
|
func TestApproveHandlerShowsPendingCommands(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{}
|
stub := &dangerousStub{}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
|
|
||||||
// Register a pending command.
|
// Register a pending command.
|
||||||
@@ -854,7 +854,7 @@ func TestApproveHandlerShowsPendingCommands(t *testing.T) {
|
|||||||
func TestApproveHandlerNoPendingCommands(t *testing.T) {
|
func TestApproveHandlerNoPendingCommands(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{}
|
stub := &dangerousStub{}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
|
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
@@ -875,7 +875,7 @@ func TestApproveHandlerNoPendingCommands(t *testing.T) {
|
|||||||
|
|
||||||
func TestRollbackNotConfigured(t *testing.T) {
|
func TestRollbackNotConfigured(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
// Dangerous is nil.
|
// Dangerous is nil.
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -895,7 +895,7 @@ func TestRollbackNotConfigured(t *testing.T) {
|
|||||||
|
|
||||||
func TestStopNotConfigured(t *testing.T) {
|
func TestStopNotConfigured(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
// Dangerous is nil.
|
// Dangerous is nil.
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -917,7 +917,7 @@ func TestDangerousCommandHelpContainsNewCommands(t *testing.T) {
|
|||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
|
|
||||||
var sentText string
|
var sentText string
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
g.helpHandler()(context.Background(), b, &models.Update{
|
g.helpHandler()(context.Background(), b, &models.Update{
|
||||||
@@ -994,7 +994,7 @@ func TestDangerousCallbackRejectsWrongRecipient(t *testing.T) {
|
|||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
const otherUserID = int64(43)
|
const otherUserID = int64(43)
|
||||||
stub := &dangerousStub{rollbackResult: "ok"}
|
stub := &dangerousStub{rollbackResult: "ok"}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID, otherUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID, otherUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, _ := newTelegramTestBot(t)
|
b, _ := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -1019,7 +1019,7 @@ func TestDangerousCallbackRejectsWrongRecipient(t *testing.T) {
|
|||||||
func TestMalformedDangerousCallback(t *testing.T) {
|
func TestMalformedDangerousCallback(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
stub := &dangerousStub{}
|
stub := &dangerousStub{}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Dangerous = stub
|
g.Dangerous = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ func fakeAPI(t *testing.T) (*bot.Bot, *[]apiCall) {
|
|||||||
func newTestLiveReply(t *testing.T, showToolCalls bool) (*liveReply, *[]apiCall) {
|
func newTestLiveReply(t *testing.T, showToolCalls bool) (*liveReply, *[]apiCall) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
b, calls := fakeAPI(t)
|
b, calls := fakeAPI(t)
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
g.SetShowToolCalls(showToolCalls)
|
g.SetShowToolCalls(showToolCalls)
|
||||||
live := g.newLiveReply(context.Background(), b, 7, 0, g.ShowToolCalls())
|
live := g.newLiveReply(context.Background(), b, 7, 0, g.ShowToolCalls())
|
||||||
t.Cleanup(live.stopRendering)
|
t.Cleanup(live.stopRendering)
|
||||||
@@ -393,7 +393,7 @@ func TestLiveReplyOpenFallsBackToPlainText(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("new test bot: %v", err)
|
t.Fatalf("new test bot: %v", err)
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
live := g.newLiveReply(context.Background(), b, 7, 0, false)
|
live := g.newLiveReply(context.Background(), b, 7, 0, false)
|
||||||
t.Cleanup(live.stopRendering)
|
t.Cleanup(live.stopRendering)
|
||||||
live.interval = 0
|
live.interval = 0
|
||||||
@@ -431,7 +431,7 @@ func TestLiveReplyEditFallsBackToPlainText(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("new test bot: %v", err)
|
t.Fatalf("new test bot: %v", err)
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
live := g.newLiveReply(context.Background(), b, 7, 0, g.ShowToolCalls())
|
live := g.newLiveReply(context.Background(), b, 7, 0, g.ShowToolCalls())
|
||||||
t.Cleanup(live.stopRendering)
|
t.Cleanup(live.stopRendering)
|
||||||
live.interval = 0
|
live.interval = 0
|
||||||
@@ -472,7 +472,7 @@ func TestLiveReplyCallbacksDoNotWaitForTelegram(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("new test bot: %v", err)
|
t.Fatalf("new test bot: %v", err)
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
g.SetShowToolCalls(true)
|
g.SetShowToolCalls(true)
|
||||||
live := g.newLiveReply(context.Background(), b, 7, 0, g.ShowToolCalls())
|
live := g.newLiveReply(context.Background(), b, 7, 0, g.ShowToolCalls())
|
||||||
t.Cleanup(live.stopRendering)
|
t.Cleanup(live.stopRendering)
|
||||||
@@ -514,7 +514,7 @@ func TestLiveReplyStopCancelsInFlightRendering(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("new test bot: %v", err)
|
t.Fatalf("new test bot: %v", err)
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
live := g.newLiveReply(ctx, b, 7, 0, false)
|
live := g.newLiveReply(ctx, b, 7, 0, false)
|
||||||
t.Cleanup(live.stopRendering)
|
t.Cleanup(live.stopRendering)
|
||||||
@@ -555,7 +555,7 @@ func TestLiveReplyFinalEditFailureSendsAuthoritativeReplyNormally(t *testing.T)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("new test bot: %v", err)
|
t.Fatalf("new test bot: %v", err)
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
live := g.newLiveReply(context.Background(), b, 7, 0, g.ShowToolCalls())
|
live := g.newLiveReply(context.Background(), b, 7, 0, g.ShowToolCalls())
|
||||||
t.Cleanup(live.stopRendering)
|
t.Cleanup(live.stopRendering)
|
||||||
live.interval = 0
|
live.interval = 0
|
||||||
@@ -865,7 +865,7 @@ func TestGatewayAbandonAllLiveDoesNotBlockOnAHungReply(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("new test bot: %v", err)
|
t.Fatalf("new test bot: %v", err)
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
g.liveDrainTimeout = 50 * time.Millisecond
|
g.liveDrainTimeout = 50 * time.Millisecond
|
||||||
|
|
||||||
live := g.newLiveReply(context.Background(), b, 7, 0, false)
|
live := g.newLiveReply(context.Background(), b, 7, 0, false)
|
||||||
@@ -910,7 +910,7 @@ func TestGatewayRegisterLiveAfterStopAbandonsImmediately(t *testing.T) {
|
|||||||
t.Fatalf("new test bot: %v", err)
|
t.Fatalf("new test bot: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
g.liveMu.Lock()
|
g.liveMu.Lock()
|
||||||
g.liveStopped = true
|
g.liveStopped = true
|
||||||
g.liveMu.Unlock()
|
g.liveMu.Unlock()
|
||||||
@@ -980,7 +980,7 @@ func TestLiveReplyMediaFallsBackToALinkOnFailure(t *testing.T) {
|
|||||||
t.Fatalf("new test bot: %v", err)
|
t.Fatalf("new test bot: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
live := g.newLiveReply(context.Background(), b, 7, 0, false)
|
live := g.newLiveReply(context.Background(), b, 7, 0, false)
|
||||||
t.Cleanup(live.stopRendering)
|
t.Cleanup(live.stopRendering)
|
||||||
live.interval = 0
|
live.interval = 0
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ func newTestMediaSender(t *testing.T, serverURL string, chatID int64, threadID i
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("new test bot: %v", err)
|
t.Fatalf("new test bot: %v", err)
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
return g.NewMediaSender(b, chatID, threadID)
|
return g.NewMediaSender(b, chatID, threadID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ func TestModelCommandShowsInlineSelector(t *testing.T) {
|
|||||||
}
|
}
|
||||||
router := gateway.NewRouter(nil, nil, "telegram")
|
router := gateway.NewRouter(nil, nil, "telegram")
|
||||||
router.Models = manager
|
router.Models = manager
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
g.defaultHandler(router)(context.Background(), b, &models.Update{
|
g.defaultHandler(router)(context.Background(), b, &models.Update{
|
||||||
@@ -194,7 +194,7 @@ func TestModelCommandDrillsFromProviderIntoFilteredModels(t *testing.T) {
|
|||||||
}
|
}
|
||||||
router := gateway.NewRouter(nil, nil, "telegram")
|
router := gateway.NewRouter(nil, nil, "telegram")
|
||||||
router.Models = manager
|
router.Models = manager
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
g.defaultHandler(router)(context.Background(), b, &models.Update{
|
g.defaultHandler(router)(context.Background(), b, &models.Update{
|
||||||
@@ -274,7 +274,7 @@ func TestModelSelectorKeyboardPageAcrossModelCounts(t *testing.T) {
|
|||||||
for i := 0; i < tt.count; i++ {
|
for i := 0; i < tt.count; i++ {
|
||||||
manager.models = append(manager.models, fmt.Sprintf("provider/model-%02d", i))
|
manager.models = append(manager.models, fmt.Sprintf("provider/model-%02d", i))
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{42}, slog.Default())
|
g := New("1:test", []int64{42}, slog.Default())
|
||||||
|
|
||||||
page := g.modelSelectorKeyboardPage(manager, "provider", 0)
|
page := g.modelSelectorKeyboardPage(manager, "provider", 0)
|
||||||
rows := page.InlineKeyboard
|
rows := page.InlineKeyboard
|
||||||
@@ -325,7 +325,7 @@ func TestModelSelectorPageCallbackAdvancesToNextPage(t *testing.T) {
|
|||||||
for i := 1; i <= 9; i++ {
|
for i := 1; i <= 9; i++ {
|
||||||
manager.models = append(manager.models, fmt.Sprintf("provider/model-%02d", i))
|
manager.models = append(manager.models, fmt.Sprintf("provider/model-%02d", i))
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{42}, slog.Default())
|
g := New("1:test", []int64{42}, slog.Default())
|
||||||
|
|
||||||
first := g.modelSelectorKeyboardPage(manager, "provider", 0)
|
first := g.modelSelectorKeyboardPage(manager, "provider", 0)
|
||||||
nav := first.InlineKeyboard[4]
|
nav := first.InlineKeyboard[4]
|
||||||
@@ -379,7 +379,7 @@ func TestProviderCallbackHonoursTheProviderRenderedInTheSelector(t *testing.T) {
|
|||||||
}
|
}
|
||||||
router := gateway.NewRouter(nil, nil, "telegram")
|
router := gateway.NewRouter(nil, nil, "telegram")
|
||||||
router.Models = manager
|
router.Models = manager
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
b, _ := newTelegramTestBot(t)
|
b, _ := newTelegramTestBot(t)
|
||||||
|
|
||||||
markup := g.providerSelectorKeyboard(manager)
|
markup := g.providerSelectorKeyboard(manager)
|
||||||
@@ -405,7 +405,7 @@ func TestModelCallbackSwitchesAndUpdatesSelector(t *testing.T) {
|
|||||||
}
|
}
|
||||||
router := gateway.NewRouter(nil, nil, "telegram")
|
router := gateway.NewRouter(nil, nil, "telegram")
|
||||||
router.Models = manager
|
router.Models = manager
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
g.defaultHandler(router)(context.Background(), b, &models.Update{
|
g.defaultHandler(router)(context.Background(), b, &models.Update{
|
||||||
@@ -451,7 +451,7 @@ func TestDirectModelSelectionWithProviderIsAtomicOnFailure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
router := gateway.NewRouter(nil, nil, "telegram")
|
router := gateway.NewRouter(nil, nil, "telegram")
|
||||||
router.Models = manager
|
router.Models = manager
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
b, _ := newTelegramTestBot(t)
|
b, _ := newTelegramTestBot(t)
|
||||||
|
|
||||||
g.handleModelCommand(context.Background(), b, &models.Message{
|
g.handleModelCommand(context.Background(), b, &models.Message{
|
||||||
@@ -467,7 +467,7 @@ func TestDirectModelSelectionWithProviderIsAtomicOnFailure(t *testing.T) {
|
|||||||
|
|
||||||
func TestModelPageIndicatorCallbackIsAnswered(t *testing.T) {
|
func TestModelPageIndicatorCallbackIsAnswered(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
g.defaultHandler(gateway.NewRouter(nil, nil, "telegram"))(context.Background(), b, &models.Update{
|
g.defaultHandler(gateway.NewRouter(nil, nil, "telegram"))(context.Background(), b, &models.Update{
|
||||||
@@ -489,7 +489,7 @@ func TestModelCallbackHonoursTheModelRenderedInTheSelector(t *testing.T) {
|
|||||||
}
|
}
|
||||||
router := gateway.NewRouter(nil, nil, "telegram")
|
router := gateway.NewRouter(nil, nil, "telegram")
|
||||||
router.Models = manager
|
router.Models = manager
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
b, _ := newTelegramTestBot(t)
|
b, _ := newTelegramTestBot(t)
|
||||||
|
|
||||||
markup := g.modelSelectorKeyboard(manager)
|
markup := g.modelSelectorKeyboard(manager)
|
||||||
@@ -528,7 +528,7 @@ func TestModelCallbackRejectsUnauthorizedAndMalformedSelections(t *testing.T) {
|
|||||||
}
|
}
|
||||||
router := gateway.NewRouter(nil, nil, "telegram")
|
router := gateway.NewRouter(nil, nil, "telegram")
|
||||||
router.Models = manager
|
router.Models = manager
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
g.defaultHandler(router)(context.Background(), b, &models.Update{
|
g.defaultHandler(router)(context.Background(), b, &models.Update{
|
||||||
@@ -574,7 +574,7 @@ func TestProviderCallbackRejectsUnauthorizedAndMalformedSelections(t *testing.T)
|
|||||||
}
|
}
|
||||||
router := gateway.NewRouter(nil, nil, "telegram")
|
router := gateway.NewRouter(nil, nil, "telegram")
|
||||||
router.Models = manager
|
router.Models = manager
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
g.defaultHandler(router)(context.Background(), b, &models.Update{
|
g.defaultHandler(router)(context.Background(), b, &models.Update{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestRestartAcknowledgesArchie(t *testing.T) {
|
func TestRestartAcknowledgesArchie(t *testing.T) {
|
||||||
g := New("1:test", "", "", []int64{42}, slog.Default())
|
g := New("1:test", []int64{42}, slog.Default())
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
g.restartHandler()(context.Background(), b, &models.Update{Message: &models.Message{
|
g.restartHandler()(context.Background(), b, &models.Update{Message: &models.Message{
|
||||||
@@ -35,7 +35,7 @@ func TestRestartAcknowledgesArchie(t *testing.T) {
|
|||||||
// blocking: the handler runs on the very bot the supervisor is about to
|
// blocking: the handler runs on the very bot the supervisor is about to
|
||||||
// stop, so blocking there would deadlock the restart it just asked for.
|
// stop, so blocking there would deadlock the restart it just asked for.
|
||||||
func TestRestartRequestNeverBlocksHandler(t *testing.T) {
|
func TestRestartRequestNeverBlocksHandler(t *testing.T) {
|
||||||
g := New("tok", "", "", []int64{1}, slog.Default())
|
g := New("tok", []int64{1}, slog.Default())
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
@@ -61,7 +61,7 @@ func TestRestartRequestNeverBlocksHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRequestRestartQueuesScopedReload(t *testing.T) {
|
func TestRequestRestartQueuesScopedReload(t *testing.T) {
|
||||||
g := New("tok", "", "", []int64{1}, slog.Default())
|
g := New("tok", []int64{1}, slog.Default())
|
||||||
if err := g.RequestRestart(); err != nil {
|
if err := g.RequestRestart(); err != nil {
|
||||||
t.Fatalf("RequestRestart: %v", err)
|
t.Fatalf("RequestRestart: %v", err)
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ func TestRequestRestartQueuesScopedReload(t *testing.T) {
|
|||||||
// A failing Reload must not be fatal: a bad config edit should leave the
|
// 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.
|
// gateway running on its previous settings, not take chat down for good.
|
||||||
func TestReloadFailureKeepsPreviousSettings(t *testing.T) {
|
func TestReloadFailureKeepsPreviousSettings(t *testing.T) {
|
||||||
g := New("original-token", "", "", []int64{1}, slog.Default())
|
g := New("original-token", []int64{1}, slog.Default())
|
||||||
g.Reload = func(*Gateway) error { return errReloadTest }
|
g.Reload = func(*Gateway) error { return errReloadTest }
|
||||||
|
|
||||||
if err := g.Reload(g); err == nil {
|
if err := g.Reload(g); err == nil {
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ import (
|
|||||||
|
|
||||||
// Gateway is a Telegram gateway.Gateway backed by go-telegram/bot.
|
// Gateway is a Telegram gateway.Gateway backed by go-telegram/bot.
|
||||||
type Gateway struct {
|
type Gateway struct {
|
||||||
Token string
|
Token string
|
||||||
WebhookURL string
|
|
||||||
WebhookSecret string
|
|
||||||
// AllowedUserIDs lists the Telegram user IDs allowed to use the bot,
|
// AllowedUserIDs lists the Telegram user IDs allowed to use the bot,
|
||||||
// matched against the sender rather than the chat so the bot cannot be
|
// matched against the sender rather than the chat so the bot cannot be
|
||||||
// reached by adding it to a group. Empty denies everyone: a bot handle
|
// reached by adding it to a group. Empty denies everyone: a bot handle
|
||||||
@@ -132,10 +130,9 @@ type Gateway struct {
|
|||||||
// false at the start of the next launch.
|
// false at the start of the next launch.
|
||||||
liveStopped bool
|
liveStopped bool
|
||||||
|
|
||||||
log *slog.Logger
|
log *slog.Logger
|
||||||
bot *bot.Bot
|
bot *bot.Bot
|
||||||
webhookCancel context.CancelFunc
|
running bool
|
||||||
running bool
|
|
||||||
|
|
||||||
// serverURL redirects the Bot API at a test server. Empty in production,
|
// serverURL redirects the Bot API at a test server. Empty in production,
|
||||||
// where the library's default endpoint is used. It exists so launch's
|
// where the library's default endpoint is used. It exists so launch's
|
||||||
@@ -158,13 +155,10 @@ type ReleaseAnnouncer interface {
|
|||||||
) error
|
) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns an unstarted Gateway. Call Start to begin webhook
|
// New returns an unstarted Gateway. Call Start to begin long-polling.
|
||||||
// processing.
|
func New(token string, allowedUserIDs []int64, log *slog.Logger) *Gateway {
|
||||||
func New(token, webhookURL, webhookSecret string, allowedUserIDs []int64, log *slog.Logger) *Gateway {
|
|
||||||
return &Gateway{
|
return &Gateway{
|
||||||
Token: token,
|
Token: token,
|
||||||
WebhookURL: webhookURL,
|
|
||||||
WebhookSecret: webhookSecret,
|
|
||||||
AllowedUserIDs: allowedUserIDs,
|
AllowedUserIDs: allowedUserIDs,
|
||||||
restartCh: make(chan restartRequest, 1),
|
restartCh: make(chan restartRequest, 1),
|
||||||
modelCallbacks: make(map[string]string),
|
modelCallbacks: make(map[string]string),
|
||||||
@@ -270,49 +264,16 @@ func (g *Gateway) registerCommandHandlers(b *bot.Bot, router *gateway.Router) {
|
|||||||
b.RegisterHandler(bot.HandlerTypeMessageText, "/deny", bot.MatchTypeExact, g.denyHandler())
|
b.RegisterHandler(bot.HandlerTypeMessageText, "/deny", bot.MatchTypeExact, g.denyHandler())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Gateway) startListening(ctx context.Context, b *bot.Bot, lifecycle gateway.Lifecycle) error {
|
func (g *Gateway) startListening(ctx context.Context, b *bot.Bot, _ gateway.Lifecycle) error {
|
||||||
if g.WebhookURL != "" {
|
g.dropPendingUpdates(ctx, b)
|
||||||
params := &bot.SetWebhookParams{
|
g.running = true
|
||||||
URL: g.WebhookURL,
|
go b.Start(ctx)
|
||||||
SecretToken: g.WebhookSecret,
|
|
||||||
MaxConnections: 40,
|
|
||||||
AllowedUpdates: []string{"message", "callback_query"},
|
|
||||||
DropPendingUpdates: true,
|
|
||||||
}
|
|
||||||
if _, err := b.SetWebhook(ctx, params); err != nil {
|
|
||||||
return fmt.Errorf("set webhook: %w", err)
|
|
||||||
}
|
|
||||||
g.log.Info("webhook set", "url", g.WebhookURL)
|
|
||||||
|
|
||||||
info, err := b.GetWebhookInfo(ctx)
|
|
||||||
if err != nil {
|
|
||||||
g.log.Warn("failed to get webhook info", "error", err)
|
|
||||||
} else {
|
|
||||||
g.log.Info(
|
|
||||||
"webhook info",
|
|
||||||
"url", info.URL,
|
|
||||||
"pending_update_count", info.PendingUpdateCount,
|
|
||||||
"last_error_message", info.LastErrorMessage,
|
|
||||||
"max_connections", info.MaxConnections,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
webhookCtx, cancel := context.WithCancel(ctx)
|
|
||||||
g.webhookCancel = cancel
|
|
||||||
g.running = true
|
|
||||||
go b.StartWebhook(webhookCtx)
|
|
||||||
lifecycle.ReportRunning()
|
|
||||||
} else {
|
|
||||||
g.dropPendingUpdates(ctx, b)
|
|
||||||
g.running = true
|
|
||||||
go b.Start(ctx)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// launch builds one bot instance, registers handlers and starts its delivery
|
// launch builds one bot instance, registers handlers and starts its
|
||||||
// worker. Webhook readiness is synchronous; long-poll readiness is reported by
|
// long-poll delivery worker. Readiness is reported by pollReadinessClient
|
||||||
// pollReadinessClient after the first successful getUpdates response.
|
// after the first successful getUpdates response.
|
||||||
func (g *Gateway) launch(ctx context.Context, router *gateway.Router, lifecycle gateway.Lifecycle) (*bot.Bot, error) {
|
func (g *Gateway) launch(ctx context.Context, router *gateway.Router, lifecycle gateway.Lifecycle) (*bot.Bot, error) {
|
||||||
// Turns are per-launch. Each queued turn carries the update handler's
|
// Turns are per-launch. Each queued turn carries the update handler's
|
||||||
// context, which is this launch's, so a /restart cancels everything
|
// context, which is this launch's, so a /restart cancels everything
|
||||||
@@ -327,15 +288,10 @@ func (g *Gateway) launch(ctx context.Context, router *gateway.Router, lifecycle
|
|||||||
}),
|
}),
|
||||||
bot.WithDefaultHandler(g.defaultHandler(router)),
|
bot.WithDefaultHandler(g.defaultHandler(router)),
|
||||||
bot.WithMiddlewares(g.panicRecoveryMiddleware(), g.updateLoggingMiddleware()),
|
bot.WithMiddlewares(g.panicRecoveryMiddleware(), g.updateLoggingMiddleware()),
|
||||||
}
|
bot.WithHTTPClient(telegramPollTimeout, &pollReadinessClient{
|
||||||
if g.WebhookSecret != "" {
|
|
||||||
opts = append(opts, bot.WithWebhookSecretToken(g.WebhookSecret))
|
|
||||||
}
|
|
||||||
if g.WebhookURL == "" {
|
|
||||||
opts = append(opts, bot.WithHTTPClient(telegramPollTimeout, &pollReadinessClient{
|
|
||||||
client: &http.Client{Timeout: telegramPollTimeout},
|
client: &http.Client{Timeout: telegramPollTimeout},
|
||||||
onRunning: lifecycle.ReportRunning,
|
onRunning: lifecycle.ReportRunning,
|
||||||
}))
|
}),
|
||||||
}
|
}
|
||||||
if g.serverURL != "" {
|
if g.serverURL != "" {
|
||||||
opts = append(opts, bot.WithServerURL(g.serverURL), bot.WithSkipGetMe())
|
opts = append(opts, bot.WithServerURL(g.serverURL), bot.WithSkipGetMe())
|
||||||
@@ -410,7 +366,7 @@ func (g *Gateway) announceRelease(ctx context.Context, b *bot.Bot) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop gracefully shuts down the bot and deletes the webhook.
|
// Stop gracefully shuts down the bot.
|
||||||
func (g *Gateway) Stop(ctx context.Context) error {
|
func (g *Gateway) Stop(ctx context.Context) error {
|
||||||
if !g.running {
|
if !g.running {
|
||||||
return nil
|
return nil
|
||||||
@@ -420,28 +376,9 @@ func (g *Gateway) Stop(ctx context.Context) error {
|
|||||||
|
|
||||||
g.abandonAllLive(ctx)
|
g.abandonAllLive(ctx)
|
||||||
|
|
||||||
if g.webhookCancel != nil {
|
|
||||||
g.webhookCancel()
|
|
||||||
g.webhookCancel = nil
|
|
||||||
}
|
|
||||||
if g.WebhookURL != "" && g.bot != nil {
|
|
||||||
if _, err := g.bot.DeleteWebhook(ctx, &bot.DeleteWebhookParams{DropPendingUpdates: true}); err != nil {
|
|
||||||
g.log.Warn("error deleting webhook", "error", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebhookHandler returns the HTTP handler for Telegram webhooks.
|
|
||||||
func (g *Gateway) WebhookHandler() http.Handler {
|
|
||||||
if g.bot == nil {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
http.Error(w, "bot not initialized", http.StatusServiceUnavailable)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return g.bot.WebhookHandler()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── command handlers (gateway-local -- no LLM) ────────────────
|
// ── command handlers (gateway-local -- no LLM) ────────────────
|
||||||
|
|
||||||
func (g *Gateway) statusHandler(router *gateway.Router) bot.HandlerFunc {
|
func (g *Gateway) statusHandler(router *gateway.Router) bot.HandlerFunc {
|
||||||
@@ -904,14 +841,6 @@ func (g *Gateway) ConfigSchema() json.RawMessage {
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Environment variable holding the Telegram bot token from @BotFather"
|
"description": "Environment variable holding the Telegram bot token from @BotFather"
|
||||||
},
|
},
|
||||||
"webhook_url": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Public HTTPS URL for Telegram webhook delivery"
|
|
||||||
},
|
|
||||||
"webhook_secret": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Secret token for webhook validation"
|
|
||||||
},
|
|
||||||
"allowed_chat_ids": {
|
"allowed_chat_ids": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": { "type": "integer" },
|
"items": { "type": "integer" },
|
||||||
|
|||||||
@@ -19,20 +19,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestName(t *testing.T) {
|
func TestName(t *testing.T) {
|
||||||
g := New("token", "", "", nil, slog.Default())
|
g := New("token", nil, slog.Default())
|
||||||
if got := g.Name(); got != "telegram" {
|
if got := g.Name(); got != "telegram" {
|
||||||
t.Errorf("Name() = %q, want telegram", got)
|
t.Errorf("Name() = %q, want telegram", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewStoresFields(t *testing.T) {
|
func TestNewStoresFields(t *testing.T) {
|
||||||
g := New("abc123", "https://example.com/webhook", "secret", []int64{42}, slog.Default())
|
g := New("abc123", []int64{42}, slog.Default())
|
||||||
if g.Token != "abc123" {
|
if g.Token != "abc123" {
|
||||||
t.Errorf("Token = %q", g.Token)
|
t.Errorf("Token = %q", g.Token)
|
||||||
}
|
}
|
||||||
if g.WebhookURL != "https://example.com/webhook" {
|
|
||||||
t.Errorf("WebhookURL = %q", g.WebhookURL)
|
|
||||||
}
|
|
||||||
if len(g.AllowedUserIDs) != 1 || g.AllowedUserIDs[0] != 42 {
|
if len(g.AllowedUserIDs) != 1 || g.AllowedUserIDs[0] != 42 {
|
||||||
t.Errorf("AllowedUserIDs = %v", g.AllowedUserIDs)
|
t.Errorf("AllowedUserIDs = %v", g.AllowedUserIDs)
|
||||||
}
|
}
|
||||||
@@ -67,7 +64,7 @@ func TestHelpDescribesPublishedCommandsAndChat(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("new test bot: %v", err)
|
t.Fatalf("new test bot: %v", err)
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.helpHandler()(context.Background(), b, &models.Update{
|
g.helpHandler()(context.Background(), b, &models.Update{
|
||||||
Message: &models.Message{
|
Message: &models.Message{
|
||||||
From: &models.User{ID: allowedUserID},
|
From: &models.User{ID: allowedUserID},
|
||||||
@@ -133,7 +130,7 @@ func TestCommandSurfaceUsesOneModelSelectorAndUsefulHelpCopy(t *testing.T) {
|
|||||||
|
|
||||||
func TestStartHasDeterministicGatewayResponse(t *testing.T) {
|
func TestStartHasDeterministicGatewayResponse(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
g.startHandler()(context.Background(), b, &models.Update{
|
g.startHandler()(context.Background(), b, &models.Update{
|
||||||
@@ -158,7 +155,7 @@ func TestStartHasDeterministicGatewayResponse(t *testing.T) {
|
|||||||
|
|
||||||
func TestVersionReportsBothComponents(t *testing.T) {
|
func TestVersionReportsBothComponents(t *testing.T) {
|
||||||
const allowedUserID = int64(42)
|
const allowedUserID = int64(42)
|
||||||
g := New("1:test", "", "", []int64{allowedUserID}, slog.Default())
|
g := New("1:test", []int64{allowedUserID}, slog.Default())
|
||||||
g.Version = func() string { return "Archie\nGateway: v1.2.3\nRuntime: v4.5.6" }
|
g.Version = func() string { return "Archie\nGateway: v1.2.3\nRuntime: v4.5.6" }
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -194,7 +191,7 @@ func (s *releaseAnnouncerStub) Announce(
|
|||||||
func TestReleaseAnnouncementTargetsAuthorizedUsers(t *testing.T) {
|
func TestReleaseAnnouncementTargetsAuthorizedUsers(t *testing.T) {
|
||||||
const message = "Archie has just been updated to v0.2.0"
|
const message = "Archie has just been updated to v0.2.0"
|
||||||
announcer := &releaseAnnouncerStub{message: message}
|
announcer := &releaseAnnouncerStub{message: message}
|
||||||
g := New("1:test", "", "", []int64{7, 8}, slog.Default())
|
g := New("1:test", []int64{7, 8}, slog.Default())
|
||||||
g.ReleaseAnnouncements = announcer
|
g.ReleaseAnnouncements = announcer
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -217,10 +214,10 @@ func TestReleaseAnnouncementTargetsAuthorizedUsers(t *testing.T) {
|
|||||||
// The allowlist must fail closed: a bot handle is public, so an unset
|
// The allowlist must fail closed: a bot handle is public, so an unset
|
||||||
// allowlist has to deny rather than admit everyone.
|
// allowlist has to deny rather than admit everyone.
|
||||||
func TestSenderAllowlistFailsClosed(t *testing.T) {
|
func TestSenderAllowlistFailsClosed(t *testing.T) {
|
||||||
if New("t", "", "", nil, slog.Default()).isSenderAllowed(100000000) {
|
if New("t", nil, slog.Default()).isSenderAllowed(100000000) {
|
||||||
t.Error("empty allowlist must deny every sender")
|
t.Error("empty allowlist must deny every sender")
|
||||||
}
|
}
|
||||||
g := New("t", "", "", []int64{100000000}, slog.Default())
|
g := New("t", []int64{100000000}, slog.Default())
|
||||||
if !g.isSenderAllowed(100000000) {
|
if !g.isSenderAllowed(100000000) {
|
||||||
t.Error("listed sender must be allowed")
|
t.Error("listed sender must be allowed")
|
||||||
}
|
}
|
||||||
@@ -230,7 +227,7 @@ func TestSenderAllowlistFailsClosed(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStartWithoutToken(t *testing.T) {
|
func TestStartWithoutToken(t *testing.T) {
|
||||||
g := New("", "", "", nil, slog.Default())
|
g := New("", nil, slog.Default())
|
||||||
router := gateway.NewRouter(nil, nil, "telegram")
|
router := gateway.NewRouter(nil, nil, "telegram")
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -263,7 +260,7 @@ func TestStartReportsRunningAfterLaunch(t *testing.T) {
|
|||||||
}))
|
}))
|
||||||
defer api.Close()
|
defer api.Close()
|
||||||
|
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
g.serverURL = api.URL
|
g.serverURL = api.URL
|
||||||
ctx, cancel := context.WithCancel(t.Context())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
started := make(chan bool, 1)
|
started := make(chan bool, 1)
|
||||||
@@ -310,7 +307,7 @@ func TestStartReportsStartingOnRestart(t *testing.T) {
|
|||||||
}))
|
}))
|
||||||
defer api.Close()
|
defer api.Close()
|
||||||
|
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
g.serverURL = api.URL
|
g.serverURL = api.URL
|
||||||
ctx, cancel := context.WithCancel(t.Context())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
events := make(chan string, 4)
|
events := make(chan string, 4)
|
||||||
@@ -348,15 +345,6 @@ func wantEvent(t *testing.T, events <-chan string, want string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWebhookHandlerReturns503WhenNotStarted(t *testing.T) {
|
|
||||||
g := New("token", "", "", nil, slog.Default())
|
|
||||||
rec := httptest.NewRecorder()
|
|
||||||
g.WebhookHandler().ServeHTTP(rec, httptest.NewRequestWithContext(context.Background(), http.MethodPost, "/", nil))
|
|
||||||
if rec.Code != http.StatusServiceUnavailable {
|
|
||||||
t.Errorf("status = %d, want 503", rec.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStartAndStopLifecycle(t *testing.T) {
|
func TestStartAndStopLifecycle(t *testing.T) {
|
||||||
// Use a noop webhook server so the bot can initialize without hitting
|
// Use a noop webhook server so the bot can initialize without hitting
|
||||||
// the real Telegram API.
|
// the real Telegram API.
|
||||||
@@ -367,7 +355,7 @@ func TestStartAndStopLifecycle(t *testing.T) {
|
|||||||
defer api.Close()
|
defer api.Close()
|
||||||
|
|
||||||
log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelWarn}))
|
log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelWarn}))
|
||||||
g := New("test-token", "", "", nil, log)
|
g := New("test-token", nil, log)
|
||||||
|
|
||||||
// Override the API base URL -- the go-telegram/bot library uses
|
// Override the API base URL -- the go-telegram/bot library uses
|
||||||
// https://api.telegram.org by default. We want it to hit our test
|
// https://api.telegram.org by default. We want it to hit our test
|
||||||
@@ -405,10 +393,10 @@ var (
|
|||||||
// ── Regression tests for previously untested paths ────────────────────
|
// ── Regression tests for previously untested paths ────────────────────
|
||||||
|
|
||||||
func TestIsSenderAllowed(t *testing.T) {
|
func TestIsSenderAllowed(t *testing.T) {
|
||||||
g := New("tok", "", "", []int64{100, 200, 300}, slog.Default())
|
g := New("tok", []int64{100, 200, 300}, slog.Default())
|
||||||
|
|
||||||
t.Run("empty allowlist denies all", func(t *testing.T) {
|
t.Run("empty allowlist denies all", func(t *testing.T) {
|
||||||
g2 := New("tok", "", "", nil, slog.Default())
|
g2 := New("tok", nil, slog.Default())
|
||||||
if g2.isSenderAllowed(999999) {
|
if g2.isSenderAllowed(999999) {
|
||||||
t.Error("empty allowlist must deny every sender, not admit them")
|
t.Error("empty allowlist must deny every sender, not admit them")
|
||||||
}
|
}
|
||||||
@@ -429,7 +417,7 @@ func TestIsSenderAllowed(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("zero and negative ids", func(t *testing.T) {
|
t.Run("zero and negative ids", func(t *testing.T) {
|
||||||
g3 := New("tok", "", "", []int64{-1, 0, 1}, slog.Default())
|
g3 := New("tok", []int64{-1, 0, 1}, slog.Default())
|
||||||
if !g3.isSenderAllowed(-1) || !g3.isSenderAllowed(0) {
|
if !g3.isSenderAllowed(-1) || !g3.isSenderAllowed(0) {
|
||||||
t.Error("explicitly listed -1 and 0 should be allowed")
|
t.Error("explicitly listed -1 and 0 should be allowed")
|
||||||
}
|
}
|
||||||
@@ -486,7 +474,7 @@ func TestUpdateMetadata(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPanicRecoveryMiddlewareDoesNotCrash(t *testing.T) {
|
func TestPanicRecoveryMiddlewareDoesNotCrash(t *testing.T) {
|
||||||
g := New("tok", "", "", nil, slog.Default())
|
g := New("tok", nil, slog.Default())
|
||||||
mw := g.panicRecoveryMiddleware()
|
mw := g.panicRecoveryMiddleware()
|
||||||
handler := mw(func(ctx context.Context, b *bot.Bot, update *models.Update) {
|
handler := mw(func(ctx context.Context, b *bot.Bot, update *models.Update) {
|
||||||
panic("test panic")
|
panic("test panic")
|
||||||
@@ -499,7 +487,7 @@ func TestPanicRecoveryMiddlewareDoesNotCrash(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateLoggingMiddlewareCallsInner(t *testing.T) {
|
func TestUpdateLoggingMiddlewareCallsInner(t *testing.T) {
|
||||||
g := New("tok", "", "", nil, slog.Default())
|
g := New("tok", nil, slog.Default())
|
||||||
mw := g.updateLoggingMiddleware()
|
mw := g.updateLoggingMiddleware()
|
||||||
called := false
|
called := false
|
||||||
handler := mw(func(ctx context.Context, b *bot.Bot, update *models.Update) {
|
handler := mw(func(ctx context.Context, b *bot.Bot, update *models.Update) {
|
||||||
@@ -515,7 +503,7 @@ func TestUpdateLoggingMiddlewareCallsInner(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAuthorizedMessageNilMessage(t *testing.T) {
|
func TestAuthorizedMessageNilMessage(t *testing.T) {
|
||||||
g := New("tok", "", "", []int64{42}, slog.Default())
|
g := New("tok", []int64{42}, slog.Default())
|
||||||
msg, ok := g.authorizedMessage(context.Background(), nil, &models.Update{ID: 1})
|
msg, ok := g.authorizedMessage(context.Background(), nil, &models.Update{ID: 1})
|
||||||
if ok || msg != nil {
|
if ok || msg != nil {
|
||||||
t.Error("nil message should return false, nil")
|
t.Error("nil message should return false, nil")
|
||||||
@@ -523,7 +511,7 @@ func TestAuthorizedMessageNilMessage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGatewayStopWhenNotRunning(t *testing.T) {
|
func TestGatewayStopWhenNotRunning(t *testing.T) {
|
||||||
g := New("tok", "", "", nil, slog.Default())
|
g := New("tok", nil, slog.Default())
|
||||||
if err := g.Stop(context.Background()); err != nil {
|
if err := g.Stop(context.Background()); err != nil {
|
||||||
t.Errorf("unexpected error stopping unstarted gateway: %v", err)
|
t.Errorf("unexpected error stopping unstarted gateway: %v", err)
|
||||||
}
|
}
|
||||||
@@ -573,7 +561,7 @@ func TestDropPendingUpdatesClearsTheBacklog(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("new test bot: %v", err)
|
t.Fatalf("new test bot: %v", err)
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
g.dropPendingUpdates(context.Background(), b)
|
g.dropPendingUpdates(context.Background(), b)
|
||||||
|
|
||||||
if !strings.Contains(gotPath, "deleteWebhook") {
|
if !strings.Contains(gotPath, "deleteWebhook") {
|
||||||
@@ -599,7 +587,7 @@ func TestDropPendingUpdatesSurvivesAPIFailure(t *testing.T) {
|
|||||||
t.Fatalf("new test bot: %v", err)
|
t.Fatalf("new test bot: %v", err)
|
||||||
}
|
}
|
||||||
var logged strings.Builder
|
var logged strings.Builder
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.NewTextHandler(&logged, nil)))
|
g := New("1:test", []int64{42}, slog.New(slog.NewTextHandler(&logged, nil)))
|
||||||
g.dropPendingUpdates(context.Background(), b) // must not panic or block
|
g.dropPendingUpdates(context.Background(), b) // must not panic or block
|
||||||
|
|
||||||
if !strings.Contains(logged.String(), "could not drop pending telegram updates") {
|
if !strings.Contains(logged.String(), "could not drop pending telegram updates") {
|
||||||
@@ -625,7 +613,7 @@ func TestLaunchDropsPendingUpdatesBeforePolling(t *testing.T) {
|
|||||||
}))
|
}))
|
||||||
defer api.Close()
|
defer api.Close()
|
||||||
|
|
||||||
g := New("1:test", "", "", []int64{42}, slog.New(slog.DiscardHandler))
|
g := New("1:test", []int64{42}, slog.New(slog.DiscardHandler))
|
||||||
g.serverURL = api.URL
|
g.serverURL = api.URL
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
var errFixtureInstall = errors.New("build failed: exit status 1")
|
var errFixtureInstall = errors.New("build failed: exit status 1")
|
||||||
|
|
||||||
func TestUpdateShowsComponentSectionsAndActions(t *testing.T) {
|
func TestUpdateShowsComponentSectionsAndActions(t *testing.T) {
|
||||||
g := New("1:test", "", "", []int64{42}, slog.Default())
|
g := New("1:test", []int64{42}, slog.Default())
|
||||||
g.Updates = &updateStub{snapshot: releaseupdate.Snapshot{Components: []releaseupdate.Component{
|
g.Updates = &updateStub{snapshot: releaseupdate.Snapshot{Components: []releaseupdate.Component{
|
||||||
{ID: "gateway", Label: "THE GATEWAY", Installed: "v0.1.0", Available: "v0.1.1", Changelog: "- Clearer help"},
|
{ID: "gateway", Label: "THE GATEWAY", Installed: "v0.1.0", Available: "v0.1.1", Changelog: "- Clearer help"},
|
||||||
{ID: "runtime", Label: "THE RUNTIME", Installed: "v0.1.0"},
|
{ID: "runtime", Label: "THE RUNTIME", Installed: "v0.1.0"},
|
||||||
@@ -47,7 +47,7 @@ func TestUpdateShowsComponentSectionsAndActions(t *testing.T) {
|
|||||||
// restarted yet when this message is sent, so it can only promise that the
|
// restarted yet when this message is sent, so it can only promise that the
|
||||||
// build/install step succeeded and a restart is queued.
|
// build/install step succeeded and a restart is queued.
|
||||||
func TestInstallUpdateStreamsProgressAndReportsSuccess(t *testing.T) {
|
func TestInstallUpdateStreamsProgressAndReportsSuccess(t *testing.T) {
|
||||||
g := New("1:test", "", "", []int64{42}, slog.Default())
|
g := New("1:test", []int64{42}, slog.Default())
|
||||||
stub := &updateStub{
|
stub := &updateStub{
|
||||||
progressText: []string{"==> fetching", "==> building"},
|
progressText: []string{"==> fetching", "==> building"},
|
||||||
result: releaseupdate.Result{
|
result: releaseupdate.Result{
|
||||||
@@ -88,7 +88,7 @@ func TestInstallUpdateStreamsProgressAndReportsSuccess(t *testing.T) {
|
|||||||
// because the reference script never reaches the restart step on a
|
// because the reference script never reaches the restart step on a
|
||||||
// non-zero exit.
|
// non-zero exit.
|
||||||
func TestInstallUpdateReportsBuildFailureWithoutClaimingRestart(t *testing.T) {
|
func TestInstallUpdateReportsBuildFailureWithoutClaimingRestart(t *testing.T) {
|
||||||
g := New("1:test", "", "", []int64{42}, slog.Default())
|
g := New("1:test", []int64{42}, slog.Default())
|
||||||
stub := &updateStub{installErr: errFixtureInstall}
|
stub := &updateStub{installErr: errFixtureInstall}
|
||||||
g.Updates = stub
|
g.Updates = stub
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
@@ -123,7 +123,7 @@ func TestReportPendingUpdateSendsAndClearsReport(t *testing.T) {
|
|||||||
if err := releaseupdate.WritePendingReport(path, report); err != nil {
|
if err := releaseupdate.WritePendingReport(path, report); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{42}, slog.Default())
|
g := New("1:test", []int64{42}, slog.Default())
|
||||||
g.UpdateReportPath = path
|
g.UpdateReportPath = path
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ func TestReportPendingUpdateClearsUnreadableReport(t *testing.T) {
|
|||||||
if err := os.WriteFile(path, []byte("{not valid json"), 0o600); err != nil {
|
if err := os.WriteFile(path, []byte("{not valid json"), 0o600); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
g := New("1:test", "", "", []int64{42}, slog.Default())
|
g := New("1:test", []int64{42}, slog.Default())
|
||||||
g.UpdateReportPath = path
|
g.UpdateReportPath = path
|
||||||
b, _ := newTelegramTestBot(t)
|
b, _ := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ func TestReportPendingUpdateClearsUnreadableReport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestReportPendingUpdateNoFileIsNoop(t *testing.T) {
|
func TestReportPendingUpdateNoFileIsNoop(t *testing.T) {
|
||||||
g := New("1:test", "", "", []int64{42}, slog.Default())
|
g := New("1:test", []int64{42}, slog.Default())
|
||||||
g.UpdateReportPath = filepath.Join(t.TempDir(), "does-not-exist.json")
|
g.UpdateReportPath = filepath.Join(t.TempDir(), "does-not-exist.json")
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ func TestReportPendingUpdateNoFileIsNoop(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestReportPendingUpdateDisabledWhenPathEmpty(t *testing.T) {
|
func TestReportPendingUpdateDisabledWhenPathEmpty(t *testing.T) {
|
||||||
g := New("1:test", "", "", []int64{42}, slog.Default())
|
g := New("1:test", []int64{42}, slog.Default())
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
g.reportPendingUpdate(context.Background(), b)
|
g.reportPendingUpdate(context.Background(), b)
|
||||||
@@ -375,7 +375,7 @@ func TestFormatPendingReportDistinguishesUnrolledBackFailure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateCallbackRejectsUnauthorizedSender(t *testing.T) {
|
func TestUpdateCallbackRejectsUnauthorizedSender(t *testing.T) {
|
||||||
g := New("1:test", "", "", []int64{42}, slog.Default())
|
g := New("1:test", []int64{42}, slog.Default())
|
||||||
g.Updates = &updateStub{}
|
g.Updates = &updateStub{}
|
||||||
b, requests := newTelegramTestBot(t)
|
b, requests := newTelegramTestBot(t)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user