@@ -5,7 +5,7 @@ import { describe, expect, test } from "bun:test";
55
66import { generateSessionId , sessionDir } from "../src/session/index.js" ;
77import type { RunState } from "../src/session/state.js" ;
8- import { createTempDirs } from "../testkit/temporary-dirs .js" ;
8+ import { spawnSignalFixture } from "./signal-helpers .js" ;
99
1010const FIXTURE = join (
1111 import . meta. dirname ,
@@ -18,28 +18,23 @@ const RUN_END_FIXTURE = join(
1818
1919describe ( "integration — crash finalizes run.json" , ( ) => {
2020 test ( "uncaughtException writes status: crashed with finishedAt, racing in-flight snapshot writes" , async ( ) => {
21- const { cwd, home, cleanup } = createTempDirs (
22- "corbits-crash-cwd-" ,
23- "corbits-crash-home-" ,
24- ) ;
2521 const sessionId = generateSessionId ( ) ;
22+ const { proc, output, cleanup } = await spawnSignalFixture ( {
23+ fixture : FIXTURE ,
24+ cwdPrefix : "corbits-crash-cwd-" ,
25+ homePrefix : "corbits-crash-home-" ,
26+ sessionId,
27+ sessionIdEnv : "CRASH_TEST_SESSION_ID" ,
28+ } ) ;
2629
2730 try {
28- const proc = Bun . spawn ( [ "bun" , "run" , FIXTURE ] , {
29- cwd,
30- env : { ...process . env , HOME : home , CRASH_TEST_SESSION_ID : sessionId } ,
31- stdout : "pipe" ,
32- stderr : "pipe" ,
33- } ) ;
34-
3531 const exitCode = await proc . exited ;
36- const stdout = await new Response ( proc . stdout ) . text ( ) ;
3732 const stderr = await new Response ( proc . stderr ) . text ( ) ;
3833
3934 expect ( exitCode ) . toBe ( 1 ) ;
4035 expect ( stderr ) . toContain ( "uncaughtException: Error: simulated crash" ) ;
4136
42- const runJsonPath = join ( stdout . trim ( ) , "run.json" ) ;
37+ const runJsonPath = join ( output . trim ( ) , "run.json" ) ;
4338 const raw = readFileSync ( runJsonPath , "utf8" ) ;
4439 const state = JSON . parse ( raw ) as RunState ;
4540
@@ -57,28 +52,19 @@ describe("integration — crash finalizes run.json", () => {
5752 } , 15_000 ) ;
5853
5954 test ( "a crash after session rotation still writes crashed for the new session" , async ( ) => {
60- const { cwd, home, cleanup } = createTempDirs (
61- "corbits-crash-cwd-" ,
62- "corbits-crash-home-" ,
63- ) ;
6455 const sessionId = generateSessionId ( ) ;
6556 const rotatedSessionId = generateSessionId ( ) ;
57+ const { proc, cwd, home, output, cleanup } = await spawnSignalFixture ( {
58+ fixture : FIXTURE ,
59+ cwdPrefix : "corbits-crash-cwd-" ,
60+ homePrefix : "corbits-crash-home-" ,
61+ sessionId,
62+ sessionIdEnv : "CRASH_TEST_SESSION_ID" ,
63+ extraEnv : { CRASH_TEST_ROTATED_SESSION_ID : rotatedSessionId } ,
64+ } ) ;
6665
6766 try {
68- const proc = Bun . spawn ( [ "bun" , "run" , FIXTURE ] , {
69- cwd,
70- env : {
71- ...process . env ,
72- HOME : home ,
73- CRASH_TEST_SESSION_ID : sessionId ,
74- CRASH_TEST_ROTATED_SESSION_ID : rotatedSessionId ,
75- } ,
76- stdout : "pipe" ,
77- stderr : "pipe" ,
78- } ) ;
79-
8067 const exitCode = await proc . exited ;
81- const stdout = await new Response ( proc . stdout ) . text ( ) ;
8268 const stderr = await new Response ( proc . stderr ) . text ( ) ;
8369
8470 expect ( exitCode ) . toBe ( 1 ) ;
@@ -95,7 +81,7 @@ describe("integration — crash finalizes run.json", () => {
9581 expect ( outgoingState . status ) . toBe ( "done" ) ;
9682 expect ( outgoingState . turnsUsed ) . toBe ( 3 ) ;
9783
98- const rotatedRunJsonPath = join ( stdout . trim ( ) , "run.json" ) ;
84+ const rotatedRunJsonPath = join ( output . trim ( ) , "run.json" ) ;
9985 const rotatedState = JSON . parse (
10086 readFileSync ( rotatedRunJsonPath , "utf8" ) ,
10187 ) as RunState ;
@@ -112,22 +98,17 @@ describe("integration — crash finalizes run.json", () => {
11298 } , 15_000 ) ;
11399
114100 test ( "an unrelated crash while the run-end write is in flight does not report crashed" , async ( ) => {
115- const { cwd, home, cleanup } = createTempDirs (
116- "corbits-crash-cwd-" ,
117- "corbits-crash-home-" ,
118- ) ;
119101 const sessionId = generateSessionId ( ) ;
102+ const { proc, output, cleanup } = await spawnSignalFixture ( {
103+ fixture : RUN_END_FIXTURE ,
104+ cwdPrefix : "corbits-crash-cwd-" ,
105+ homePrefix : "corbits-crash-home-" ,
106+ sessionId,
107+ sessionIdEnv : "RUN_END_TEST_SESSION_ID" ,
108+ } ) ;
120109
121110 try {
122- const proc = Bun . spawn ( [ "bun" , "run" , RUN_END_FIXTURE ] , {
123- cwd,
124- env : { ...process . env , HOME : home , RUN_END_TEST_SESSION_ID : sessionId } ,
125- stdout : "pipe" ,
126- stderr : "pipe" ,
127- } ) ;
128-
129111 const exitCode = await proc . exited ;
130- const stdout = await new Response ( proc . stdout ) . text ( ) ;
131112 const stderr = await new Response ( proc . stderr ) . text ( ) ;
132113
133114 expect ( exitCode ) . toBe ( 1 ) ;
@@ -139,7 +120,7 @@ describe("integration — crash finalizes run.json", () => {
139120 // saveState write resolved; the crash handler then saw a live run and
140121 // wrote "crashed" via saveCrashState, clobbering the clean finish.
141122 // Clearing the handle before the await closes that window.
142- const runJsonPath = join ( stdout . trim ( ) , "run.json" ) ;
123+ const runJsonPath = join ( output . trim ( ) , "run.json" ) ;
143124 const raw = readFileSync ( runJsonPath , "utf8" ) ;
144125 const state = JSON . parse ( raw ) as RunState ;
145126 expect ( state . status ) . not . toBe ( "crashed" ) ;
0 commit comments