test: clear feishu drive cleanup timers

This commit is contained in:
Shakker
2026-05-09 01:12:43 +01:00
parent d857b83d5a
commit b945680f7e

View File

@@ -21,6 +21,22 @@ function createFeishuToolRuntime(): PluginRuntime {
return {} as PluginRuntime;
}
async function raceWithNextMacrotask<T>(promise: Promise<T>): Promise<T | "pending"> {
let timer: ReturnType<typeof setTimeout> | undefined;
try {
return await Promise.race([
promise,
new Promise<"pending">((resolve) => {
timer = setTimeout(() => resolve("pending"), 0);
}),
]);
} finally {
if (timer) {
clearTimeout(timer);
}
}
}
function createDriveToolApi(params: {
config: OpenClawPluginApi["config"];
registerTool: OpenClawPluginApi["registerTool"];
@@ -559,10 +575,7 @@ describe("registerFeishuDriveTools", () => {
action: "reply_comment",
content: "ambient success",
});
const status = await Promise.race([
replyCommentPromise.then(() => "done"),
new Promise<string>((resolve) => setTimeout(() => resolve("pending"), 0)),
]);
const status = await raceWithNextMacrotask(replyCommentPromise.then(() => "done"));
expect(status).toBe("done");
expect(requestMock).toHaveBeenNthCalledWith(
@@ -656,10 +669,7 @@ describe("registerFeishuDriveTools", () => {
action: "add_comment",
content: "ambient top-level comment",
});
const status = await Promise.race([
addCommentPromise.then(() => "done"),
new Promise<string>((resolve) => setTimeout(() => resolve("pending"), 0)),
]);
const status = await raceWithNextMacrotask(addCommentPromise.then(() => "done"));
expect(status).toBe("done");
expect(requestMock).toHaveBeenCalledWith(