@@ -177,46 +177,71 @@ async function runTest() {
177177 console . log ( " ✅ support decision works correctly" ) ;
178178
179179 // ----------------------------------------------------------------
180- // Scenario 2: contextualize — should create linked entry
180+ // Scenario 2: merge — should update support_info on merged memory
181181 // ----------------------------------------------------------------
182- console . log ( "Test 2: contextualize decision creates linked entry..." ) ;
182+ console . log ( "Test 2: merge decision updates support_info..." ) ;
183+ dedupDecision = "merge" ;
184+ dedupContextLabel = "late_night" ;
185+ logs . length = 0 ;
186+
187+ const stats2 = await extractor . extractAndPersist (
188+ "用户再次确认深夜也会喝乌龙茶。" ,
189+ "test-session" ,
190+ { scope : "test" , scopeFilter : [ "test" ] } ,
191+ ) ;
192+
193+ const entries2 = await store . list ( [ "test" ] , undefined , 10 , 0 ) ;
194+ assert . equal ( entries2 . length , 1 , "merge should NOT create new entry" ) ;
195+ assert . equal ( stats2 . merged , 1 , "merged count should be 1" ) ;
196+
197+ const meta2 = JSON . parse ( entries2 [ 0 ] . metadata || "{}" ) ;
198+ const si2 = parseSupportInfo ( meta2 . support_info ) ;
199+ const lateNightSlice = si2 . slices . find ( s => s . context === "late_night" ) ;
200+ assert . ok ( lateNightSlice , "late_night slice should exist after merge" ) ;
201+ assert . equal ( lateNightSlice . confirmations , 1 , "late_night confirmations should be 1" ) ;
202+ console . log ( " ✅ merge decision works correctly" ) ;
203+
204+ // ----------------------------------------------------------------
205+ // Scenario 3: contextualize — should create linked entry
206+ // ----------------------------------------------------------------
207+ console . log ( "Test 3: contextualize decision creates linked entry..." ) ;
183208 dedupDecision = "contextualize" ;
184209 dedupContextLabel = "night" ;
185210 logs . length = 0 ;
186211
187- const stats2 = await extractor . extractAndPersist (
212+ const stats3 = await extractor . extractAndPersist (
188213 "用户说晚上改喝花茶。" ,
189214 "test-session" ,
190215 { scope : "test" , scopeFilter : [ "test" ] } ,
191216 ) ;
192217
193- const entries2 = await store . list ( [ "test" ] , undefined , 10 , 0 ) ;
194- assert . equal ( entries2 . length , 2 , "contextualize should create 1 new entry" ) ;
195- assert . equal ( stats2 . created , 1 , "created count should be 1" ) ;
218+ const entries3 = await store . list ( [ "test" ] , undefined , 10 , 0 ) ;
219+ assert . equal ( entries3 . length , 2 , "contextualize should create 1 new entry" ) ;
220+ assert . equal ( stats3 . created , 1 , "created count should be 1" ) ;
196221 console . log ( " ✅ contextualize decision works correctly" ) ;
197222
198223 // ----------------------------------------------------------------
199- // Scenario 3 : contradict — should record contradiction + new entry
224+ // Scenario 4 : contradict — should record contradiction + new entry
200225 // ----------------------------------------------------------------
201- console . log ( "Test 3 : contradict decision records contradiction..." ) ;
226+ console . log ( "Test 4 : contradict decision records contradiction..." ) ;
202227 dedupDecision = "contradict" ;
203228 dedupContextLabel = "weekend" ;
204229 logs . length = 0 ;
205230
206- const stats3 = await extractor . extractAndPersist (
231+ const stats4 = await extractor . extractAndPersist (
207232 "用户说周末不喝茶了。" ,
208233 "test-session" ,
209234 { scope : "test" , scopeFilter : [ "test" ] } ,
210235 ) ;
211236
212- const entries3 = await store . list ( [ "test" ] , undefined , 10 , 0 ) ;
213- assert . equal ( entries3 . length , 3 , "contradict should create 1 new entry" ) ;
214- assert . equal ( stats3 . created , 1 , "created count should be 1" ) ;
237+ const entries4 = await store . list ( [ "test" ] , undefined , 10 , 0 ) ;
238+ assert . equal ( entries4 . length , 3 , "contradict should create 1 new entry" ) ;
239+ assert . equal ( stats4 . created , 1 , "created count should be 1" ) ;
215240
216241 // Check contradictions recorded on some existing entry
217242 // (with constant vectors, dedup may match any existing entry)
218243 let foundWeekend = false ;
219- for ( const entry of entries3 ) {
244+ for ( const entry of entries4 ) {
220245 const meta = JSON . parse ( entry . metadata || "{}" ) ;
221246 const si = parseSupportInfo ( meta . support_info ) ;
222247 const weekendSlice = si . slices . find ( s => s . context === "weekend" ) ;
0 commit comments