33import fs from "node:fs" ;
44import os from "node:os" ;
55import path from "node:path" ;
6- import { afterAll , beforeEach , expect , it , vi } from "vitest" ;
6+ import { afterAll , afterEach , beforeEach , expect , it , vi } from "vitest" ;
77import type { OpenClawConfig } from "../config/types.openclaw.js" ;
8+ import { clearCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-state.js" ;
89import type { PluginMetadataSnapshot } from "./plugin-metadata-snapshot.types.js" ;
910import { createColdPluginFixture } from "./test-helpers/cold-plugin-fixtures.js" ;
1011
1112const counters = vi . hoisted ( ( ) => ( { manifestRegistryRebuilds : 0 , discoveryScans : 0 } ) ) ;
1213
13- vi . mock ( "./ plugin-registry-contributions .js" , async ( importOriginal ) => {
14- const actual = await importOriginal < typeof import ( "./ plugin-registry-contributions .js" ) > ( ) ;
14+ vi . mock ( "../config/io. plugin-metadata .js" , async ( importOriginal ) => {
15+ const actual = await importOriginal < typeof import ( "../config/io. plugin-metadata .js" ) > ( ) ;
1516 return {
1617 ...actual ,
17- loadPluginManifestRegistryForPluginRegistry : (
18- ...args : Parameters < typeof actual . loadPluginManifestRegistryForPluginRegistry >
18+ resolveConfigWidePluginManifestRegistry : (
19+ ...args : Parameters < typeof actual . resolveConfigWidePluginManifestRegistry >
1920 ) => {
2021 counters . manifestRegistryRebuilds += 1 ;
21- return actual . loadPluginManifestRegistryForPluginRegistry ( ...args ) ;
22+ return actual . resolveConfigWidePluginManifestRegistry ( ...args ) ;
2223 } ,
2324 } ;
2425} ) ;
@@ -89,11 +90,16 @@ function countResolve(metadataSnapshot: PluginMetadataSnapshot): {
8990}
9091
9192beforeEach ( ( ) => {
93+ clearCurrentPluginMetadataSnapshot ( ) ;
9294 vi . stubEnv ( "OPENCLAW_DISABLE_BUNDLED_PLUGINS" , "1" ) ;
9395 vi . stubEnv ( "OPENCLAW_HOME" , path . join ( tempRoot , "home" ) ) ;
9496 vi . stubEnv ( "OPENCLAW_STATE_DIR" , path . join ( tempRoot , "state" ) ) ;
9597} ) ;
9698
99+ afterEach ( ( ) => {
100+ clearCurrentPluginMetadataSnapshot ( ) ;
101+ } ) ;
102+
97103afterAll ( ( ) => {
98104 fs . rmSync ( tempRoot , { recursive : true , force : true } ) ;
99105 vi . unstubAllEnvs ( ) ;
@@ -117,11 +123,16 @@ it("only reuses a snapshot that answers for the whole config", () => {
117123 const env = process . env ;
118124 const withoutSnapshot = resolveEffectivePluginIds ( { config, env } ) ;
119125 const full = countResolve ( loadPluginMetadataSnapshot ( { config, env } ) ) ;
126+ clearCurrentPluginMetadataSnapshot ( ) ;
120127 // `recordPluginInstallSource` asks for one plugin's effective state, which scopes the
121128 // snapshot to that plugin and truncates its manifest set to that plugin alone.
122- const scoped = countResolve (
123- loadPluginMetadataSnapshot ( { config, env, pluginIds : [ "other-plugin" ] } ) ,
124- ) ;
129+ const scopedSnapshot = loadPluginMetadataSnapshot ( {
130+ config,
131+ env,
132+ pluginIds : [ "other-plugin" ] ,
133+ } ) ;
134+ clearCurrentPluginMetadataSnapshot ( ) ;
135+ const scoped = countResolve ( scopedSnapshot ) ;
125136
126137 expect ( { full : full . ids , scoped : scoped . ids } ) . toEqual ( {
127138 full : withoutSnapshot ,
0 commit comments