@@ -6974,6 +6974,80 @@ async fn terminal_panes_have_their_own_identity_shell_and_lifecycle() {
69746974 let _ = std:: fs:: remove_dir_all ( & dir) ;
69756975}
69766976
6977+ /// #437: a WHITESPACE title must not silently un-promote the draft.
6978+ ///
6979+ /// `thread.created` is the only event `orchestrationEventEffects.ts:31`
6980+ /// promotes a draft on, and its contract payload types `title` as
6981+ /// `TrimmedNonEmptyString` — `TrimmedString.check(isNonEmpty())`, so the client
6982+ /// TRIMS FIRST and then requires non-empty. The backend used to accept any
6983+ /// title that was merely `!s.is_empty()`, so a titleSeed of " " encoded fine
6984+ /// here, decoded to "" there, failed the check, and took the WHOLE EVENT with
6985+ /// it. The durable row still existed and the turn still ran; only the promotion
6986+ /// was lost, which at the glass is "2 minutes for a hi" with the composer stuck
6987+ /// on Thinking — indistinguishable from a hung backend.
6988+ ///
6989+ /// The assertion is that a whitespace title falls through to the SAME fallback
6990+ /// an absent title takes, so the payload can never carry a value the client
6991+ /// will refuse. Asserted on the announced thread because it and the event are
6992+ /// built from one `title` binding.
6993+ #[ tokio:: test]
6994+ async fn a_whitespace_title_falls_back_instead_of_shipping_an_undecodable_event ( ) {
6995+ let ( state, _dir) = test_state ( ) . await ;
6996+
6997+ let ( tx, mut rx) = mpsc:: unbounded_channel ( ) ;
6998+ request ( & state, & tx, "orchestration.subscribeShell" , json ! ( { } ) ) . await ;
6999+ let _ = drain ( & mut rx) ;
7000+
7001+ let command = json ! ( {
7002+ "type" : "thread.turn.start" ,
7003+ "commandId" : "c-ws" ,
7004+ "threadId" : "t-ws" ,
7005+ // Whitespace everywhere a title can come from, so the fallback is the
7006+ // only honest source left. The message text is whitespace too —
7007+ // otherwise it would supply the title and the test would pass without
7008+ // the trim ever being exercised.
7009+ "titleSeed" : " " ,
7010+ "message" : { "messageId" : "m-ws" , "role" : "user" , "text" : " " , "attachments" : [ ] } ,
7011+ "runtimeMode" : "full-access" ,
7012+ "bootstrap" : { "createThread" : { "projectId" : "p-ws" , "title" : " \t " } } ,
7013+ } ) ;
7014+ ensure_thread_on_shell ( & state, & command) . await . unwrap ( ) ;
7015+
7016+ let announced = drain_until ( & mut rx, std:: time:: Duration :: from_secs ( 2 ) , |f| {
7017+ f. get ( "values" )
7018+ . and_then ( |v| v. as_array ( ) )
7019+ . map ( |arr| {
7020+ arr. iter ( )
7021+ . any ( |x| x. get ( "kind" ) . and_then ( Value :: as_str) == Some ( "thread-upserted" ) )
7022+ } )
7023+ . unwrap_or ( false )
7024+ } )
7025+ . await ;
7026+ let upsert = announced
7027+ . iter ( )
7028+ . flat_map ( |f| f[ "values" ] . as_array ( ) . cloned ( ) . unwrap_or_default ( ) )
7029+ . find ( |v| v[ "kind" ] == "thread-upserted" )
7030+ . unwrap_or_else ( || panic ! ( "no thread-upserted in {announced:#?}" ) ) ;
7031+ let title = upsert[ "thread" ] [ "title" ] . as_str ( ) . unwrap_or_default ( ) ;
7032+
7033+ assert_eq ! (
7034+ title. trim( ) ,
7035+ title,
7036+ "#437: the title still carries surrounding whitespace, so the contract \
7037+ trims it to something shorter than what the backend recorded"
7038+ ) ;
7039+ assert ! (
7040+ !title. is_empty( ) ,
7041+ "#437: a whitespace-only title survived as an empty/blank title. \
7042+ `TrimmedNonEmptyString` refuses it, the client drops `thread.created` \
7043+ entirely, and the draft never promotes."
7044+ ) ;
7045+ assert_eq ! (
7046+ title, "New thread" ,
7047+ "#437: a blank title must take the SAME fallback an absent title takes"
7048+ ) ;
7049+ }
7050+
69777051/// #137/#78/#79: the FIRST turn's context reaches the thread.
69787052///
69797053/// The composer chooses a project, a worktree/branch and a runtime mode
0 commit comments