@@ -46,21 +46,43 @@ describe("app planFiles", () => {
4646 const files = planFiles ( makeTemplateConfig ( { enableMcpPlaywright : true } ) )
4747 const filePaths = getGeneratedFilePaths ( files )
4848 const runtime = getGeneratedFile ( files , "docker-git-browser-runtime.sh" )
49+ const cdpGuard = getGeneratedFile ( files , "docker-git-cdp-guard" )
50+ const browserDockerfile = getGeneratedFile ( files , "Dockerfile.browser" )
51+ const startExtra = getGeneratedFile ( files , "mcp-playwright-start-extra.sh" )
4952 const dockerfile = getGeneratedFile ( files , "Dockerfile" )
5053
5154 expect ( filePaths ) . toContain ( "Dockerfile.browser" )
55+ expect ( filePaths ) . toContain ( "docker-git-cdp-guard" )
5256 expect ( filePaths ) . toContain ( "mcp-playwright-start-extra.sh" )
5357 expect ( filePaths ) . toContain ( "docker-git-browser-runtime.sh" )
58+ expect ( cdpGuard . mode ) . toBe ( 0o755 )
59+ expect ( cdpGuard . contents ) . toContain ( "#!/usr/bin/env node" )
60+ expect ( cdpGuard . contents ) . toContain ( "const upstreamHost = \"127.0.0.1\";" )
61+ expect ( cdpGuard . contents ) . toContain ( "const upstreamPort = 9222;" )
62+ expect ( cdpGuard . contents ) . toContain ( "const listenHost = \"0.0.0.0\";" )
63+ expect ( cdpGuard . contents ) . toContain ( "const listenPort = 9223;" )
64+ expect ( cdpGuard . contents ) . not . toContain ( "MCP_PLAYWRIGHT_UPSTREAM_CDP_HOST" )
65+ expect ( cdpGuard . contents ) . not . toContain ( "MCP_PLAYWRIGHT_CDP_GUARD_PORT" )
66+ expect ( cdpGuard . contents ) . toContain ( "Browser.close" )
67+ expect ( browserDockerfile . contents ) . toContain ( "COPY docker-git-cdp-guard /usr/local/bin/docker-git-cdp-guard" )
68+ expect ( browserDockerfile . contents ) . not . toContain ( "RUN cat <<'EOF' > /usr/local/bin/docker-git-cdp-guard" )
69+ expect ( startExtra . contents ) . toContain ( "guard_pid=\"$!\"" )
70+ expect ( startExtra . contents ) . toContain ( "falling back to socat" )
71+ expect ( startExtra . contents ) . toContain ( "socat TCP-LISTEN:9223,fork,reuseaddr TCP:127.0.0.1:9222" )
5472 expect ( runtime . mode ) . toBe ( 0o755 )
5573 expect ( runtime . contents ) . toContain ( "if [[ \"${MCP_PLAYWRIGHT_ENABLE:-0}\" != \"1\" ]]; then" )
74+ expect ( runtime . contents ) . toContain ( String . raw `printf '%s\n' "http://127.0.0.1:9223"` )
75+ expect ( runtime . contents ) . not . toContain ( "printf '%s\\n' \"${MCP_PLAYWRIGHT_CDP_ENDPOINT:-http://127.0.0.1:9223}\"" )
5676 expect ( runtime . contents ) . toContain ( "docker_git_wait_for_playwright_cdp()" )
5777 expect ( runtime . contents ) . toContain ( "MCP_PLAYWRIGHT_ENABLE=0" )
5878 expect ( runtime . contents ) . not . toContain ( "\\${MCP_PLAYWRIGHT_ENABLE:-0}" )
5979 expect ( dockerfile . contents ) . toContain (
60- "COPY Dockerfile.browser mcp-playwright-start-extra.sh docker-git-browser-runtime.sh /opt/docker-git/browser/"
80+ "COPY Dockerfile.browser docker-git-cdp-guard mcp-playwright-start-extra.sh docker-git-browser-runtime.sh /opt/docker-git/browser/"
6181 )
6282 expect ( dockerfile . contents ) . toContain ( "ARG PLAYWRIGHT_MCP_VERSION=0.0.75" )
6383 expect ( dockerfile . contents ) . toContain ( "RUN npm install -g \"@playwright/mcp@${PLAYWRIGHT_MCP_VERSION}\"" )
84+ expect ( dockerfile . contents ) . toContain ( "CDP_ENDPOINT=\"http://127.0.0.1:9223\"" )
85+ expect ( dockerfile . contents ) . not . toContain ( "CDP_ENDPOINT=\"${MCP_PLAYWRIGHT_CDP_ENDPOINT:-}\"" )
6486 expect ( dockerfile . contents ) . toContain ( "MCP_PLAYWRIGHT_CDP_TIMEOUT=\"${MCP_PLAYWRIGHT_CDP_TIMEOUT:-60000}\"" )
6587 expect ( runtime . contents ) . toContain ( "invalid MCP_PLAYWRIGHT_READY_ATTEMPTS" )
6688 expect ( runtime . contents ) . toContain ( "while (( attempt <= attempts )); do" )
0 commit comments