惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
月光博客
月光博客
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
Stack Overflow Blog
Stack Overflow Blog
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家
宝玉的分享
宝玉的分享
A
About on SuperTechFans
Vercel News
Vercel News
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 【当耐特】
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Visual Studio Blog
Jina AI
Jina AI
Y
Y Combinator Blog
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(plugins): resolve native plugin sdk aliases (#85298) ...
steipete · 2026-05-22 · via Recent Commits to openclaw:main

@@ -0,0 +1,159 @@

1+

import fs from "node:fs";

2+

import { createRequire } from "node:module";

3+

import os from "node:os";

4+

import path from "node:path";

5+

import { afterEach, describe, expect, it } from "vitest";

6+

import {

7+

installOpenClawPluginSdkNativeResolver,

8+

resetOpenClawPluginSdkNativeResolverForTest,

9+

} from "./plugin-sdk-native-resolver.js";

10+11+

afterEach(() => {

12+

resetOpenClawPluginSdkNativeResolverForTest();

13+

});

14+15+

function writeJsonFile(targetPath: string, value: unknown): void {

16+

fs.mkdirSync(path.dirname(targetPath), { recursive: true });

17+

fs.writeFileSync(targetPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");

18+

}

19+20+

function writeFakeOpenClawPackage(root: string): { distRoot: string; loaderModulePath: string } {

21+

writeJsonFile(path.join(root, "package.json"), {

22+

name: "openclaw",

23+

type: "module",

24+

bin: {

25+

openclaw: "./openclaw.mjs",

26+

},

27+

exports: {

28+

"./cli-entry": "./dist/cli-entry.js",

29+

"./plugin-sdk": "./dist/plugin-sdk/root-alias.cjs",

30+

"./plugin-sdk/channel-message": "./dist/plugin-sdk/channel-message.js",

31+

"./plugin-sdk/source-only": "./dist/plugin-sdk/source-only.js",

32+

},

33+

});

34+

fs.writeFileSync(path.join(root, "openclaw.mjs"), "#!/usr/bin/env node\n", "utf8");

35+

const distRoot = path.join(root, "dist");

36+

const pluginSdkDir = path.join(distRoot, "plugin-sdk");

37+

fs.mkdirSync(pluginSdkDir, { recursive: true });

38+

fs.writeFileSync(path.join(pluginSdkDir, "root-alias.cjs"), "module.exports = {};\n", "utf8");

39+

fs.writeFileSync(

40+

path.join(pluginSdkDir, "channel-message.js"),

41+

['export const defineChannelMessageAdapter = () => "adapter";', ""].join("\n"),

42+

"utf8",

43+

);

44+

const loaderModulePath = path.join(distRoot, "plugins", "loader.js");

45+

fs.mkdirSync(path.dirname(loaderModulePath), { recursive: true });

46+

fs.writeFileSync(loaderModulePath, "export default {};\n", "utf8");

47+

return { distRoot, loaderModulePath };

48+

}

49+50+

function writeExternalPluginEntry(root: string): string {

51+

writeJsonFile(path.join(root, "package.json"), {

52+

name: "external-plugin",

53+

type: "module",

54+

});

55+

const entry = path.join(root, "dist", "runtime-api.js");

56+

fs.mkdirSync(path.dirname(entry), { recursive: true });

57+

fs.writeFileSync(entry, "export default {};\n", "utf8");

58+

return entry;

59+

}

60+61+

describe("installOpenClawPluginSdkNativeResolver", () => {

62+

it("keeps native aliases on JS dist artifacts when source files exist", () => {

63+

const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-sdk-native-source-resolver-"));

64+

const { loaderModulePath } = writeFakeOpenClawPackage(root);

65+

const sourceChannelMessagePath = path.join(root, "src", "plugin-sdk", "channel-message.ts");

66+

fs.mkdirSync(path.dirname(sourceChannelMessagePath), { recursive: true });

67+

fs.writeFileSync(sourceChannelMessagePath, "export const sourceOnly = true;\n", "utf8");

68+

const externalPluginEntry = writeExternalPluginEntry(path.join(root, "external-plugin"));

69+70+

const installedAliases = installOpenClawPluginSdkNativeResolver({

71+

modulePath: loaderModulePath,

72+

pluginModulePath: externalPluginEntry,

73+

pluginSdkResolution: "src",

74+

});

75+76+

expect(installedAliases).toContain("openclaw/plugin-sdk/channel-message");

77+

const requireFromPlugin = createRequire(externalPluginEntry);

78+

expect(fs.realpathSync(requireFromPlugin.resolve("openclaw/plugin-sdk/channel-message"))).toBe(

79+

fs.realpathSync(path.join(root, "dist", "plugin-sdk", "channel-message.js")),

80+

);

81+

});

82+83+

it("lets built external plugins resolve OpenClaw SDK subpaths with createRequire", () => {

84+

const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-sdk-native-resolver-"));

85+

const { distRoot, loaderModulePath } = writeFakeOpenClawPackage(root);

86+

const externalPluginEntry = writeExternalPluginEntry(path.join(root, "external-plugin"));

87+88+

const distMode = fs.statSync(distRoot).mode;

89+

if (process.platform !== "win32") {

90+

fs.chmodSync(distRoot, 0o555);

91+

}

92+93+

try {

94+

const installedAliases = installOpenClawPluginSdkNativeResolver({

95+

modulePath: loaderModulePath,

96+

pluginModulePath: externalPluginEntry,

97+

pluginSdkResolution: "dist",

98+

});

99+100+

expect(installedAliases).toContain("openclaw/plugin-sdk/channel-message");

101+

expect(fs.existsSync(path.join(distRoot, "extensions"))).toBe(false);

102+

const requireFromPlugin = createRequire(externalPluginEntry);

103+

expect(

104+

fs.realpathSync(requireFromPlugin.resolve("openclaw/plugin-sdk/channel-message")),

105+

).toBe(fs.realpathSync(path.join(root, "dist", "plugin-sdk", "channel-message.js")));

106+

const sdk = requireFromPlugin("openclaw/plugin-sdk/channel-message") as {

107+

defineChannelMessageAdapter?: () => string;

108+

};

109+110+

expect(sdk.defineChannelMessageAdapter?.()).toBe("adapter");

111+

expect(() => requireFromPlugin.resolve("openclaw/not-plugin-sdk/channel-message")).toThrow();

112+

} finally {

113+

if (process.platform !== "win32") {

114+

fs.chmodSync(distRoot, distMode);

115+

}

116+

}

117+

});

118+119+

it("does not resolve SDK aliases for parents outside registered plugin roots", () => {

120+

const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-sdk-native-guard-"));

121+

const { loaderModulePath } = writeFakeOpenClawPackage(root);

122+

const externalPluginEntry = writeExternalPluginEntry(path.join(root, "external-plugin"));

123+

const unrelatedRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-sdk-native-outside-"));

124+

const unrelatedEntry = path.join(unrelatedRoot, "runtime-api.js");

125+

fs.mkdirSync(path.dirname(unrelatedEntry), { recursive: true });

126+

fs.writeFileSync(unrelatedEntry, "export default {};\n", "utf8");

127+128+

installOpenClawPluginSdkNativeResolver({

129+

modulePath: loaderModulePath,

130+

pluginModulePath: externalPluginEntry,

131+

pluginSdkResolution: "dist",

132+

});

133+134+

const requireFromPlugin = createRequire(externalPluginEntry);

135+

const requireFromOutside = createRequire(unrelatedEntry);

136+

expect(requireFromPlugin.resolve("openclaw/plugin-sdk/channel-message")).toBeTruthy();

137+

expect(() => requireFromOutside.resolve("openclaw/plugin-sdk/channel-message")).toThrow();

138+

});

139+140+

it("does not register source-only SDK subpaths for native resolution", () => {

141+

const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-sdk-native-source-only-"));

142+

const { loaderModulePath } = writeFakeOpenClawPackage(root);

143+

const sourceOnlyPath = path.join(root, "src", "plugin-sdk", "source-only.ts");

144+

fs.mkdirSync(path.dirname(sourceOnlyPath), { recursive: true });

145+

fs.writeFileSync(sourceOnlyPath, "export const sourceOnly = true;\n", "utf8");

146+

const externalPluginEntry = writeExternalPluginEntry(path.join(root, "external-plugin"));

147+148+

const installedAliases = installOpenClawPluginSdkNativeResolver({

149+

modulePath: loaderModulePath,

150+

pluginModulePath: externalPluginEntry,

151+

pluginSdkResolution: "src",

152+

});

153+154+

expect(installedAliases).toContain("openclaw/plugin-sdk/channel-message");

155+

expect(installedAliases).not.toContain("openclaw/plugin-sdk/source-only");

156+

const requireFromPlugin = createRequire(externalPluginEntry);

157+

expect(() => requireFromPlugin.resolve("openclaw/plugin-sdk/source-only")).toThrow();

158+

});

159+

});