@@ -6,13 +6,53 @@ import { sleep } from '@sim/utils/helpers'
66import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
77import * as Y from 'yjs'
88
9+ interface TestStreamEntry {
10+ id : string
11+ message : Record < string , string >
12+ }
13+
14+ interface TestRedisClient {
15+ isOpen : boolean
16+ connect ( ) : Promise < void >
17+ quit ( ) : Promise < void >
18+ on ( ) : TestRedisClient
19+ duplicate ( ) : TestRedisClient
20+ xAdd ( key : string , id : string , fields : Record < string , string > ) : Promise < string >
21+ xRange (
22+ key : string ,
23+ start : string ,
24+ end : string ,
25+ options ?: { COUNT ?: number }
26+ ) : Promise < TestStreamEntry [ ] >
27+ xRevRange (
28+ key : string ,
29+ start : string ,
30+ end : string ,
31+ options ?: { COUNT ?: number }
32+ ) : Promise < TestStreamEntry [ ] >
33+ xLen ( key : string ) : Promise < number >
34+ xTrim ( key : string , strategy : string , minId : string ) : Promise < void >
35+ xRead (
36+ streams : { key : string ; id : string } [ ] ,
37+ options ?: { BLOCK ?: number ; COUNT ?: number }
38+ ) : Promise < { name : string ; messages : TestStreamEntry [ ] } [ ] | null >
39+ set ( key : string , value : string , options ?: { NX ?: boolean } ) : Promise < string | null >
40+ get ( key : string ) : Promise < string | null >
41+ del ( keys : string | string [ ] ) : Promise < number >
42+ eval (
43+ script : string ,
44+ options : { keys : string [ ] ; arguments : string [ ] }
45+ ) : Promise < string | number | boolean | null >
46+ expire ( ) : Promise < number >
47+ }
48+
949/**
1050 * One shared in-memory Redis backing per test, so several {@link FileDocStore} instances (modelling
1151 * several ECS tasks) all talk to the "same Redis". A minimal fake of just the stream/lock ops the
1252 * store uses.
1353 */
1454interface Backing {
15- streams : Map < string , { id : string ; message : Record < string , string > } [ ] >
55+ streams : Map < string , TestStreamEntry [ ] >
1656 kv : Map < string , string >
1757 dedupe : Map < string , string [ ] >
1858 seq : number
@@ -51,13 +91,13 @@ function compareStreamIds(left: string, right: string): bigint {
5191 return leftMs === rightMs ? leftSequence - rightSequence : leftMs - rightMs
5292}
5393
54- function makeClient ( ) : any {
94+ function makeClient ( ) : TestRedisClient {
5595 const b = ( ) => {
5696 if ( ! state . backing ) throw new Error ( 'backing not initialized' )
5797 return state . backing
5898 }
5999 const nextId = ( ) => b ( ) . nextIds ?. shift ( ) ?? `${ ++ b ( ) . seq } -0`
60- const client : any = {
100+ const client : TestRedisClient = {
61101 isOpen : true ,
62102 connect : async ( ) => {
63103 client . isOpen = true
@@ -118,8 +158,7 @@ function makeClient(): any {
118158 client . isOpen = false
119159 throw new Error ( 'The client is closed' )
120160 }
121- const res : { name : string ; messages : { id : string ; message : Record < string , string > } [ ] } [ ] =
122- [ ]
161+ const res : { name : string ; messages : TestStreamEntry [ ] } [ ] = [ ]
123162 for ( const { key, id } of streams ) {
124163 const after = ( b ( ) . streams . get ( key ) ?? [ ] )
125164 . filter ( ( e ) => compareStreamIds ( e . id , id ) > 0n )
0 commit comments