@@ -5,15 +5,28 @@ import type { MemoryTypeConfig } from '@codingcode/infra';
55
66describe ( 'Memory Extractor' , ( ) => {
77 const createMockLlm = ( response : string ) => ( {
8+ complete : vi . fn ( ( ) =>
9+ Promise . resolve ( {
10+ ok : true as const ,
11+ value : { content : response , finishReason : 'stop' as const } ,
12+ } )
13+ ) ,
814 completeStream : vi . fn ( ( ) => ( {
915 stream : ( async function * ( ) {
1016 yield response ;
1117 } ) ( ) ,
1218 response : Promise . resolve ( {
13- ok : true ,
14- value : { content : response } ,
19+ ok : true as const ,
20+ value : { content : response , finishReason : 'stop' as const } ,
1521 } ) ,
1622 } ) ) ,
23+ modelInfo : {
24+ provider : 'mock' ,
25+ model : 'mock' ,
26+ maxTokens : 4096 ,
27+ supportsToolCalling : true ,
28+ supportsStreaming : true ,
29+ } ,
1730 } ) ;
1831
1932 const defaultTypes : MemoryTypeConfig [ ] = [
@@ -83,6 +96,12 @@ describe('Memory Extractor', () => {
8396
8497 it ( 'handles LLM call failure gracefully' , async ( ) => {
8598 const llm = {
99+ complete : vi . fn ( ( ) =>
100+ Promise . resolve ( {
101+ ok : false ,
102+ value : { content : '' } ,
103+ } as any )
104+ ) ,
86105 completeStream : vi . fn ( ( ) => ( {
87106 stream : ( async function * ( ) {
88107 throw new Error ( 'Stream error' ) ;
@@ -92,6 +111,13 @@ describe('Memory Extractor', () => {
92111 value : { content : '' } ,
93112 } as any ) ,
94113 } ) ) ,
114+ modelInfo : {
115+ provider : 'mock' ,
116+ model : 'mock' ,
117+ maxTokens : 4096 ,
118+ supportsToolCalling : true ,
119+ supportsStreaming : true ,
120+ } ,
95121 } ;
96122
97123 const transcript : StructuredTranscript = {
@@ -129,7 +155,7 @@ describe('Memory Extractor', () => {
129155 llm : mockLlm ,
130156 } ) ;
131157
132- const callArgs = mockLlm . completeStream . mock . calls [ 0 ] [ 0 ] ;
158+ const callArgs = ( mockLlm . completeStream . mock . calls as any ) [ 0 ] [ 0 ] as any ;
133159 expect ( callArgs . messages [ 0 ] . content ) . toContain ( '已有记忆' ) ;
134160 expect ( callArgs . messages [ 0 ] . content ) . toContain ( 'Old info' ) ;
135161 } ) ;
@@ -150,7 +176,7 @@ describe('Memory Extractor', () => {
150176 llm : mockLlm ,
151177 } ) ;
152178
153- const callArgs = mockLlm . completeStream . mock . calls [ 0 ] [ 0 ] ;
179+ const callArgs = ( mockLlm . completeStream . mock . calls as any ) [ 0 ] [ 0 ] as any ;
154180 expect ( callArgs . messages [ 0 ] . content ) . toContain ( '[user]' ) ;
155181 expect ( callArgs . messages [ 0 ] . content ) . toContain ( '[user+assistant]' ) ;
156182 expect ( callArgs . messages [ 0 ] . content ) . toContain ( '[user+tool]' ) ;
@@ -173,7 +199,7 @@ describe('Memory Extractor', () => {
173199 llm : mockLlm ,
174200 } ) ;
175201
176- const callArgs = mockLlm . completeStream . mock . calls [ 0 ] [ 0 ] ;
202+ const callArgs = ( mockLlm . completeStream . mock . calls as any ) [ 0 ] [ 0 ] as any ;
177203 // Should not mention reference guidance
178204 expect ( callArgs . system ) . not . toContain ( 'reference' ) ;
179205 } ) ;
@@ -194,7 +220,7 @@ describe('Memory Extractor', () => {
194220 llm : mockLlm ,
195221 } ) ;
196222
197- const callArgs = mockLlm . completeStream . mock . calls [ 0 ] [ 0 ] ;
223+ const callArgs = ( mockLlm . completeStream . mock . calls as any ) [ 0 ] [ 0 ] as any ;
198224 expect ( callArgs . messages ) . toHaveLength ( 1 ) ;
199225 expect ( callArgs . messages [ 0 ] . role ) . toBe ( 'user' ) ;
200226 expect ( callArgs . messages [ 0 ] . content ) . toBeTruthy ( ) ;
@@ -216,7 +242,7 @@ describe('Memory Extractor', () => {
216242 llm : mockLlm ,
217243 } ) ;
218244
219- const callArgs = mockLlm . completeStream . mock . calls [ 0 ] [ 0 ] ;
245+ const callArgs = ( mockLlm . completeStream . mock . calls as any ) [ 0 ] [ 0 ] as any ;
220246 // system contains instructions, not transcript data
221247 expect ( callArgs . system ) . toContain ( '规则' ) ;
222248 expect ( callArgs . system ) . toContain ( '记忆类型' ) ;
0 commit comments