@@ -48,9 +48,11 @@ import { PTY_PROTOCOL_REPLY_MAX_BYTES } from '../pty-screen-collector.js';
4848
4949const NO_ABORT = new AbortController ( ) . signal ;
5050const TEMPORARY_WORKSPACES = new Set < string > ( ) ;
51+ const SQLITE_SHELL_RUN_STORES = new Set < ReturnType < typeof createSqliteShellRunStore > > ( ) ;
5152const REAL_WINDOWS_GIT_BASH = windowsGitBashPlan ( ) ;
5253
5354after ( async ( ) => {
55+ for ( const store of SQLITE_SHELL_RUN_STORES ) store . close ( ) ;
5456 await Promise . all (
5557 [ ...TEMPORARY_WORKSPACES ] . map ( ( path ) => rm ( path , { recursive : true , force : true } ) ) ,
5658 ) ;
@@ -59,7 +61,7 @@ after(async () => {
5961describe ( 'ShellRunProcessManager' , ( ) => {
6062 test ( 'rejects unprojectable provider tool-call identities before durable admission' , async ( ) => {
6163 const cwd = await workspace ( ) ;
62- const store = createSqliteShellRunStore ( cwd ) ;
64+ const store = sqliteShellRunStore ( cwd ) ;
6365 const manager = createManager ( store ) ;
6466 const completions : boolean [ ] = [ ] ;
6567 const maximumMultibyteId = '😀' . repeat ( SHELL_RUN_SOURCE_TOOL_CALL_ID_MAX_BYTES / 4 ) ;
@@ -87,7 +89,7 @@ describe('ShellRunProcessManager', () => {
8789
8890 test ( 'keeps the default pipe path separated, durable, redacted, and observed' , async ( ) => {
8991 const cwd = await workspace ( ) ;
90- const store = createSqliteShellRunStore ( cwd ) ;
92+ const store = sqliteShellRunStore ( cwd ) ;
9193 const manager = createManager ( store ) ;
9294 const result = await manager . runForegroundBash (
9395 shellInput ( {
@@ -231,7 +233,7 @@ describe('ShellRunProcessManager', () => {
231233
232234 test ( 'keeps foreground execution bounded and rejects PTY promotion' , async ( ) => {
233235 const cwd = await workspace ( ) ;
234- const store = createSqliteShellRunStore ( await workspace ( ) ) ;
236+ const store = sqliteShellRunStore ( await workspace ( ) ) ;
235237 const manager = createManager ( store ) ;
236238 const abort = new AbortController ( ) ;
237239 const running = manager . runForegroundBash (
@@ -265,7 +267,7 @@ describe('ShellRunProcessManager', () => {
265267
266268 test ( 'hands off a long pipe command without output and publishes monotonic revisions' , async ( ) => {
267269 const updates : ShellRunUpdate [ ] = [ ] ;
268- const store = createSqliteShellRunStore ( await workspace ( ) ) ;
270+ const store = sqliteShellRunStore ( await workspace ( ) ) ;
269271 const manager = createManager ( store , ( update ) => updates . push ( update ) ) ;
270272 const initial = await manager . runBackgroundBash (
271273 shellInput ( {
@@ -308,7 +310,7 @@ describe('ShellRunProcessManager', () => {
308310 } ) ;
309311
310312 test ( 'notifies resource owners when foreground and background commands reach terminal state' , async ( ) => {
311- const store = createSqliteShellRunStore ( await workspace ( ) ) ;
313+ const store = sqliteShellRunStore ( await workspace ( ) ) ;
312314 const manager = createManager ( store ) ;
313315 const completions : boolean [ ] = [ ] ;
314316 await manager . runForegroundBash (
@@ -386,7 +388,7 @@ describe('ShellRunProcessManager', () => {
386388 test ( 'commits a durable starting identity before the native pipe process spawns' , async ( ) => {
387389 const cwd = await workspace ( ) ;
388390 const marker = join ( cwd , 'spawned' ) ;
389- const backingStore = createSqliteShellRunStore ( cwd ) ;
391+ const backingStore = sqliteShellRunStore ( cwd ) ;
390392 const createCommitted = deferred < void > ( ) ;
391393 const releaseCreate = deferred < void > ( ) ;
392394 const store : ShellRunStore = {
@@ -439,7 +441,7 @@ describe('ShellRunProcessManager', () => {
439441 for ( const lifecycle of [ 'session' , 'runtime' ] as const ) {
440442 const cwd = await workspace ( ) ;
441443 const marker = join ( cwd , `${ lifecycle } -spawned` ) ;
442- const backingStore = createSqliteShellRunStore ( cwd ) ;
444+ const backingStore = sqliteShellRunStore ( cwd ) ;
443445 const createCommitted = deferred < void > ( ) ;
444446 const releaseCreate = deferred < void > ( ) ;
445447 const store : ShellRunStore = {
@@ -500,7 +502,7 @@ describe('ShellRunProcessManager', () => {
500502
501503 test ( 'rechecks the session fence after the durable running commit' , async ( ) => {
502504 const cwd = await workspace ( ) ;
503- const backingStore = createSqliteShellRunStore ( cwd ) ;
505+ const backingStore = sqliteShellRunStore ( cwd ) ;
504506 const runningCommitted = deferred < void > ( ) ;
505507 const releaseRunning = deferred < void > ( ) ;
506508 const store : ShellRunStore = {
@@ -625,7 +627,7 @@ describe('ShellRunProcessManager', () => {
625627 } , async ( context ) => {
626628 const processDiscovery = delayPosixProcessDiscovery ( context ) ;
627629 const abort = new AbortController ( ) ;
628- const backingStore = createSqliteShellRunStore ( await workspace ( ) ) ;
630+ const backingStore = sqliteShellRunStore ( await workspace ( ) ) ;
629631 const runningCommitted = deferred < void > ( ) ;
630632 const releaseRunning = deferred < void > ( ) ;
631633 const store : ShellRunStore = {
@@ -1107,7 +1109,7 @@ describe('ShellRunProcessManager', () => {
11071109 } ) ;
11081110
11091111 test ( 'recovers durable starting and running records without live handles as orphaned' , async ( ) => {
1110- const store = createSqliteShellRunStore ( await workspace ( ) ) ;
1112+ const store = sqliteShellRunStore ( await workspace ( ) ) ;
11111113 await store . createShellRun ( record ( { shellRunId : 'orphan-starting' , status : 'starting' } ) ) ;
11121114 await store . createShellRun ( record ( { shellRunId : 'orphan-running' , status : 'running' } ) ) ;
11131115 await store . createShellRun ( {
@@ -1134,7 +1136,7 @@ describe('ShellRunProcessManager', () => {
11341136 } ) ;
11351137
11361138 test ( 'concurrent orphan observers converge on the same durable terminal record' , async ( ) => {
1137- const backingStore = createSqliteShellRunStore ( await workspace ( ) ) ;
1139+ const backingStore = sqliteShellRunStore ( await workspace ( ) ) ;
11381140 await backingStore . createShellRun (
11391141 record ( { shellRunId : 'concurrent-orphan' , status : 'running' } ) ,
11401142 ) ;
@@ -1174,7 +1176,7 @@ describe('ShellRunProcessManager', () => {
11741176 } ) ;
11751177
11761178 test ( 'keeps unauthorized refs non-disclosing and rejects malformed selectors before storage' , async ( ) => {
1177- const store = createSqliteShellRunStore ( await workspace ( ) ) ;
1179+ const store = sqliteShellRunStore ( await workspace ( ) ) ;
11781180 await store . createShellRun ( {
11791181 ...record ( { shellRunId : 'owned-by-another-session' , status : 'running' } ) ,
11801182 sessionId : 'session-2' ,
@@ -1678,7 +1680,7 @@ describe('ShellRunProcessManager', () => {
16781680 test ( 'publishes raw PTY deltas and exposes a bounded replay snapshot' , async ( ) => {
16791681 const cwd = await workspace ( ) ;
16801682 const events : ShellRunPtyDataEvent [ ] = [ ] ;
1681- const manager = createManager ( createSqliteShellRunStore ( cwd ) , undefined , {
1683+ const manager = createManager ( sqliteShellRunStore ( cwd ) , undefined , {
16821684 onPtyData : ( event ) => events . push ( event ) ,
16831685 } ) ;
16841686 const run = await manager . runBackgroundBash (
@@ -1719,7 +1721,7 @@ describe('ShellRunProcessManager', () => {
17191721
17201722 test ( 'keeps concurrent PTY control and Read persistence in parser-cut order' , async ( ) => {
17211723 const updates : ShellRunUpdate [ ] = [ ] ;
1722- const store = createSqliteShellRunStore ( await workspace ( ) ) ;
1724+ const store = sqliteShellRunStore ( await workspace ( ) ) ;
17231725 const manager = createManager ( store , ( update ) => updates . push ( update ) ) ;
17241726 const initial = await manager . runBackgroundBash (
17251727 shellInput ( {
@@ -1792,7 +1794,7 @@ describe('ShellRunProcessManager', () => {
17921794 const dsrSeen = join ( cwd , 'dsr-seen' ) ;
17931795 const exitGate = join ( cwd , 'exit-gate' ) ;
17941796 const sizeBeforeExit = join ( cwd , 'size-before-exit' ) ;
1795- const store = createSqliteShellRunStore ( await workspace ( ) ) ;
1797+ const store = sqliteShellRunStore ( await workspace ( ) ) ;
17961798 const manager = createManager ( store ) ;
17971799 const initial = await manager . runBackgroundBash (
17981800 shellInput ( {
@@ -1907,7 +1909,7 @@ describe('ShellRunProcessManager', () => {
19071909 test ( 'writeStdin itself returns terminal status when persist is held through finalization' , async ( ) => {
19081910 const cwd = await workspace ( ) ;
19091911 const exitGate = join ( cwd , 'exit-gate' ) ;
1910- const backingStore = createSqliteShellRunStore ( await workspace ( ) ) ;
1912+ const backingStore = sqliteShellRunStore ( await workspace ( ) ) ;
19111913 const persistHeld = deferred < void > ( ) ;
19121914 const releasePersist = deferred < void > ( ) ;
19131915 let holdNextObservation = false ;
@@ -2041,7 +2043,7 @@ describe('ShellRunProcessManager', () => {
20412043 const cwd = await workspace ( ) ;
20422044 const dirtyTrigger = join ( cwd , 'emit-dirty' ) ;
20432045 const dirtyWritten = join ( cwd , 'dirty-written' ) ;
2044- const store = createSqliteShellRunStore ( await workspace ( ) ) ;
2046+ const store = sqliteShellRunStore ( await workspace ( ) ) ;
20452047 // The test owns flush timing: no automatic flush fires until it says so, so the
20462048 // "not yet committed" window cannot be closed by a periodic flush racing the clock.
20472049 const flushes = manualFlushScheduler ( ) ;
@@ -2597,7 +2599,7 @@ describe('ShellRunProcessManager', () => {
25972599 // Durable ShellRun creation fails once (the SQLite authority has no
25982600 // filesystem seam to block on), then succeeds; the manager must release
25992601 // the reserved slot on the failed startup.
2600- const backingStore = createSqliteShellRunStore ( cwd ) ;
2602+ const backingStore = sqliteShellRunStore ( cwd ) ;
26012603 let durableFailureArmed = true ;
26022604 const store : ShellRunStore = {
26032605 async createShellRun ( record ) {
@@ -2809,7 +2811,7 @@ async function createTestManager(
28092811 scheduleTimeout ?: ShellRunProcessManagerInput [ 'scheduleTimeout' ] ;
28102812 } ,
28112813) : Promise < ShellRunProcessManager > {
2812- return createManager ( createSqliteShellRunStore ( await workspace ( ) ) , onShellRunUpdate , options ) ;
2814+ return createManager ( sqliteShellRunStore ( await workspace ( ) ) , onShellRunUpdate , options ) ;
28132815}
28142816
28152817function shellInput ( input : {
@@ -2965,6 +2967,12 @@ async function workspace(): Promise<string> {
29652967 return path ;
29662968}
29672969
2970+ function sqliteShellRunStore ( workspaceRoot : string ) : ShellRunStore {
2971+ const store = createSqliteShellRunStore ( workspaceRoot ) ;
2972+ SQLITE_SHELL_RUN_STORES . add ( store ) ;
2973+ return store ;
2974+ }
2975+
29682976async function waitUntil (
29692977 predicate : ( ) => boolean | Promise < boolean > ,
29702978 timeoutMs = 3_000 ,
0 commit comments