Skip to content

Commit 37763e4

Browse files
authored
refactor(feishu): remove thread-binding test reset (#124276)
1 parent 715e324 commit 37763e4

5 files changed

Lines changed: 39 additions & 31 deletions

File tree

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
// Feishu API module exposes the plugin public contract.
22
export { createFeishuThreadBindingManager } from "./src/thread-bindings.js";
3-
export { testing as feishuThreadBindingTesting } from "./src/thread-bindings.js";

‎extensions/feishu/src/subagent-hooks.test.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@ import {
33
getRequiredHookHandler,
44
registerHookHandlersForTest,
55
} from "openclaw/plugin-sdk/channel-test-helpers";
6-
import { beforeEach, describe, expect, it } from "vitest";
6+
import { afterEach, describe, expect, it } from "vitest";
77
import type { ClawdbotConfig, OpenClawPluginApi } from "../runtime-api.js";
88
import { registerFeishuSubagentHooks } from "../subagent-hooks-api.js";
99
import { handleFeishuSubagentSpawning } from "./subagent-hooks.js";
10-
import {
11-
createFeishuThreadBindingManager,
12-
testing as threadBindingTesting,
13-
} from "./thread-bindings.js";
10+
import { createFeishuThreadBindingManager as createFeishuThreadBindingManagerImpl } from "./thread-bindings.js";
1411

1512
const baseConfig: ClawdbotConfig = {
1613
session: { mainKey: "main", scope: "per-sender" },
1714
channels: { feishu: {} },
1815
};
1916

17+
type FeishuThreadBindingManager = ReturnType<typeof createFeishuThreadBindingManagerImpl>;
18+
let trackedManager: FeishuThreadBindingManager | null = null;
19+
20+
function createFeishuThreadBindingManager(
21+
params: Parameters<typeof createFeishuThreadBindingManagerImpl>[0],
22+
): FeishuThreadBindingManager {
23+
trackedManager = createFeishuThreadBindingManagerImpl(params);
24+
return trackedManager;
25+
}
26+
2027
function registerHandlersForTest(config: Record<string, unknown> = baseConfig) {
2128
return registerHookHandlersForTest<OpenClawPluginApi>({
2229
config,
@@ -87,8 +94,9 @@ function managedHookFixture() {
8794
}
8895

8996
describe("feishu subagent hook handlers", () => {
90-
beforeEach(() => {
91-
threadBindingTesting.resetFeishuThreadBindingsForTests();
97+
afterEach(() => {
98+
trackedManager?.stop();
99+
trackedManager = null;
92100
});
93101

94102
it("binds a Feishu DM conversation on subagent_spawning", async () => {

‎extensions/feishu/src/thread-bindings.test.ts‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
// Feishu tests cover thread bindings plugin behavior.
22
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
33
import { getSessionBindingService } from "openclaw/plugin-sdk/conversation-runtime";
4-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5-
import { testing, createFeishuThreadBindingManager } from "./thread-bindings.js";
4+
import { afterEach, describe, expect, it, vi } from "vitest";
5+
import { createFeishuThreadBindingManager as createFeishuThreadBindingManagerImpl } from "./thread-bindings.js";
66

77
const baseCfg = {
88
session: { mainKey: "main", scope: "per-sender" },
99
} satisfies OpenClawConfig;
1010

11-
describe("Feishu thread bindings", () => {
12-
beforeEach(() => {
13-
testing.resetFeishuThreadBindingsForTests();
14-
});
11+
type FeishuThreadBindingManager = ReturnType<typeof createFeishuThreadBindingManagerImpl>;
12+
let trackedManager: FeishuThreadBindingManager | null = null;
1513

14+
function createFeishuThreadBindingManager(
15+
params: Parameters<typeof createFeishuThreadBindingManagerImpl>[0],
16+
): FeishuThreadBindingManager {
17+
trackedManager = createFeishuThreadBindingManagerImpl(params);
18+
return trackedManager;
19+
}
20+
21+
describe("Feishu thread bindings", () => {
1622
afterEach(() => {
23+
trackedManager?.stop();
24+
trackedManager = null;
1725
vi.restoreAllMocks();
1826
});
1927

‎extensions/feishu/src/thread-bindings.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,3 @@ export function getFeishuThreadBindingManager(
349349
): FeishuThreadBindingManager | null {
350350
return getState().managersByAccountId.get(normalizeAccountId(accountId)) ?? null;
351351
}
352-
353-
export const testing = {
354-
resetFeishuThreadBindingsForTests() {
355-
for (const manager of getState().managersByAccountId.values()) {
356-
manager.stop();
357-
}
358-
getState().managersByAccountId.clear();
359-
getState().bindingsByAccountConversation.clear();
360-
},
361-
};

‎src/channels/plugins/contracts/test-helpers/registry-session-binding.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ type ChannelConversationBindingManager = Awaited<
162162
ReturnType<ChannelConversationBindingManagerFactory>
163163
>;
164164
let discordSessionBindingManager: ChannelConversationBindingManager | null = null;
165+
let feishuSessionBindingManager: ChannelConversationBindingManager | null = null;
165166
let matrixSessionBindingManager: ChannelConversationBindingManager | null = null;
166167
let telegramSessionBindingManager: ChannelConversationBindingManager | null = null;
167168

@@ -173,10 +174,7 @@ type FeishuContractApi = {
173174
createFeishuThreadBindingManager: (params: {
174175
accountId?: string;
175176
cfg: OpenClawConfig;
176-
}) => unknown;
177-
feishuThreadBindingTesting: {
178-
resetFeishuThreadBindingsForTests: () => void;
179-
};
177+
}) => ChannelConversationBindingManager;
180178
};
181179

182180
type IMessageContractApi = {
@@ -251,6 +249,11 @@ async function stopDiscordSessionBindingManager() {
251249
discordSessionBindingManager = null;
252250
}
253251

252+
async function stopFeishuSessionBindingManager() {
253+
await feishuSessionBindingManager?.stop();
254+
feishuSessionBindingManager = null;
255+
}
256+
254257
async function stopMatrixSessionBindingManager() {
255258
await matrixSessionBindingManager?.stop();
256259
matrixSessionBindingManager = null;
@@ -276,8 +279,7 @@ async function prepareDiscordSessionBindingContract() {
276279
}
277280

278281
async function prepareFeishuSessionBindingContract() {
279-
const api = await getContractApi<FeishuContractApi>("feishu");
280-
api.feishuThreadBindingTesting.resetFeishuThreadBindingsForTests();
282+
await stopFeishuSessionBindingManager();
281283
}
282284

283285
async function prepareIMessageSessionBindingContract() {
@@ -411,11 +413,12 @@ const sessionBindingContractEntries = {
411413
ensureManager: async () => {
412414
const { createFeishuThreadBindingManager } =
413415
await getContractApi<FeishuContractApi>("feishu");
414-
createFeishuThreadBindingManager({
416+
feishuSessionBindingManager ??= createFeishuThreadBindingManager({
415417
accountId: "default",
416418
cfg: baseSessionBindingCfg,
417419
});
418420
},
421+
stopManager: stopFeishuSessionBindingManager,
419422
}),
420423
imessage: createSessionBindingContractEntry({
421424
id: "imessage",

0 commit comments

Comments
 (0)