Skip to content

Commit dbd1940

Browse files
Szercursoragent
andauthored
Fix flaky test: auto-generated IDs colliding with hardcoded vahter IDs (#112)
The shared ID counter in TgMessageUtils started at 1, so auto-generated user IDs could reach 34 or 69 (the hardcoded vahter IDs). When this happened, isBanAuthorized silently rejected the ban (can't ban a vahter), causing "Vahter can unban user" to fail intermittently depending on test collection execution order. Fix: - Bump counter start to 100000 to avoid all hardcoded IDs - Add /unbanChatMember to FakeTgApi (was returning 500) - Add verbose console logger to CI so test execution order is visible Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 55acbef commit dbd1940

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
with:
2020
global-json-file: global.json
2121
- name: Tests
22-
run: dotnet test -c Release --logger "trx;LogFileName=test-results.trx"
22+
run: dotnet test -c Release --logger "trx;LogFileName=test-results.trx" --logger "console;verbosity=detailed"
2323

2424
# upload test results
2525
- name: Upload dotnet test results

src/VahterBanBot.Tests/TgMessageUtils.fs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ open Telegram.Bot.Types
66
open Telegram.Bot.Types.Enums
77

88
type Tg() =
9-
static let mutable i = 1L // higher than the data in the test_seed.sql
9+
// Start well above all hardcoded IDs used in tests and config to prevent
10+
// auto-generated user/message/chat IDs from colliding with them:
11+
// Vahter IDs: 34, 69 (ALLOWED_USERS) — collision makes isBanAuthorized reject bans silently
12+
// FakeTgApi admin: 42 (/getChatAdministrators)
13+
// Bot user ID: 1337 (BOT_USER_ID)
14+
// Seed user IDs: 1001-1010 (test_seed.sql)
15+
// Seed message IDs: 10001-10499 (test_seed.sql)
16+
static let mutable i = 100_000L
1017
static let nextInt64() = Interlocked.Increment &i
1118
static let next() = nextInt64() |> int
1219
static member user (?id: int64, ?username: string, ?firstName: string) =

src/VahterBanBot/FakeTgApi.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let fakeTgApi (botConf: BotConfiguration) (request: HttpRequestMessage) =
5151
resp.Content <- new ByteArrayContent(content)
5252
resp.Content.Headers.ContentType <- MediaTypeHeaderValue("application/octet-stream")
5353
resp
54-
elif url.EndsWith "/deleteMessage" || url.EndsWith "/banChatMember" then
54+
elif url.EndsWith "/deleteMessage" || url.EndsWith "/banChatMember" || url.EndsWith "/unbanChatMember" then
5555
// respond with "true"
5656
apiResult "true"
5757
elif url.EndsWith "/sendMessage" then

0 commit comments

Comments
 (0)