fix: make sandboxed sessions usable for real git workflows
Address three integration gaps found in review: - Bind ~/.gitconfig read-only in the sandbox base layer so `git commit` finds user.name/email inside the jail (spec §3). - Bind a worktree session's repo common .git dir writable: the worktree's real gitdir lives at <repo>/.git/worktrees/<branch>, outside the bound cwd, so git was broken in sandboxed worktree sessions. - doctor now gates on sandbox.is_available() (the single source of truth shared with the New Session dialog) rather than a raw shutil.which, so it agrees with the service on non-Linux platforms (spec §6). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+37
-7
@@ -1547,10 +1547,15 @@ def sandbox_service(factory, db, tmux, sandbox_harness):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sandboxed_create_wraps_command(sandbox_service, db, tmux, sandbox_harness):
|
||||
with patch("hqt.sessions.service.sandbox.is_available", return_value=True), patch(
|
||||
"hqt.sessions.service.sandbox.wrap", return_value=["bwrap", "--", "claude"]
|
||||
) as mock_wrap:
|
||||
async def test_sandboxed_create_wraps_command(
|
||||
sandbox_service, db, tmux, sandbox_harness
|
||||
):
|
||||
with (
|
||||
patch("hqt.sessions.service.sandbox.is_available", return_value=True),
|
||||
patch(
|
||||
"hqt.sessions.service.sandbox.wrap", return_value=["bwrap", "--", "claude"]
|
||||
) as mock_wrap,
|
||||
):
|
||||
result = await sandbox_service.create_session(
|
||||
project_id=1,
|
||||
harness_name="claude-code",
|
||||
@@ -1558,9 +1563,10 @@ async def test_sandboxed_create_wraps_command(sandbox_service, db, tmux, sandbox
|
||||
)
|
||||
mock_wrap.assert_called_once()
|
||||
sandbox_harness["claude-code"].build_spawn_config.assert_called_once()
|
||||
assert sandbox_harness["claude-code"].build_spawn_config.call_args.kwargs[
|
||||
"sandboxed"
|
||||
] is True
|
||||
assert (
|
||||
sandbox_harness["claude-code"].build_spawn_config.call_args.kwargs["sandboxed"]
|
||||
is True
|
||||
)
|
||||
assert tmux.spawn.call_args.args[0].command == ["bwrap", "--", "claude"]
|
||||
assert result.session.sandbox_json == '{"fs": "rw", "net": true}'
|
||||
|
||||
@@ -1582,3 +1588,27 @@ async def test_sandboxed_create_raises_when_bwrap_missing(sandbox_service, db):
|
||||
harness_name="claude-code",
|
||||
sandbox=SandboxPolicy(fs="rw", net=True),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sandboxed_worktree_binds_repo_git_dir(
|
||||
sandbox_service, db, tmux, sandbox_harness, fake_worktree
|
||||
):
|
||||
"""A sandboxed worktree session binds the repo's common .git writable so
|
||||
git works inside the jail (the worktree's gitdir lives under <repo>/.git)."""
|
||||
from hqt.sandbox import Bind
|
||||
|
||||
with (
|
||||
patch("hqt.sessions.service.sandbox.is_available", return_value=True),
|
||||
patch(
|
||||
"hqt.sessions.service.sandbox.wrap", return_value=["bwrap", "--", "claude"]
|
||||
) as mock_wrap,
|
||||
):
|
||||
await sandbox_service.create_session(
|
||||
project_id=1,
|
||||
harness_name="claude-code",
|
||||
worktree_branch="feature-x",
|
||||
sandbox=SandboxPolicy(fs="rw", net=True),
|
||||
)
|
||||
binds = mock_wrap.call_args.args[3]
|
||||
assert Bind(Path("/tmp/myproj/.git"), writable=True) in binds
|
||||
|
||||
Reference in New Issue
Block a user