Support {container} placeholder in WEBTERM_DOCKER_AUTO_COMMAND

Allows per-container customization of the auto command. For example:
  WEBTERM_DOCKER_AUTO_COMMAND='tmux new-session -ADs {container}'

This creates a tmux session named after the container instead of using
a fixed session name for all containers.
This commit is contained in:
GitHub Copilot
2026-01-31 10:14:39 +00:00
parent 7556539b6f
commit 9c5e3781c7
2 changed files with 35 additions and 1 deletions
+31
View File
@@ -241,6 +241,37 @@ class TestSessionManager:
assert isinstance(result, DockerExecSession)
assert result.exec_spec.user == "testuser"
@pytest.mark.asyncio
@pytest.mark.skipif(platform.system() == "Windows", reason="Terminal not supported on Windows")
async def test_new_docker_exec_session_container_placeholder(
self, mock_poller, mock_path, monkeypatch
):
"""Test that {container} placeholder in auto command is replaced with container name."""
from webterm.docker_exec_session import DockerExecSession
monkeypatch.setenv("WEBTERM_DOCKER_AUTO_COMMAND", "tmux new-session -ADs {container}")
app = App(
name="my-webapp",
slug="my-webapp",
path="./",
command=AUTO_COMMAND_SENTINEL,
terminal=True,
)
manager = SessionManager(mock_poller, mock_path, [app])
with patch.object(DockerExecSession, "open", new_callable=AsyncMock):
result = await manager.new_session(
"my-webapp",
SessionID("test-session"),
RouteKey("test-route"),
)
assert result is not None
assert isinstance(result, DockerExecSession)
# Verify the container name was substituted into the command
assert result.exec_spec.command == ["tmux", "new-session", "-ADs", "my-webapp"]
class TestSessionManagerRoutes:
"""Tests for SessionManager route handling."""