



























@@ -2,6 +2,7 @@ import { Command } from "commander";
22import type { Mock } from "vitest";
33import { vi } from "vitest";
44import type { OpenClawConfig } from "../config/types.openclaw.js";
5+import type { PluginInstallRecord } from "../config/types.plugins.js";
56import { createCliRuntimeCapture } from "./test-runtime-capture.js";
6778type UnknownMock = Mock<(...args: unknown[]) => unknown>;
@@ -14,7 +15,13 @@ type ListMarketplacePluginsFn =
1415(typeof import("../plugins/marketplace.js"))["listMarketplacePlugins"];
1516type ResolveMarketplaceInstallShortcutFn =
1617(typeof import("../plugins/marketplace.js"))["resolveMarketplaceInstallShortcut"];
17-type LoadPluginInstallRecordsParams = { config?: OpenClawConfig };
18+type PluginInstallRecordMap = Record<string, PluginInstallRecord>;
19+20+let mockInstalledPluginIndexInstallRecords: PluginInstallRecordMap = {};
21+22+function clonePluginInstallRecords(records: PluginInstallRecordMap): PluginInstallRecordMap {
23+return structuredClone(records);
24+}
18251926// oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- Test helper preserves mock call and result types.
2027function invokeMock<TArgs extends unknown[], TResult>(mock: unknown, ...args: TArgs): TResult {
@@ -33,14 +40,15 @@ export const listMarketplacePlugins: Mock<ListMarketplacePluginsFn> = vi.fn();
3340export const resolveMarketplaceInstallShortcut: Mock<ResolveMarketplaceInstallShortcutFn> = vi.fn();
3441export const enablePluginInConfig: UnknownMock = vi.fn();
3542export const recordPluginInstall: UnknownMock = vi.fn();
36-export const loadInstalledPluginIndexInstallRecords: AsyncUnknownMock = vi.fn(
37-async (...args: unknown[]) => {
38-const params = args[0] as LoadPluginInstallRecordsParams | undefined;
39-return structuredClone(params?.config?.plugins?.installs ?? {});
40-},
43+export const loadInstalledPluginIndexInstallRecords: AsyncUnknownMock = vi.fn(async () =>
44+clonePluginInstallRecords(mockInstalledPluginIndexInstallRecords),
4145);
4246export const writePersistedInstalledPluginIndexInstallRecords: AsyncUnknownMock = vi.fn(
43-async () => undefined,
47+async (records: unknown) => {
48+mockInstalledPluginIndexInstallRecords = clonePluginInstallRecords(
49+(records ?? {}) as PluginInstallRecordMap,
50+);
51+},
4452);
4553export const clearPluginManifestRegistryCache: UnknownMock = vi.fn();
4654export const loadPluginManifestRegistry: UnknownMock = vi.fn();
@@ -69,6 +77,10 @@ const { defaultRuntime, runtimeLogs, runtimeErrors, resetRuntimeCapture } =
69777078export { runtimeErrors, runtimeLogs };
717980+export function setInstalledPluginIndexInstallRecords(records: PluginInstallRecordMap): void {
81+mockInstalledPluginIndexInstallRecords = clonePluginInstallRecords(records);
82+}
83+7284function restoreRuntimeCaptureMocks() {
7385defaultRuntime.log.mockReset();
7486defaultRuntime.log.mockImplementation((...args: unknown[]) => {
@@ -465,6 +477,7 @@ export function resetPluginsCliTestState() {
465477resolveMarketplaceInstallShortcut.mockReset();
466478enablePluginInConfig.mockReset();
467479recordPluginInstall.mockReset();
480+mockInstalledPluginIndexInstallRecords = {};
468481loadInstalledPluginIndexInstallRecords.mockReset();
469482writePersistedInstalledPluginIndexInstallRecords.mockReset();
470483clearPluginManifestRegistryCache.mockReset();
@@ -525,11 +538,14 @@ export function resetPluginsCliTestState() {
525538recordPluginInstall.mockImplementation(
526539((cfg: OpenClawConfig) => cfg) as (...args: unknown[]) => unknown,
527540);
528-loadInstalledPluginIndexInstallRecords.mockImplementation(async (...args: unknown[]) => {
529-const params = args[0] as LoadPluginInstallRecordsParams | undefined;
530-return structuredClone(params?.config?.plugins?.installs ?? {});
541+loadInstalledPluginIndexInstallRecords.mockImplementation(async () =>
542+clonePluginInstallRecords(mockInstalledPluginIndexInstallRecords),
543+);
544+writePersistedInstalledPluginIndexInstallRecords.mockImplementation(async (records: unknown) => {
545+mockInstalledPluginIndexInstallRecords = clonePluginInstallRecords(
546+(records ?? {}) as PluginInstallRecordMap,
547+);
531548});
532-writePersistedInstalledPluginIndexInstallRecords.mockResolvedValue(undefined);
533549loadPluginManifestRegistry.mockReturnValue({
534550plugins: [],
535551diagnostics: [],
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。