@@ -386,6 +386,57 @@ describe("Ctrl+C exit", () => {
386386 }
387387 } ) ;
388388 } ) ;
389+
390+ test ( "dispose unlinks ephemeralPath and leaves the operator path" , async ( ) => {
391+ await withShell ( async ( { shell } ) => {
392+ const dir = mkdtempSync ( join ( tmpdir ( ) , "ctrlc-attach-dispose-" ) ) ;
393+ const ephemeral = join ( dir , "ours.png" ) ;
394+ const operator = join ( dir , "theirs.png" ) ;
395+ writeFileSync ( ephemeral , "ephemeral-bytes" ) ;
396+ writeFileSync ( operator , "operator-bytes" ) ;
397+ try {
398+ addPendingAttachment ( shell , pendingImage ( "ours" , { ephemeralPath : ephemeral } ) ) ;
399+ addPendingAttachment ( shell , pendingImage ( "theirs" , { path : operator } ) ) ;
400+
401+ shell . dispose ( ) ;
402+
403+ expect ( existsSync ( ephemeral ) ) . toBe ( false ) ;
404+ expect ( existsSync ( operator ) ) . toBe ( true ) ;
405+ } finally {
406+ rmSync ( dir , { recursive : true , force : true } ) ;
407+ }
408+ } ) ;
409+ } ) ;
410+
411+ test ( "busy double-Ctrl+C quit unlinks ephemeralPath and leaves the operator path" , async ( ) => {
412+ await withShell ( async ( { shell } ) => {
413+ const dir = mkdtempSync ( join ( tmpdir ( ) , "ctrlc-attach-quit-" ) ) ;
414+ const ephemeral = join ( dir , "ours.png" ) ;
415+ const operator = join ( dir , "theirs.png" ) ;
416+ writeFileSync ( ephemeral , "ephemeral-bytes" ) ;
417+ writeFileSync ( operator , "operator-bytes" ) ;
418+ try {
419+ setShellRunState ( shell , "busy" ) ;
420+ addPendingAttachment ( shell , pendingImage ( "ours" , { ephemeralPath : ephemeral } ) ) ;
421+ addPendingAttachment ( shell , pendingImage ( "theirs" , { path : operator } ) ) ;
422+ setShellExitHandler ( shell , ( ) => {
423+ shell . dispose ( ) ;
424+ } ) ;
425+
426+ handleCtrlC ( shell , 0 ) ;
427+ expect ( shell . pendingAttachments ) . toHaveLength ( 2 ) ;
428+ expect ( existsSync ( ephemeral ) ) . toBe ( true ) ;
429+ expect ( existsSync ( operator ) ) . toBe ( true ) ;
430+
431+ handleCtrlC ( shell , 1 ) ;
432+
433+ expect ( existsSync ( ephemeral ) ) . toBe ( false ) ;
434+ expect ( existsSync ( operator ) ) . toBe ( true ) ;
435+ } finally {
436+ rmSync ( dir , { recursive : true , force : true } ) ;
437+ }
438+ } ) ;
439+ } ) ;
389440} ) ;
390441
391442function pendingImage ( id : string , extra ?: Partial < PendingImageAttachment > ) : PendingImageAttachment {
0 commit comments