(new): PollTimeout config, RateLimiter.Cleanup
(fix): compact payload escape, Draft.push validation, plugin logger ownership, worker StopAndWait, getChatLimiter deadlock, runner ctx-after-tick (refactor): remove NewPayload, buildSceneKey from sceneRuntime, unify ToJSON fallback (tests): compact round-trip, Draft.push state, RateLimiter.Cleanup eviction (doc): changelog v1.0.0 rewrite, NewCommand dual-use godoc
This commit is contained in:
+19
-1
@@ -19,7 +19,7 @@ func TestDraftFlushRequiresChatID(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMsgContextNewDraftWorksWithoutLimiter(t *testing.T) {
|
||||
ctx := &MsgContext{
|
||||
ctx := &MessageContext{
|
||||
API: &tgapi.API{},
|
||||
Msg: &tgapi.Message{
|
||||
Chat: &tgapi.Chat{ID: 42, Type: tgapi.ChatTypePrivate},
|
||||
@@ -31,6 +31,7 @@ func TestMsgContextNewDraftWorksWithoutLimiter(t *testing.T) {
|
||||
draft := ctx.NewDraft()
|
||||
if draft == nil {
|
||||
t.Fatal("expected draft")
|
||||
return
|
||||
}
|
||||
if draft.chatID != 42 {
|
||||
t.Fatalf("unexpected chat id: %d", draft.chatID)
|
||||
@@ -53,3 +54,20 @@ func TestDraftPushRejectsLongMessage(t *testing.T) {
|
||||
t.Fatalf("expected ErrMessageTooLong, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDraftPushLeavesMessageUnchangedOnValidationFailure covers the validation
|
||||
// order fix: when the candidate Message (current + new text) overflows the
|
||||
// Telegram limit, the existing Message must remain intact so callers can
|
||||
// recover and retry with a shorter payload instead of finding the draft in
|
||||
// a half-mutated state.
|
||||
func TestDraftPushLeavesMessageUnchangedOnValidationFailure(t *testing.T) {
|
||||
draft := NewRandomDraftProvider(&tgapi.API{}).NewDraft(tgapi.ParseNone).SetChat(42, 0)
|
||||
draft.Message = "hello"
|
||||
|
||||
if err := draft.Push(strings.Repeat("a", maxMessageTextLen+1)); !errors.Is(err, ErrMessageTooLong) {
|
||||
t.Fatalf("expected ErrMessageTooLong, got %v", err)
|
||||
}
|
||||
if draft.Message != "hello" {
|
||||
t.Fatalf("expected draft Message to stay %q, got %q", "hello", draft.Message)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user