@@ -170,7 +170,9 @@ import {
170170 collectComposerContextReferences ,
171171 composerRecallContext ,
172172 formatComposerContextReference ,
173+ recallComposerText ,
173174} from "@t3tools/shared/composerContextReferences" ;
175+ import { serializeComposerMessageForServer } from "../lib/composerContext" ;
174176import { appAtomRegistry } from "./atom-registry" ;
175177import { startComposerDraftOperation } from "./composerDraftOperations" ;
176178import { threadOutboxManager } from "./thread-outbox" ;
@@ -476,17 +478,39 @@ describe("mobile composer drafts", () => {
476478 } ,
477479 ) ;
478480
479- it ( "keeps recall provenance through a recovered draft's unchanged save" , ( ) => {
480- const context = { version : 1 , records : [ ] , composerRecall : " original\n" } as const ;
481- const restored = decodePersistedComposerState ( {
482- schemaVersion : 1 ,
483- drafts : { thread : { text : "original" , attachments : [ ] , context } } ,
484- } ) . drafts . thread ! ;
485- expect (
486- composerRecallContext ( "original" , restored . text , restored . context , "original" )
487- ?. composerRecall ,
488- ) . toBe ( " original\n" ) ;
489- } ) ;
481+ it . each ( [ 0 , 1 ] ) (
482+ "keeps recall provenance only through a recovered draft's unchanged save (%s records)" ,
483+ ( recordCount ) => {
484+ const referenceDraft = contextDraft ( 0 , recordCount ) ;
485+ const references = referenceDraft . text ? ` ${ referenceDraft . text } ` : "" ;
486+ const text = `original${ references } ` ;
487+ const context = { ...referenceDraft . context ! , composerRecall : " original\n" } ;
488+ const restored = decodePersistedComposerState ( {
489+ schemaVersion : 1 ,
490+ drafts : { thread : { text, attachments : [ ] , context } } ,
491+ } ) . drafts . thread ! ;
492+ appAtomRegistry . set ( composerDraftsAtom , { thread : restored } ) ;
493+ setComposerDraftText ( "thread" , text ) ;
494+ const unchanged = getComposerDraftSnapshot ( "thread" ) ;
495+ expect (
496+ composerRecallContext ( text , unchanged . text , unchanged . context , text ) ?. composerRecall ,
497+ ) . toBe ( " original\n" ) ;
498+ const unchangedMessage = serializeComposerMessageForServer ( unchanged . text , unchanged . context ) ;
499+ expect ( recallComposerText ( unchangedMessage . text , unchangedMessage . context ) ) . toBe (
500+ " original\n" ,
501+ ) ;
502+
503+ const editedAuthored = " changed after recovery\n" ;
504+ setComposerDraftText ( "thread" , `${ editedAuthored } ${ references } ` ) ;
505+ const edited = decodePersistedComposerState ( {
506+ schemaVersion : 1 ,
507+ drafts : { thread : getComposerDraftSnapshot ( "thread" ) } ,
508+ } ) . drafts . thread ! ;
509+ const sent = serializeComposerMessageForServer ( edited . text , edited . context ) ;
510+ expect ( recallComposerText ( sent . text , sent . context ) ) . toBe ( editedAuthored ) ;
511+ expect ( edited . context ?. records ) . toEqual ( context . records ) ;
512+ } ,
513+ ) ;
490514
491515 it ( "retains a pick matching cached state until the live shell confirms it" , ( ) => {
492516 const environmentId = EnvironmentId . make ( "environment-1" ) ;
0 commit comments