11// Msteams tests cover polls plugin behavior.
22import crypto from "node:crypto" ;
33import fs from "node:fs" ;
4- import os from "node:os" ;
54import path from "node:path" ;
65import {
76 createPluginStateKeyedStoreForTests ,
87 resetPluginStateStoreForTests ,
98} from "openclaw/plugin-sdk/plugin-state-test-runtime" ;
10- import { beforeEach , describe , expect , it } from "vitest" ;
9+ import { useAutoCleanupTempDirTracker } from "openclaw/plugin-sdk/test-env" ;
10+ import { afterAll , beforeEach , describe , expect , it } from "vitest" ;
1111import {
1212 buildMSTeamsPollCard ,
1313 createMSTeamsPollStoreState ,
@@ -17,6 +17,13 @@ import {
1717import { setMSTeamsRuntime } from "./runtime.js" ;
1818import { msteamsRuntimeStub } from "./test-support/runtime.js" ;
1919
20+ const tempDirs = useAutoCleanupTempDirTracker ( ( cleanup ) =>
21+ afterAll ( ( ) => {
22+ resetPluginStateStoreForTests ( ) ;
23+ cleanup ( ) ;
24+ } ) ,
25+ ) ;
26+
2027describe ( "msteams polls" , ( ) => {
2128 beforeEach ( ( ) => {
2229 resetPluginStateStoreForTests ( ) ;
@@ -50,7 +57,7 @@ describe("msteams polls", () => {
5057 } ) ;
5158
5259 it ( "stores and records poll votes" , async ( ) => {
53- const home = await fs . promises . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-msteams-polls-" ) ) ;
60+ const home = tempDirs . make ( "openclaw-msteams-polls-" ) ;
5461 const store = createMSTeamsPollStoreState ( { homedir : ( ) => home } ) ;
5562 await store . createPoll ( {
5663 id : "poll-2" ,
@@ -73,7 +80,7 @@ describe("msteams polls", () => {
7380 } ) ;
7481
7582 it ( "deduplicates selections before enforcing maxSelections" , async ( ) => {
76- const home = await fs . promises . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-msteams-polls-" ) ) ;
83+ const home = tempDirs . make ( "openclaw-msteams-polls-" ) ;
7784 const store = createMSTeamsPollStoreState ( { homedir : ( ) => home } ) ;
7885 await store . createPoll ( {
7986 id : "poll-dedupe" ,
@@ -103,7 +110,7 @@ describe("state poll store", () => {
103110 } ) ;
104111
105112 it ( "ignores legacy JSON polls at runtime" , async ( ) => {
106- const stateDir = await fs . promises . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-msteams-polls-" ) ) ;
113+ const stateDir = tempDirs . make ( "openclaw-msteams-polls-" ) ;
107114 const filePath = path . join ( stateDir , "msteams-polls.json" ) ;
108115 await fs . promises . writeFile (
109116 filePath ,
@@ -141,7 +148,7 @@ describe("state poll store", () => {
141148 } ) ;
142149
143150 it ( "hashes external poll ids before using plugin-state keys" , async ( ) => {
144- const stateDir = await fs . promises . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-msteams-polls-" ) ) ;
151+ const stateDir = tempDirs . make ( "openclaw-msteams-polls-" ) ;
145152 const store = createMSTeamsPollStoreState ( { stateDir } ) ;
146153 const longPollId = `poll-${ "x" . repeat ( 900 ) } ` ;
147154
@@ -165,7 +172,7 @@ describe("state poll store", () => {
165172 } ) ;
166173
167174 it ( "serializes concurrent votes for the same poll" , async ( ) => {
168- const stateDir = await fs . promises . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-msteams-polls-" ) ) ;
175+ const stateDir = tempDirs . make ( "openclaw-msteams-polls-" ) ;
169176 const store = createMSTeamsPollStoreState ( { stateDir } ) ;
170177 await store . createPoll ( {
171178 id : "poll-race" ,
@@ -193,7 +200,7 @@ describe("state poll store", () => {
193200 { selections : [ "0" , "1x" ] , expected : [ "0" ] } ,
194201 { selections : [ "+0" , "0x1" , "1" ] , expected : [ "0" , "1" ] } ,
195202 ] ) ( "accepts only strict decimal poll selections" , async ( { selections, expected } ) => {
196- const stateDir = await fs . promises . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-msteams-polls-" ) ) ;
203+ const stateDir = tempDirs . make ( "openclaw-msteams-polls-" ) ;
197204 const store = createMSTeamsPollStoreState ( { stateDir } ) ;
198205 await store . createPoll ( {
199206 id : "poll-strict-selections" ,
@@ -214,7 +221,7 @@ describe("state poll store", () => {
214221 } ) ;
215222
216223 it ( "keeps large vote maps split across bounded rows" , async ( ) => {
217- const stateDir = await fs . promises . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-msteams-polls-" ) ) ;
224+ const stateDir = tempDirs . make ( "openclaw-msteams-polls-" ) ;
218225 const store = createMSTeamsPollStoreState ( { stateDir } ) ;
219226 const votes = Object . fromEntries (
220227 Array . from ( { length : 500 } , ( _ , index ) => [
@@ -239,7 +246,7 @@ describe("state poll store", () => {
239246 } ) ;
240247
241248 it ( "deletes vote buckets when pruning over the poll cap" , async ( ) => {
242- const stateDir = await fs . promises . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-msteams-polls-" ) ) ;
249+ const stateDir = tempDirs . make ( "openclaw-msteams-polls-" ) ;
243250 const env = { ...process . env , OPENCLAW_STATE_DIR : stateDir } ;
244251 const metadataStore = createPluginStateKeyedStoreForTests < Omit < MSTeamsPoll , "votes" > > (
245252 "msteams" ,
0 commit comments