@@ -21,20 +21,20 @@ describe('Real Database Workflow Integration', () => {
2121 // Create temp directory
2222 tempDir = path . join ( os . tmpdir ( ) , `db-test-${ Date . now ( ) } ` ) ;
2323 fs . mkdirSync ( tempDir , { recursive : true } ) ;
24-
24+
2525 // Create database adapter
2626 const dbPath = path . join ( tempDir , 'test.db' ) ;
2727 adapter = new SQLiteAdapter ( 'test-project' , {
2828 dbPath,
2929 busyTimeout : 5000 ,
3030 } ) ;
31-
31+
3232 await adapter . connect ( ) ;
3333 await adapter . initializeSchema ( ) ;
34-
34+
3535 // Create retriever
3636 retriever = new ContextRetriever ( adapter ) ;
37-
37+
3838 // Create router
3939 router = new QueryRouter ( ) ;
4040 router . registerTier ( {
@@ -71,9 +71,9 @@ describe('Real Database Workflow Integration', () => {
7171 depth : 0 ,
7272 digest_text : 'Project initialized successfully' ,
7373 } ) ;
74-
74+
7575 expect ( parentId ) . toBeTruthy ( ) ;
76-
76+
7777 // Create child frames
7878 const childIds = [ ] ;
7979 for ( let i = 0 ; i < 5 ; i ++ ) {
@@ -89,30 +89,30 @@ describe('Real Database Workflow Integration', () => {
8989 } ) ;
9090 childIds . push ( childId ) ;
9191 }
92-
92+
9393 expect ( childIds ) . toHaveLength ( 5 ) ;
94-
94+
9595 // Retrieve parent frame
9696 const parent = await adapter . getFrame ( parentId ) ;
9797 expect ( parent ) . toBeDefined ( ) ;
9898 expect ( parent ?. name ) . toBe ( 'Initialize Project' ) ;
99-
99+
100100 // Search for frames
101101 const searchResults = await adapter . search ( {
102102 query : 'task' ,
103103 searchType : 'text' ,
104104 limit : 10 ,
105105 } ) ;
106-
106+
107107 expect ( searchResults . length ) . toBeGreaterThan ( 0 ) ;
108- expect ( searchResults . some ( f => f . name . includes ( 'Task' ) ) ) . toBe ( true ) ;
109-
108+ expect ( searchResults . some ( ( f ) => f . name . includes ( 'Task' ) ) ) . toBe ( true ) ;
109+
110110 // Update frame state and digest
111111 await adapter . updateFrame ( childIds [ 0 ] , {
112112 state : 'error' ,
113113 digest_text : 'Task failed: Error occurred' ,
114114 } ) ;
115-
115+
116116 const updatedFrame = await adapter . getFrame ( childIds [ 0 ] ) ;
117117 expect ( updatedFrame ?. state ) . toBe ( 'error' ) ;
118118 expect ( updatedFrame ?. digest_text ) . toContain ( 'Task failed' ) ;
@@ -121,13 +121,28 @@ describe('Real Database Workflow Integration', () => {
121121 it ( 'should handle context retrieval with relevance ranking' , async ( ) => {
122122 // Create diverse frames
123123 const frames = [
124- { name : 'Authentication Setup' , digest_text : 'Implemented JWT authentication with refresh tokens' } ,
125- { name : 'Database Migration' , digest_text : 'Migrated user table to add email verification' } ,
126- { name : 'API Endpoint' , digest_text : 'Created REST API for user management' } ,
127- { name : 'Test Suite' , digest_text : 'Added integration tests for authentication flow' } ,
128- { name : 'Bug Fix' , digest_text : 'Fixed login error with special characters' } ,
124+ {
125+ name : 'Authentication Setup' ,
126+ digest_text : 'Implemented JWT authentication with refresh tokens' ,
127+ } ,
128+ {
129+ name : 'Database Migration' ,
130+ digest_text : 'Migrated user table to add email verification' ,
131+ } ,
132+ {
133+ name : 'API Endpoint' ,
134+ digest_text : 'Created REST API for user management' ,
135+ } ,
136+ {
137+ name : 'Test Suite' ,
138+ digest_text : 'Added integration tests for authentication flow' ,
139+ } ,
140+ {
141+ name : 'Bug Fix' ,
142+ digest_text : 'Fixed login error with special characters' ,
143+ } ,
129144 ] ;
130-
145+
131146 for ( const frame of frames ) {
132147 await adapter . createFrame ( {
133148 parent_frame_id : null ,
@@ -140,26 +155,26 @@ describe('Real Database Workflow Integration', () => {
140155 digest_text : frame . digest_text ,
141156 } ) ;
142157 }
143-
158+
144159 // Test retrieval with different queries
145160 const queries = [
146161 { text : 'authentication' , expectedMatch : 'Authentication Setup' } ,
147162 { text : 'database' , expectedMatch : 'Database Migration' } ,
148163 { text : 'login error' , expectedMatch : 'Bug Fix' } ,
149164 { text : 'JWT token' , expectedMatch : 'Authentication Setup' } ,
150165 ] ;
151-
166+
152167 for ( const query of queries ) {
153168 const result = await retriever . retrieveContext ( {
154169 text : query . text ,
155170 maxResults : 5 ,
156171 } ) ;
157-
172+
158173 // Context retriever may not always return results for simple text matching
159174 // This is more of a semantic search test
160175 if ( result . contexts . length > 0 ) {
161- // If we get results, they should be relevant
162- expect ( result . retrievalTimeMs ) . toBeLessThan ( 100 ) ;
176+ // If we get results, they should be relevant (relaxed for CI)
177+ expect ( result . retrievalTimeMs ) . toBeLessThan ( 500 ) ;
163178 } else {
164179 // Empty results are also valid for this simple test
165180 expect ( result . totalMatches ) . toBe ( 0 ) ;
@@ -174,7 +189,7 @@ describe('Real Database Workflow Integration', () => {
174189 { type : 'write' , data : { name : 'New Frame' } } ,
175190 { type : 'search' , data : { query : 'test' } } ,
176191 ] ;
177-
192+
178193 for ( const query of queries ) {
179194 const result = await router . route (
180195 `${ query . type } -query` ,
@@ -195,10 +210,10 @@ describe('Real Database Workflow Integration', () => {
195210 return 'success' ;
196211 }
197212 ) ;
198-
213+
199214 expect ( result ) . toBeDefined ( ) ;
200215 }
201-
216+
202217 // Check metrics
203218 const metrics = router . getMetrics ( ) ;
204219 expect ( metrics . totalQueries ) . toBe ( 3 ) ;
@@ -210,7 +225,7 @@ describe('Real Database Workflow Integration', () => {
210225 it ( 'should handle bulk operations efficiently' , async ( ) => {
211226 const startTime = Date . now ( ) ;
212227 const frameIds = [ ] ;
213-
228+
214229 // Bulk insert frames
215230 for ( let i = 0 ; i < 100 ; i ++ ) {
216231 const id = await adapter . createFrame ( {
@@ -225,11 +240,11 @@ describe('Real Database Workflow Integration', () => {
225240 } ) ;
226241 frameIds . push ( id ) ;
227242 }
228-
243+
229244 const insertTime = Date . now ( ) - startTime ;
230245 expect ( frameIds ) . toHaveLength ( 100 ) ;
231246 expect ( insertTime ) . toBeLessThan ( 1000 ) ; // Should complete in under 1 second
232-
247+
233248 // Bulk search
234249 const searchStart = Date . now ( ) ;
235250 const results = await adapter . search ( {
@@ -238,10 +253,10 @@ describe('Real Database Workflow Integration', () => {
238253 limit : 50 ,
239254 } ) ;
240255 const searchTime = Date . now ( ) - searchStart ;
241-
256+
242257 expect ( results . length ) . toBeLessThanOrEqual ( 50 ) ;
243258 expect ( searchTime ) . toBeLessThan ( 100 ) ; // Search should be fast
244-
259+
245260 // Verify data integrity
246261 const frame50 = await adapter . getFrame ( frameIds [ 50 ] ) ;
247262 expect ( frame50 ?. name ) . toBe ( 'Bulk Operation 50' ) ;
@@ -251,7 +266,7 @@ describe('Real Database Workflow Integration', () => {
251266 it ( 'should handle concurrent operations' , async ( ) => {
252267 // Test concurrent reads and writes
253268 const operations = [ ] ;
254-
269+
255270 // Concurrent writes
256271 for ( let i = 0 ; i < 10 ; i ++ ) {
257272 operations . push (
@@ -266,38 +281,38 @@ describe('Real Database Workflow Integration', () => {
266281 } )
267282 ) ;
268283 }
269-
284+
270285 const frameIds = await Promise . all ( operations ) ;
271286 expect ( frameIds ) . toHaveLength ( 10 ) ;
272287 expect ( new Set ( frameIds ) . size ) . toBe ( 10 ) ; // All IDs should be unique
273-
288+
274289 // Concurrent reads
275290 const readOps = frameIds . map ( ( id : any ) => adapter . getFrame ( id ) ) ;
276291 const frames = await Promise . all ( readOps ) ;
277-
278- expect ( frames . every ( f => f !== null ) ) . toBe ( true ) ;
279- expect ( frames . every ( f => f ?. run_id === 'concurrent-run' ) ) . toBe ( true ) ;
292+
293+ expect ( frames . every ( ( f ) => f !== null ) ) . toBe ( true ) ;
294+ expect ( frames . every ( ( f ) => f ?. run_id === 'concurrent-run' ) ) . toBe ( true ) ;
280295 } ) ;
281296
282297 it ( 'should handle error conditions gracefully' , async ( ) => {
283298 // Test invalid frame retrieval
284299 const missingFrame = await adapter . getFrame ( 'non-existent-id' ) ;
285300 expect ( missingFrame ) . toBeNull ( ) ;
286-
301+
287302 // Test empty search
288303 const emptySearch = await adapter . search ( {
289304 query : 'xyzabc123notfound' ,
290305 searchType : 'text' ,
291306 limit : 10 ,
292307 } ) ;
293308 expect ( emptySearch ) . toHaveLength ( 0 ) ;
294-
309+
295310 // Test invalid update - SQLite adapter may not throw on non-existent ID
296311 // it just won't update anything
297312 await adapter . updateFrame ( 'non-existent' , { state : 'completed' } ) ;
298313 const stillMissing = await adapter . getFrame ( 'non-existent' ) ;
299314 expect ( stillMissing ) . toBeNull ( ) ;
300-
315+
301316 // Test retrieval with empty query
302317 const emptyRetrieval = await retriever . retrieveContext ( {
303318 text : '' ,
@@ -306,4 +321,4 @@ describe('Real Database Workflow Integration', () => {
306321 expect ( emptyRetrieval . contexts ) . toHaveLength ( 0 ) ;
307322 expect ( emptyRetrieval . totalMatches ) . toBe ( 0 ) ;
308323 } ) ;
309- } ) ;
324+ } ) ;
0 commit comments