



















@@ -1,5 +1,6 @@
11import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
22import type { ChannelPluginCatalogEntry } from "../channels/plugins/catalog.js";
3+import type { ChannelPlugin } from "../channels/plugins/types.plugin.js";
34import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "../plugins/runtime.js";
45import { createTestRegistry } from "../test-utils/channel-plugins.js";
56import {
@@ -23,6 +24,10 @@ const registryRefreshMocks = vi.hoisted(() => ({
2324refreshPluginRegistryAfterConfigMutation: vi.fn(async () => undefined),
2425}));
252627+const gatewayMocks = vi.hoisted(() => ({
28+callGateway: vi.fn(async () => ({ stopped: true })),
29+}));
30+2631vi.mock("../channels/plugins/catalog.js", async () => {
2732const actual = await vi.importActual<typeof import("../channels/plugins/catalog.js")>(
2833"../channels/plugins/catalog.js",
@@ -54,6 +59,10 @@ vi.mock("./channel-setup/plugin-install.js", async () => {
54595560vi.mock("../cli/plugins-registry-refresh.js", () => registryRefreshMocks);
566162+vi.mock("../gateway/call.js", () => ({
63+callGateway: gatewayMocks.callGateway,
64+}));
65+5766const runtime = createTestRuntime();
58675968describe("channelsRemoveCommand", () => {
@@ -86,6 +95,8 @@ describe("channelsRemoveCommand", () => {
8695createTestRegistry(),
8796);
8897registryRefreshMocks.refreshPluginRegistryAfterConfigMutation.mockClear();
98+gatewayMocks.callGateway.mockClear();
99+gatewayMocks.callGateway.mockResolvedValue({ stopped: true });
89100setActivePluginRegistry(createTestRegistry());
90101});
91102@@ -170,4 +181,71 @@ describe("channelsRemoveCommand", () => {
170181expect(runtime.error).not.toHaveBeenCalled();
171182expect(runtime.exit).not.toHaveBeenCalled();
172183});
184+185+it("stops an active gateway channel runtime before deleting a runtime-backed account", async () => {
186+configMocks.readConfigFileSnapshot.mockResolvedValue({
187+ ...baseConfigSnapshot,
188+config: {
189+channels: {
190+"external-chat": {
191+enabled: true,
192+token: "token-1",
193+},
194+},
195+},
196+});
197+const catalogEntry: ChannelPluginCatalogEntry = createExternalChatCatalogEntry();
198+catalogMocks.listChannelPluginCatalogEntries.mockReturnValue([catalogEntry]);
199+const scopedPlugin = {
200+ ...createExternalChatDeletePlugin(),
201+gateway: {
202+startAccount: vi.fn(),
203+},
204+} as ChannelPlugin;
205+vi.mocked(loadChannelSetupPluginRegistrySnapshotForChannel).mockReturnValue(
206+createTestRegistry([
207+{
208+pluginId: "@vendor/external-chat-plugin",
209+plugin: scopedPlugin,
210+source: "test",
211+},
212+]),
213+);
214+215+await channelsRemoveCommand(
216+{
217+channel: "external-chat",
218+account: "default",
219+delete: true,
220+},
221+runtime,
222+{ hasFlags: true },
223+);
224+225+expect(gatewayMocks.callGateway).toHaveBeenCalledWith({
226+config: {
227+channels: {
228+"external-chat": {
229+enabled: true,
230+token: "token-1",
231+},
232+},
233+},
234+method: "channels.stop",
235+params: {
236+channel: "external-chat",
237+accountId: "default",
238+},
239+mode: "backend",
240+clientName: "gateway-client",
241+deviceIdentity: null,
242+});
243+expect(configMocks.writeConfigFile).toHaveBeenCalledWith(
244+expect.not.objectContaining({
245+channels: expect.objectContaining({
246+"external-chat": expect.anything(),
247+}),
248+}),
249+);
250+});
173251});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。