diff --git a/src/plugins/bundled-capability-runtime.test.ts b/src/plugins/bundled-capability-runtime.test.ts new file mode 100644 index 00000000000..67ee7b334b5 --- /dev/null +++ b/src/plugins/bundled-capability-runtime.test.ts @@ -0,0 +1,24 @@ +import { describe, expect, it } from "vitest"; +import { buildVitestCapabilityShimAliasMap } from "./bundled-capability-runtime.js"; + +describe("buildVitestCapabilityShimAliasMap", () => { + it("keeps scoped and unscoped capability shim aliases aligned", () => { + const aliasMap = buildVitestCapabilityShimAliasMap(); + + expect(aliasMap["openclaw/plugin-sdk/llm-task"]).toBe( + aliasMap["@openclaw/plugin-sdk/llm-task"], + ); + expect(aliasMap["openclaw/plugin-sdk/config-runtime"]).toBe( + aliasMap["@openclaw/plugin-sdk/config-runtime"], + ); + expect(aliasMap["openclaw/plugin-sdk/media-runtime"]).toBe( + aliasMap["@openclaw/plugin-sdk/media-runtime"], + ); + expect(aliasMap["openclaw/plugin-sdk/provider-onboard"]).toBe( + aliasMap["@openclaw/plugin-sdk/provider-onboard"], + ); + expect(aliasMap["openclaw/plugin-sdk/speech-core"]).toBe( + aliasMap["@openclaw/plugin-sdk/speech-core"], + ); + }); +}); diff --git a/src/plugins/bundled-capability-runtime.ts b/src/plugins/bundled-capability-runtime.ts index 02bb8244947..baa4d670282 100644 --- a/src/plugins/bundled-capability-runtime.ts +++ b/src/plugins/bundled-capability-runtime.ts @@ -25,6 +25,41 @@ import type { OpenClawPluginDefinition, OpenClawPluginModule } from "./types.js" const log = createSubsystemLogger("plugins"); +const CAPABILITY_VITEST_SHIM_ALIASES = [ + { + subpath: "llm-task", + target: new URL("./capability-runtime-vitest-shims/llm-task.ts", import.meta.url), + }, + { + subpath: "config-runtime", + target: new URL("./capability-runtime-vitest-shims/config-runtime.ts", import.meta.url), + }, + { + subpath: "media-runtime", + target: new URL("./capability-runtime-vitest-shims/media-runtime.ts", import.meta.url), + }, + { + subpath: "provider-onboard", + target: new URL("../plugin-sdk/provider-onboard.ts", import.meta.url), + }, + { + subpath: "speech-core", + target: new URL("./capability-runtime-vitest-shims/speech-core.ts", import.meta.url), + }, +] as const; + +export function buildVitestCapabilityShimAliasMap(): Record { + return Object.fromEntries( + CAPABILITY_VITEST_SHIM_ALIASES.flatMap(({ subpath, target }) => { + const targetPath = fileURLToPath(target); + return [ + [`openclaw/plugin-sdk/${subpath}`, targetPath], + [`@openclaw/plugin-sdk/${subpath}`, targetPath], + ]; + }), + ); +} + function applyVitestCapabilityAliasOverrides(params: { aliasMap: Record; pluginSdkResolution?: PluginSdkResolutionPreference; @@ -44,36 +79,7 @@ function applyVitestCapabilityAliasOverrides(params: { // Capability contract loads only need a narrow SDK slice. Keep those // helpers on a tiny source graph so Vitest does not pull the dist chunk // bundle that also drags Matrix/WhatsApp code into these tests. - "openclaw/plugin-sdk/llm-task": fileURLToPath( - new URL("./capability-runtime-vitest-shims/llm-task.ts", import.meta.url), - ), - "@openclaw/plugin-sdk/llm-task": fileURLToPath( - new URL("./capability-runtime-vitest-shims/llm-task.ts", import.meta.url), - ), - "openclaw/plugin-sdk/config-runtime": fileURLToPath( - new URL("./capability-runtime-vitest-shims/config-runtime.ts", import.meta.url), - ), - "@openclaw/plugin-sdk/config-runtime": fileURLToPath( - new URL("./capability-runtime-vitest-shims/config-runtime.ts", import.meta.url), - ), - "openclaw/plugin-sdk/media-runtime": fileURLToPath( - new URL("./capability-runtime-vitest-shims/media-runtime.ts", import.meta.url), - ), - "@openclaw/plugin-sdk/media-runtime": fileURLToPath( - new URL("./capability-runtime-vitest-shims/media-runtime.ts", import.meta.url), - ), - "openclaw/plugin-sdk/provider-onboard": fileURLToPath( - new URL("../plugin-sdk/provider-onboard.ts", import.meta.url), - ), - "@openclaw/plugin-sdk/provider-onboard": fileURLToPath( - new URL("../plugin-sdk/provider-onboard.ts", import.meta.url), - ), - "openclaw/plugin-sdk/speech-core": fileURLToPath( - new URL("./capability-runtime-vitest-shims/speech-core.ts", import.meta.url), - ), - "@openclaw/plugin-sdk/speech-core": fileURLToPath( - new URL("./capability-runtime-vitest-shims/speech-core.ts", import.meta.url), - ), + ...buildVitestCapabilityShimAliasMap(), }; }