























@@ -390,6 +390,127 @@ describe("bundled channel entry shape guards", () => {
390390}
391391});
392392393+it("falls back through the cached loader for package-local dist entries needing SDK aliases", async () => {
394+const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-bundled-package-dist-"));
395+const pluginDir = path.join(root, "extensions", "alpha", "dist");
396+fs.mkdirSync(pluginDir, { recursive: true });
397+fs.writeFileSync(path.join(root, "package.json"), '{"type":"module"}\n', "utf8");
398+fs.writeFileSync(
399+path.join(pluginDir, "index.js"),
400+[
401+'import { defineBundledChannelEntry } from "openclaw/plugin-sdk/channel-entry-contract";',
402+"export default defineBundledChannelEntry({",
403+" id: 'alpha',",
404+" name: 'Alpha',",
405+" description: 'Alpha',",
406+" importMetaUrl: import.meta.url,",
407+" plugin: { specifier: './plugin.js', exportName: 'plugin' },",
408+"});",
409+"",
410+].join("\n"),
411+"utf8",
412+);
413+fs.writeFileSync(
414+path.join(pluginDir, "plugin.js"),
415+[
416+"export const plugin = {",
417+" id: 'alpha',",
418+" meta: { id: 'alpha', label: 'Package dist Alpha' },",
419+" capabilities: {},",
420+" config: {},",
421+"};",
422+"",
423+].join("\n"),
424+"utf8",
425+);
426+427+vi.doMock("./bundled-root.js", () => ({
428+resolveBundledChannelRootScope: () => ({
429+packageRoot: root,
430+cacheKey: `${root}:package-local-dist`,
431+}),
432+}));
433+vi.doMock("../../plugins/bundled-channel-runtime.js", () => ({
434+listBundledChannelPluginMetadata: () => [
435+{
436+ ...alphaChannelMetadata(),
437+source: {
438+source: path.join(root, "extensions", "alpha", "index.ts"),
439+built: path.join(root, "extensions", "alpha", "index.ts"),
440+},
441+},
442+],
443+resolveBundledChannelGeneratedPath: () => path.join(pluginDir, "index.js"),
444+}));
445+446+try {
447+const bundled = await importFreshModule<typeof import("./bundled.js")>(
448+import.meta.url,
449+"./bundled.js?scope=bundled-package-local-dist-sdk-alias",
450+);
451+452+expect(bundled.requireBundledChannelPlugin("alpha").meta.label).toBe("Package dist Alpha");
453+} finally {
454+fs.rmSync(root, { recursive: true, force: true });
455+}
456+});
457+458+it("falls back through the cached loader for direct override dist entries needing SDK aliases", async () => {
459+const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-bundled-direct-dist-"));
460+const previousBundledPluginsDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
461+const pluginsRoot = path.join(root, "bundled-plugins");
462+const pluginDir = path.join(pluginsRoot, "alpha", "dist");
463+fs.mkdirSync(pluginDir, { recursive: true });
464+fs.writeFileSync(path.join(pluginsRoot, "package.json"), '{"type":"module"}\n', "utf8");
465+fs.writeFileSync(
466+path.join(pluginDir, "index.js"),
467+[
468+'import { defineBundledChannelEntry } from "openclaw/plugin-sdk/channel-entry-contract";',
469+"export default defineBundledChannelEntry({",
470+" id: 'alpha',",
471+" name: 'Alpha',",
472+" description: 'Alpha',",
473+" importMetaUrl: import.meta.url,",
474+" plugin: { specifier: './plugin.js', exportName: 'plugin' },",
475+"});",
476+"",
477+].join("\n"),
478+"utf8",
479+);
480+fs.writeFileSync(
481+path.join(pluginDir, "plugin.js"),
482+[
483+"export const plugin = {",
484+" id: 'alpha',",
485+" meta: { id: 'alpha', label: 'Direct dist Alpha' },",
486+" capabilities: {},",
487+" config: {},",
488+"};",
489+"",
490+].join("\n"),
491+"utf8",
492+);
493+494+vi.doMock("../../plugins/bundled-channel-runtime.js", () => ({
495+listBundledChannelPluginMetadata: () => [alphaChannelMetadata()],
496+resolveBundledChannelGeneratedPath: () => path.join(pluginDir, "index.js"),
497+}));
498+499+try {
500+process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = pluginsRoot;
501+502+const bundled = await importFreshModule<typeof import("./bundled.js")>(
503+import.meta.url,
504+"./bundled.js?scope=bundled-direct-dist-sdk-alias",
505+);
506+507+expect(bundled.requireBundledChannelPlugin("alpha").meta.label).toBe("Direct dist Alpha");
508+} finally {
509+restoreBundledPluginsDir(previousBundledPluginsDir);
510+fs.rmSync(root, { recursive: true, force: true });
511+}
512+});
513+393514it("treats direct bundled plugin-tree overrides as scan roots", async () => {
394515const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-bundled-direct-override-"));
395516const previousBundledPluginsDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。