@@ -3017,11 +3017,18 @@ test("integration: sessions read shows assistant updates before the prompt finis
30173017 try {
30183018 const history = await waitFor ( async ( ) => {
30193019 const result = await runCli (
3020- [ ...baseAgentArgs ( cwd ) , "--format" , "quiet " , "sessions" , "read" ] ,
3020+ [ ...baseAgentArgs ( cwd ) , "--format" , "json " , "sessions" , "read" ] ,
30213021 homeDir ,
30223022 ) ;
30233023 assert . equal ( result . code , 0 , result . stderr ) ;
3024- return result . stdout . includes ( "foreground-live-update" ) ? result . stdout : null ;
3024+ const payload = JSON . parse ( result . stdout . trim ( ) ) as {
3025+ entries ?: Array < { role ?: string ; textPreview ?: string } > ;
3026+ } ;
3027+ const assistantEntry = payload . entries ?. find (
3028+ ( entry ) =>
3029+ entry . role === "assistant" && entry . textPreview ?. includes ( "foreground-live-update" ) ,
3030+ ) ;
3031+ return assistantEntry ? result . stdout : null ;
30253032 } , 5_000 ) ;
30263033
30273034 assert . equal ( promptChild . exitCode , null , "prompt should still be running" ) ;
@@ -3079,11 +3086,18 @@ test("integration: --no-wait stdin prompt checkpoints live assistant updates", a
30793086
30803087 const history = await waitFor ( async ( ) => {
30813088 const result = await runCli (
3082- [ ...baseAgentArgs ( cwd ) , "--format" , "quiet " , "sessions" , "read" ] ,
3089+ [ ...baseAgentArgs ( cwd ) , "--format" , "json " , "sessions" , "read" ] ,
30833090 homeDir ,
30843091 ) ;
30853092 assert . equal ( result . code , 0 , result . stderr ) ;
3086- return result . stdout . includes ( "background-live-update" ) ? result . stdout : null ;
3093+ const payload = JSON . parse ( result . stdout . trim ( ) ) as {
3094+ entries ?: Array < { role ?: string ; textPreview ?: string } > ;
3095+ } ;
3096+ const assistantEntry = payload . entries ?. find (
3097+ ( entry ) =>
3098+ entry . role === "assistant" && entry . textPreview ?. includes ( "background-live-update" ) ,
3099+ ) ;
3100+ return assistantEntry ? result . stdout : null ;
30873101 } , 5_000 ) ;
30883102
30893103 assert . match ( history , / b a c k g r o u n d - l i v e - u p d a t e / ) ;
@@ -3100,6 +3114,91 @@ test("integration: --no-wait stdin prompt checkpoints live assistant updates", a
31003114 } ) ;
31013115} ) ;
31023116
3117+ test ( "integration: sessions close stays closed after live checkpoints" , async ( ) => {
3118+ await withTempHome ( async ( homeDir ) => {
3119+ const cwd = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "acpx-integration-cwd-" ) ) ;
3120+
3121+ try {
3122+ const created = await runCli (
3123+ [ ...baseAgentArgs ( cwd ) , "--format" , "json" , "sessions" , "new" ] ,
3124+ homeDir ,
3125+ ) ;
3126+ assert . equal ( created . code , 0 , created . stderr ) ;
3127+ const createdPayload = JSON . parse ( created . stdout . trim ( ) ) as {
3128+ acpxRecordId ?: string ;
3129+ } ;
3130+ const sessionId = createdPayload . acpxRecordId ;
3131+ assert . equal ( typeof sessionId , "string" ) ;
3132+
3133+ const promptChild = spawn (
3134+ process . execPath ,
3135+ [
3136+ CLI_PATH ,
3137+ ...baseAgentArgs ( cwd ) ,
3138+ "--format" ,
3139+ "quiet" ,
3140+ "prompt" ,
3141+ "stream-sleep 5000 close-live-update" ,
3142+ ] ,
3143+ {
3144+ env : {
3145+ ...process . env ,
3146+ HOME : homeDir ,
3147+ } ,
3148+ stdio : [ "ignore" , "pipe" , "pipe" ] ,
3149+ } ,
3150+ ) ;
3151+
3152+ try {
3153+ await waitFor ( async ( ) => {
3154+ const result = await runCli (
3155+ [ ...baseAgentArgs ( cwd ) , "--format" , "json" , "sessions" , "read" ] ,
3156+ homeDir ,
3157+ ) ;
3158+ assert . equal ( result . code , 0 , result . stderr ) ;
3159+ const payload = JSON . parse ( result . stdout . trim ( ) ) as {
3160+ entries ?: Array < { role ?: string ; textPreview ?: string } > ;
3161+ } ;
3162+ const assistantEntry = payload . entries ?. find (
3163+ ( entry ) =>
3164+ entry . role === "assistant" && entry . textPreview ?. includes ( "close-live-update" ) ,
3165+ ) ;
3166+ return assistantEntry ? true : null ;
3167+ } , 5_000 ) ;
3168+
3169+ const closed = await runCli (
3170+ [ ...baseAgentArgs ( cwd ) , "--format" , "json" , "sessions" , "close" ] ,
3171+ homeDir ,
3172+ ) ;
3173+ assert . equal ( closed . code , 0 , closed . stderr ) ;
3174+ if ( promptChild . exitCode == null && promptChild . signalCode == null ) {
3175+ await awaitChildClose ( promptChild ) . catch ( ( ) => { } ) ;
3176+ }
3177+
3178+ const recordPath = path . join (
3179+ homeDir ,
3180+ ".acpx" ,
3181+ "sessions" ,
3182+ `${ encodeURIComponent ( sessionId as string ) } .json` ,
3183+ ) ;
3184+ const storedRecord = JSON . parse ( await fs . readFile ( recordPath , "utf8" ) ) as {
3185+ closed ?: boolean ;
3186+ closed_at ?: string ;
3187+ } ;
3188+ assert . equal ( storedRecord . closed , true ) ;
3189+ assert . equal ( typeof storedRecord . closed_at , "string" ) ;
3190+ } finally {
3191+ if ( promptChild . exitCode == null && promptChild . signalCode == null ) {
3192+ promptChild . kill ( "SIGKILL" ) ;
3193+ await awaitChildClose ( promptChild ) . catch ( ( ) => { } ) ;
3194+ }
3195+ }
3196+ } finally {
3197+ await fs . rm ( cwd , { recursive : true , force : true } ) ;
3198+ }
3199+ } ) ;
3200+ } ) ;
3201+
31033202test ( "integration: session remains resumable after queue owner exits and agent has exited" , async ( ) => {
31043203 await withTempHome ( async ( homeDir ) => {
31053204 const cwd = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "acpx-integration-cwd-" ) ) ;
0 commit comments