@@ -159,6 +159,81 @@ describe("diffConfigPaths", () => {
159159 expect ( changedPaths ) . toEqual ( [ "mcp" , "mcp.apps" ] ) ;
160160 expect ( buildGatewayReloadPlan ( changedPaths ) . restartReasons ) . toContain ( "mcp.apps" ) ;
161161 } ) ;
162+
163+ it . each ( [
164+ {
165+ name : "adds agents" ,
166+ prev : { } ,
167+ next : {
168+ agents : {
169+ ownership : "explicit" ,
170+ defaults : { sessionStore : { agentId : "ops" } } ,
171+ entries : { ops : { } } ,
172+ } ,
173+ } ,
174+ expectedPaths : [ "agents.ownership" , "agents.defaults.sessionStore" , "agents.entries" ] ,
175+ } ,
176+ {
177+ name : "removes agents" ,
178+ prev : {
179+ agents : {
180+ ownership : "explicit" ,
181+ defaults : { sessionStore : { agentId : "ops" } } ,
182+ entries : { ops : { } } ,
183+ } ,
184+ } ,
185+ next : { } ,
186+ expectedPaths : [ "agents.ownership" , "agents.defaults.sessionStore" , "agents.entries" ] ,
187+ } ,
188+ {
189+ name : "adds agent defaults" ,
190+ prev : { agents : { ownership : "explicit" , entries : { ops : { } } } } ,
191+ next : {
192+ agents : {
193+ ownership : "explicit" ,
194+ defaults : { sessionStore : { agentId : "ops" } } ,
195+ entries : { ops : { } } ,
196+ } ,
197+ } ,
198+ expectedPaths : [ "agents.defaults.sessionStore" ] ,
199+ } ,
200+ {
201+ name : "removes agent defaults" ,
202+ prev : {
203+ agents : {
204+ ownership : "explicit" ,
205+ defaults : { sessionStore : { agentId : "ops" } } ,
206+ entries : { ops : { } } ,
207+ } ,
208+ } ,
209+ next : { agents : { ownership : "explicit" , entries : { ops : { } } } } ,
210+ expectedPaths : [ "agents.defaults.sessionStore" ] ,
211+ } ,
212+ {
213+ name : "adds session config" ,
214+ prev : { } ,
215+ next : { session : { scope : "global" , store : "/tmp/fixed.sqlite" } } ,
216+ expectedPaths : [ "session.scope" , "session.store" ] ,
217+ } ,
218+ {
219+ name : "removes session config" ,
220+ prev : { session : { scope : "global" , store : "/tmp/fixed.sqlite" } } ,
221+ next : { } ,
222+ expectedPaths : [ "session.scope" , "session.store" ] ,
223+ } ,
224+ ] ) ( "preserves hook policy dependencies when it $name" , ( { prev, next, expectedPaths } ) => {
225+ const changedPaths = diffGatewayReloadPaths ( prev as OpenClawConfig , next as OpenClawConfig ) ;
226+
227+ for ( const expectedPath of expectedPaths ) {
228+ expect ( changedPaths ) . toContain ( expectedPath ) ;
229+ }
230+ expect ( buildGatewayReloadPlan ( changedPaths ) ) . toMatchObject ( {
231+ restartGateway : false ,
232+ refreshHooksPolicy : true ,
233+ reloadHooks : false ,
234+ restartGmailWatcher : false ,
235+ } ) ;
236+ } ) ;
162237} ) ;
163238
164239describe ( "buildGatewayReloadPlan" , ( ) => {
@@ -343,6 +418,37 @@ describe("buildGatewayReloadPlan", () => {
343418 } ) ;
344419 } ) ;
345420
421+ it . each ( [
422+ { path : "agents.entries" , restartHeartbeat : true } ,
423+ { path : "agents.ownership" , restartHeartbeat : false } ,
424+ { path : "agents.defaults.sessionStore" , restartHeartbeat : false } ,
425+ { path : "agents.defaults.sessionStore.agentId" , restartHeartbeat : false } ,
426+ { path : "session.scope" , restartHeartbeat : false } ,
427+ { path : "session.store" , restartHeartbeat : false } ,
428+ ] ) ( "refreshes only hook target policy for $path" , ( { path, restartHeartbeat } ) => {
429+ const plan = buildGatewayReloadPlan ( [ path ] ) ;
430+
431+ expect ( plan ) . toMatchObject ( {
432+ restartGateway : false ,
433+ refreshHooksPolicy : true ,
434+ reloadHooks : false ,
435+ restartGmailWatcher : false ,
436+ restartHeartbeat,
437+ } ) ;
438+ expect ( isNoopGatewayReloadPlan ( plan ) ) . toBe ( false ) ;
439+ } ) ;
440+
441+ it . each ( [
442+ "agents" ,
443+ "agents.defaults" ,
444+ "agents.defaults.systemAgent.agentId" ,
445+ "agents.list" ,
446+ "session" ,
447+ "session.mainKey" ,
448+ ] ) ( "does not broadly refresh hook target policy for %s" , ( path ) => {
449+ expect ( buildGatewayReloadPlan ( [ path ] ) . refreshHooksPolicy ) . not . toBe ( true ) ;
450+ } ) ;
451+
346452 it . each ( [
347453 "agents.defaults" ,
348454 "agents.defaults.compaction" ,
0 commit comments