@@ -9,10 +9,16 @@ const mocks = vi.hoisted(() => ({
99 vi . fn < typeof import ( "../channel-plugin-ids.js" ) . resolveChannelPluginIds > ( ) ,
1010 resolveEffectivePluginIds :
1111 vi . fn < typeof import ( "../effective-plugin-ids.js" ) . resolveEffectivePluginIds > ( ) ,
12+ collectConfiguredMemoryEmbeddingProviderIds :
13+ vi . fn <
14+ typeof import ( "../gateway-startup-plugin-ids.js" ) . collectConfiguredMemoryEmbeddingProviderIds
15+ > ( ) ,
1216 applyPluginAutoEnable :
1317 vi . fn < typeof import ( "../../config/plugin-auto-enable.js" ) . applyPluginAutoEnable > ( ) ,
1418 resolvePluginMetadataSnapshot :
1519 vi . fn < typeof import ( "../plugin-metadata-snapshot.js" ) . resolvePluginMetadataSnapshot > ( ) ,
20+ isPluginMetadataSnapshotCompatible :
21+ vi . fn < typeof import ( "../plugin-metadata-snapshot.js" ) . isPluginMetadataSnapshotCompatible > ( ) ,
1622 resolveAgentWorkspaceDir : vi . fn <
1723 typeof import ( "../../agents/agent-scope.js" ) . resolveAgentWorkspaceDir
1824 > ( ( ) => "/resolved-workspace" ) ,
@@ -39,6 +45,12 @@ vi.mock("../effective-plugin-ids.js", () => ({
3945 mocks . resolveEffectivePluginIds ( ...args ) ,
4046} ) ) ;
4147
48+ vi . mock ( "../gateway-startup-plugin-ids.js" , ( ) => ( {
49+ collectConfiguredMemoryEmbeddingProviderIds : (
50+ ...args : Parameters < typeof mocks . collectConfiguredMemoryEmbeddingProviderIds >
51+ ) => mocks . collectConfiguredMemoryEmbeddingProviderIds ( ...args ) ,
52+ } ) ) ;
53+
4254vi . mock ( "../../config/plugin-auto-enable.js" , ( ) => ( {
4355 applyPluginAutoEnable : ( ...args : Parameters < typeof mocks . applyPluginAutoEnable > ) =>
4456 mocks . applyPluginAutoEnable ( ...args ) ,
@@ -48,6 +60,9 @@ vi.mock("../plugin-metadata-snapshot.js", () => ({
4860 resolvePluginMetadataSnapshot : (
4961 ...args : Parameters < typeof mocks . resolvePluginMetadataSnapshot >
5062 ) => mocks . resolvePluginMetadataSnapshot ( ...args ) ,
63+ isPluginMetadataSnapshotCompatible : (
64+ ...args : Parameters < typeof mocks . isPluginMetadataSnapshotCompatible >
65+ ) => mocks . isPluginMetadataSnapshotCompatible ( ...args ) ,
5166} ) ) ;
5267
5368vi . mock ( "../../agents/agent-scope.js" , ( ) => ( {
@@ -59,6 +74,28 @@ vi.mock("../../agents/agent-scope.js", () => ({
5974
6075import { ensurePluginRegistryLoaded } from "./runtime-registry-loader.js" ;
6176
77+ function useMemoryProviderOwner ( params : {
78+ adapterId : string ;
79+ contract : "embeddingProviders" | "memoryEmbeddingProviders" ;
80+ pluginId : string ;
81+ } ) : void {
82+ mocks . resolvePluginMetadataSnapshot . mockReturnValue ( {
83+ policyHash : "test" ,
84+ index : {
85+ installRecords : { } ,
86+ plugins : [
87+ {
88+ pluginId : params . pluginId ,
89+ contributions : {
90+ contracts : { [ params . contract ] : [ params . adapterId ] } ,
91+ } ,
92+ } ,
93+ ] ,
94+ } ,
95+ manifestRegistry : { plugins : [ ] , diagnostics : [ ] } ,
96+ } as never ) ;
97+ }
98+
6299function requireLoadOptions ( ) : Record < string , unknown > {
63100 const options = mocks . loadOpenClawPlugins . mock . calls [ 0 ] ?. [ 0 ] ;
64101 if ( ! options ) {
@@ -70,6 +107,8 @@ function requireLoadOptions(): Record<string, unknown> {
70107describe ( "ensurePluginRegistryLoaded" , ( ) => {
71108 beforeEach ( ( ) => {
72109 vi . clearAllMocks ( ) ;
110+ mocks . resolvePluginMetadataSnapshot . mockReset ( ) ;
111+ mocks . isPluginMetadataSnapshotCompatible . mockReturnValue ( true ) ;
73112 mocks . applyPluginAutoEnable . mockImplementation ( ( params ) => ( {
74113 config : params . config ?? { } ,
75114 changes : [ ] ,
@@ -121,4 +160,114 @@ describe("ensurePluginRegistryLoaded", () => {
121160 } ) ,
122161 ) ;
123162 } ) ;
163+
164+ it ( "loads only the selected memory backend and embedding provider owners" , ( ) => {
165+ const config = {
166+ memory : { search : { provider : "openai" } } ,
167+ plugins : {
168+ allow : [ "acpx" , "memory-core" ] ,
169+ slots : { memory : "memory-core" } ,
170+ entries : { unrelated : { enabled : true } } ,
171+ } ,
172+ } ;
173+ mocks . collectConfiguredMemoryEmbeddingProviderIds . mockReturnValue ( new Set ( [ "openai" ] ) ) ;
174+
175+ ensurePluginRegistryLoaded ( { scope : "memory" , config } ) ;
176+
177+ expect ( mocks . collectConfiguredMemoryEmbeddingProviderIds ) . toHaveBeenCalledWith ( config ) ;
178+ expect ( requireLoadOptions ( ) ) . toEqual (
179+ expect . objectContaining ( {
180+ config,
181+ activationSourceConfig : config ,
182+ onlyPluginIds : [ "memory-core" , "openai" ] ,
183+ throwOnLoadError : true ,
184+ } ) ,
185+ ) ;
186+ } ) ;
187+
188+ it . each ( [
189+ {
190+ adapterId : "gemini" ,
191+ contract : "memoryEmbeddingProviders" as const ,
192+ pluginId : "google" ,
193+ } ,
194+ {
195+ adapterId : "local" ,
196+ contract : "embeddingProviders" as const ,
197+ pluginId : "llama-cpp" ,
198+ } ,
199+ ] ) ( "loads the $pluginId owner for the $adapterId memory adapter" , ( provider ) => {
200+ const config = {
201+ memory : { search : { provider : provider . adapterId } } ,
202+ plugins : { slots : { memory : "memory-core" } } ,
203+ } ;
204+ mocks . collectConfiguredMemoryEmbeddingProviderIds . mockReturnValue (
205+ new Set ( [ provider . adapterId ] ) ,
206+ ) ;
207+ useMemoryProviderOwner ( provider ) ;
208+
209+ ensurePluginRegistryLoaded ( { scope : "memory" , config } ) ;
210+
211+ expect ( requireLoadOptions ( ) . onlyPluginIds ) . toEqual (
212+ [ provider . pluginId , "memory-core" ] . toSorted ( ) ,
213+ ) ;
214+ } ) ;
215+
216+ it ( "keeps a denied memory provider owner denied" , ( ) => {
217+ const config = {
218+ memory : { search : { provider : "gemini" } } ,
219+ plugins : {
220+ allow : [ "memory-core" ] ,
221+ deny : [ "google" ] ,
222+ slots : { memory : "memory-core" } ,
223+ } ,
224+ } ;
225+ mocks . collectConfiguredMemoryEmbeddingProviderIds . mockReturnValue ( new Set ( [ "gemini" ] ) ) ;
226+ useMemoryProviderOwner ( {
227+ adapterId : "gemini" ,
228+ contract : "memoryEmbeddingProviders" ,
229+ pluginId : "google" ,
230+ } ) ;
231+
232+ ensurePluginRegistryLoaded ( { scope : "memory" , config } ) ;
233+
234+ const options = requireLoadOptions ( ) ;
235+ expect ( options . onlyPluginIds ) . toEqual ( [ "google" , "memory-core" ] ) ;
236+ expect ( options . config ) . toEqual ( config ) ;
237+ expect ( options . activationSourceConfig ) . toEqual ( config ) ;
238+ } ) ;
239+
240+ it ( "keeps an explicitly disabled memory provider owner disabled" , ( ) => {
241+ const config = {
242+ memory : { search : { provider : "local" } } ,
243+ plugins : {
244+ entries : { "llama-cpp" : { enabled : false } } ,
245+ slots : { memory : "memory-core" } ,
246+ } ,
247+ } ;
248+ mocks . collectConfiguredMemoryEmbeddingProviderIds . mockReturnValue ( new Set ( [ "local" ] ) ) ;
249+ useMemoryProviderOwner ( {
250+ adapterId : "local" ,
251+ contract : "embeddingProviders" ,
252+ pluginId : "llama-cpp" ,
253+ } ) ;
254+
255+ ensurePluginRegistryLoaded ( { scope : "memory" , config } ) ;
256+
257+ const options = requireLoadOptions ( ) ;
258+ expect ( options . onlyPluginIds ) . toEqual ( [ "llama-cpp" , "memory-core" ] ) ;
259+ expect ( options . config ) . toEqual ( config ) ;
260+ expect ( options . activationSourceConfig ) . toEqual ( config ) ;
261+ } ) ;
262+
263+ it ( "keeps an empty memory scope empty when no backend is selected" , ( ) => {
264+ mocks . collectConfiguredMemoryEmbeddingProviderIds . mockReturnValue ( new Set ( ) ) ;
265+
266+ ensurePluginRegistryLoaded ( {
267+ scope : "memory" ,
268+ config : { plugins : { slots : { memory : "none" } } } ,
269+ } ) ;
270+
271+ expect ( requireLoadOptions ( ) . onlyPluginIds ) . toEqual ( [ ] ) ;
272+ } ) ;
124273} ) ;
0 commit comments