@@ -19,6 +19,7 @@ import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
1919import { beforeEach , describe , expect , it , vi } from "vitest" ;
2020import { setDiscordRuntime } from "../runtime.js" ;
2121import { EMPTY_DISCORD_TEST_CONFIG } from "../test-support/config.js" ;
22+ import { resetThreadBindingsForTests } from "./thread-bindings.test-support.js" ;
2223
2324type DiscordRuntime = Parameters < typeof setDiscordRuntime > [ 0 ] ;
2425
@@ -67,7 +68,7 @@ vi.mock("../send.messages.js", () => ({
6768 createThreadDiscord : hoisted . createThreadDiscord ,
6869} ) ) ;
6970
70- const { testing , createThreadBindingManager } = await import ( "./thread-bindings.manager.js" ) ;
71+ const { createThreadBindingManager } = await import ( "./thread-bindings.manager.js" ) ;
7172const {
7273 autoBindSpawnedDiscordSubagent,
7374 reconcileAcpThreadBindingsOnStartup,
@@ -77,7 +78,6 @@ const {
7778} = await import ( "./thread-bindings.lifecycle.js" ) ;
7879const { resolveThreadBindingInactivityExpiresAt, resolveThreadBindingMaxAgeExpiresAt } =
7980 await import ( "./thread-bindings.state.js" ) ;
80- const { resolveThreadBindingIntroText } = await import ( "./thread-bindings.messages.js" ) ;
8181const discordClientModule = await import ( "../client.js" ) ;
8282const discordThreadBindingApi = await import ( "./thread-bindings.discord-api.js" ) ;
8383const acpRuntime = await import ( "openclaw/plugin-sdk/acp-runtime" ) ;
@@ -128,7 +128,7 @@ function mockCallArg(mock: unknown, callIndex: number, argIndex: number, label:
128128describe ( "thread binding lifecycle" , ( ) => {
129129 beforeEach ( ( ) => {
130130 resetPluginStateStoreForTests ( ) ;
131- testing . resetThreadBindingsForTests ( ) ;
131+ resetThreadBindingsForTests ( ) ;
132132 setDiscordRuntime ( {
133133 state : {
134134 openSyncKeyedStore : ( options : OpenKeyedStoreOptions ) =>
@@ -264,7 +264,7 @@ describe("thread binding lifecycle", () => {
264264 createTestThreadBindingManager ( {
265265 accountId : "default" ,
266266 persist : false ,
267- enableSweeper : false ,
267+ enableSweeper : true ,
268268 idleTimeoutMs : 24 * 60 * 60 * 1000 ,
269269 maxAgeMs : 0 ,
270270 } ) ;
@@ -294,27 +294,6 @@ describe("thread binding lifecycle", () => {
294294 return binding ;
295295 } ;
296296
297- it ( "includes idle and max-age details in intro text" , ( ) => {
298- const intro = resolveThreadBindingIntroText ( {
299- agentId : "main" ,
300- label : "worker" ,
301- idleTimeoutMs : 24 * 60 * 60 * 1000 ,
302- maxAgeMs : 48 * 60 * 60 * 1000 ,
303- } ) ;
304- expect ( intro ) . toContain ( "idle auto-unfocus after 24h inactivity" ) ;
305- expect ( intro ) . toContain ( "max age 48h" ) ;
306- } ) ;
307-
308- it ( "includes cwd near the top of intro text" , ( ) => {
309- const intro = resolveThreadBindingIntroText ( {
310- agentId : "codex" ,
311- idleTimeoutMs : 24 * 60 * 60 * 1000 ,
312- sessionCwd : "/home/bob/clawd" ,
313- sessionDetails : [ "session ids: pending (available after the first reply)" ] ,
314- } ) ;
315- expect ( intro ) . toContain ( "\ncwd: /home/bob/clawd\nsession ids: pending" ) ;
316- } ) ;
317-
318297 it . each ( [
319298 {
320299 name : "auto-unfocuses idle-expired bindings and sends inactivity message" ,
@@ -338,7 +317,7 @@ describe("thread binding lifecycle", () => {
338317 accountId : "default" ,
339318 cfg : EMPTY_DISCORD_TEST_CONFIG ,
340319 persist : false ,
341- enableSweeper : false ,
320+ enableSweeper : true ,
342321 idleTimeoutMs,
343322 maxAgeMs,
344323 } ) ;
@@ -361,7 +340,6 @@ describe("thread binding lifecycle", () => {
361340 hoisted . sendWebhookMessageDiscord . mockClear ( ) ;
362341
363342 await vi . advanceTimersByTimeAsync ( 120_000 ) ;
364- await testing . runThreadBindingSweepForAccount ( "default" ) ;
365343
366344 expect ( manager . getByThreadId ( "thread-1" ) ) . toBeUndefined ( ) ;
367345 if ( expectNoProbe ) {
@@ -402,7 +380,6 @@ describe("thread binding lifecycle", () => {
402380 hoisted . restGet . mockRejectedValueOnce ( probeError ) ;
403381
404382 await vi . advanceTimersByTimeAsync ( 120_000 ) ;
405- await testing . runThreadBindingSweepForAccount ( "default" ) ;
406383
407384 if ( keepsBinding ) {
408385 expectFields ( requireBinding ( manager , "thread-1" ) , "thread binding" , {
@@ -570,7 +547,7 @@ describe("thread binding lifecycle", () => {
570547 const manager = createTestThreadBindingManager ( {
571548 accountId : "default" ,
572549 persist : false ,
573- enableSweeper : false ,
550+ enableSweeper : true ,
574551 idleTimeoutMs : 60_000 ,
575552 maxAgeMs : 0 ,
576553 } ) ;
@@ -594,7 +571,6 @@ describe("thread binding lifecycle", () => {
594571 expect ( updated [ 0 ] ?. idleTimeoutMs ) . toBe ( 0 ) ;
595572
596573 await vi . advanceTimersByTimeAsync ( 240_000 ) ;
597- await testing . runThreadBindingSweepForAccount ( "default" ) ;
598574
599575 expectFields ( requireBinding ( manager , "thread-1" ) , "thread binding" , {
600576 threadId : "thread-1" ,
@@ -612,7 +588,7 @@ describe("thread binding lifecycle", () => {
612588 const manager = createTestThreadBindingManager ( {
613589 accountId : "default" ,
614590 persist : false ,
615- enableSweeper : false ,
591+ enableSweeper : true ,
616592 idleTimeoutMs : 60_000 ,
617593 maxAgeMs : 0 ,
618594 } ) ;
@@ -658,7 +634,6 @@ describe("thread binding lifecycle", () => {
658634 hoisted . sendMessageDiscord . mockClear ( ) ;
659635
660636 await vi . advanceTimersByTimeAsync ( 120_000 ) ;
661- await testing . runThreadBindingSweepForAccount ( "default" ) ;
662637
663638 expectFields ( requireBinding ( manager , "thread-2" ) , "thread binding" , {
664639 threadId : "thread-2" ,
@@ -716,7 +691,7 @@ describe("thread binding lifecycle", () => {
716691 const stateDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-thread-bindings-" ) ) ;
717692 process . env . OPENCLAW_STATE_DIR = stateDir ;
718693 try {
719- testing . resetThreadBindingsForTests ( ) ;
694+ resetThreadBindingsForTests ( ) ;
720695 vi . setSystemTime ( new Date ( "2026-02-20T00:00:00.000Z" ) ) ;
721696 const manager = createTestThreadBindingManager ( {
722697 accountId : "default" ,
@@ -740,7 +715,7 @@ describe("thread binding lifecycle", () => {
740715 vi . setSystemTime ( touchedAt ) ;
741716 manager . touchThread ( { threadId : "thread-1" } ) ;
742717
743- testing . resetThreadBindingsForTests ( ) ;
718+ resetThreadBindingsForTests ( ) ;
744719 const reloaded = createTestThreadBindingManager ( {
745720 accountId : "default" ,
746721 persist : true ,
@@ -758,7 +733,7 @@ describe("thread binding lifecycle", () => {
758733 } ) ,
759734 ) . toBe ( new Date ( "2026-02-20T00:01:30.000Z" ) . getTime ( ) ) ;
760735 } finally {
761- testing . resetThreadBindingsForTests ( ) ;
736+ resetThreadBindingsForTests ( ) ;
762737 if ( previousStateDir === undefined ) {
763738 delete process . env . OPENCLAW_STATE_DIR ;
764739 } else {
@@ -1853,7 +1828,7 @@ describe("thread binding lifecycle", () => {
18531828 const stateDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-thread-bindings-" ) ) ;
18541829 process . env . OPENCLAW_STATE_DIR = stateDir ;
18551830 try {
1856- testing . resetThreadBindingsForTests ( ) ;
1831+ resetThreadBindingsForTests ( ) ;
18571832 const now = Date . now ( ) ;
18581833 const store = createPluginStateSyncKeyedStoreForTests ( "discord" , {
18591834 namespace : "thread-bindings" ,
@@ -1879,7 +1854,7 @@ describe("thread binding lifecycle", () => {
18791854 expect ( removed ) . toHaveLength ( 1 ) ;
18801855 expect ( store . entries ( ) ) . toStrictEqual ( [ ] ) ;
18811856 } finally {
1882- testing . resetThreadBindingsForTests ( ) ;
1857+ resetThreadBindingsForTests ( ) ;
18831858 if ( previousStateDir === undefined ) {
18841859 delete process . env . OPENCLAW_STATE_DIR ;
18851860 } else {
0 commit comments