
























@@ -21,6 +21,22 @@ function createFeishuToolRuntime(): PluginRuntime {
2121return {} as PluginRuntime;
2222}
232324+async function raceWithNextMacrotask<T>(promise: Promise<T>): Promise<T | "pending"> {
25+let timer: ReturnType<typeof setTimeout> | undefined;
26+try {
27+return await Promise.race([
28+promise,
29+new Promise<"pending">((resolve) => {
30+timer = setTimeout(() => resolve("pending"), 0);
31+}),
32+]);
33+} finally {
34+if (timer) {
35+clearTimeout(timer);
36+}
37+}
38+}
39+2440function createDriveToolApi(params: {
2541config: OpenClawPluginApi["config"];
2642registerTool: OpenClawPluginApi["registerTool"];
@@ -559,10 +575,7 @@ describe("registerFeishuDriveTools", () => {
559575action: "reply_comment",
560576content: "ambient success",
561577});
562-const status = await Promise.race([
563-replyCommentPromise.then(() => "done"),
564-new Promise<string>((resolve) => setTimeout(() => resolve("pending"), 0)),
565-]);
578+const status = await raceWithNextMacrotask(replyCommentPromise.then(() => "done"));
566579567580expect(status).toBe("done");
568581expect(requestMock).toHaveBeenNthCalledWith(
@@ -656,10 +669,7 @@ describe("registerFeishuDriveTools", () => {
656669action: "add_comment",
657670content: "ambient top-level comment",
658671});
659-const status = await Promise.race([
660-addCommentPromise.then(() => "done"),
661-new Promise<string>((resolve) => setTimeout(() => resolve("pending"), 0)),
662-]);
672+const status = await raceWithNextMacrotask(addCommentPromise.then(() => "done"));
663673664674expect(status).toBe("done");
665675expect(requestMock).toHaveBeenCalledWith(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。