























@@ -1,7 +1,56 @@
11import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
22import type { ConfigFileSnapshot, OpenClawConfig } from "../config/types.js";
3+import type { PluginMetadataSnapshot } from "../plugins/plugin-metadata-snapshot.js";
34import { buildTestConfigSnapshot } from "./test-helpers.config-snapshots.js";
456+const applyPluginAutoEnable = vi.hoisted(() =>
7+vi.fn((params: { config: OpenClawConfig }) => ({
8+config: params.config,
9+changes: [] as string[],
10+autoEnabledReasons: {} as Record<string, string[]>,
11+})),
12+);
13+const pluginManifestRegistry = vi.hoisted(() => ({ plugins: [], diagnostics: [] }));
14+const pluginMetadataSnapshot = vi.hoisted(
15+(): PluginMetadataSnapshot => ({
16+index: {
17+version: 1,
18+hostContractVersion: "test",
19+compatRegistryVersion: "test",
20+migrationVersion: 1,
21+policyHash: "policy",
22+generatedAtMs: 0,
23+installRecords: {},
24+plugins: [],
25+diagnostics: [],
26+},
27+registryDiagnostics: [],
28+manifestRegistry: pluginManifestRegistry,
29+plugins: [],
30+diagnostics: [],
31+byPluginId: new Map(),
32+normalizePluginId: (pluginId) => pluginId,
33+owners: {
34+channels: new Map(),
35+channelConfigs: new Map(),
36+providers: new Map(),
37+modelCatalogProviders: new Map(),
38+cliBackends: new Map(),
39+setupProviders: new Map(),
40+commandAliases: new Map(),
41+contracts: new Map(),
42+},
43+metrics: {
44+registrySnapshotMs: 0,
45+manifestRegistryMs: 0,
46+ownerMapsMs: 0,
47+totalMs: 0,
48+indexPluginCount: 0,
49+manifestPluginCount: 0,
50+},
51+}),
52+);
53+554vi.mock("../config/config.js", () => ({
655applyConfigOverrides: vi.fn((config: OpenClawConfig) => config),
756isNixMode: false,
@@ -33,6 +82,10 @@ vi.mock("../config/config.js", () => ({
3382writeConfigFile: vi.fn(),
3483}));
358485+vi.mock("../config/plugin-auto-enable.js", () => ({
86+applyPluginAutoEnable: (params: { config: OpenClawConfig }) => applyPluginAutoEnable(params),
87+}));
88+3689vi.mock("./config-recovery-notice.js", () => ({
3790enqueueConfigRecoveryNotice: vi.fn(),
3891}));
@@ -118,6 +171,7 @@ describe("gateway startup config recovery", () => {
118171resolved: sourceConfig,
119172 runtimeConfig,
120173config: runtimeConfig,
174+ pluginMetadataSnapshot,
121175} satisfies ConfigFileSnapshot;
122176vi.mocked(configIo.readConfigFileSnapshot).mockResolvedValueOnce(snapshot);
123177const log = { info: vi.fn(), warn: vi.fn() };
@@ -133,6 +187,11 @@ describe("gateway startup config recovery", () => {
133187});
134188135189expect(configIo.readConfigFileSnapshot).toHaveBeenCalledTimes(1);
190+expect(applyPluginAutoEnable).toHaveBeenCalledWith({
191+config: sourceConfig,
192+env: process.env,
193+manifestRegistry: pluginManifestRegistry,
194+});
136195expect(configIo.replaceConfigFile).not.toHaveBeenCalled();
137196expect(log.info).not.toHaveBeenCalled();
138197});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。