11import { describe , expect , it , vi } from "vitest"
2+ import type { RepositoryReviewSnapshot } from "../../review-comments/types"
23
34const { capture } = vi . hoisted ( ( ) => ( { capture : vi . fn ( ) } ) )
45vi . mock ( "../../review-comments/capture-repository-review-snapshot/index.ts" , ( ) => ( {
@@ -11,7 +12,7 @@ const repositoryId = "11111111-2222-4333-8444-555555555555"
1112const prototypeId = "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa"
1213const capturedAt = new Date ( "2026-11-13T10:00:00Z" )
1314
14- function snapshot ( ) {
15+ function snapshot ( ) : RepositoryReviewSnapshot {
1516 const author = {
1617 userId : "22222222-2222-4222-8222-222222222222" ,
1718 login : "mona" ,
@@ -24,10 +25,22 @@ function snapshot() {
2425 threads : [
2526 {
2627 id : 101 ,
28+ storageId : "77777777-7777-4777-8777-777777777777" ,
2729 repositoryId,
2830 prototype : { id : prototypeId , name : "Design" , branch : "design" } ,
2931 buildNumber : 7 ,
30- anchor : { } ,
32+ anchor : {
33+ schemaVersion : 1 ,
34+ kind : "element" ,
35+ route : { pathname : "/" , search : "" , hash : "" } ,
36+ selector : "#section" ,
37+ accessibleName : "Section" ,
38+ tagName : "section" ,
39+ selectedText : "" ,
40+ rect : { x : 0 , y : 0 , width : 100 , height : 100 } ,
41+ viewport : { width : 1000 , height : 800 , scrollX : 0 , scrollY : 0 } ,
42+ elementOffset : { x : 0 , y : 0 } ,
43+ } ,
3144 activityVersion : 1 ,
3245 createdAt : capturedAt ,
3346 updatedAt : capturedAt ,
@@ -52,6 +65,29 @@ function snapshot() {
5265}
5366
5467describe ( "createReviewCommentLearningSource()" , ( ) => {
68+ it ( "keeps retained deleted bodies out of the package collection" , async ( ) => {
69+ const value = snapshot ( )
70+ value . threads [ 0 ] ! . root = {
71+ ...value . threads [ 0 ] ! . root ,
72+ body : null ,
73+ deletedAt : capturedAt ,
74+ }
75+ capture . mockResolvedValue ( value )
76+ const source = createReviewCommentLearningSource ( { } as never , "https://hub.example.com" )
77+
78+ const result = await source . captureCompleteSnapshot ( { repositoryId } )
79+ const collection = result . collection as {
80+ calls : Array < {
81+ result : { threads : Array < { body : string | null ; deletedAt : string | null } > }
82+ } >
83+ }
84+
85+ expect ( collection . calls [ 0 ] ?. result . threads [ 0 ] ) . toMatchObject ( {
86+ body : null ,
87+ deletedAt : capturedAt . toISOString ( ) ,
88+ } )
89+ } )
90+
5591 it ( "resolves only evidence whose source and observed comment version match" , async ( ) => {
5692 const value = snapshot ( )
5793 capture . mockResolvedValue ( value )
0 commit comments