refactor(plugins): extract alias candidate resolution

This commit is contained in:
Peter Steinberger
2026-03-08 00:28:36 +00:00
parent 7ac7b39eff
commit e758d49361
2 changed files with 74 additions and 20 deletions

View File

@@ -1351,6 +1351,20 @@ describe("loadOpenClawPlugins", () => {
expect(resolved).toBe(distFile);
});
it("prefers dist candidates first for production src runtime", () => {
const { root, srcFile, distFile } = createPluginSdkAliasFixture();
const candidates = withEnv({ NODE_ENV: "production", VITEST: undefined }, () =>
__testing.listPluginSdkAliasCandidates({
srcFile: "index.ts",
distFile: "index.js",
modulePath: path.join(root, "src", "plugins", "loader.ts"),
}),
);
expect(candidates.indexOf(distFile)).toBeLessThan(candidates.indexOf(srcFile));
});
it("prefers src plugin-sdk alias when loader runs from src in non-production", () => {
const { root, srcFile } = createPluginSdkAliasFixture();
@@ -1364,6 +1378,20 @@ describe("loadOpenClawPlugins", () => {
expect(resolved).toBe(srcFile);
});
it("prefers src candidates first for non-production src runtime", () => {
const { root, srcFile, distFile } = createPluginSdkAliasFixture();
const candidates = withEnv({ NODE_ENV: undefined }, () =>
__testing.listPluginSdkAliasCandidates({
srcFile: "index.ts",
distFile: "index.js",
modulePath: path.join(root, "src", "plugins", "loader.ts"),
}),
);
expect(candidates.indexOf(srcFile)).toBeLessThan(candidates.indexOf(distFile));
});
it("falls back to src plugin-sdk alias when dist is missing in production", () => {
const { root, srcFile, distFile } = createPluginSdkAliasFixture();
fs.rmSync(distFile);