44 */
55
66import { describe , it , expect , beforeEach , afterEach } from 'vitest' ;
7- import { TestEnvironment , TestSession , ActivityRecord } from '../helpers/test-environment.js' ;
8- import { generateTestFrames , generateSearchQueries } from '../fixtures/test-data-generator.js' ;
7+ import {
8+ TestEnvironment ,
9+ TestSession ,
10+ ActivityRecord ,
11+ } from '../helpers/test-environment.js' ;
12+ import {
13+ generateTestFrames ,
14+ generateSearchQueries ,
15+ } from '../fixtures/test-data-generator.js' ;
916
1017describe ( 'Full Session Lifecycle' , ( ) => {
1118 let env : TestEnvironment ;
@@ -24,13 +31,13 @@ describe('Full Session Lifecycle', () => {
2431 const project = await env . createProject ( 'test-app' ) ;
2532 expect ( project . id ) . toContain ( 'e2e-test-project' ) ;
2633 expect ( project . path ) . toContain ( 'test-app' ) ;
27-
34+
2835 // Step 2: Start development session
2936 const session = await env . startSession ( 'dev-session-1' ) ;
3037 expect ( session ) . toBeDefined ( ) ;
3138 expect ( session . frameManager ) . toBeDefined ( ) ;
3239 expect ( session . sharedContext ) . toBeDefined ( ) ;
33-
40+
3441 // Step 3: Record development activities
3542 const activities : ActivityRecord [ ] = [
3643 { type : 'file_edit' , file : 'src/app.ts' } ,
@@ -39,28 +46,28 @@ describe('Full Session Lifecycle', () => {
3946 { type : 'test_run' , status : 'pass' } ,
4047 { type : 'commit' , message : 'Fix test failures' } ,
4148 ] ;
42-
49+
4350 const frameIds = await session . recordActivity ( activities ) ;
4451 expect ( frameIds ) . toHaveLength ( 5 ) ;
45-
52+
4653 // Step 4: Save context before clear
4754 const savedContext = await session . saveContext ( ) ;
4855 expect ( savedContext . frames ) . toHaveLength ( 5 ) ;
4956 expect ( savedContext . sessionId ) . toBe ( 'dev-session-1' ) ;
50-
57+
5158 // Step 5: Simulate Claude clear
5259 await env . simulateClear ( ) ;
53-
60+
5461 // Step 6: Restore context after clear
5562 const restoredContext = await env . restoreContext ( 'dev-session-1' ) ;
5663 expect ( restoredContext . frames ) . toHaveLength ( 5 ) ;
5764 expect ( restoredContext . sessionId ) . toBe ( 'dev-session-1' ) ;
58-
65+
5966 // Verify frame content preserved
6067 const firstFrame = restoredContext . frames [ 0 ] ;
6168 expect ( firstFrame . name ) . toContain ( 'Edit' ) ;
6269 expect ( firstFrame . type ) . toBe ( 'operation' ) ;
63-
70+
6471 // Step 7: Generate handoff document
6572 const handoff = await session . generateHandoff ( ) ;
6673 expect ( handoff ) . toContain ( '# Session Handoff' ) ;
@@ -76,36 +83,36 @@ describe('Full Session Lifecycle', () => {
7683 { type : 'file_edit' , file : 'api.ts' } ,
7784 { type : 'command' , command : 'npm test' } ,
7885 ] ) ;
79-
86+
8087 const contextA = await sessionA . saveContext ( ) ;
8188 expect ( contextA . frames ) . toHaveLength ( 2 ) ;
82-
89+
8390 // Session B reads and extends context
8491 const sessionB = await env . startSession ( 'session-b' ) ;
85-
92+
8693 // Session B should be able to query Session A's frames
8794 const retriever = sessionB . retriever ;
8895 const searchResult = await retriever . retrieveContext ( {
8996 text : 'api.ts' ,
9097 maxResults : 5 ,
9198 } ) ;
92-
99+
93100 expect ( searchResult . contexts . length ) . toBeGreaterThan ( 0 ) ;
94101 expect ( searchResult . contexts [ 0 ] . frame . name ) . toContain ( 'api.ts' ) ;
95-
102+
96103 // Session B adds more work
97104 await sessionB . recordActivity ( [
98105 { type : 'file_edit' , file : 'api.test.ts' } ,
99106 { type : 'test_run' , status : 'pass' } ,
100107 ] ) ;
101-
108+
102109 const contextB = await sessionB . saveContext ( ) ;
103110 expect ( contextB . frames . length ) . toBeGreaterThanOrEqual ( 2 ) ;
104111 } ) ;
105112
106113 it ( 'should handle error recovery workflow' , async ( ) => {
107114 const session = await env . startSession ( 'error-recovery' ) ;
108-
115+
109116 // Simulate error scenario
110117 const activities : ActivityRecord [ ] = [
111118 { type : 'command' , command : 'npm run build' } ,
@@ -114,24 +121,24 @@ describe('Full Session Lifecycle', () => {
114121 { type : 'command' , command : 'npm run build' } ,
115122 { type : 'test_run' , status : 'pass' } ,
116123 ] ;
117-
124+
118125 const frameIds = await session . recordActivity ( activities ) ;
119-
126+
120127 // Verify error was recorded
121128 const db = await env . getDatabase ( ) ;
122129 const errorFrame = await db . getFrame ( frameIds [ 1 ] ) ;
123130 expect ( errorFrame ?. type ) . toBe ( 'error' ) ;
124131 expect ( errorFrame ?. state ) . toBe ( 'error' ) ;
125-
132+
126133 // Search for error patterns
127134 const errorSearch = await session . retriever . retrieveContext ( {
128135 text : 'build failed' ,
129136 maxResults : 10 ,
130137 } ) ;
131-
138+
132139 expect ( errorSearch . contexts . length ) . toBeGreaterThan ( 0 ) ;
133140 expect ( errorSearch . contexts [ 0 ] . frame . digest_text ) . toContain ( 'Build failed' ) ;
134-
141+
135142 // Generate handoff should include error context
136143 const handoff = await session . generateHandoff ( ) ;
137144 expect ( handoff ) . toContain ( '[error]' ) ;
@@ -141,7 +148,7 @@ describe('Full Session Lifecycle', () => {
141148 it ( 'should handle large session with many frames' , async ( ) => {
142149 const session = await env . startSession ( 'large-session' ) ;
143150 const db = await env . getDatabase ( ) ;
144-
151+
145152 // Generate many activities
146153 const activities : ActivityRecord [ ] = [ ] ;
147154 for ( let i = 0 ; i < 100 ; i ++ ) {
@@ -151,10 +158,10 @@ describe('Full Session Lifecycle', () => {
151158 status : i % 3 === 0 ? 'fail' : 'pass' ,
152159 } ) ;
153160 }
154-
161+
155162 const frameIds = await session . recordActivity ( activities ) ;
156163 expect ( frameIds ) . toHaveLength ( 100 ) ;
157-
164+
158165 // Test search performance
159166 const startTime = Date . now ( ) ;
160167 const searchResult = await db . search ( {
@@ -163,25 +170,25 @@ describe('Full Session Lifecycle', () => {
163170 limit : 20 ,
164171 } ) ;
165172 const searchTime = Date . now ( ) - startTime ;
166-
173+
167174 expect ( searchResult . length ) . toBeLessThanOrEqual ( 20 ) ;
168175 expect ( searchTime ) . toBeLessThan ( 100 ) ; // Should be fast
169-
176+
170177 // Test context retrieval with large dataset
171178 const queries = generateSearchQueries ( ) ;
172179 for ( const query of queries . slice ( 0 , 5 ) ) {
173180 const result = await session . retriever . retrieveContext ( {
174181 text : query ,
175182 maxResults : 10 ,
176183 } ) ;
177-
184+
178185 expect ( result . retrievalTimeMs ) . toBeLessThan ( 200 ) ;
179186 }
180187 } ) ;
181188
182189 it ( 'should handle workflow transitions' , async ( ) => {
183190 const session = await env . startSession ( 'workflow-test' ) ;
184-
191+
185192 // Start TDD workflow
186193 await session . recordActivity ( [
187194 { type : 'command' , command : 'stackmemory workflow start tdd' } ,
@@ -191,39 +198,19 @@ describe('Full Session Lifecycle', () => {
191198 { type : 'test_run' , status : 'pass' } ,
192199 { type : 'file_edit' , file : 'src/feature.ts' } , // Refactor
193200 ] ) ;
194-
201+
195202 // Save workflow state
196203 const context = await session . saveContext ( ) ;
197204 expect ( context . frames ) . toHaveLength ( 6 ) ;
198-
205+
199206 // Verify workflow pattern detected
200207 const frames = context . frames ;
201- const hasTestFirst = frames . some ( f => f . name . includes ( 'test' ) && f . state === 'completed' ) ;
202- const hasImplementation = frames . some ( f => f . name . includes ( 'feature.ts' ) ) ;
203-
208+ const hasTestFirst = frames . some (
209+ ( f ) => f . name . includes ( 'test' ) && f . state === 'completed'
210+ ) ;
211+ const hasImplementation = frames . some ( ( f ) => f . name . includes ( 'feature.ts' ) ) ;
212+
204213 expect ( hasTestFirst ) . toBe ( true ) ;
205214 expect ( hasImplementation ) . toBe ( true ) ;
206215 } ) ;
207-
208- it . skip ( 'should handle CLI commands integration - needs separate setup' , async ( ) => {
209- // Test CLI commands in the environment
210-
211- // Initialize via CLI
212- const initOutput = await env . runCLICommand ( 'init' ) ;
213- expect ( initOutput ) . toContain ( 'StackMemory initialized' ) ;
214-
215- // Check status
216- const statusOutput = await env . runCLICommand ( 'status' ) ;
217- expect ( statusOutput ) . toContain ( 'StackMemory Status' ) ;
218-
219- // Test workflow commands
220- const workflowList = await env . runCLICommand ( 'workflow --list' ) ;
221- expect ( workflowList ) . toContain ( 'Available Workflows' ) ;
222- expect ( workflowList ) . toContain ( 'tdd' ) ;
223- expect ( workflowList ) . toContain ( 'feature' ) ;
224-
225- // Test clear status
226- const clearStatus = await env . runCLICommand ( 'clear --status' ) ;
227- expect ( clearStatus ) . toContain ( 'Context Usage' ) ;
228- } ) ;
229- } ) ;
216+ } ) ;
0 commit comments