@@ -107,7 +107,8 @@ describe("prepared model runtime snapshots", () => {
107107 getTesting ( ) . resetPreparedModelRuntimeSnapshotsForTest ( ) ;
108108 mocks . discoverAuthStorage . mockClear ( ) ;
109109 mocks . discoverModels . mockClear ( ) ;
110- mocks . ensureOpenClawModelsJson . mockClear ( ) ;
110+ mocks . ensureOpenClawModelsJson . mockReset ( ) ;
111+ mocks . ensureOpenClawModelsJson . mockResolvedValue ( { agentDir : "/tmp/agent" , wrote : false } ) ;
111112 mocks . buildPreparedModelCatalogSnapshot . mockClear ( ) ;
112113 mocks . ensureRuntimePluginsLoaded . mockClear ( ) ;
113114 mocks . loadStaticCatalog . mockClear ( ) ;
@@ -700,6 +701,22 @@ describe("prepared model runtime snapshots", () => {
700701 }
701702 } ) ;
702703
704+ it ( "does not replay an auth mutation that occurs before the first owner is registered" , async ( ) => {
705+ getTesting ( ) . setModelRuntimeBuildTimeoutMsForTest ( 100 ) ;
706+ mocks . configuredAgentIds = [ "default" ] ;
707+ mocks . ensureRuntimePluginsLoaded . mockImplementationOnce ( ( ) => {
708+ mocks . mutationListener ?.( { affectsInheritedStores : true } ) ;
709+ } ) ;
710+ mocks . ensureOpenClawModelsJson
711+ . mockResolvedValueOnce ( { agentDir : "/tmp/unused-agent" , wrote : false } )
712+ . mockImplementationOnce ( async ( ) => await new Promise < never > ( ( ) => { } ) ) ;
713+
714+ await expect (
715+ refreshPreparedModelRuntimeSnapshots ( { } , { gatewayLifecycle : true } ) ,
716+ ) . resolves . toBeUndefined ( ) ;
717+ expect ( mocks . ensureOpenClawModelsJson ) . toHaveBeenCalledOnce ( ) ;
718+ } ) ;
719+
703720 it ( "awaits auth invalidation queued during lifecycle publication" , async ( ) => {
704721 mocks . configuredAgentIds = [ "default" ] ;
705722 await refreshPreparedModelRuntimeSnapshots ( { } ) ;
0 commit comments