


























@@ -0,0 +1,84 @@
1+import fs from "node:fs/promises";
2+import os from "node:os";
3+import path from "node:path";
4+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5+import { setLoggerOverride } from "../logging.js";
6+import { createTestRuntime } from "./test-runtime-config-helpers.js";
7+8+const pluginRegistryMocks = vi.hoisted(() => ({
9+loadPluginRegistrySnapshot: vi.fn(() => ({ plugins: [] })),
10+listPluginContributionIds: vi.fn(() => ["external-chat"]),
11+}));
12+13+vi.mock("../plugins/plugin-registry.js", () => ({
14+loadPluginRegistrySnapshot: pluginRegistryMocks.loadPluginRegistrySnapshot,
15+listPluginContributionIds: pluginRegistryMocks.listPluginContributionIds,
16+}));
17+18+vi.mock("../channels/plugins/index.js", () => ({
19+listChannelPlugins: vi.fn(() => {
20+throw new Error("channels logs must not load channel plugins");
21+}),
22+}));
23+24+import { channelsLogsCommand } from "./channels/logs.js";
25+26+const runtime = createTestRuntime();
27+28+function logLine(params: { module: string; message: string }) {
29+return JSON.stringify({
30+time: "2026-04-25T12:00:00.000Z",
31+0: params.message,
32+_meta: {
33+logLevelName: "INFO",
34+name: JSON.stringify({ module: params.module }),
35+},
36+});
37+}
38+39+describe("channelsLogsCommand", () => {
40+let tempDir: string;
41+let logPath: string;
42+43+beforeEach(async () => {
44+tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-channels-logs-"));
45+logPath = path.join(tempDir, "openclaw.log");
46+setLoggerOverride({ file: logPath });
47+runtime.log.mockClear();
48+runtime.error.mockClear();
49+runtime.exit.mockClear();
50+pluginRegistryMocks.loadPluginRegistrySnapshot.mockClear();
51+pluginRegistryMocks.listPluginContributionIds.mockClear();
52+});
53+54+afterEach(async () => {
55+setLoggerOverride(null);
56+await fs.rm(tempDir, { recursive: true, force: true });
57+});
58+59+it("filters external plugin channel logs from the persisted manifest registry", async () => {
60+await fs.writeFile(
61+logPath,
62+[
63+logLine({ module: "gateway/channels/external-chat/send", message: "external sent" }),
64+logLine({ module: "gateway/channels/slack/send", message: "slack sent" }),
65+].join("\n"),
66+);
67+68+await channelsLogsCommand({ channel: "external-chat", json: true }, runtime);
69+70+expect(pluginRegistryMocks.loadPluginRegistrySnapshot).toHaveBeenCalledOnce();
71+expect(pluginRegistryMocks.listPluginContributionIds).toHaveBeenCalledWith(
72+expect.objectContaining({
73+contribution: "channels",
74+includeDisabled: true,
75+}),
76+);
77+const payload = JSON.parse(String(runtime.log.mock.calls[0]?.[0])) as {
78+channel: string;
79+lines: Array<{ message: string }>;
80+};
81+expect(payload.channel).toBe("external-chat");
82+expect(payload.lines.map((line) => line.message)).toEqual(["external sent"]);
83+});
84+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。