diff --git a/src/hqt/tui/screens/new_session.py b/src/hqt/tui/screens/new_session.py index 2b43fd6..3ff3070 100644 --- a/src/hqt/tui/screens/new_session.py +++ b/src/hqt/tui/screens/new_session.py @@ -63,15 +63,20 @@ class NewSessionScreen( "bubblewrap not found — run `hqt doctor`", id="sandbox-warning", ) - yield Label("Filesystem access:") - yield Select( - [("Read-write", "rw"), ("Read-only", "ro")], - id="fs-select", - value="rw", - allow_blank=False, - ) - yield Label("Network:") - yield Switch(id="net-switch", value=True) + # Sub-options of the sandbox switch: only meaningful when sandboxing + # is on, so hidden until then (mirrors the worktree -> branch reveal). + sandbox_options = Vertical(id="sandbox-options") + sandbox_options.display = False + with sandbox_options: + yield Label("Filesystem access:") + yield Select( + [("Read-write", "rw"), ("Read-only", "ro")], + id="fs-select", + value="rw", + allow_blank=False, + ) + yield Label("Network:") + yield Switch(id="net-switch", value=True) with Horizontal(classes="dialog-actions"): yield Button("OK", variant="primary", id="ok-btn") yield Button("Cancel", id="cancel-btn") @@ -89,6 +94,11 @@ class NewSessionScreen( else: branch_input.display = False + def on_switch_changed(self, event: Switch.Changed) -> None: + if event.switch.id != "sandbox-switch": + return + self.query_one("#sandbox-options", Vertical).display = event.value + def on_button_pressed(self, event: Button.Pressed) -> None: if event.button.id == "ok-btn": self._submit() diff --git a/tests/test_tui.py b/tests/test_tui.py index 77b2111..f3582fb 100644 --- a/tests/test_tui.py +++ b/tests/test_tui.py @@ -1869,3 +1869,29 @@ async def test_poll_sessions_dispatches_due_prompts_and_notifies(): mock_service.dispatch_due_prompts.assert_awaited_once() assert any("Prompt sent" in call[0] for call in notify_calls) + + +@pytest.mark.asyncio +async def test_sandbox_options_hidden_until_switch_on(): + """The fs/net rows are sub-options of the sandbox switch: hidden until it is + turned on, shown when on, hidden again when turned back off.""" + app = HqtApp() + async with app.run_test(size=(120, 40)) as pilot: + from hqt.tui.screens.new_session import NewSessionScreen + from textual.widgets import Switch + + app.push_screen( + NewSessionScreen(["claude"], is_git_repo=True, sandbox_available=True) + ) + await pilot.pause() + options = app.screen.query_one("#sandbox-options") + assert options.display is False + + switch = app.screen.query_one("#sandbox-switch", Switch) + switch.value = True + await pilot.pause() + assert options.display is True + + switch.value = False + await pilot.pause() + assert options.display is False