11import { describe , expect , it } from "@effect/vitest"
22
3- import {
4- defaultTemplateConfig ,
5- planFiles ,
6- renderDockerfile ,
7- type TemplateConfig
8- } from "../../test-adapters/core-templates.js"
3+ import { defaultTemplateConfig , planFiles , type TemplateConfig } from "../../test-adapters/core-templates.js"
94
105const makeTemplateConfig = ( overrides : Partial < TemplateConfig > = { } ) : TemplateConfig => ( {
116 ...defaultTemplateConfig ,
@@ -30,28 +25,45 @@ const makeTemplateConfig = (overrides: Partial<TemplateConfig> = {}): TemplateCo
3025 ...overrides
3126} )
3227
28+ type PlannedFile = ReturnType < typeof planFiles > [ number ]
29+ type GeneratedFile = Extract < PlannedFile , { readonly _tag : "File" } >
30+
31+ const getGeneratedFile = ( files : ReadonlyArray < PlannedFile > , relativePath : string ) : GeneratedFile => {
32+ const file = files . find (
33+ ( candidate ) : candidate is GeneratedFile => candidate . _tag === "File" && candidate . relativePath === relativePath
34+ )
35+ if ( file === undefined ) {
36+ throw new Error ( `Missing generated file: ${ relativePath } ` )
37+ }
38+ return file
39+ }
40+
41+ const getGeneratedFilePaths = ( files : ReadonlyArray < PlannedFile > ) : ReadonlyArray < string > =>
42+ files . flatMap ( ( file ) => file . _tag === "File" ? [ file . relativePath ] : [ ] )
43+
3344describe ( "app planFiles" , ( ) => {
3445 it ( "includes nested browser runtime artifacts when Playwright is enabled" , ( ) => {
3546 const files = planFiles ( makeTemplateConfig ( { enableMcpPlaywright : true } ) )
36- const filePaths = files . flatMap ( ( file ) => file . _tag === "File" ? [ file . relativePath ] : [ ] )
37- const runtime = files . find (
38- ( file ) : file is Extract < ( typeof files ) [ number ] , { readonly _tag : "File" } > =>
39- file . _tag === "File" && file . relativePath === "docker-git-browser-runtime.sh"
40- )
41- const dockerfile = renderDockerfile ( makeTemplateConfig ( { enableMcpPlaywright : true } ) )
47+ const filePaths = getGeneratedFilePaths ( files )
48+ const runtime = getGeneratedFile ( files , "docker-git-browser-runtime.sh" )
49+ const dockerfile = getGeneratedFile ( files , "Dockerfile" )
4250
4351 expect ( filePaths ) . toContain ( "Dockerfile.browser" )
4452 expect ( filePaths ) . toContain ( "mcp-playwright-start-extra.sh" )
4553 expect ( filePaths ) . toContain ( "docker-git-browser-runtime.sh" )
46- expect ( runtime ) . toBeDefined ( )
47- expect ( runtime ?. mode ) . toBe ( 0o755 )
48- expect ( runtime ?. contents ) . toContain ( "if [[ \"${MCP_PLAYWRIGHT_ENABLE:-0}\" != \"1\" ]]; then" )
49- expect ( runtime ?. contents ) . toContain ( "docker_git_wait_for_playwright_cdp()" )
50- expect ( runtime ?. contents ) . toContain ( "MCP_PLAYWRIGHT_ENABLE=0" )
51- expect ( runtime ?. contents ) . not . toContain ( "\\${MCP_PLAYWRIGHT_ENABLE:-0}" )
52- expect ( dockerfile ) . toContain (
54+ expect ( runtime . mode ) . toBe ( 0o755 )
55+ expect ( runtime . contents ) . toContain ( "if [[ \"${MCP_PLAYWRIGHT_ENABLE:-0}\" != \"1\" ]]; then" )
56+ expect ( runtime . contents ) . toContain ( "docker_git_wait_for_playwright_cdp()" )
57+ expect ( runtime . contents ) . toContain ( "MCP_PLAYWRIGHT_ENABLE=0" )
58+ expect ( runtime . contents ) . not . toContain ( "\\${MCP_PLAYWRIGHT_ENABLE:-0}" )
59+ expect ( dockerfile . contents ) . toContain (
5360 "COPY Dockerfile.browser mcp-playwright-start-extra.sh docker-git-browser-runtime.sh /opt/docker-git/browser/"
5461 )
55- expect ( dockerfile ) . toContain ( "MCP_PLAYWRIGHT_CDP_TIMEOUT=\"${MCP_PLAYWRIGHT_CDP_TIMEOUT:-60000}\"" )
62+ expect ( dockerfile . contents ) . toContain ( "ARG PLAYWRIGHT_MCP_VERSION=0.0.75" )
63+ expect ( dockerfile . contents ) . toContain ( "RUN npm install -g \"@playwright/mcp@${PLAYWRIGHT_MCP_VERSION}\"" )
64+ expect ( dockerfile . contents ) . toContain ( "MCP_PLAYWRIGHT_CDP_TIMEOUT=\"${MCP_PLAYWRIGHT_CDP_TIMEOUT:-60000}\"" )
65+ expect ( runtime . contents ) . toContain ( "invalid MCP_PLAYWRIGHT_READY_ATTEMPTS" )
66+ expect ( runtime . contents ) . toContain ( "while (( attempt <= attempts )); do" )
67+ expect ( runtime . contents ) . not . toContain ( "for attempt in $(seq 1 \"$attempts\")" )
5668 } )
5769} )
0 commit comments