@@ -171,115 +171,107 @@ describe("tool.write", () => {
171171 } )
172172
173173 describe ( "file permissions" , ( ) => {
174- it . live ( "sets file permissions when writing sensitive data" , ( ) =>
175- provideTmpdirInstance ( ( dir ) =>
176- Effect . gen ( function * ( ) {
177- const filepath = path . join ( dir , "sensitive.json" )
178- yield * run ( { filePath : filepath , content : JSON . stringify ( { secret : "data" } ) } )
174+ it . instance ( "sets file permissions when writing sensitive data" , ( ) =>
175+ Effect . gen ( function * ( ) {
176+ const test = yield * TestInstance
177+ const filepath = path . join ( test . directory , "sensitive.json" )
178+ yield * run ( { filePath : filepath , content : JSON . stringify ( { secret : "data" } ) } )
179179
180- if ( process . platform !== "win32" ) {
181- const stats = yield * Effect . promise ( ( ) => fs . stat ( filepath ) )
182- expect ( stats . mode & 0o777 ) . toBe ( 0o644 )
183- }
184- } ) ,
185- ) ,
180+ if ( process . platform !== "win32" ) {
181+ const stats = yield * Effect . promise ( ( ) => fs . stat ( filepath ) )
182+ expect ( stats . mode & 0o777 ) . toBe ( 0o644 )
183+ }
184+ } ) ,
186185 )
187186 } )
188187
189188 describe ( "content types" , ( ) => {
190- it . live ( "writes JSON content" , ( ) =>
191- provideTmpdirInstance ( ( dir ) =>
192- Effect . gen ( function * ( ) {
193- const filepath = path . join ( dir , "data.json" )
194- const data = { key : "value" , nested : { array : [ 1 , 2 , 3 ] } }
195- yield * run ( { filePath : filepath , content : JSON . stringify ( data , null , 2 ) } )
189+ it . instance ( "writes JSON content" , ( ) =>
190+ Effect . gen ( function * ( ) {
191+ const test = yield * TestInstance
192+ const filepath = path . join ( test . directory , "data.json" )
193+ const data = { key : "value" , nested : { array : [ 1 , 2 , 3 ] } }
194+ yield * run ( { filePath : filepath , content : JSON . stringify ( data , null , 2 ) } )
196195
197- const content = yield * Effect . promise ( ( ) => fs . readFile ( filepath , "utf-8" ) )
198- expect ( JSON . parse ( content ) ) . toEqual ( data )
199- } ) ,
200- ) ,
196+ const content = yield * Effect . promise ( ( ) => fs . readFile ( filepath , "utf-8" ) )
197+ expect ( JSON . parse ( content ) ) . toEqual ( data )
198+ } ) ,
201199 )
202200
203- it . live ( "writes binary-safe content" , ( ) =>
204- provideTmpdirInstance ( ( dir ) =>
205- Effect . gen ( function * ( ) {
206- const filepath = path . join ( dir , "binary.bin" )
207- const content = "Hello\x00World\x01\x02\x03"
208- yield * run ( { filePath : filepath , content } )
201+ it . instance ( "writes binary-safe content" , ( ) =>
202+ Effect . gen ( function * ( ) {
203+ const test = yield * TestInstance
204+ const filepath = path . join ( test . directory , "binary.bin" )
205+ const content = "Hello\x00World\x01\x02\x03"
206+ yield * run ( { filePath : filepath , content } )
209207
210- const buf = yield * Effect . promise ( ( ) => fs . readFile ( filepath ) )
211- expect ( buf . toString ( ) ) . toBe ( content )
212- } ) ,
213- ) ,
208+ const buf = yield * Effect . promise ( ( ) => fs . readFile ( filepath ) )
209+ expect ( buf . toString ( ) ) . toBe ( content )
210+ } ) ,
214211 )
215212
216- it . live ( "writes empty content" , ( ) =>
217- provideTmpdirInstance ( ( dir ) =>
218- Effect . gen ( function * ( ) {
219- const filepath = path . join ( dir , "empty.txt" )
220- yield * run ( { filePath : filepath , content : "" } )
213+ it . instance ( "writes empty content" , ( ) =>
214+ Effect . gen ( function * ( ) {
215+ const test = yield * TestInstance
216+ const filepath = path . join ( test . directory , "empty.txt" )
217+ yield * run ( { filePath : filepath , content : "" } )
221218
222- const content = yield * Effect . promise ( ( ) => fs . readFile ( filepath , "utf-8" ) )
223- expect ( content ) . toBe ( "" )
219+ const content = yield * Effect . promise ( ( ) => fs . readFile ( filepath , "utf-8" ) )
220+ expect ( content ) . toBe ( "" )
224221
225- const stats = yield * Effect . promise ( ( ) => fs . stat ( filepath ) )
226- expect ( stats . size ) . toBe ( 0 )
227- } ) ,
228- ) ,
222+ const stats = yield * Effect . promise ( ( ) => fs . stat ( filepath ) )
223+ expect ( stats . size ) . toBe ( 0 )
224+ } ) ,
229225 )
230226
231- it . live ( "writes multi-line content" , ( ) =>
232- provideTmpdirInstance ( ( dir ) =>
233- Effect . gen ( function * ( ) {
234- const filepath = path . join ( dir , "multiline.txt" )
235- const lines = [ "Line 1" , "Line 2" , "Line 3" , "" ] . join ( "\n" )
236- yield * run ( { filePath : filepath , content : lines } )
227+ it . instance ( "writes multi-line content" , ( ) =>
228+ Effect . gen ( function * ( ) {
229+ const test = yield * TestInstance
230+ const filepath = path . join ( test . directory , "multiline.txt" )
231+ const lines = [ "Line 1" , "Line 2" , "Line 3" , "" ] . join ( "\n" )
232+ yield * run ( { filePath : filepath , content : lines } )
237233
238- const content = yield * Effect . promise ( ( ) => fs . readFile ( filepath , "utf-8" ) )
239- expect ( content ) . toBe ( lines )
240- } ) ,
241- ) ,
234+ const content = yield * Effect . promise ( ( ) => fs . readFile ( filepath , "utf-8" ) )
235+ expect ( content ) . toBe ( lines )
236+ } ) ,
242237 )
243238
244- it . live ( "handles different line endings" , ( ) =>
245- provideTmpdirInstance ( ( dir ) =>
246- Effect . gen ( function * ( ) {
247- const filepath = path . join ( dir , "crlf.txt" )
248- const content = "Line 1\r\nLine 2\r\nLine 3"
249- yield * run ( { filePath : filepath , content } )
239+ it . instance ( "handles different line endings" , ( ) =>
240+ Effect . gen ( function * ( ) {
241+ const test = yield * TestInstance
242+ const filepath = path . join ( test . directory , "crlf.txt" )
243+ const content = "Line 1\r\nLine 2\r\nLine 3"
244+ yield * run ( { filePath : filepath , content } )
250245
251- const buf = yield * Effect . promise ( ( ) => fs . readFile ( filepath ) )
252- expect ( buf . toString ( ) ) . toBe ( content )
253- } ) ,
254- ) ,
246+ const buf = yield * Effect . promise ( ( ) => fs . readFile ( filepath ) )
247+ expect ( buf . toString ( ) ) . toBe ( content )
248+ } ) ,
255249 )
256250 } )
257251
258252 describe ( "error handling" , ( ) => {
259- it . live ( "throws error when OS denies write access" , ( ) =>
260- provideTmpdirInstance ( ( dir ) =>
261- Effect . gen ( function * ( ) {
262- const readonlyPath = path . join ( dir , "readonly.txt" )
263- yield * Effect . promise ( ( ) => fs . writeFile ( readonlyPath , "test" , "utf-8" ) )
264- yield * Effect . promise ( ( ) => fs . chmod ( readonlyPath , 0o444 ) )
265- const exit = yield * run ( { filePath : readonlyPath , content : "new content" } ) . pipe ( Effect . exit )
266- expect ( exit . _tag ) . toBe ( "Failure" )
267- } ) ,
268- ) ,
253+ it . instance ( "throws error when OS denies write access" , ( ) =>
254+ Effect . gen ( function * ( ) {
255+ const test = yield * TestInstance
256+ const readonlyPath = path . join ( test . directory , "readonly.txt" )
257+ yield * Effect . promise ( ( ) => fs . writeFile ( readonlyPath , "test" , "utf-8" ) )
258+ yield * Effect . promise ( ( ) => fs . chmod ( readonlyPath , 0o444 ) )
259+ const exit = yield * run ( { filePath : readonlyPath , content : "new content" } ) . pipe ( Effect . exit )
260+ expect ( exit . _tag ) . toBe ( "Failure" )
261+ } ) ,
269262 )
270263 } )
271264
272265 describe ( "title generation" , ( ) => {
273- it . live ( "returns relative path as title" , ( ) =>
274- provideTmpdirInstance ( ( dir ) =>
275- Effect . gen ( function * ( ) {
276- const filepath = path . join ( dir , "src" , "components" , "Button.tsx" )
277- yield * Effect . promise ( ( ) => fs . mkdir ( path . dirname ( filepath ) , { recursive : true } ) )
266+ it . instance ( "returns relative path as title" , ( ) =>
267+ Effect . gen ( function * ( ) {
268+ const test = yield * TestInstance
269+ const filepath = path . join ( test . directory , "src" , "components" , "Button.tsx" )
270+ yield * Effect . promise ( ( ) => fs . mkdir ( path . dirname ( filepath ) , { recursive : true } ) )
278271
279- const result = yield * run ( { filePath : filepath , content : "export const Button = () => {}" } )
280- expect ( result . title ) . toEndWith ( path . join ( "src" , "components" , "Button.tsx" ) )
281- } ) ,
282- ) ,
272+ const result = yield * run ( { filePath : filepath , content : "export const Button = () => {}" } )
273+ expect ( result . title ) . toEndWith ( path . join ( "src" , "components" , "Button.tsx" ) )
274+ } ) ,
283275 )
284276 } )
285277} )
0 commit comments