11// Telegram tests cover probe plugin behavior.
22import { withFetchPreconnect } from "openclaw/plugin-sdk/test-env" ;
3- import { afterEach , describe , expect , it , vi , type Mock } from "vitest" ;
4- import { probeTelegram , resetTelegramProbeFetcherCacheForTests } from "./probe.js" ;
3+ import { afterEach , beforeEach , describe , expect , it , vi , type Mock } from "vitest" ;
4+ import { probeTelegram } from "./probe.js" ;
55
66const resolveTelegramTransport = vi . hoisted ( ( ) => vi . fn ( ) ) ;
77const makeProxyFetch = vi . hoisted ( ( ) => vi . fn ( ) ) ;
@@ -31,8 +31,9 @@ vi.mock("openclaw/plugin-sdk/response-limit-runtime", async (importOriginal) =>
3131} ) ;
3232
3333describe ( "probeTelegram retry logic" , ( ) => {
34- const token = "test-token" ;
3534 const timeoutMs = 5000 ;
35+ let tokenIndex = 0 ;
36+ let token = "" ;
3637 const originalFetch = global . fetch ;
3738 let forceFallbackMock : Mock ;
3839
@@ -92,11 +93,13 @@ describe("probeTelegram retry logic", () => {
9293 expect ( result . bot ?. username ) . toBe ( "test_bot" ) ;
9394 }
9495
96+ beforeEach ( ( ) => {
97+ token = `test-token-${ ++ tokenIndex } ` ;
98+ } ) ;
99+
95100 afterEach ( ( ) => {
96- resetTelegramProbeFetcherCacheForTests ( ) ;
97101 resolveTelegramTransport . mockReset ( ) ;
98102 makeProxyFetch . mockReset ( ) ;
99- vi . unstubAllEnvs ( ) ;
100103 vi . clearAllMocks ( ) ;
101104 if ( originalFetch ) {
102105 global . fetch = originalFetch ;
@@ -237,7 +240,7 @@ describe("probeTelegram retry logic", () => {
237240 allows_users_to_create_topics : false ,
238241 } ) ;
239242 expect ( fetchMock ) . toHaveBeenCalledTimes ( 1 ) ;
240- expect ( fetchMock . mock . calls . at ( 0 ) ?. [ 0 ] ) . toBe ( " https://api.telegram.org/bottest- token/getMe" ) ;
243+ expect ( fetchMock . mock . calls . at ( 0 ) ?. [ 0 ] ) . toBe ( ` https://api.telegram.org/bot ${ token } /getMe` ) ;
241244 } ) ;
242245
243246 it ( "uses resolver-scoped Telegram fetch with probe network options" , async ( ) => {
@@ -264,9 +267,6 @@ describe("probeTelegram retry logic", () => {
264267
265268 it ( "reuses probe fetcher across repeated probes for the same account transport settings" , async ( ) => {
266269 const fetchMock = installFetchMock ( ) ;
267- vi . stubEnv ( "VITEST" , "" ) ;
268- vi . stubEnv ( "NODE_ENV" , "production" ) ;
269-
270270 mockGetMeSuccess ( fetchMock ) ;
271271 mockGetWebhookInfoSuccess ( fetchMock ) ;
272272 await probeTelegram ( `${ token } -cache` , timeoutMs , {
@@ -290,9 +290,6 @@ describe("probeTelegram retry logic", () => {
290290
291291 it ( "does not reuse probe fetcher cache when network settings differ" , async ( ) => {
292292 const fetchMock = installFetchMock ( ) ;
293- vi . stubEnv ( "VITEST" , "" ) ;
294- vi . stubEnv ( "NODE_ENV" , "production" ) ;
295-
296293 mockGetMeSuccess ( fetchMock ) ;
297294 mockGetWebhookInfoSuccess ( fetchMock ) ;
298295 await probeTelegram ( `${ token } -cache-variant` , timeoutMs , {
@@ -327,9 +324,6 @@ describe("probeTelegram retry logic", () => {
327324 close,
328325 } ;
329326 } ) ;
330- vi . stubEnv ( "VITEST" , "" ) ;
331- vi . stubEnv ( "NODE_ENV" , "production" ) ;
332-
333327 for ( let i = 0 ; i < 65 ; i += 1 ) {
334328 mockGetMeSuccess ( fetchMock ) ;
335329 mockGetWebhookInfoSuccess ( fetchMock ) ;
@@ -349,9 +343,6 @@ describe("probeTelegram retry logic", () => {
349343
350344 it ( "reuses probe fetcher cache across token rotation when accountId is stable" , async ( ) => {
351345 const fetchMock = installFetchMock ( ) ;
352- vi . stubEnv ( "VITEST" , "" ) ;
353- vi . stubEnv ( "NODE_ENV" , "production" ) ;
354-
355346 mockGetMeSuccess ( fetchMock ) ;
356347 mockGetWebhookInfoSuccess ( fetchMock ) ;
357348 await probeTelegram ( `${ token } -old` , timeoutMs , {
0 commit comments