




















@@ -1,75 +1,70 @@
1-import path from "node:path";
2-import { describe, expect, it, vi } from "vitest";
3-import { clearPluginDiscoveryCache } from "../plugins/discovery.js";
4-import { clearPluginManifestRegistryCache } from "../plugins/manifest-registry.js";
1+import { beforeEach, describe, expect, it, vi } from "vitest";
526-const runChannelPluginStartupMaintenanceMock = vi.fn().mockResolvedValue(undefined);
3+const runChannelPluginStartupMaintenanceMock = vi.hoisted(() =>
4+vi.fn().mockResolvedValue(undefined),
5+);
7687vi.mock("../channels/plugins/lifecycle-startup.js", () => ({
9-runChannelPluginStartupMaintenance: runChannelPluginStartupMaintenanceMock,
8+runChannelPluginStartupMaintenance: (params: unknown) =>
9+runChannelPluginStartupMaintenanceMock(params),
1010}));
111112-import {
13-getFreePort,
14-installGatewayTestHooks,
15-startGatewayServer,
16-testState,
17-} from "./test-helpers.js";
12+vi.mock("../agents/agent-scope.js", () => ({
13+resolveAgentWorkspaceDir: () => "/workspace",
14+resolveDefaultAgentId: () => "default",
15+}));
181619-installGatewayTestHooks({ scope: "suite" });
17+vi.mock("../agents/subagent-registry.js", () => ({
18+initSubagentRegistry: vi.fn(),
19+}));
20202121describe("gateway startup channel maintenance wiring", () => {
22-it("runs startup channel maintenance with the resolved startup config", async () => {
23-const previousBundledPluginsDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
24-const previousSkipChannels = process.env.OPENCLAW_SKIP_CHANNELS;
25-process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = path.resolve(process.cwd(), "extensions");
26-process.env.OPENCLAW_SKIP_CHANNELS = "0";
27-clearPluginDiscoveryCache();
28-clearPluginManifestRegistryCache();
22+beforeEach(() => {
23+vi.resetModules();
2924runChannelPluginStartupMaintenanceMock.mockClear();
25+});
302631-testState.channelsConfig = {
32-matrix: {
33-homeserver: "https://matrix.example.org",
34-userId: "@bot:example.org",
35-accessToken: "tok-123",
36-},
37-};
27+it("runs startup channel maintenance with the resolved startup config", async () => {
28+const { prepareGatewayPluginBootstrap } = await import("./server-startup-plugins.js");
382939-let server: Awaited<ReturnType<typeof startGatewayServer>> | undefined;
40-try {
41-server = await startGatewayServer(await getFreePort());
30+await prepareGatewayPluginBootstrap({
31+cfgAtStart: {
32+plugins: { enabled: true },
33+},
34+startupRuntimeConfig: {
35+plugins: { enabled: true },
36+channels: {
37+matrix: {
38+homeserver: "https://matrix.example.org",
39+userId: "@bot:example.org",
40+accessToken: "tok-123",
41+},
42+},
43+},
44+minimalTestGateway: true,
45+log: {
46+info: vi.fn(),
47+warn: vi.fn(),
48+error: vi.fn(),
49+debug: vi.fn(),
50+},
51+});
425243-expect(runChannelPluginStartupMaintenanceMock).toHaveBeenCalledTimes(1);
44-expect(runChannelPluginStartupMaintenanceMock).toHaveBeenCalledWith(
45-expect.objectContaining({
46-cfg: expect.objectContaining({
47-channels: expect.objectContaining({
48-matrix: expect.objectContaining({
49-homeserver: "https://matrix.example.org",
50-userId: "@bot:example.org",
51-accessToken: "tok-123",
52-}),
53+expect(runChannelPluginStartupMaintenanceMock).toHaveBeenCalledTimes(1);
54+expect(runChannelPluginStartupMaintenanceMock).toHaveBeenCalledWith(
55+expect.objectContaining({
56+cfg: expect.objectContaining({
57+channels: expect.objectContaining({
58+matrix: expect.objectContaining({
59+homeserver: "https://matrix.example.org",
60+userId: "@bot:example.org",
61+accessToken: "tok-123",
5362}),
5463}),
55-env: process.env,
56-log: expect.anything(),
5764}),
58-);
59-} finally {
60-await server?.close();
61-if (previousBundledPluginsDir === undefined) {
62-delete process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
63-} else {
64-process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = previousBundledPluginsDir;
65-}
66-if (previousSkipChannels === undefined) {
67-delete process.env.OPENCLAW_SKIP_CHANNELS;
68-} else {
69-process.env.OPENCLAW_SKIP_CHANNELS = previousSkipChannels;
70-}
71-clearPluginDiscoveryCache();
72-clearPluginManifestRegistryCache();
73-}
65+env: process.env,
66+log: expect.anything(),
67+}),
68+);
7469});
7570});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。