@@ -122,34 +122,36 @@ describe("agent runtime plugin registries", () => {
122122 ) ;
123123 } ) ;
124124
125- it ( "reuses the Gateway inbound registry and loads only its selected provider delta" , ( ) => {
125+ it ( "reuses the current Gateway generation and loads only the imported-plugin delta" , ( ) => {
126126 const config = { } as never ;
127- const gatewayPlugin = {
128- id : "gateway-owned" ,
129- origin : "bundled" ,
130- rootDir : "/dist/extensions/gateway-owned" ,
131- source : "/dist/extensions/gateway-owned/index.js" ,
132- status : "loaded" ,
127+ const workspaceDir = "/tmp/default-workspace" ;
128+ const activeRegistry = {
129+ plugins : [
130+ { id : "gateway-owned" , origin : "bundled" , status : "loaded" } ,
131+ {
132+ id : "deferred" ,
133+ origin : "bundled" ,
134+ status : "loaded" ,
135+ format : "openclaw" ,
136+ imported : false ,
137+ } ,
138+ ] ,
133139 } ;
134- const activeRegistry = { plugins : [ gatewayPlugin ] } ;
135- const selectedRegistry = { plugins : [ gatewayPlugin , { id : "selected-provider" } ] } ;
136140 const metadataSnapshot = {
137- ...createMetadataSnapshot ( "/tmp/default-workspace" , undefined ) ,
141+ ...createMetadataSnapshot ( workspaceDir , undefined ) ,
138142 manifestRegistry : {
139143 diagnostics : [ ] ,
140144 plugins : [
141- {
142- id : "gateway-owned" ,
143- origin : "bundled" ,
144- rootDir : "/extensions/gateway-owned" ,
145- source : "/extensions/gateway-owned/index.ts" ,
146- } ,
145+ { id : "gateway-owned" , origin : "bundled" } ,
146+ { id : "deferred" , origin : "bundled" } ,
147147 ] ,
148148 } ,
149149 } ;
150+ const selectedRegistry = { plugins : [ ...activeRegistry . plugins , { id : "selected-provider" } ] } ;
150151 hoisted . getActivePluginRegistry . mockReturnValue ( activeRegistry ) ;
152+ hoisted . getActivePluginRegistryWorkspaceDir . mockReturnValue ( workspaceDir ) ;
151153 hoisted . getActivePluginRuntimeSubagentMode . mockReturnValue ( "gateway-bindable" ) ;
152- hoisted . getCurrentPluginMetadataSnapshot . mockImplementation ( ( ) => metadataSnapshot ) ;
154+ hoisted . getCurrentPluginMetadataSnapshot . mockReturnValue ( metadataSnapshot ) ;
153155 hoisted . loadPluginRegistryHandle . mockReturnValue ( selectedRegistry ) ;
154156 hoisted . resolveAgentRuntimePluginLoadPlan . mockImplementation ( ( { basePluginIds } ) => ( {
155157 config,
@@ -162,71 +164,82 @@ describe("agent runtime plugin registries", () => {
162164 allowGatewaySubagentBinding : true ,
163165 config,
164166 runtimePluginSelections : [ { provider : "selected" , modelId : "model" } ] ,
165- workspaceDir : "/tmp/default-workspace" ,
167+ workspaceDir,
166168 } ,
167169 metadataSnapshot as never ,
168170 createPreparedInboundRegistryLoader ( ) ,
171+ true ,
169172 ) ;
170173
171174 expect ( prepared . inboundPluginRegistry ) . toBe ( activeRegistry ) ;
172175 expect ( prepared . runtimePluginRegistry ) . toBe ( selectedRegistry ) ;
176+ expect ( hoisted . resolveAgentRuntimePluginLoadPlan ) . toHaveBeenCalledWith (
177+ expect . objectContaining ( { basePluginIds : [ "gateway-owned" ] } ) ,
178+ ) ;
173179 expect ( hoisted . loadPluginRegistryHandle ) . toHaveBeenCalledOnce ( ) ;
174180 expect ( hoisted . loadPluginRegistryHandle ) . toHaveBeenCalledWith (
175181 expect . objectContaining ( {
176182 onlyPluginIds : [ "gateway-owned" , "selected-provider" ] ,
183+ preferBuiltPluginArtifacts : true ,
177184 } ) ,
178185 ) ;
179186 } ) ;
180187
181- it ( "refuses Gateway registry reuse for a non-current metadata generation" , ( ) => {
188+ it . each ( [
189+ {
190+ name : "custom environment" ,
191+ input : { env : { OPENCLAW_STATE_DIR : "/tmp/custom-state" } } ,
192+ } ,
193+ {
194+ name : "non-bindable mode" ,
195+ setup : ( ) => hoisted . getActivePluginRuntimeSubagentMode . mockReturnValue ( "default" ) ,
196+ } ,
197+ {
198+ name : "different workspace" ,
199+ setup : ( ) => hoisted . getActivePluginRegistryWorkspaceDir . mockReturnValue ( "/tmp/other" ) ,
200+ } ,
201+ {
202+ name : "stale metadata generation" ,
203+ setup : ( ) => hoisted . getCurrentPluginMetadataSnapshot . mockReturnValue ( { } ) ,
204+ } ,
205+ {
206+ name : "manifest mismatch" ,
207+ setup : ( activeRegistry : { plugins : Array < { origin : string } > } ) => {
208+ activeRegistry . plugins [ 0 ] ! . origin = "external" ;
209+ } ,
210+ } ,
211+ ] ) ( "refuses Gateway registry reuse for $name" , ( { input, setup } ) => {
182212 const config = { } as never ;
183- const gatewayPlugin = {
184- id : "gateway-owned" ,
185- origin : "bundled" ,
186- rootDir : "/dist/extensions/gateway-owned" ,
187- source : "/dist/extensions/gateway-owned/index.js" ,
188- status : "loaded" ,
213+ const workspaceDir = "/tmp/default-workspace" ;
214+ const activeRegistry = {
215+ plugins : [ { id : "gateway-owned" , origin : "bundled" , status : "loaded" } ] ,
189216 } ;
190- const activeRegistry = { plugins : [ gatewayPlugin ] } ;
191217 const metadataSnapshot = {
192- ...createMetadataSnapshot ( "/tmp/default-workspace" , undefined ) ,
218+ ...createMetadataSnapshot ( workspaceDir , undefined ) ,
193219 manifestRegistry : {
194220 diagnostics : [ ] ,
195- plugins : [
196- {
197- id : "gateway-owned" ,
198- origin : "bundled" ,
199- rootDir : "/extensions/gateway-owned" ,
200- source : "/extensions/gateway-owned/index.ts" ,
201- } ,
202- ] ,
221+ plugins : [ { id : "gateway-owned" , origin : "bundled" } ] ,
203222 } ,
204223 } ;
205224 hoisted . getActivePluginRegistry . mockReturnValue ( activeRegistry ) ;
225+ hoisted . getActivePluginRegistryWorkspaceDir . mockReturnValue ( workspaceDir ) ;
206226 hoisted . getActivePluginRuntimeSubagentMode . mockReturnValue ( "gateway-bindable" ) ;
207- // A different (older/leaked) generation is current: identity must fail closed.
208- hoisted . getCurrentPluginMetadataSnapshot . mockReturnValue (
209- createMetadataSnapshot ( "/tmp/default-workspace" , undefined ) ,
210- ) ;
211- hoisted . loadPluginRegistryHandle . mockReturnValue ( { plugins : [ ] } ) ;
212- hoisted . resolveAgentRuntimePluginLoadPlan . mockImplementation ( ( { basePluginIds } ) => ( {
213- config,
214- pluginIds : basePluginIds ,
215- } ) ) ;
227+ hoisted . getCurrentPluginMetadataSnapshot . mockReturnValue ( metadataSnapshot ) ;
228+ setup ?.( activeRegistry ) ;
216229
217- const loadInboundRegistry = createPreparedInboundRegistryLoader ( ) ;
218- const inbound = loadInboundRegistry (
230+ const inbound = createPreparedInboundRegistryLoader ( ) (
219231 {
220232 agentDir : "/tmp/agent" ,
221233 allowGatewaySubagentBinding : true ,
222234 config,
223- workspaceDir : "/tmp/default-workspace" ,
235+ workspaceDir,
236+ ...input ,
224237 } ,
225238 metadataSnapshot as never ,
226239 ) ;
227240
228241 expect ( inbound ) . not . toBe ( activeRegistry ) ;
229- expect ( hoisted . loadPluginRegistryHandle ) . toHaveBeenCalled ( ) ;
242+ expect ( hoisted . loadPluginRegistryHandle ) . toHaveBeenCalledOnce ( ) ;
230243 } ) ;
231244
232245 it ( "keeps direct no-current loads on the requested workspace" , ( ) => {
0 commit comments