|
| 1 | +import { sanitizeAssistantVisibleText } from "openclaw/plugin-sdk/text-chunking"; |
1 | 2 | // Plugin-shape coherence contract for bundled channel plugins. |
2 | 3 | // |
3 | 4 | // Catalog routing keys off plugin ids, docs surfaces render `meta.docsPath`, |
|
14 | 15 | // slash commands through gateway HTTP routes). |
15 | 16 | // - blockStreaming=true does not imply a streaming adapter (coalesce tuning |
16 | 17 | // is optional). |
17 | | -import { beforeAll, describe, expect, it, vi } from "vitest"; |
| 18 | +import { beforeAll, describe, expect, it } from "vitest"; |
18 | 19 | import { listBundledPackageChannelMetadata } from "../../../plugins/bundled-package-channel-metadata.js"; |
19 | 20 | import { |
20 | 21 | getBundledChannelPluginAsync, |
21 | 22 | listBundledChannelPluginIds, |
22 | 23 | } from "./test-helpers/bundled-channel-plugin-loader.js"; |
23 | 24 |
|
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 | | - |
33 | 25 | const CHAT_TYPES = new Set(["direct", "group", "channel", "thread"]); |
34 | 26 | const bundledChannelPluginIds = listBundledChannelPluginIds(); |
35 | 27 | const packageMetadataById = new Map( |
@@ -60,18 +52,25 @@ describe("bundled channel plugin shape coherence", () => { |
60 | 52 | }); |
61 | 53 |
|
62 | 54 | it.each(SHARED_SANITIZER_CHANNEL_IDS)( |
63 | | - "%s wires outbound sanitizeText through the shared sanitizer", |
| 55 | + "%s applies shared sanitizer semantics to outbound text", |
64 | 56 | (id) => { |
65 | 57 | const sanitizeText = plugins.get(id)?.outbound?.sanitizeText; |
66 | 58 | if (!sanitizeText) { |
67 | 59 | throw new Error(`Missing outbound sanitizeText hook for ${id}`); |
68 | 60 | } |
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); |
72 | 71 |
|
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); |
75 | 74 | }, |
76 | 75 | ); |
77 | 76 |
|
|
0 commit comments