@@ -135,7 +135,7 @@ import {
135135 clearPendingThreadCreationOutcome ,
136136 pendingThreadCreationOutcomesAtom ,
137137} from "./pending-thread-creation" ;
138- import { threadComposerErrorAtom } from "./thread-composer-error" ;
138+ import { setThreadComposerError , threadComposerErrorsAtom } from "./thread-composer-error" ;
139139import type { QueuedThreadMessage } from "./thread-outbox-model" ;
140140import * as composerDrafts from "./use-composer-drafts" ;
141141import { recoverFailedThreadDraft } from "./recover-failed-thread-draft" ;
@@ -208,7 +208,7 @@ afterEach(() => {
208208 appAtomRegistry . set ( composerDrafts . composerCloudDraftsAtom , { accountId : null , signedOut : { } } ) ;
209209 appAtomRegistry . set ( editingQueuedMessageIdsAtom , { } ) ;
210210 appAtomRegistry . set ( pendingThreadCreationOutcomesAtom , { } ) ;
211- appAtomRegistry . set ( threadComposerErrorAtom ( "environment-1:thread-1" ) , null ) ;
211+ appAtomRegistry . set ( threadComposerErrorsAtom , { } ) ;
212212 harness . draftFile . setWriteError ( null ) ;
213213 harness . removePersistedFile . mockClear ( ) ;
214214 harness . removeOutboxMessage . mockClear ( ) ;
@@ -441,6 +441,25 @@ describe("thread outbox drain delivery cleanup", () => {
441441 expect ( appAtomRegistry . get ( acknowledgedThreadMessagesAtom ) ) . toEqual ( [ message ] ) ;
442442 } ) ;
443443
444+ it ( "clears an error about the delivered message but keeps one about another message" , async ( ) => {
445+ const threadKey = "environment-1:thread-1" ;
446+ const retried = queuedMessage ( { messageId : "message-retried" , text : "retried" } ) ;
447+ await harness . manager . enqueue ( retried ) ;
448+ // A failed recovery left this message queued with an error about it.
449+ setThreadComposerError ( threadKey , "could not be restored" , retried . messageId ) ;
450+
451+ await completeQueuedMessageDelivery ( retried , harness . manager . revisionOf ( retried . messageId ) ) ;
452+ expect ( appAtomRegistry . get ( threadComposerErrorsAtom ) [ threadKey ] ) . toBeUndefined ( ) ;
453+
454+ const other = queuedMessage ( { messageId : "message-other" , text : "other" } ) ;
455+ await harness . manager . enqueue ( other ) ;
456+ // The thread's error explains a different, rejected message still in the draft.
457+ setThreadComposerError ( threadKey , "rejected" , "message-rejected" ) ;
458+
459+ await completeQueuedMessageDelivery ( other , harness . manager . revisionOf ( other . messageId ) ) ;
460+ expect ( appAtomRegistry . get ( threadComposerErrorsAtom ) [ threadKey ] ?. message ) . toBe ( "rejected" ) ;
461+ } ) ;
462+
444463 it ( "keeps a delivered message when its editor opens during storage removal" , async ( ) => {
445464 const message = queuedMessage ( {
446465 messageId : "message-editor-removal-race" ,
@@ -697,9 +716,7 @@ describe("thread outbox recovery rollback", () => {
697716 } ) ;
698717 expect ( remainingMessages ( ) ) . toEqual ( [ ] ) ;
699718 // The creation's failure card shows the reason; the composer is hidden.
700- expect (
701- appAtomRegistry . get ( threadComposerErrorAtom ( `${ message . environmentId } :${ message . threadId } ` ) ) ,
702- ) . toBeNull ( ) ;
719+ expect ( appAtomRegistry . get ( threadComposerErrorsAtom ) ) . toEqual ( { } ) ;
703720 // The thread screen opened for this creation reads the failure from here.
704721 expect (
705722 appAtomRegistry . get ( pendingThreadCreationOutcomesAtom ) [
@@ -738,8 +755,8 @@ describe("thread outbox recovery rollback", () => {
738755 expect ( appAtomRegistry . get ( pendingThreadCreationOutcomesAtom ) ) . toEqual ( { } ) ;
739756 // The thread screen shows why the message came back into the composer.
740757 expect (
741- appAtomRegistry . get ( threadComposerErrorAtom ( `${ message . environmentId } :${ message . threadId } ` ) ) ,
742- ) . toBe ( "rejected" ) ;
758+ appAtomRegistry . get ( threadComposerErrorsAtom ) [ `${ message . environmentId } :${ message . threadId } ` ] ,
759+ ) . toEqual ( { message : "rejected" , messageId : message . messageId } ) ;
743760 } ) ;
744761
745762 it ( "rolls a failed recovery merge back so the retry cannot duplicate the text" , async ( ) => {
@@ -765,6 +782,6 @@ describe("thread outbox recovery rollback", () => {
765782 "typed offline\n\nqueued text" ,
766783 ) ;
767784 expect ( remainingMessages ( ) ) . toEqual ( [ ] ) ;
768- expect ( appAtomRegistry . get ( threadComposerErrorAtom ( draftKey ) ) ) . toBe ( "too large" ) ;
785+ expect ( appAtomRegistry . get ( threadComposerErrorsAtom ) [ draftKey ] ?. message ) . toBe ( "too large" ) ;
769786 } ) ;
770787} ) ;
0 commit comments