Skip to content

Commit 4464bee

Browse files
committed
fix(browser): restore Rust lifecycle guarantees
1 parent 835bbb5 commit 4464bee

7 files changed

Lines changed: 53 additions & 3 deletions

File tree

packages/app/src/lib/core/templates-entrypoint/tasks.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,5 +315,27 @@ export const renderEntrypointRustBrowserConnection = (): string =>
315315
" echo \"[browser] Rust browser connection is ready via $browser_bin on $network_mode\"",
316316
"}",
317317
"",
318+
"docker_git_stop_playwright_browser() {",
319+
" if [[ \"${MCP_PLAYWRIGHT_ENABLE:-0}\" != \"1\" ]]; then",
320+
" return 0",
321+
" fi",
322+
"",
323+
" local browser_bin=\"\"",
324+
" local candidate",
325+
" for candidate in /usr/local/bin/docker-git-browser-connection /root/.cargo/bin/docker-git-browser-connection /usr/local/cargo/bin/docker-git-browser-connection $(command -v docker-git-browser-connection 2>/dev/null || true); do",
326+
" if [[ -x \"$candidate\" ]]; then",
327+
" browser_bin=\"$candidate\"",
328+
" break",
329+
" fi",
330+
" done",
331+
"",
332+
" if [[ -z \"$browser_bin\" ]]; then",
333+
" return 0",
334+
" fi",
335+
"",
336+
" local project_container=\"${DOCKER_GIT_PROJECT_CONTAINER_NAME:-$(hostname)}\"",
337+
" \"$browser_bin\" stop --project \"$project_container\" >> /var/log/docker-git-browser.log 2>&1 || true",
338+
"}",
339+
"",
318340
"docker_git_start_rust_browser_connection"
319341
].join("\n")

packages/app/src/lib/core/templates/dockerfile-prelude.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ RUN set -eu; \
7575
7676
# Install unified Rust browser connection (noVNC + CDP + single dg-*-browser guarantee)
7777
# Replaces all previous TS/MCP browser-connection duplication (per issue #347)
78-
RUN cargo install --git https://github.com/ProverCoderAI/rust-browser-connection --rev c36f263ebc5d0acdf155113914f08cafefa69c56 --locked --bins --root /usr/local \
78+
RUN cargo install --git https://github.com/ProverCoderAI/rust-browser-connection --rev b69fa095da54a97c440738abd56e3abf3344ab70 --locked --bins --root /usr/local \
7979
&& /usr/local/bin/docker-git-browser-connection --version \
8080
&& /usr/local/bin/browser-connection --version
8181

packages/app/tests/docker-git/core-templates.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ describe("app planFiles", () => {
6767
expect(dockerfile.contents).toContain("/usr/local/bin/browser-connection --version")
6868
expect(dockerfile.contents).not.toContain("docker-git-playwright-mcp")
6969
expect(entrypoint.contents).toContain("docker_git_start_rust_browser_connection")
70+
expect(entrypoint.contents).toContain("docker_git_stop_playwright_browser()")
7071
expect(entrypoint.contents).toContain("docker-git-browser-connection")
7172
expect(entrypoint.contents).toContain("local network_mode=\"container:${project_container}\"")
73+
expect(entrypoint.contents).toContain("stop --project \"$project_container\"")
7274
})
7375
})

packages/lib/src/core/templates-entrypoint/tasks.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,5 +315,27 @@ export const renderEntrypointRustBrowserConnection = (): string =>
315315
" echo \"[browser] Rust browser connection is ready via $browser_bin on $network_mode\"",
316316
"}",
317317
"",
318+
"docker_git_stop_playwright_browser() {",
319+
" if [[ \"${MCP_PLAYWRIGHT_ENABLE:-0}\" != \"1\" ]]; then",
320+
" return 0",
321+
" fi",
322+
"",
323+
" local browser_bin=\"\"",
324+
" local candidate",
325+
" for candidate in /usr/local/bin/docker-git-browser-connection /root/.cargo/bin/docker-git-browser-connection /usr/local/cargo/bin/docker-git-browser-connection $(command -v docker-git-browser-connection 2>/dev/null || true); do",
326+
" if [[ -x \"$candidate\" ]]; then",
327+
" browser_bin=\"$candidate\"",
328+
" break",
329+
" fi",
330+
" done",
331+
"",
332+
" if [[ -z \"$browser_bin\" ]]; then",
333+
" return 0",
334+
" fi",
335+
"",
336+
" local project_container=\"${DOCKER_GIT_PROJECT_CONTAINER_NAME:-$(hostname)}\"",
337+
" \"$browser_bin\" stop --project \"$project_container\" >> /var/log/docker-git-browser.log 2>&1 || true",
338+
"}",
339+
"",
318340
"docker_git_start_rust_browser_connection"
319341
].join("\n")

packages/lib/src/core/templates/dockerfile-prelude.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ RUN set -eu; \
7575
7676
# Install unified Rust browser connection (noVNC + CDP + single dg-*-browser guarantee)
7777
# Replaces all previous TS/MCP browser-connection duplication (per issue #347)
78-
RUN cargo install --git https://github.com/ProverCoderAI/rust-browser-connection --rev c36f263ebc5d0acdf155113914f08cafefa69c56 --locked --bins --root /usr/local \
78+
RUN cargo install --git https://github.com/ProverCoderAI/rust-browser-connection --rev b69fa095da54a97c440738abd56e3abf3344ab70 --locked --bins --root /usr/local \
7979
&& /usr/local/bin/docker-git-browser-connection --version \
8080
&& /usr/local/bin/browser-connection --version
8181

packages/lib/tests/core/templates.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ describe("renderDockerfile", () => {
234234
const dockerfile = renderDockerfile(makeTemplateConfig({ enableMcpPlaywright: true }))
235235

236236
expectContainsAll(dockerfile, [
237-
"cargo install --git https://github.com/ProverCoderAI/rust-browser-connection --rev c36f263ebc5d0acdf155113914f08cafefa69c56 --locked --bins --root /usr/local",
237+
"cargo install --git https://github.com/ProverCoderAI/rust-browser-connection --rev b69fa095da54a97c440738abd56e3abf3344ab70 --locked --bins --root /usr/local",
238238
"/usr/local/bin/docker-git-browser-connection --version",
239239
"/usr/local/bin/browser-connection --version",
240240
"# Unified Rust browser (dg-*-browser) is started by docker-git-browser-connection binary"
@@ -764,8 +764,10 @@ describe("renderDockerCompose", () => {
764764
expect(dockerfile?.contents).not.toContain("docker-git-playwright-mcp")
765765
expect(dockerfile?.contents).not.toContain("COPY Dockerfile.browser")
766766
expect(entrypoint?.contents).toContain("docker_git_start_rust_browser_connection")
767+
expect(entrypoint?.contents).toContain("docker_git_stop_playwright_browser()")
767768
expect(entrypoint?.contents).toContain("docker-git-browser-connection")
768769
expect(entrypoint?.contents).toContain('local network_mode="container:${project_container}"')
770+
expect(entrypoint?.contents).toContain('stop --project "$project_container"')
769771
})
770772
it("renders Rust browser startup before MCP client config", () => {
771773
const entrypoint = renderEntrypoint(makeTemplateConfig({ enableMcpPlaywright: true }))

packages/lib/tests/usecases/mcp-playwright.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ describe("enableMcpPlaywrightProjectFiles", () => {
136136

137137
const entrypointAfter = yield* _(fs.readFileString(path.join(outDir, "entrypoint.sh")))
138138
expect(entrypointAfter).toContain("docker_git_start_rust_browser_connection")
139+
expect(entrypointAfter).toContain("docker_git_stop_playwright_browser()")
139140
expect(entrypointAfter).toContain("docker-git-browser-connection")
141+
expect(entrypointAfter).toContain('stop --project "$project_container"')
140142
expect(entrypointAfter).toContain('command = "browser-connection"')
141143
expect(entrypointAfter).toContain('args = ["--project", "$DOCKER_GIT_BROWSER_PROJECT", "--network", "$DOCKER_GIT_BROWSER_NETWORK"]')
142144

0 commit comments

Comments
 (0)