|
1 | 1 | // Feishu tests cover reply dispatcher plugin behavior. |
2 | 2 | import os from "node:os"; |
3 | 3 | import path from "node:path"; |
| 4 | +import { createReplyDispatcherWithTyping } from "openclaw/plugin-sdk/reply-runtime"; |
4 | 5 | import { afterAll, beforeEach, describe, expect, it, vi } from "vitest"; |
5 | 6 |
|
6 | 7 | type StreamingSessionStub = { |
@@ -2090,6 +2091,75 @@ describe("createFeishuReplyDispatcher streaming behavior", () => { |
2090 | 2091 | }); |
2091 | 2092 | }); |
2092 | 2093 |
|
| 2094 | + it("does not send no-visible-reply fallback after an intentional silent block reply", async () => { |
| 2095 | + const runtime = createRuntimeLogger(); |
| 2096 | + const { result, options } = createDispatcherHarness({ runtime, sessionKey: "main" }); |
| 2097 | + |
| 2098 | + options.onSkip?.({ text: "NO_REPLY" }, { kind: "block", reason: "silent" }); |
| 2099 | + await expect(result.ensureNoVisibleReplyFallback("empty-complete")).resolves.toBe(false); |
| 2100 | + |
| 2101 | + expect(sendMessageFeishuMock).not.toHaveBeenCalled(); |
| 2102 | + expect(result.getVisibleReplyState()).toEqual({ |
| 2103 | + visibleReplySent: false, |
| 2104 | + skippedFinalReason: "silent", |
| 2105 | + }); |
| 2106 | + }); |
| 2107 | + |
| 2108 | + it("still sends no-visible-reply fallback after a non-silent block skip", async () => { |
| 2109 | + const runtime = createRuntimeLogger(); |
| 2110 | + const { result, options } = createDispatcherHarness({ runtime, sessionKey: "main" }); |
| 2111 | + |
| 2112 | + options.onSkip?.({ text: "" }, { kind: "block", reason: "empty" }); |
| 2113 | + await expect(result.ensureNoVisibleReplyFallback("empty-complete")).resolves.toBe(true); |
| 2114 | + |
| 2115 | + expect(sendMessageFeishuMock).toHaveBeenCalledTimes(1); |
| 2116 | + expect(String(firstMockArg(sendMessageFeishuMock, "send message params").text)).toContain( |
| 2117 | + "without visible content", |
| 2118 | + ); |
| 2119 | + expect(result.getVisibleReplyState()).toEqual({ |
| 2120 | + visibleReplySent: true, |
| 2121 | + skippedFinalReason: null, |
| 2122 | + }); |
| 2123 | + }); |
| 2124 | + |
| 2125 | + it("suppresses the fallback for a real NO_REPLY block reply through the full dispatch pipeline", async () => { |
| 2126 | + // Unlike the tests above (which invoke the captured onSkip callback |
| 2127 | + // directly), this drives the exact production call path: the shared |
| 2128 | + // createReplyDispatcherWithTyping + normalizeReplyPayload pipeline decides |
| 2129 | + // "NO_REPLY" is silent on its own and calls Feishu's onSkip for us. Only |
| 2130 | + // the outbound Feishu HTTP calls are mocked, same as every other test here. |
| 2131 | + const runtime = createRuntimeLogger(); |
| 2132 | + const { result, options } = createDispatcherHarness({ runtime, sessionKey: "main" }); |
| 2133 | + const { dispatcher } = createReplyDispatcherWithTyping(options); |
| 2134 | + |
| 2135 | + dispatcher.sendBlockReply({ text: "NO_REPLY" }); |
| 2136 | + await expect(result.ensureNoVisibleReplyFallback("empty-complete")).resolves.toBe(false); |
| 2137 | + |
| 2138 | + expect(sendMessageFeishuMock).not.toHaveBeenCalled(); |
| 2139 | + expect(result.getVisibleReplyState()).toEqual({ |
| 2140 | + visibleReplySent: false, |
| 2141 | + skippedFinalReason: "silent", |
| 2142 | + }); |
| 2143 | + }); |
| 2144 | + |
| 2145 | + it("still delivers the fallback for a real genuinely-empty block reply through the full dispatch pipeline", async () => { |
| 2146 | + const runtime = createRuntimeLogger(); |
| 2147 | + const { result, options } = createDispatcherHarness({ runtime, sessionKey: "main" }); |
| 2148 | + const { dispatcher } = createReplyDispatcherWithTyping(options); |
| 2149 | + |
| 2150 | + dispatcher.sendBlockReply({ text: "" }); |
| 2151 | + await expect(result.ensureNoVisibleReplyFallback("empty-complete")).resolves.toBe(true); |
| 2152 | + |
| 2153 | + expect(sendMessageFeishuMock).toHaveBeenCalledTimes(1); |
| 2154 | + expect(String(firstMockArg(sendMessageFeishuMock, "send message params").text)).toContain( |
| 2155 | + "without visible content", |
| 2156 | + ); |
| 2157 | + expect(result.getVisibleReplyState()).toEqual({ |
| 2158 | + visibleReplySent: true, |
| 2159 | + skippedFinalReason: null, |
| 2160 | + }); |
| 2161 | + }); |
| 2162 | + |
2093 | 2163 | it("sends no-visible-reply fallback when a final fails after an earlier silent skip", async () => { |
2094 | 2164 | useNonStreamingAutoAccount(); |
2095 | 2165 | const runtime = createRuntimeLogger(); |
|
0 commit comments