mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
test(discord): add regression tests for reasoning tag stripping in stream
Verify that partial stream updates containing <thinking> tags are stripped before reaching the draft preview, and that pure "Reasoning:\n" partials are suppressed entirely. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
Peter Steinberger
parent
e8a4d5d9bd
commit
6ea1607f1c
@@ -476,4 +476,49 @@ describe("processDiscordMessage draft streaming", () => {
|
||||
|
||||
expect(draftStream.forceNewMessage).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("strips reasoning tags from partial stream updates", async () => {
|
||||
const draftStream = createMockDraftStream();
|
||||
createDiscordDraftStream.mockReturnValueOnce(draftStream);
|
||||
|
||||
dispatchInboundMessage.mockImplementationOnce(async (params?: DispatchInboundParams) => {
|
||||
await params?.replyOptions?.onPartialReply?.({
|
||||
text: "<thinking>Let me think about this</thinking>\nThe answer is 42",
|
||||
});
|
||||
return { queuedFinal: false, counts: { final: 0, tool: 0, block: 0 } };
|
||||
});
|
||||
|
||||
const ctx = await createBaseContext({
|
||||
discordConfig: { streamMode: "partial" },
|
||||
});
|
||||
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
await processDiscordMessage(ctx as any);
|
||||
|
||||
const updates = draftStream.update.mock.calls.map((call) => call[0]);
|
||||
for (const text of updates) {
|
||||
expect(text).not.toContain("<thinking>");
|
||||
}
|
||||
});
|
||||
|
||||
it("skips pure-reasoning partial updates without updating draft", async () => {
|
||||
const draftStream = createMockDraftStream();
|
||||
createDiscordDraftStream.mockReturnValueOnce(draftStream);
|
||||
|
||||
dispatchInboundMessage.mockImplementationOnce(async (params?: DispatchInboundParams) => {
|
||||
await params?.replyOptions?.onPartialReply?.({
|
||||
text: "Reasoning:\nThe user asked about X so I need to consider Y",
|
||||
});
|
||||
return { queuedFinal: false, counts: { final: 0, tool: 0, block: 0 } };
|
||||
});
|
||||
|
||||
const ctx = await createBaseContext({
|
||||
discordConfig: { streamMode: "partial" },
|
||||
});
|
||||
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
await processDiscordMessage(ctx as any);
|
||||
|
||||
expect(draftStream.update).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user