@@ -1380,6 +1380,65 @@ describe("discoverOpenClawPlugins", () => {
13801380 ) . toBe ( true ) ;
13811381 } ) ;
13821382
1383+ it ( "adds managed ownership to bundled candidates deduplicated in the shared scan" , ( ) => {
1384+ const stateDir = makeTempDir ( ) ;
1385+ const bundledDir = path . join ( stateDir , "bundled" ) ;
1386+ const plainDir = path . join ( bundledDir , "plain" ) ;
1387+ const packageDir = path . join ( bundledDir , "package" ) ;
1388+ mkdirSafe ( plainDir ) ;
1389+ mkdirSafe ( packageDir ) ;
1390+ writePluginManifest ( { pluginDir : plainDir , id : "plain" } ) ;
1391+ writePluginEntry ( path . join ( plainDir , "index.js" ) ) ;
1392+ writePluginPackageManifest ( {
1393+ packageDir,
1394+ packageName : "@openclaw/package" ,
1395+ extensions : [ "./index.js" ] ,
1396+ } ) ;
1397+ writePluginManifest ( { pluginDir : packageDir , id : "package" } ) ;
1398+ writePluginEntry ( path . join ( packageDir , "index.js" ) ) ;
1399+ const env = buildDiscoveryEnvWithOverrides ( stateDir , {
1400+ OPENCLAW_BUNDLED_PLUGINS_DIR : bundledDir ,
1401+ } ) ;
1402+ const installRecords = {
1403+ "plain-owner" : { source : "path" , installPath : plainDir } ,
1404+ "package-owner" : { source : "path" , installPath : packageDir } ,
1405+ } satisfies Record < string , PluginInstallRecord > ;
1406+
1407+ const result = discoverOpenClawPlugins ( { env, installRecords } ) ;
1408+
1409+ expectCandidateSource ( result . candidates , "plain" , path . join ( plainDir , "index.js" ) ) ;
1410+ expectCandidateFields ( requireCandidateById ( result . candidates , "plain" ) , {
1411+ origin : "bundled" ,
1412+ packageName : undefined ,
1413+ installOwner : "plain-owner" ,
1414+ } ) ;
1415+ expectCandidateSource ( result . candidates , "package" , path . join ( packageDir , "index.js" ) ) ;
1416+ expectCandidateFields ( requireCandidateById ( result . candidates , "package" ) , {
1417+ origin : "bundled" ,
1418+ packageName : "@openclaw/package" ,
1419+ installOwner : "package-owner" ,
1420+ } ) ;
1421+
1422+ const ambiguous = discoverOpenClawPlugins ( {
1423+ env,
1424+ installRecords : {
1425+ ...installRecords ,
1426+ "other-owner" : installRecords [ "plain-owner" ] ,
1427+ } ,
1428+ } ) ;
1429+
1430+ expectCandidateFields ( requireCandidateById ( ambiguous . candidates , "plain" ) , {
1431+ origin : "bundled" ,
1432+ installOwner : undefined ,
1433+ installOwnerAmbiguous : true ,
1434+ } ) ;
1435+ expectDiagnostic ( {
1436+ diagnostics : ambiguous . diagnostics ,
1437+ level : "error" ,
1438+ messageIncludes : "multiple plugin install records claim the same package path" ,
1439+ } ) ;
1440+ } ) ;
1441+
13831442 it ( "reuses one filesystem realpath lookup per package root within a discovery run" , ( ) => {
13841443 const stateDir = makeTempDir ( ) ;
13851444 const packageDir = path . join ( stateDir , "extensions" , "pack" ) ;
0 commit comments