1- import * as fs from "node:fs"
2- import * as os from "node:os"
3- import * as path from "node:path"
4-
1+ import * as FileSystem from "@effect/platform/FileSystem"
2+ import * as Path from "@effect/platform/Path"
53import { NodeContext } from "@effect/platform-node"
64import { describe , expect , it } from "@effect/vitest"
75import { Effect } from "effect"
86
97import type { TemplateConfig } from "../../src/core/domain.js"
108import { prepareProjectFiles } from "../../src/usecases/actions/prepare-files.js"
119
12- const withTempDir = < A , E , R > ( use : ( tempDir : string ) => Effect . Effect < A , E , R > ) : Effect . Effect < A , E , R > =>
10+ const withTempDir = < A , E , R > (
11+ use : ( tempDir : string ) => Effect . Effect < A , E , R >
12+ ) : Effect . Effect < A , E , R | FileSystem . FileSystem > =>
1313 Effect . scoped (
1414 Effect . gen ( function * ( _ ) {
15+ const fs = yield * _ ( FileSystem . FileSystem )
1516 const tempDir = yield * _ (
16- Effect . acquireRelease (
17- Effect . sync ( ( ) => fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "docker-git-force-env-" ) ) ) ,
18- ( dir ) => Effect . sync ( ( ) => fs . rmSync ( dir , { recursive : true , force : true } ) )
19- )
17+ fs . makeTempDirectoryScoped ( {
18+ prefix : "docker-git-force-env-"
19+ } )
2020 )
2121 return yield * _ ( use ( tempDir ) )
2222 } )
2323 )
2424
25- const makeGlobalConfig = ( root : string ) : TemplateConfig => ( {
25+ const makeGlobalConfig = ( root : string , path : Path . Path ) : TemplateConfig => ( {
2626 containerName : "dg-test" ,
2727 serviceName : "dg-test" ,
2828 sshUser : "dev" ,
@@ -41,7 +41,11 @@ const makeGlobalConfig = (root: string): TemplateConfig => ({
4141 pnpmVersion : "10.27.0"
4242} )
4343
44- const makeProjectConfig = ( outDir : string , enableMcpPlaywright : boolean ) : TemplateConfig => ( {
44+ const makeProjectConfig = (
45+ outDir : string ,
46+ enableMcpPlaywright : boolean ,
47+ path : Path . Path
48+ ) : TemplateConfig => ( {
4549 containerName : "dg-test" ,
4650 serviceName : "dg-test" ,
4751 sshUser : "dev" ,
@@ -60,14 +64,33 @@ const makeProjectConfig = (outDir: string, enableMcpPlaywright: boolean): Templa
6064 pnpmVersion : "10.27.0"
6165} )
6266
67+ const isRecord = ( value : unknown ) : value is Record < string , unknown > =>
68+ typeof value === "object" && value !== null
69+
70+ const readEnableMcpPlaywrightFlag = ( value : unknown ) : boolean | undefined => {
71+ if ( ! isRecord ( value ) ) {
72+ return undefined
73+ }
74+
75+ const template = value . template
76+ if ( ! isRecord ( template ) ) {
77+ return undefined
78+ }
79+
80+ const flag = template . enableMcpPlaywright
81+ return typeof flag === "boolean" ? flag : undefined
82+ }
83+
6384describe ( "prepareProjectFiles" , ( ) => {
6485 it . effect ( "force-env refresh rewrites managed templates" , ( ) =>
6586 withTempDir ( ( root ) =>
6687 Effect . gen ( function * ( _ ) {
88+ const fs = yield * _ ( FileSystem . FileSystem )
89+ const path = yield * _ ( Path . Path )
6790 const outDir = path . join ( root , "project" )
68- const globalConfig = makeGlobalConfig ( root )
69- const withoutMcp = makeProjectConfig ( outDir , false )
70- const withMcp = makeProjectConfig ( outDir , true )
91+ const globalConfig = makeGlobalConfig ( root , path )
92+ const withoutMcp = makeProjectConfig ( outDir , false , path )
93+ const withMcp = makeProjectConfig ( outDir , true , path )
7194
7295 yield * _ (
7396 prepareProjectFiles ( outDir , root , globalConfig , withoutMcp , {
@@ -76,9 +99,7 @@ describe("prepareProjectFiles", () => {
7699 } )
77100 )
78101
79- const composeBefore = yield * _ (
80- Effect . sync ( ( ) => fs . readFileSync ( path . join ( outDir , "docker-compose.yml" ) , "utf8" ) )
81- )
102+ const composeBefore = yield * _ ( fs . readFileString ( path . join ( outDir , "docker-compose.yml" ) ) )
82103 expect ( composeBefore ) . not . toContain ( "dg-test-browser" )
83104
84105 yield * _ (
@@ -88,16 +109,13 @@ describe("prepareProjectFiles", () => {
88109 } )
89110 )
90111
91- const composeAfter = yield * _ (
92- Effect . sync ( ( ) => fs . readFileSync ( path . join ( outDir , "docker-compose.yml" ) , "utf8" ) )
93- )
94- const configAfter = yield * _ (
95- Effect . sync ( ( ) => JSON . parse ( fs . readFileSync ( path . join ( outDir , "docker-git.json" ) , "utf8" ) ) )
96- )
112+ const composeAfter = yield * _ ( fs . readFileString ( path . join ( outDir , "docker-compose.yml" ) ) )
113+ const configAfterText = yield * _ ( fs . readFileString ( path . join ( outDir , "docker-git.json" ) ) )
114+ const configAfter = yield * _ ( Effect . sync ( ( ) : unknown => JSON . parse ( configAfterText ) ) )
97115
98116 expect ( composeAfter ) . toContain ( "dg-test-browser" )
99117 expect ( composeAfter ) . toContain ( 'MCP_PLAYWRIGHT_ENABLE: "1"' )
100- expect ( configAfter . template . enableMcpPlaywright ) . toBe ( true )
118+ expect ( readEnableMcpPlaywrightFlag ( configAfter ) ) . toBe ( true )
101119 } )
102120 ) . pipe ( Effect . provide ( NodeContext . layer ) ) )
103121} )
0 commit comments