@@ -12,6 +12,16 @@ const EMPTY_DELETE_REPLY_ID = "b2".repeat(32);
1212const EMPTY_DELETE_ROOT_CONTENT = "Inbox empty-edit root message." ;
1313const EMPTY_DELETE_REPLY_CONTENT =
1414 "Selected Inbox reply remains after root deletion." ;
15+ const COLD_ROOT_ID = "c3" . repeat ( 32 ) ;
16+ const COLD_SELECTED_REPLY_ID = "f4" . repeat ( 32 ) ;
17+ const COLD_DELETED_EDIT_ID = "0a" . repeat ( 32 ) ;
18+ const COLD_SIBLING_REPLY_ID = "1b" . repeat ( 32 ) ;
19+ const COLD_SIBLING_EDIT_ID = "2c" . repeat ( 32 ) ;
20+ const COLD_ROOT_CONTENT = "Cold Inbox thread root." ;
21+ const COLD_SELECTED_ORIGINAL_CONTENT = "Cold Inbox reply original text." ;
22+ const COLD_SELECTED_RETRACTED_CONTENT = "Cold Inbox reply retracted edit text." ;
23+ const COLD_SIBLING_ORIGINAL_CONTENT = "Cold Inbox sibling reply original text." ;
24+ const COLD_SIBLING_EDITED_CONTENT = "Cold Inbox sibling reply edited text." ;
1525const ATTACHMENT_URL = `https://mock.relay/media/${ "a" . repeat ( 64 ) } .pdf` ;
1626const ATTACHMENT_FILENAME = "inbox-edit-proof.pdf" ;
1727const SHOTS = "test-results/inbox-edit" ;
@@ -40,6 +50,8 @@ type MockWindow = Window & {
4050 pubkey ?: string ;
4151 mentionPubkeys ?: string [ ] ;
4252 id ?: string ;
53+ kind ?: number ;
54+ extraTags ?: string [ ] [ ] ;
4355 } ) => {
4456 content : string ;
4557 created_at : number ;
@@ -498,3 +510,141 @@ test("cancelling an empty Inbox edit deletion preserves content and edit mode",
498510 ) ,
499511 ) . toBe ( 0 ) ;
500512} ) ;
513+
514+ // Regression test for the cold Inbox hydration closure. A deletion can target
515+ // an edit event instead of the original message, and `formatTimelineMessages`
516+ // drops an edit only when the edit's own id is in the deletion set. A one-hop
517+ // `#e` fetch over the context message ids returns the edit but not the deletion
518+ // of that edit, so a cold Inbox open re-applies retracted content. The sibling
519+ // reply is the positive control: its live edit is NOT deleted, so it must still
520+ // render as edited after the same cold fetch.
521+ test ( "cold Inbox open drops an edit that was itself deleted" , async ( {
522+ page,
523+ } ) => {
524+ await installMockBridge ( page ) ;
525+ await page . goto ( "/" ) ;
526+ await expect ( page . getByTestId ( "home-inbox-list" ) ) . toBeVisible ( ) ;
527+ await page . waitForFunction ( ( ) => {
528+ const win = window as MockWindow ;
529+ return (
530+ typeof win . __BUZZ_E2E_EMIT_MOCK_MESSAGE__ === "function" &&
531+ typeof win . __BUZZ_E2E_PUSH_MOCK_FEED_ITEM__ === "function"
532+ ) ;
533+ } ) ;
534+
535+ await page . evaluate (
536+ ( {
537+ channelId,
538+ currentPubkey,
539+ deletedEditId,
540+ rootContent,
541+ rootId,
542+ selectedOriginalContent,
543+ selectedReplyId,
544+ selectedRetractedContent,
545+ siblingEditId,
546+ siblingEditedContent,
547+ siblingOriginalContent,
548+ siblingReplyId,
549+ } ) => {
550+ const win = window as MockWindow ;
551+ const emit = win . __BUZZ_E2E_EMIT_MOCK_MESSAGE__ ;
552+ const push = win . __BUZZ_E2E_PUSH_MOCK_FEED_ITEM__ ;
553+ if ( ! emit || ! push ) {
554+ throw new Error ( "Mock bridge helpers are unavailable." ) ;
555+ }
556+
557+ const root = emit ( {
558+ channelName : "general" ,
559+ content : rootContent ,
560+ id : rootId ,
561+ pubkey : currentPubkey ,
562+ } ) ;
563+ const selectedReply = emit ( {
564+ channelName : "general" ,
565+ content : selectedOriginalContent ,
566+ id : selectedReplyId ,
567+ mentionPubkeys : [ currentPubkey ] ,
568+ parentEventId : root . id ,
569+ pubkey : currentPubkey ,
570+ } ) ;
571+ const siblingReply = emit ( {
572+ channelName : "general" ,
573+ content : siblingOriginalContent ,
574+ id : siblingReplyId ,
575+ parentEventId : root . id ,
576+ pubkey : currentPubkey ,
577+ } ) ;
578+
579+ // The retracted edit: published, then deleted by a kind:5 that targets
580+ // the EDIT event, never the reply itself.
581+ const retractedEdit = emit ( {
582+ channelName : "general" ,
583+ content : selectedRetractedContent ,
584+ extraTags : [ [ "e" , selectedReply . id ] ] ,
585+ id : deletedEditId ,
586+ kind : 40003 ,
587+ pubkey : currentPubkey ,
588+ } ) ;
589+ emit ( {
590+ channelName : "general" ,
591+ content : "" ,
592+ extraTags : [ [ "e" , retractedEdit . id ] ] ,
593+ kind : 5 ,
594+ pubkey : currentPubkey ,
595+ } ) ;
596+
597+ // Positive control: a live edit with no deletion of its own.
598+ emit ( {
599+ channelName : "general" ,
600+ content : siblingEditedContent ,
601+ extraTags : [ [ "e" , siblingReply . id ] ] ,
602+ id : siblingEditId ,
603+ kind : 40003 ,
604+ pubkey : currentPubkey ,
605+ } ) ;
606+
607+ push ( {
608+ category : "mention" ,
609+ channel_id : channelId ,
610+ channel_name : "general" ,
611+ content : selectedReply . content ,
612+ created_at : selectedReply . created_at ,
613+ id : selectedReply . id ,
614+ kind : selectedReply . kind ,
615+ pubkey : selectedReply . pubkey ,
616+ tags : selectedReply . tags ,
617+ } ) ;
618+ } ,
619+ {
620+ channelId : GENERAL_CHANNEL_ID ,
621+ currentPubkey : CURRENT_PUBKEY ,
622+ deletedEditId : COLD_DELETED_EDIT_ID ,
623+ rootContent : COLD_ROOT_CONTENT ,
624+ rootId : COLD_ROOT_ID ,
625+ selectedOriginalContent : COLD_SELECTED_ORIGINAL_CONTENT ,
626+ selectedReplyId : COLD_SELECTED_REPLY_ID ,
627+ selectedRetractedContent : COLD_SELECTED_RETRACTED_CONTENT ,
628+ siblingEditId : COLD_SIBLING_EDIT_ID ,
629+ siblingEditedContent : COLD_SIBLING_EDITED_CONTENT ,
630+ siblingOriginalContent : COLD_SIBLING_ORIGINAL_CONTENT ,
631+ siblingReplyId : COLD_SIBLING_REPLY_ID ,
632+ } ,
633+ ) ;
634+
635+ // First selection of this item: every edit and deletion must come from the
636+ // hydration fetch, not from an optimistic local write.
637+ await page . getByTestId ( `home-inbox-item-${ COLD_SELECTED_REPLY_ID } ` ) . click ( ) ;
638+ const detail = page . getByTestId ( "home-inbox-detail" ) ;
639+ const siblingRow = detail . locator (
640+ `[data-message-id="${ COLD_SIBLING_REPLY_ID } "]` ,
641+ ) ;
642+ await expect ( siblingRow ) . toContainText ( COLD_SIBLING_EDITED_CONTENT ) ;
643+
644+ const selectedRow = detail . locator (
645+ `[data-message-id="${ COLD_SELECTED_REPLY_ID } "]` ,
646+ ) ;
647+ await expect ( selectedRow ) . toContainText ( COLD_SELECTED_ORIGINAL_CONTENT ) ;
648+ await expect ( selectedRow ) . not . toContainText ( COLD_SELECTED_RETRACTED_CONTENT ) ;
649+ await expect ( detail ) . not . toContainText ( COLD_SELECTED_RETRACTED_CONTENT ) ;
650+ } ) ;
0 commit comments