11import * as NodeCrypto from "@effect/platform-node/NodeCrypto" ;
22import { describe , expect , it } from "@effect/vitest" ;
3- import { ProjectId , type TerminalEvent , type TerminalSessionSnapshot } from "@t3tools/contracts" ;
3+ import {
4+ ProjectId ,
5+ TerminalNotRunningError ,
6+ type TerminalEvent ,
7+ type TerminalSessionSnapshot ,
8+ } from "@t3tools/contracts" ;
49import * as Deferred from "effect/Deferred" ;
510import * as Effect from "effect/Effect" ;
611import * as Fiber from "effect/Fiber" ;
@@ -35,7 +40,7 @@ const openSnapshot = (history: string): TerminalSessionSnapshot => ({
3540const makeHarness = Effect . fn ( function * ( options : {
3641 readonly history ?: string ;
3742 readonly opening ?: Deferred . Deferred < void > ;
38- readonly shell ?: string ;
43+ readonly shell ?: string | null ;
3944} ) {
4045 const listeners = new Set < ( event : TerminalEvent ) => Effect . Effect < void > > ( ) ;
4146 const writes = yield * Queue . unbounded < string > ( ) ;
@@ -46,7 +51,10 @@ const makeHarness = Effect.fn(function* (options: {
4651 ? Deferred . succeed ( options . opening , undefined ) . pipe ( Effect . andThen ( Effect . never ) )
4752 : Effect . void
4853 ) . pipe ( Effect . as ( openSnapshot ( options . history ?? "" ) ) ) ,
49- getShell : ( ) => Effect . succeed ( options . shell ?? "/bin/zsh" ) ,
54+ getShell : ( ) =>
55+ options . shell === null
56+ ? Effect . fail ( new TerminalNotRunningError ( { threadId, terminalId } ) )
57+ : Effect . succeed ( options . shell ?? "/bin/zsh" ) ,
5058 subscribe : ( listener ) =>
5159 Effect . sync ( ( ) => {
5260 listeners . add ( listener ) ;
@@ -94,7 +102,7 @@ const makeHarness = Effect.fn(function* (options: {
94102const setup = Effect . fn ( function * (
95103 options : {
96104 readonly history ?: string ;
97- readonly shell ?: string ;
105+ readonly shell ?: string | null ;
98106 } = { } ,
99107) {
100108 const harness = yield * makeHarness ( options ) ;
@@ -173,13 +181,20 @@ describe("ProjectSetupScriptRunner", () => {
173181 } ) ,
174182 ) ;
175183
176- it . effect ( "does not type into a shell that exits during startup" , ( ) =>
177- Effect . gen ( function * ( ) {
178- const { completion, writes, emit } = yield * setup ( ) ;
179- yield * emit ( { ...event , type : "exited" , exitCode : 1 , exitSignal : null } ) ;
180- expect ( yield * completion ) . toMatchObject ( { exitCode : null } ) ;
181- yield * TestClock . adjust ( "1 minute" ) ;
182- expect ( yield * Queue . size ( writes ) ) . toBe ( 0 ) ;
183- } ) ,
184+ it . effect . each ( [ false , true ] ) (
185+ "does not type into a shell that exits during startup (before shell lookup: %s)" ,
186+ ( beforeShellLookup ) =>
187+ Effect . gen ( function * ( ) {
188+ const { completion, writes, emit, listeners } = yield * setup (
189+ beforeShellLookup ? { shell : null } : { } ,
190+ ) ;
191+ if ( ! beforeShellLookup ) {
192+ yield * emit ( { ...event , type : "exited" , exitCode : 1 , exitSignal : null } ) ;
193+ }
194+ expect ( yield * completion ) . toMatchObject ( { exitCode : null } ) ;
195+ yield * TestClock . adjust ( "1 minute" ) ;
196+ expect ( yield * Queue . size ( writes ) ) . toBe ( 0 ) ;
197+ expect ( listeners . size ) . toBe ( 0 ) ;
198+ } ) ,
184199 ) ;
185200} ) ;
0 commit comments