Skip to content

Commit 8e2b01c

Browse files
committed
fix(feishu): 修复 NO_REPLY block 误触发无可见内容兜底,并迁移 delivery-trace 测试挂钩
Feishu DM 中意图静默的 NO_REPLY 会经 block 路径跳过,但 onSkip 原先只记录 final,导致误发“无可见内容”兜底。现将 silent 的 block skip 一并纳入状态,并补充直接回调与完整调度管线回归测试。 同时按 #110775 / #110095 对 msteams/slack 的同一模式,移除 feishu delivery-trace 中已失效的 createReplyDispatcherWithTyping 捕获缝,改为直接使用 createFeishuReplyDispatcher 返回的 dispatcherOptions/delivery,修复 main 上既有的金标失败并解除 ci-gate 阻塞。 Related: #109912 Closes: #110744
1 parent 63a32e3 commit 8e2b01c

3 files changed

Lines changed: 78 additions & 22 deletions

File tree

‎extensions/feishu/src/delivery-trace.test.ts‎

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Feishu delivery trace goldens: replayable wire-level lifecycle recordings.
22
//
3-
// IN events are fed straight into the reply-dispatcher wiring (the options
4-
// createReplyDispatcherWithTyping receives plus replyOptions callbacks); OUT
3+
// IN events are fed straight into the reply-dispatcher wiring (the core-owned
4+
// dispatcher options and delivery returned by createFeishuReplyDispatcher plus
5+
// replyOptions callbacks); OUT
56
// events are recorded at the mocked Lark SDK client and the mocked CardKit
67
// HTTP fetch, so streaming-card entity calls are captured at the wire seam.
78
// Refresh goldens with OPENCLAW_TRACE_UPDATE=1 (see delivery-trace harness docs).
@@ -37,7 +38,6 @@ type FeishuTraceState = {
3738
account: ResolvedFeishuAccount | null;
3839
larkClient: unknown;
3940
cardKitFetch: typeof fetch | null;
40-
dispatcherOptions: FeishuDispatcherOptions | null;
4141
messageCount: number;
4242
reactionCount: number;
4343
cardCount: number;
@@ -51,7 +51,6 @@ const traceState = vi.hoisted(
5151
account: null,
5252
larkClient: null,
5353
cardKitFetch: null,
54-
dispatcherOptions: null,
5554
messageCount: 0,
5655
reactionCount: 0,
5756
cardCount: 0,
@@ -88,17 +87,6 @@ vi.mock("./client.js", async (importOriginal) => {
8887
};
8988
});
9089

91-
vi.mock("openclaw/plugin-sdk/reply-runtime", async (importOriginal) => {
92-
const actual = await importOriginal<Record<string, unknown>>();
93-
return {
94-
...actual,
95-
createReplyDispatcherWithTyping: (options: FeishuDispatcherOptions) => {
96-
traceState.dispatcherOptions = options;
97-
return { dispatcher: {}, replyOptions: {}, markDispatchIdle: () => {} };
98-
},
99-
};
100-
});
101-
10290
// Module-scoped runtime stub (not the shared global runtime slot) so
10391
// isolate=false workers never leak this stub into other feishu test files.
10492
// channel.text uses the real chunking/table helpers because overflow
@@ -161,15 +149,13 @@ afterAll(() => {
161149
vi.doUnmock("./client.js");
162150
vi.doUnmock("./runtime.js");
163151
vi.doUnmock("./streaming-card.js");
164-
vi.doUnmock("openclaw/plugin-sdk/reply-runtime");
165152
vi.resetModules();
166153
});
167154

168155
afterEach(() => {
169156
traceState.account = null;
170157
traceState.larkClient = null;
171158
traceState.cardKitFetch = null;
172-
traceState.dispatcherOptions = null;
173159
traceState.wireFaults = [];
174160
streamingStartBackoffUntilByAccount.clear();
175161
});
@@ -378,10 +364,10 @@ function setupFeishuTrace(recorder: WireRecorder, scenario: DeliveryTraceScenari
378364
sendTarget: "oc-trace-chat",
379365
replyToMessageId: "om-inbound",
380366
});
381-
const options = traceState.dispatcherOptions;
382-
if (!options) {
383-
throw new Error("dispatcher options were not captured");
384-
}
367+
const options = {
368+
...created.dispatcherOptions,
369+
deliver: created.delivery.deliver,
370+
} as FeishuDispatcherOptions;
385371

386372
return async (step: DeliveryTraceInStep) => {
387373
switch (step.kind) {

‎extensions/feishu/src/reply-dispatcher.test.ts‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Feishu tests cover reply dispatcher plugin behavior.
22
import os from "node:os";
33
import path from "node:path";
4+
import { createReplyDispatcherWithTyping } from "openclaw/plugin-sdk/reply-runtime";
45
import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";
56

67
type StreamingSessionStub = {
@@ -2090,6 +2091,75 @@ describe("createFeishuReplyDispatcher streaming behavior", () => {
20902091
});
20912092
});
20922093

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+
20932163
it("sends no-visible-reply fallback when a final fails after an earlier silent skip", async () => {
20942164
useNonStreamingAutoAccount();
20952165
const runtime = createRuntimeLogger();

‎extensions/feishu/src/reply-dispatcher.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ export function createFeishuReplyDispatcher(params: CreateFeishuReplyDispatcherP
670670
conversationType: chatId.startsWith("oc_") ? "group" : "direct",
671671
},
672672
onSkip: (_payload, info) => {
673-
if (info.kind === "final") {
673+
if (info.kind === "final" || (info.kind === "block" && info.reason === "silent")) {
674674
skippedFinalReason = info.reason;
675675
}
676676
},

0 commit comments

Comments
 (0)