@@ -2,7 +2,7 @@ import { isChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbou
22// Mattermost tests cover send plugin behavior.
33import { expectProvidedCfgSkipsRuntimeLoad } from "openclaw/plugin-sdk/channel-test-helpers" ;
44import { convertMarkdownTables } from "openclaw/plugin-sdk/text-chunking" ;
5- import { beforeEach , describe , expect , it , vi } from "vitest" ;
5+ import { beforeAll , beforeEach , describe , expect , it , vi } from "vitest" ;
66
77let sendMessageMattermost : typeof import ( "./send.js" ) . sendMessageMattermost ;
88let parseMattermostTarget : typeof import ( "./target-resolution.js" ) . parseMattermostTarget ;
@@ -226,16 +226,24 @@ vi.mock("../runtime.js", () => ({
226226 } ) ,
227227} ) ) ;
228228
229+ beforeAll ( async ( ) => {
230+ ( { sendMessageMattermost } = await import ( "./send.js" ) ) ;
231+ ( { parseMattermostTarget } = await import ( "./target-resolution.js" ) ) ;
232+ } ) ;
233+
229234describe ( "sendMessageMattermost" , ( ) => {
230- beforeEach ( async ( ) => {
231- vi . resetModules ( ) ;
235+ let defaultAccountSequence = 0 ;
236+
237+ beforeEach ( ( ) => {
232238 mockState . loadConfig . mockReset ( ) ;
233239 mockState . loadConfig . mockReturnValue ( { } ) ;
234240 mockState . recordActivity . mockReset ( ) ;
235241 mockState . resolveMattermostAccount . mockReset ( ) ;
242+ // Production caches are keyed by token; keep each test in its own real namespace.
243+ const cacheNamespace = `mattermost-cache-${ defaultAccountSequence ++ } ` ;
236244 mockState . resolveMattermostAccount . mockReturnValue ( {
237245 accountId : "default" ,
238- botToken : "bot-token" ,
246+ botToken : cacheNamespace ,
239247 baseUrl : "https://mattermost.example.com" ,
240248 config : { } ,
241249 } ) ;
@@ -257,8 +265,6 @@ describe("sendMessageMattermost", () => {
257265 mockState . fetchMattermostUserTeams . mockResolvedValue ( [ { id : "team-1" } ] ) ;
258266 mockState . fetchMattermostChannelByName . mockResolvedValue ( { id : "town-square" } ) ;
259267 mockState . uploadMattermostFile . mockResolvedValue ( { id : "file-1" } ) ;
260- ( { sendMessageMattermost } = await import ( "./send.js" ) ) ;
261- ( { parseMattermostTarget } = await import ( "./target-resolution.js" ) ) ;
262268 } ) ;
263269
264270 it ( "uses provided cfg and skips runtime loadConfig" , async ( ) => {
@@ -965,8 +971,7 @@ describe("sendMessageMattermost user-first resolution", () => {
965971describe ( "sendMessageMattermost outbound cache bounds" , ( ) => {
966972 const baseUrl = "https://mattermost.example.com" ;
967973
968- beforeEach ( async ( ) => {
969- vi . resetModules ( ) ;
974+ beforeEach ( ( ) => {
970975 vi . clearAllMocks ( ) ;
971976 mockState . resolveMattermostAccount . mockReturnValue ( {
972977 accountId : "default" ,
@@ -989,7 +994,6 @@ describe("sendMessageMattermost outbound cache bounds", () => {
989994 mockState . fetchMattermostChannelByName . mockImplementation (
990995 async ( _client , _teamId : string , name : string ) => ( { id : `channel-${ name } ` } ) ,
991996 ) ;
992- ( { sendMessageMattermost } = await import ( "./send.js" ) ) ;
993997 } ) ;
994998
995999 const send = async ( to : string , token : string ) =>
0 commit comments