@@ -186,6 +186,50 @@ async fn exact_update_replay_returns_the_same_fact_delta_and_commit_receipt() {
186186 assert_eq ! ( committed. commit_receipt( ) , replayed. commit_receipt( ) ) ;
187187}
188188
189+ /// The correction-time payload purge is scoped to detector findings: a clean
190+ /// superseded payload row must survive an ordinary update so as-of reads keep
191+ /// serving the fact's history.
192+ #[ tokio:: test]
193+ async fn update_retains_clean_superseded_payload_rows_for_as_of_reads ( ) {
194+ let ( _directory, database) = database ( ) . await ;
195+ let store = DatabaseFactStore :: new ( & database) ;
196+ let control = write_control ( ) ;
197+ let target = added_target ( & store, & control) . await ;
198+
199+ store
200+ . update_project_memory_fact (
201+ update_command (
202+ target. clone ( ) ,
203+ "operation.crud-clean-supersede" ,
204+ "The canonical update keeps clean history readable." ,
205+ 0.8 ,
206+ ) ,
207+ & control,
208+ )
209+ . await
210+ . expect ( "commit clean canonical update" ) ;
211+
212+ let mut rows = database
213+ . read_connection ( )
214+ . query (
215+ "SELECT COUNT(*) FROM memory_v2_assertion_payloads WHERE fact_id = ?1" ,
216+ [ target. fact_id ( ) . as_str ( ) ] ,
217+ )
218+ . await
219+ . expect ( "count at-rest payload rows" ) ;
220+ let retained: i64 = rows
221+ . next ( )
222+ . await
223+ . expect ( "read payload row count" )
224+ . expect ( "payload row count is present" )
225+ . get ( 0 )
226+ . expect ( "payload row count is an integer" ) ;
227+ assert_eq ! (
228+ retained, 2 ,
229+ "a clean superseded payload row must stay readable for as-of history"
230+ ) ;
231+ }
232+
189233#[ tokio:: test]
190234async fn reused_update_operation_with_changed_patch_conflicts_without_mutation ( ) {
191235 let ( _directory, database) = database ( ) . await ;
0 commit comments