@@ -145,6 +145,7 @@ import { editingQueuedMessageIdsAtom } from "./use-thread-outbox";
145145import {
146146 completeQueuedMessageDelivery ,
147147 logThreadOutboxDeliveryFailure ,
148+ logThreadOutboxUploadFailure ,
148149 prepareQueuedMessageAttachments ,
149150 recoverEditedCreationAfterDelivery ,
150151 removeAcknowledgedExistingThreadMessage ,
@@ -775,44 +776,127 @@ describe("thread outbox recovery rollback", () => {
775776} ) ;
776777
777778describe ( "thread outbox failure logging" , ( ) => {
778- it ( "keeps ordinary transport retries out of console.warn and silent by default" , ( ) => {
779+ // Tagged errors match shouldRetryThreadOutboxDelivery's transport tags, so
780+ // the assertions cover the real failure classification, not a
781+ // predetermined action argument.
782+ const transportError = { _tag : "RpcClientError" } ;
783+ const serverDecidedError = { _tag : "OrchestrationDispatchCommandError" } ;
784+
785+ function failureLogging ( input : Parameters < typeof logThreadOutboxDeliveryFailure > [ 0 ] ) : {
786+ readonly action : string ;
787+ readonly warnCalls : ReadonlyArray < unknown [ ] > ;
788+ readonly logCalls : ReadonlyArray < unknown [ ] > ;
789+ } {
779790 const warn = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
780791 const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } ) ;
781792 try {
782- logThreadOutboxDeliveryFailure ( "retry" , { messageId : "m1" } ) ;
783- expect ( warn ) . not . toHaveBeenCalled ( ) ;
784- expect ( log ) . not . toHaveBeenCalled ( ) ;
793+ return {
794+ action : logThreadOutboxDeliveryFailure ( input ) ,
795+ warnCalls : [ ...warn . mock . calls ] ,
796+ logCalls : [ ...log . mock . calls ] ,
797+ } ;
785798 } finally {
786799 warn . mockRestore ( ) ;
787800 log . mockRestore ( ) ;
788801 }
802+ }
803+
804+ it ( "keeps offline transport retries silent by default at both stages" , ( ) => {
805+ for ( const stage of [ "settings-sync" , "start-turn" ] as const ) {
806+ const { action, warnCalls, logCalls } = failureLogging ( {
807+ stage,
808+ error : transportError ,
809+ interrupted : false ,
810+ context : { messageId : "m1" } ,
811+ } ) ;
812+ expect ( action ) . toBe ( "retry" ) ;
813+ expect ( warnCalls ) . toEqual ( [ ] ) ;
814+ expect ( logCalls ) . toEqual ( [ ] ) ;
815+ }
789816 } ) ;
790817
791- it ( "surfaces retry details when the thread-outbox debug filter is enabled" , ( ) => {
818+ it ( "surfaces transport retry details when the thread-outbox debug filter is enabled" , ( ) => {
792819 vi . stubGlobal ( "__T3_DEBUG__" , [ "thread-outbox" ] ) ;
793820 const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } ) ;
794821 try {
795- logThreadOutboxDeliveryFailure ( "retry" , { messageId : "m1" } ) ;
822+ logThreadOutboxDeliveryFailure ( {
823+ stage : "start-turn" ,
824+ error : transportError ,
825+ interrupted : false ,
826+ context : { messageId : "m1" } ,
827+ } ) ;
796828 expect ( log ) . toHaveBeenCalledWith (
797829 "[t3-thread-outbox] queued message delivery failed" ,
798- expect . objectContaining ( { messageId : "m1" } ) ,
830+ expect . objectContaining ( { messageId : "m1" , action : "retry" } ) ,
799831 ) ;
800832 } finally {
801833 log . mockRestore ( ) ;
802834 vi . unstubAllGlobals ( ) ;
803835 }
804836 } ) ;
805837
806- it ( "still warns when the server decided the message must be restored" , ( ) => {
838+ it ( "warns when the server decided the message must be restored" , ( ) => {
839+ const { action, warnCalls } = failureLogging ( {
840+ stage : "start-turn" ,
841+ error : serverDecidedError ,
842+ interrupted : false ,
843+ context : { messageId : "m2" } ,
844+ } ) ;
845+ expect ( action ) . toBe ( "restore" ) ;
846+ expect ( warnCalls ) . toEqual ( [
847+ [
848+ "[thread-outbox] queued message delivery failed" ,
849+ expect . objectContaining ( { messageId : "m2" , action : "restore" } ) ,
850+ ] ,
851+ ] ) ;
852+ } ) ;
853+
854+ it ( "warns on a nontransport settings-sync failure even though it resolves to a retry" , ( ) => {
855+ const { action, warnCalls } = failureLogging ( {
856+ stage : "settings-sync" ,
857+ error : serverDecidedError ,
858+ interrupted : false ,
859+ context : { messageId : "m3" } ,
860+ } ) ;
861+ expect ( action ) . toBe ( "retry" ) ;
862+ expect ( warnCalls ) . toEqual ( [
863+ [
864+ "[thread-outbox] queued message delivery failed" ,
865+ expect . objectContaining ( { stage : "settings-sync" , action : "retry" } ) ,
866+ ] ,
867+ ] ) ;
868+ } ) ;
869+
870+ it ( "routes retryable attachment-upload failures to the debug log and warns on the rest" , ( ) => {
807871 const warn = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
872+ const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } ) ;
808873 try {
809- logThreadOutboxDeliveryFailure ( "restore" , { messageId : "m2" } ) ;
874+ logThreadOutboxUploadFailure ( transportError ) ;
875+ expect ( warn ) . not . toHaveBeenCalled ( ) ;
876+ expect ( log ) . not . toHaveBeenCalled ( ) ;
877+
878+ logThreadOutboxUploadFailure ( serverDecidedError ) ;
810879 expect ( warn ) . toHaveBeenCalledWith (
811- "[thread-outbox] queued message delivery failed " ,
812- expect . objectContaining ( { messageId : "m2" } ) ,
880+ "[thread-outbox] failed to upload attachments " ,
881+ serverDecidedError ,
813882 ) ;
814883 } finally {
815884 warn . mockRestore ( ) ;
885+ log . mockRestore ( ) ;
886+ }
887+ } ) ;
888+
889+ it ( "logs retryable attachment-upload failures when the debug filter is enabled" , ( ) => {
890+ vi . stubGlobal ( "__T3_DEBUG__" , [ "thread-outbox" ] ) ;
891+ const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } ) ;
892+ try {
893+ logThreadOutboxUploadFailure ( transportError ) ;
894+ expect ( log ) . toHaveBeenCalledWith ( "[t3-thread-outbox] attachment upload failed; retrying" , {
895+ error : transportError ,
896+ } ) ;
897+ } finally {
898+ log . mockRestore ( ) ;
899+ vi . unstubAllGlobals ( ) ;
816900 }
817901 } ) ;
818902} ) ;
0 commit comments