@@ -136,6 +136,20 @@ async function setupAcpxAndHelperRegistry() {
136136 return { workspaceDir, acpxRoot, helperRoot } ;
137137}
138138
139+ function useStableMetadataSnapshot ( manifestRegistry : PluginManifestRegistry ) : void {
140+ const snapshot = {
141+ manifestRegistry,
142+ plugins : manifestRegistry . plugins ,
143+ normalizePluginId : ( pluginId : string ) =>
144+ manifestRegistry . plugins . find ( ( plugin ) => plugin . legacyPluginIds ?. includes ( pluginId ) ) ?. id ??
145+ pluginId ,
146+ } ;
147+ hoisted . loadPluginMetadataSnapshot
148+ . mockReturnValueOnce ( snapshot )
149+ . mockReturnValueOnce ( snapshot )
150+ . mockReturnValueOnce ( snapshot ) ;
151+ }
152+
139153async function setupPluginOutsideSkills ( ) {
140154 const workspaceDir = await tempDirs . make ( "openclaw-" ) ;
141155 const pluginRoot = await tempDirs . make ( "openclaw-plugin-" ) ;
@@ -236,6 +250,57 @@ describe("resolvePluginSkillDirs", () => {
236250 expect ( dirs ) . toEqual ( expectedDirs ( { acpxRoot, helperRoot } ) ) ;
237251 } ) ;
238252
253+ it . each ( [
254+ {
255+ name : "unavailable to available" ,
256+ initiallyAvailable : false ,
257+ firstIncludesAcpx : false ,
258+ secondIncludesAcpx : true ,
259+ } ,
260+ {
261+ name : "available to unavailable" ,
262+ initiallyAvailable : true ,
263+ firstIncludesAcpx : true ,
264+ secondIncludesAcpx : false ,
265+ } ,
266+ ] ) (
267+ "invalidates the memo when ACP changes from $name with stable inputs" ,
268+ async ( { initiallyAvailable, firstIncludesAcpx, secondIncludesAcpx } ) => {
269+ const { workspaceDir, acpxRoot, helperRoot } = await setupAcpxAndHelperRegistry ( ) ;
270+ const manifestRegistry = buildRegistry ( { acpxRoot, helperRoot } ) ;
271+ useStableMetadataSnapshot ( manifestRegistry ) ;
272+ const config = {
273+ acp : { enabled : true } ,
274+ plugins : {
275+ entries : {
276+ acpx : { enabled : true } ,
277+ helper : { enabled : true } ,
278+ } ,
279+ } ,
280+ } as OpenClawConfig ;
281+ if ( initiallyAvailable ) {
282+ registerHealthyAcpBackend ( ) ;
283+ }
284+
285+ const first = resolvePluginSkillDirs ( { workspaceDir, config } ) ;
286+
287+ if ( initiallyAvailable ) {
288+ acpRuntimeTesting . resetAcpRuntimeBackendsForTests ( ) ;
289+ } else {
290+ registerHealthyAcpBackend ( ) ;
291+ }
292+ const second = resolvePluginSkillDirs ( { workspaceDir, config } ) ;
293+
294+ const dirsForState = ( includeAcpx : boolean ) => [
295+ ...( includeAcpx ? [ path . resolve ( acpxRoot , "skills" ) ] : [ ] ) ,
296+ path . resolve ( helperRoot , "skills" ) ,
297+ ] ;
298+ expect ( first ) . toEqual ( dirsForState ( firstIncludesAcpx ) ) ;
299+ expect ( second ) . toEqual ( dirsForState ( secondIncludesAcpx ) ) ;
300+ expect ( resolvePluginSkillDirs ( { workspaceDir, config } ) ) . toBe ( second ) ;
301+ } ,
302+ ) ;
303+
239304 it ( "rejects plugin skill paths that escape the plugin root" , async ( ) => {
240305 const { workspaceDir, pluginRoot, outsideSkills } = await setupPluginOutsideSkills ( ) ;
241306 await fs . mkdir ( path . join ( pluginRoot , "skills" ) , { recursive : true } ) ;
0 commit comments