@@ -188,17 +188,25 @@ function expectSuccessfulSessionsUsage(
188188 return result . sessions ;
189189}
190190
191- function mockStoredSession ( key : string , sessionId : string ) {
191+ function mockStoredSession (
192+ key : string ,
193+ sessionId : string ,
194+ options : { resolution ?: "valid" | "missing" } = { } ,
195+ ) {
192196 const entry = { sessionId, updatedAt : 1_000 } ;
197+ const storePath = "/tmp/agents/opus/agent/openclaw-agent.sqlite" ;
193198 vi . mocked ( loadGatewaySessionEntryReadOnly ) . mockReturnValueOnce ( {
194199 cfg : TEST_RUNTIME_CONFIG ,
195200 canonicalKey : key ,
196201 entry,
197202 legacyKey : undefined ,
198203 store : { [ key ] : entry } ,
199204 storeKeys : [ key ] ,
200- storePath : "/tmp/agents/opus/sessions/sessions.json" ,
205+ storePath,
201206 } ) ;
207+ vi . mocked ( resolveExistingUsageSessionFile ) . mockReturnValueOnce (
208+ options . resolution === "missing" ? undefined : `sqlite:opus:${ sessionId } :${ storePath } ` ,
209+ ) ;
202210 return entry ;
203211}
204212
@@ -852,8 +860,7 @@ describe("sessions.usage", () => {
852860
853861 it ( "fails closed when a canonical stored target no longer matches" , async ( ) => {
854862 const key = "agent:opus:stale" ;
855- mockStoredSession ( key , "stale" ) ;
856- vi . mocked ( resolveExistingUsageSessionFile ) . mockReturnValueOnce ( undefined ) ;
863+ mockStoredSession ( key , "stale" , { resolution : "missing" } ) ;
857864 const respond = await runSessionsUsageTimeseries ( { key } ) ;
858865 expect ( mockArg ( respond , 0 , 0 ) ) . toBe ( false ) ;
859866 expect ( vi . mocked ( loadSessionUsageTimeSeries ) ) . not . toHaveBeenCalled ( ) ;
0 commit comments