@@ -248,6 +248,77 @@ describe("GraphitiAsyncService", () => {
248248 assertEquals ( timers . clearedTimers . length , 1 ) ;
249249 } ) ;
250250
251+ it ( "preserves fact-only cache refreshes when node search degrades" , async ( ) => {
252+ const cacheSets : Array < {
253+ query : string ;
254+ nodes : Array < { uuid : string ; name : string ; summary : string } > ;
255+ episodeSummaries ?: string [ ] ;
256+ nodeRefs : string [ ] ;
257+ } > = [ ] ;
258+
259+ const service = new GraphitiAsyncService (
260+ {
261+ getEpisodes ( ) {
262+ return Promise . resolve ( [ ] ) ;
263+ } ,
264+ searchMemoryFacts ( ) {
265+ return Promise . resolve ( [
266+ {
267+ fact : "fact:alpha" ,
268+ source_node : { name : "Source" } ,
269+ target_node : { name : "alpha" } ,
270+ } ,
271+ ] ) ;
272+ } ,
273+ searchNodesWithStatus ( ) {
274+ return Promise . resolve ( {
275+ nodes : [ { uuid : "node:alpha" , name : "alpha" , summary : "unused" } ] ,
276+ degraded : true ,
277+ } ) ;
278+ } ,
279+ } as never ,
280+ {
281+ get ( ) {
282+ return Promise . resolve ( null ) ;
283+ } ,
284+ getMeta ( ) {
285+ return Promise . resolve ( { lastQuery : "alpha" } ) ;
286+ } ,
287+ rememberRefreshQuery ( ) {
288+ return Promise . resolve ( ) ;
289+ } ,
290+ set (
291+ _groupId : string ,
292+ entry : {
293+ query : string ;
294+ refreshedAt : number ;
295+ nodes : Array < { uuid : string ; name : string ; summary : string } > ;
296+ episodeSummaries ?: string [ ] ;
297+ nodeRefs : string [ ] ;
298+ } ,
299+ ) {
300+ cacheSets . push ( entry ) ;
301+ return Promise . resolve ( ) ;
302+ } ,
303+ } as never ,
304+ {
305+ drainGroup : ( ) => Promise . resolve ( { status : "idle" as const } ) ,
306+ } as never ,
307+ ) ;
308+
309+ service . scheduleCacheRefresh ( "group-1" , "alpha" ) ;
310+ await flushMicrotasks ( ) ;
311+ await service . dispose ( ) ;
312+
313+ assertEquals ( cacheSets . length , 1 ) ;
314+ assertEquals ( cacheSets [ 0 ] ?. query , "alpha" ) ;
315+ assertEquals ( cacheSets [ 0 ] ?. nodes , [ ] ) ;
316+ assertEquals ( cacheSets [ 0 ] ?. episodeSummaries , [
317+ "Source → alpha: fact:alpha" ,
318+ ] ) ;
319+ assertEquals ( cacheSets [ 0 ] ?. nodeRefs , [ ] ) ;
320+ } ) ;
321+
251322 it ( "does not start a second drain while a slow drain is still in flight" , async ( ) => {
252323 const timers = createFakeTimers ( ) ;
253324 const drainDeferred = deferred < { status : "idle" } > ( ) ;
0 commit comments