@@ -29,6 +29,7 @@ function writeFakeOpenClawPackage(root: string): { distRoot: string; loaderModul
2929 exports : {
3030 "./cli-entry" : "./dist/cli-entry.js" ,
3131 "./plugin-sdk" : "./dist/plugin-sdk/root-alias.cjs" ,
32+ "./plugin-sdk/agent-runtime" : "./dist/plugin-sdk/agent-runtime.js" ,
3233 "./plugin-sdk/channel-message" : "./dist/plugin-sdk/channel-message.js" ,
3334 "./plugin-sdk/channel-outbound" : "./dist/plugin-sdk/channel-outbound.js" ,
3435 "./plugin-sdk/source-only" : "./dist/plugin-sdk/source-only.js" ,
@@ -39,6 +40,11 @@ function writeFakeOpenClawPackage(root: string): { distRoot: string; loaderModul
3940 const pluginSdkDir = path . join ( distRoot , "plugin-sdk" ) ;
4041 fs . mkdirSync ( pluginSdkDir , { recursive : true } ) ;
4142 fs . writeFileSync ( path . join ( pluginSdkDir , "root-alias.cjs" ) , "module.exports = {};\n" , "utf8" ) ;
43+ fs . writeFileSync (
44+ path . join ( pluginSdkDir , "agent-runtime.js" ) ,
45+ "export const agentRuntimeSource = import.meta.url;\n" ,
46+ "utf8" ,
47+ ) ;
4248 fs . writeFileSync (
4349 path . join ( pluginSdkDir , "channel-message.js" ) ,
4450 [ 'export * from "./channel-outbound.js";' , "" ] . join ( "\n" ) ,
@@ -74,6 +80,37 @@ function writeNormalizationCoreSource(root: string): string {
7480}
7581
7682describe ( "installOpenClawPluginSdkNativeResolver" , ( ) => {
83+ it ( "resolves installed plugin SDK imports to the dev source root" , ( ) => {
84+ const stableRoot = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-sdk-native-stable-" ) ) ;
85+ const devRoot = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-sdk-native-dev-source-" ) ) ;
86+ const { loaderModulePath } = writeFakeOpenClawPackage ( stableRoot ) ;
87+ writeFakeOpenClawPackage ( devRoot ) ;
88+ fs . mkdirSync ( path . join ( devRoot , "src" ) , { recursive : true } ) ;
89+ fs . mkdirSync ( path . join ( devRoot , "extensions" ) , { recursive : true } ) ;
90+ const externalPluginEntry = writeExternalPluginEntry ( path . join ( stableRoot , "external-plugin" ) ) ;
91+ const previousDevSourceRoot = process . env . OPENCLAW_DEV_SOURCE_ROOT ;
92+ process . env . OPENCLAW_DEV_SOURCE_ROOT = devRoot ;
93+
94+ try {
95+ const installedAliases = installOpenClawPluginSdkNativeResolver ( {
96+ modulePath : loaderModulePath ,
97+ pluginModulePath : externalPluginEntry ,
98+ } ) ;
99+
100+ expect ( installedAliases ) . toContain ( "openclaw/plugin-sdk/agent-runtime" ) ;
101+ const requireFromPlugin = createRequire ( externalPluginEntry ) ;
102+ expect ( fs . realpathSync ( requireFromPlugin . resolve ( "openclaw/plugin-sdk/agent-runtime" ) ) ) . toBe (
103+ fs . realpathSync ( path . join ( devRoot , "dist" , "plugin-sdk" , "agent-runtime.js" ) ) ,
104+ ) ;
105+ } finally {
106+ if ( previousDevSourceRoot === undefined ) {
107+ delete process . env . OPENCLAW_DEV_SOURCE_ROOT ;
108+ } else {
109+ process . env . OPENCLAW_DEV_SOURCE_ROOT = previousDevSourceRoot ;
110+ }
111+ }
112+ } ) ;
113+
77114 it ( "keeps native aliases on JS dist artifacts when source files exist" , ( ) => {
78115 const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-sdk-native-source-resolver-" ) ) ;
79116 const { loaderModulePath } = writeFakeOpenClawPackage ( root ) ;
0 commit comments