1- import { describe , expect , test } from "bun:test"
2- import { AppRuntime } from "../../src/effect/app-runtime"
1+ import { describe , expect } from "bun:test"
32import { Effect } from "effect"
4- import { Instance } from "../../src/project/instance"
5- import { WithInstance } from "../../src/project/with-instance"
63import { Pty } from "../../src/pty"
74import { Shell } from "../../src/shell/shell"
8- import { tmpdir } from "../fixture/fixture "
5+ import { testEffect } from "../lib/effect "
96
107Shell . preferred . reset ( )
118
9+ const it = testEffect ( Pty . defaultLayer )
10+
11+ const createPty = ( input : Pty . CreateInput ) =>
12+ Effect . acquireRelease (
13+ Effect . gen ( function * ( ) {
14+ const pty = yield * Pty . Service
15+ const info = yield * pty . create ( input )
16+ return { pty, info }
17+ } ) ,
18+ ( { pty, info } ) => pty . remove ( info . id ) . pipe ( Effect . ignore ) ,
19+ ) . pipe ( Effect . map ( ( { info } ) => info ) )
20+
1221describe ( "pty shell args" , ( ) => {
1322 if ( process . platform !== "win32" ) return
1423
1524 const ps = Bun . which ( "pwsh" ) || Bun . which ( "powershell" )
1625 if ( ps ) {
17- test (
26+ it . instance (
1827 "does not add login args to pwsh" ,
19- async ( ) => {
20- await using dir = await tmpdir ( )
21- await WithInstance . provide ( {
22- directory : dir . path ,
23- fn : ( ) =>
24- AppRuntime . runPromise (
25- Effect . gen ( function * ( ) {
26- const pty = yield * Pty . Service
27- const info = yield * pty . create ( { command : ps , title : "pwsh" } )
28- try {
29- expect ( info . args ) . toEqual ( [ ] )
30- } finally {
31- yield * pty . remove ( info . id )
32- }
33- } ) ,
34- ) ,
35- } )
36- } ,
28+ ( ) =>
29+ Effect . gen ( function * ( ) {
30+ const info = yield * createPty ( { command : ps , title : "pwsh" } )
31+ expect ( info . args ) . toEqual ( [ ] )
32+ } ) ,
3733 { timeout : 30000 } ,
3834 )
3935 }
@@ -44,62 +40,36 @@ describe("pty shell args", () => {
4440 return Shell . gitbash ( )
4541 } ) ( )
4642 if ( bash ) {
47- test (
43+ it . instance (
4844 "adds login args to bash" ,
49- async ( ) => {
50- await using dir = await tmpdir ( )
51- await WithInstance . provide ( {
52- directory : dir . path ,
53- fn : ( ) =>
54- AppRuntime . runPromise (
55- Effect . gen ( function * ( ) {
56- const pty = yield * Pty . Service
57- const info = yield * pty . create ( { command : bash , title : "bash" } )
58- try {
59- expect ( info . args ) . toEqual ( [ "-l" ] )
60- } finally {
61- yield * pty . remove ( info . id )
62- }
63- } ) ,
64- ) ,
65- } )
66- } ,
45+ ( ) =>
46+ Effect . gen ( function * ( ) {
47+ const info = yield * createPty ( { command : bash , title : "bash" } )
48+ expect ( info . args ) . toEqual ( [ "-l" ] )
49+ } ) ,
6750 { timeout : 30000 } ,
6851 )
6952 }
7053} )
7154
7255describe ( "pty configured shell" , ( ) => {
73- test (
56+ const configured = process . platform === "win32" ? Bun . which ( "pwsh" ) || Bun . which ( "powershell" ) : Bun . which ( "bash" )
57+
58+ it . instance (
7459 "uses configured shell for default PTY command" ,
75- async ( ) => {
76- const configured = process . platform === "win32" ? Bun . which ( "pwsh" ) || Bun . which ( "powershell" ) : Bun . which ( "bash" )
77- if ( ! configured ) return
60+ ( ) =>
61+ Effect . gen ( function * ( ) {
62+ if ( ! configured ) return
7863
79- await using dir = await tmpdir ( {
80- config : { shell : Shell . name ( configured ) } ,
81- } )
82- await WithInstance . provide ( {
83- directory : dir . path ,
84- fn : ( ) =>
85- AppRuntime . runPromise (
86- Effect . gen ( function * ( ) {
87- const pty = yield * Pty . Service
88- const info = yield * pty . create ( { title : "configured" } )
89- try {
90- if ( process . platform === "win32" ) {
91- expect ( info . command . toLowerCase ( ) ) . toBe ( configured . toLowerCase ( ) )
92- } else {
93- expect ( info . command ) . toBe ( configured )
94- }
95- expect ( info . args ) . toEqual ( process . platform === "win32" ? [ ] : [ "-l" ] )
96- } finally {
97- yield * pty . remove ( info . id )
98- }
99- } ) ,
100- ) ,
101- } )
102- } ,
64+ const info = yield * createPty ( { title : "configured" } )
65+ if ( process . platform === "win32" ) {
66+ expect ( info . command . toLowerCase ( ) ) . toBe ( configured . toLowerCase ( ) )
67+ } else {
68+ expect ( info . command ) . toBe ( configured )
69+ }
70+ expect ( info . args ) . toEqual ( process . platform === "win32" ? [ ] : [ "-l" ] )
71+ } ) ,
72+ configured ? { config : { shell : Shell . name ( configured ) } } : undefined ,
10373 { timeout : 30000 } ,
10474 )
10575} )
0 commit comments