fix(plugins): share capability vitest shim aliases

This commit is contained in:
Vincent Koc
2026-04-14 16:55:30 +01:00
parent 30dcebae80
commit b4e38a7eb0
2 changed files with 60 additions and 30 deletions

View File

@@ -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"],
);
});
});

View File

@@ -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<string, string> {
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<string, string>;
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(),
};
}