refactor(test): dedupe bundled plugin record fixtures

This commit is contained in:
Vincent Koc
2026-06-18 21:10:31 +08:00
parent 712e45daf1
commit aad0559de0
3 changed files with 13 additions and 78 deletions

View File

@@ -2,8 +2,9 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
import { clearPluginCommands, registerPluginCommand } from "../../plugins/commands.js";
import { createPluginRegistry, type PluginRecord } from "../../plugins/registry.js";
import { createPluginRegistry } from "../../plugins/registry.js";
import type { PluginRuntime } from "../../plugins/runtime/types.js";
import { createBundledPluginRecord } from "../../plugins/status.test-helpers.js";
import type { PluginCommandContext, PluginCommandHandler } from "../../plugins/types.js";
import type { MsgContext } from "../templating.js";
import { createDiagnosticsCommandHandler } from "./commands-diagnostics.js";
@@ -104,44 +105,6 @@ function buildDiagnosticsParams(
} as HandleCommandsParams;
}
function createBundledPluginRecord(id: string): PluginRecord {
return {
id,
name: id,
source: `bundled:${id}`,
rootDir: `/bundled/${id}`,
origin: "bundled",
enabled: true,
status: "loaded",
toolNames: [],
hookNames: [],
channelIds: [],
cliBackendIds: [],
providerIds: [],
embeddingProviderIds: [],
speechProviderIds: [],
realtimeTranscriptionProviderIds: [],
realtimeVoiceProviderIds: [],
mediaUnderstandingProviderIds: [],
transcriptSourceProviderIds: [],
imageGenerationProviderIds: [],
videoGenerationProviderIds: [],
musicGenerationProviderIds: [],
webFetchProviderIds: [],
webSearchProviderIds: [],
migrationProviderIds: [],
memoryEmbeddingProviderIds: [],
agentHarnessIds: [],
cliCommands: [],
services: [],
gatewayDiscoveryServiceIds: [],
commands: [],
httpRoutes: 0,
hookCount: 0,
configSchema: false,
} as PluginRecord;
}
function registerHostTrustedReservedCommandForTest(
command: Parameters<typeof registerPluginCommand>[1],
) {

View File

@@ -13,9 +13,10 @@ import {
matchPluginCommand,
registerPluginCommand,
} from "./commands.js";
import { createPluginRegistry, type PluginRecord } from "./registry.js";
import { createPluginRegistry } from "./registry.js";
import { setActivePluginRegistry } from "./runtime.js";
import type { PluginRuntime } from "./runtime/types.js";
import { createBundledPluginRecord } from "./status.test-helpers.js";
const completionMocks = vi.hoisted(() => ({
prepareSimpleCompletionModelForAgent: vi.fn(),
@@ -48,44 +49,6 @@ function createVoiceCommand(overrides: Partial<Parameters<typeof registerPluginC
};
}
function createBundledPluginRecord(id: string): PluginRecord {
return {
id,
name: id,
source: `bundled:${id}`,
rootDir: `/bundled/${id}`,
origin: "bundled",
enabled: true,
status: "loaded",
toolNames: [],
hookNames: [],
channelIds: [],
cliBackendIds: [],
providerIds: [],
embeddingProviderIds: [],
speechProviderIds: [],
realtimeTranscriptionProviderIds: [],
realtimeVoiceProviderIds: [],
mediaUnderstandingProviderIds: [],
transcriptSourceProviderIds: [],
imageGenerationProviderIds: [],
videoGenerationProviderIds: [],
musicGenerationProviderIds: [],
webFetchProviderIds: [],
webSearchProviderIds: [],
migrationProviderIds: [],
memoryEmbeddingProviderIds: [],
agentHarnessIds: [],
cliCommands: [],
services: [],
gatewayDiscoveryServiceIds: [],
commands: [],
httpRoutes: 0,
hookCount: 0,
configSchema: false,
} as PluginRecord;
}
function registerHostTrustedReservedCommandForTest(
command: Parameters<typeof registerPluginCommand>[1],
) {

View File

@@ -93,6 +93,15 @@ export function createPluginRecord(
};
}
export function createBundledPluginRecord(id: string): PluginRecord {
return createPluginRecord({
id,
source: `bundled:${id}`,
rootDir: `/bundled/${id}`,
origin: "bundled",
});
}
export function createTypedHook(params: {
pluginId: string;
hookName: PluginHookName;