Skip to content

Commit 1c1671d

Browse files
committed
test(channels): verify built sanitizer semantics
1 parent b1f2aae commit 1c1671d

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

‎src/channels/plugins/contracts/plugin-shape.contract.test.ts‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { sanitizeAssistantVisibleText } from "openclaw/plugin-sdk/text-chunking";
12
// Plugin-shape coherence contract for bundled channel plugins.
23
//
34
// Catalog routing keys off plugin ids, docs surfaces render `meta.docsPath`,
@@ -14,22 +15,13 @@
1415
// slash commands through gateway HTTP routes).
1516
// - blockStreaming=true does not imply a streaming adapter (coalesce tuning
1617
// is optional).
17-
import { beforeAll, describe, expect, it, vi } from "vitest";
18+
import { beforeAll, describe, expect, it } from "vitest";
1819
import { listBundledPackageChannelMetadata } from "../../../plugins/bundled-package-channel-metadata.js";
1920
import {
2021
getBundledChannelPluginAsync,
2122
listBundledChannelPluginIds,
2223
} from "./test-helpers/bundled-channel-plugin-loader.js";
2324

24-
const sanitizeAssistantVisibleTextMock = vi.hoisted(() =>
25-
vi.fn((text: string) => `shared-sanitizer:${text}`),
26-
);
27-
28-
vi.mock("openclaw/plugin-sdk/text-chunking", async (importOriginal) => {
29-
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/text-chunking")>();
30-
return { ...actual, sanitizeAssistantVisibleText: sanitizeAssistantVisibleTextMock };
31-
});
32-
3325
const CHAT_TYPES = new Set(["direct", "group", "channel", "thread"]);
3426
const bundledChannelPluginIds = listBundledChannelPluginIds();
3527
const packageMetadataById = new Map(
@@ -60,18 +52,25 @@ describe("bundled channel plugin shape coherence", () => {
6052
});
6153

6254
it.each(SHARED_SANITIZER_CHANNEL_IDS)(
63-
"%s wires outbound sanitizeText through the shared sanitizer",
55+
"%s applies shared sanitizer semantics to outbound text",
6456
(id) => {
6557
const sanitizeText = plugins.get(id)?.outbound?.sanitizeText;
6658
if (!sanitizeText) {
6759
throw new Error(`Missing outbound sanitizeText hook for ${id}`);
6860
}
69-
const text = `visible:${id}`;
70-
71-
sanitizeAssistantVisibleTextMock.mockClear();
61+
const visible = `Visible answer: ${id}`;
62+
const text = [
63+
'<invoke name="read">payload</invoke></minimax:tool_call>',
64+
'<tool_result>{"output":"hidden"}</tool_result>',
65+
"[Tool Call: read (ID: toolu_1)]",
66+
'Arguments: {"path":"/tmp/x"}',
67+
"<think>secret</think>",
68+
visible,
69+
].join("\n");
70+
const expected = sanitizeAssistantVisibleText(text);
7271

73-
expect(sanitizeText({ text, payload: { text } })).toBe(`shared-sanitizer:${text}`);
74-
expect(sanitizeAssistantVisibleTextMock).toHaveBeenCalledExactlyOnceWith(text);
72+
expect(expected).toBe(visible);
73+
expect(sanitizeText({ text, payload: { text } })).toBe(expected);
7574
},
7675
);
7776

0 commit comments

Comments
 (0)