@@ -11,10 +11,13 @@ import {
1111import { composerDraftEnvironmentId } from "../lib/composerAttachmentUploadQueue" ;
1212import { isQueuedEditDraftKey , queuedEditDraftKey } from "./queued-edit-draft-key" ;
1313import {
14- queuedRunEditIsDirty ,
14+ beginQueuedRunEdit ,
15+ getQueuedRunEdit ,
16+ recoverQueuedRunEdit ,
1517 resolveQueuedEditPayload ,
1618 type QueuedRunEdit ,
1719} from "./queued-run-edit" ;
20+ import { getComposerDraftSnapshot , setComposerDraftText } from "./use-composer-drafts" ;
1821
1922const image = ( id : string ) : ChatAttachment => ( {
2023 type : "image" ,
@@ -109,13 +112,36 @@ describe("resolveQueuedEditPayload", () => {
109112 } ) ;
110113} ) ;
111114
112- describe ( "queuedRunEditIsDirty" , ( ) => {
113- it ( "treats an untouched edit as clean so a steered message is not restored" , ( ) => {
114- expect ( queuedRunEditIsDirty ( edit ( [ ] ) , { text : "original" , attachments : [ ] } ) ) . toBe ( false ) ;
115+ describe ( "recoverQueuedRunEdit" , ( ) => {
116+ const threadKey = "env:thread-recover" ;
117+ const runId = RunId . make ( "run-1" ) ;
118+ const editKey = queuedEditDraftKey ( threadKey , runId ) ;
119+
120+ it ( "drops an untouched edit without restoring the sent message" , ( ) => {
121+ beginQueuedRunEdit ( threadKey , edit ( [ ] ) ) ;
122+
123+ expect ( recoverQueuedRunEdit ( threadKey , runId ) ) . toBe ( "clean" ) ;
124+ expect ( getQueuedRunEdit ( threadKey ) ) . toBeNull ( ) ;
125+ expect ( getComposerDraftSnapshot ( threadKey ) . text ) . toBe ( "" ) ;
126+ expect ( getComposerDraftSnapshot ( editKey ) . text ) . toBe ( "" ) ;
127+ } ) ;
128+
129+ it ( "discards a changed edit when the thread draft already has content" , ( ) => {
130+ setComposerDraftText ( threadKey , "unsent draft" ) ;
131+ beginQueuedRunEdit ( threadKey , edit ( [ ] ) ) ;
132+ setComposerDraftText ( editKey , "revised" ) ;
133+
134+ expect ( recoverQueuedRunEdit ( threadKey , runId ) ) . toBe ( "discarded" ) ;
135+ expect ( getQueuedRunEdit ( threadKey ) ) . toBeNull ( ) ;
136+ expect ( getComposerDraftSnapshot ( threadKey ) . text ) . toBe ( "unsent draft" ) ;
137+ setComposerDraftText ( threadKey , "" ) ;
115138 } ) ;
116139
117- it ( "treats changed text or a new attachment as an edit worth keeping" , ( ) => {
118- expect ( queuedRunEditIsDirty ( edit ( [ ] ) , { text : "revised" , attachments : [ ] } ) ) . toBe ( true ) ;
119- expect ( queuedRunEditIsDirty ( edit ( [ ] ) , { text : "original" , attachments : [ { } ] } ) ) . toBe ( true ) ;
140+ it ( "ignores a run the composer is no longer editing" , ( ) => {
141+ beginQueuedRunEdit ( threadKey , edit ( [ ] ) ) ;
142+
143+ expect ( recoverQueuedRunEdit ( threadKey , RunId . make ( "run-2" ) ) ) . toBeNull ( ) ;
144+ expect ( getQueuedRunEdit ( threadKey ) ?. runId ) . toBe ( runId ) ;
145+ expect ( recoverQueuedRunEdit ( threadKey , runId ) ) . toBe ( "clean" ) ;
120146 } ) ;
121147} ) ;
0 commit comments