refactor(webui): remove obsolete native workspace picker paths
This commit is contained in:
1 parent
024d181013
commit
8a795b428e
32 files changed
+186
-593
No files matched your search
@@ -5,7 +5,7 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from nanobot.webui import native_folder_picker as picker
|
||||
from nanobot.webui import native_file_picker as picker
|
||||
|
||||
|
||||
def _picker_command(tmp_path: Path, body: str) -> picker._PickerCommand:
|
||||
@@ -15,23 +15,9 @@ def _picker_command(tmp_path: Path, body: str) -> picker._PickerCommand:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pick_native_folder_returns_selected_directory(tmp_path, monkeypatch) -> None:
|
||||
async def test_pick_native_file_uses_secret_free_environment(tmp_path, monkeypatch) -> None:
|
||||
selected = tmp_path / "project"
|
||||
selected.mkdir()
|
||||
command = _picker_command(tmp_path, f"print({str(selected)!r}, end='')")
|
||||
monkeypatch.setattr(
|
||||
picker,
|
||||
"_picker_command",
|
||||
lambda: command,
|
||||
)
|
||||
|
||||
assert await picker.pick_native_folder() == str(selected)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pick_native_folder_uses_secret_free_environment(tmp_path, monkeypatch) -> None:
|
||||
selected = tmp_path / "project"
|
||||
selected.mkdir()
|
||||
selected.write_text("ssh-key")
|
||||
command = _picker_command(tmp_path, f"print({str(selected)!r}, end='')")
|
||||
monkeypatch.setattr(picker, "_picker_command", lambda: command)
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
@@ -45,7 +31,7 @@ async def test_pick_native_folder_uses_secret_free_environment(tmp_path, monkeyp
|
||||
|
||||
monkeypatch.setattr(picker.asyncio, "create_subprocess_exec", capture_spawn)
|
||||
|
||||
assert await picker.pick_native_folder() == str(selected)
|
||||
assert await picker.pick_native_file() == str(selected)
|
||||
assert captured_env["HOME"] == str(tmp_path)
|
||||
assert "OPENAI_API_KEY" not in captured_env
|
||||
|
||||
@@ -64,42 +50,15 @@ def test_picker_environment_preserves_linux_display_context(monkeypatch) -> None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pick_native_folder_maps_dialog_cancel_to_none(tmp_path, monkeypatch) -> None:
|
||||
command = _picker_command(tmp_path, "raise SystemExit(1)")
|
||||
monkeypatch.setattr(
|
||||
picker,
|
||||
"_picker_command",
|
||||
lambda: command,
|
||||
)
|
||||
|
||||
assert await picker.pick_native_folder() is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pick_native_folder_rejects_non_directory_result(tmp_path, monkeypatch) -> None:
|
||||
missing = tmp_path / "missing"
|
||||
command = _picker_command(tmp_path, f"print({str(missing)!r}, end='')")
|
||||
monkeypatch.setattr(
|
||||
picker,
|
||||
"_picker_command",
|
||||
lambda: command,
|
||||
)
|
||||
|
||||
with pytest.raises(picker.NativeFolderPickerError, match="invalid directory"):
|
||||
await picker.pick_native_folder()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pick_native_folder_reports_unavailable(monkeypatch) -> None:
|
||||
async def test_pick_native_file_reports_unavailable(monkeypatch) -> None:
|
||||
monkeypatch.setattr(picker, "_picker_command", lambda: None)
|
||||
|
||||
assert picker.native_folder_picker_available() is False
|
||||
with pytest.raises(picker.NativeFolderPickerError, match="unavailable"):
|
||||
await picker.pick_native_folder()
|
||||
with pytest.raises(picker.NativeFilePickerError, match="unavailable"):
|
||||
await picker.pick_native_file()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pick_native_folder_wraps_process_start_failure(tmp_path, monkeypatch) -> None:
|
||||
async def test_pick_native_file_wraps_process_start_failure(tmp_path, monkeypatch) -> None:
|
||||
command = _picker_command(tmp_path, "raise AssertionError('not started')")
|
||||
monkeypatch.setattr(picker, "_picker_command", lambda: command)
|
||||
|
||||
@@ -108,8 +67,8 @@ async def test_pick_native_folder_wraps_process_start_failure(tmp_path, monkeypa
|
||||
|
||||
monkeypatch.setattr(picker.asyncio, "create_subprocess_exec", fail_spawn)
|
||||
|
||||
with pytest.raises(picker.NativeFolderPickerError, match="failed to start"):
|
||||
await picker.pick_native_folder()
|
||||
with pytest.raises(picker.NativeFilePickerError, match="failed to start"):
|
||||
await picker.pick_native_file()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("result", ["file", "directory", "cancel"])
|
||||
@@ -118,9 +77,9 @@ async def test_pick_native_file_returns_only_existing_file_path(tmp_path, monkey
|
||||
selected.write_text("must-not-be-read-or-returned")
|
||||
output = str(selected if result == "file" else tmp_path)
|
||||
command = _picker_command(tmp_path, "raise SystemExit(1)" if result == "cancel" else f"print({output!r})")
|
||||
monkeypatch.setattr(picker, "_picker_command", lambda kind: command)
|
||||
monkeypatch.setattr(picker, "_picker_command", lambda: command)
|
||||
if result == "directory":
|
||||
with pytest.raises(picker.NativeFolderPickerError, match="invalid file"):
|
||||
with pytest.raises(picker.NativeFilePickerError, match="invalid file"):
|
||||
await picker.pick_native_file()
|
||||
else:
|
||||
assert await picker.pick_native_file() == (str(selected) if result == "file" else None)
|
||||
@@ -133,7 +92,7 @@ def test_file_picker_uses_platform_file_dialog(monkeypatch, platform, marker):
|
||||
monkeypatch.setattr(picker.sys, "platform", platform)
|
||||
monkeypatch.setattr(picker.shutil, "which", lambda executable: executable)
|
||||
monkeypatch.setenv("DISPLAY", ":test")
|
||||
command = picker._picker_command("file")
|
||||
command = picker._picker_command()
|
||||
assert command is not None
|
||||
assert marker in " ".join(command.argv)
|
||||
assert "--directory" not in command.argv
|
||||
@@ -143,7 +102,7 @@ def test_file_picker_is_unavailable_on_headless_linux(monkeypatch):
|
||||
monkeypatch.setattr(picker.sys, "platform", "linux")
|
||||
monkeypatch.delenv("DISPLAY", raising=False)
|
||||
monkeypatch.delenv("WAYLAND_DISPLAY", raising=False)
|
||||
assert picker._picker_command("file") is None
|
||||
assert picker._picker_command() is None
|
||||
|
||||
|
||||
async def test_file_picker_cancellation_reaps_process(monkeypatch):
|
||||
@@ -153,7 +112,7 @@ async def test_file_picker_cancellation_reaps_process(monkeypatch):
|
||||
process = MagicMock(returncode=None)
|
||||
process.communicate = AsyncMock(side_effect=asyncio.CancelledError)
|
||||
process.wait = AsyncMock(return_value=0)
|
||||
monkeypatch.setattr(picker, "_picker_command", lambda kind: picker._PickerCommand(("picker",), frozenset()))
|
||||
monkeypatch.setattr(picker, "_picker_command", lambda: picker._PickerCommand(("picker",), frozenset()))
|
||||
monkeypatch.setattr(asyncio, "create_subprocess_exec", AsyncMock(return_value=process))
|
||||
with pytest.raises(asyncio.CancelledError):
|
||||
await picker.pick_native_file()
|
||||
@@ -43,7 +43,6 @@ def test_workspace_payload_is_config_data_dir_scoped(tmp_path, monkeypatch) -> N
|
||||
assert payload["default_scope"]["access_mode"] == "full"
|
||||
assert payload["default_access_mode"] == "default"
|
||||
assert payload["controls"]["can_change_project"] is True
|
||||
assert payload["controls"]["can_pick_folder"] is False
|
||||
|
||||
|
||||
def test_workspace_payload_allows_remote_project_selection_without_full_access(
|
||||
@@ -64,7 +63,6 @@ def test_workspace_payload_allows_remote_project_selection_without_full_access(
|
||||
assert payload["default_scope"]["project_path"] == str(default.resolve())
|
||||
assert payload["controls"]["can_change_project"] is True
|
||||
assert payload["controls"]["can_use_full_access"] is False
|
||||
assert payload["controls"]["can_pick_folder"] is False
|
||||
|
||||
|
||||
def test_workspace_payload_hides_project_selection_when_unavailable(
|
||||
@@ -86,22 +84,6 @@ def test_workspace_payload_hides_project_selection_when_unavailable(
|
||||
assert payload["controls"]["can_use_full_access"] is False
|
||||
|
||||
|
||||
def test_workspace_payload_advertises_native_folder_picker(tmp_path, monkeypatch) -> None:
|
||||
monkeypatch.setattr("nanobot.webui.workspaces.get_webui_dir", lambda: tmp_path / "webui")
|
||||
default = tmp_path / "default"
|
||||
default.mkdir()
|
||||
|
||||
payload = workspaces_payload(
|
||||
default_workspace=default,
|
||||
default_restrict_to_workspace=False,
|
||||
can_change_project=True,
|
||||
can_use_full_access=True,
|
||||
folder_picker_available=True,
|
||||
)
|
||||
|
||||
assert payload["controls"]["can_pick_folder"] is True
|
||||
|
||||
|
||||
def test_workspace_payload_uses_webui_default_access_mode(tmp_path, monkeypatch) -> None:
|
||||
monkeypatch.setattr("nanobot.webui.workspaces.get_webui_dir", lambda: tmp_path / "webui")
|
||||
default = tmp_path / "default"
|
||||
@@ -442,7 +424,7 @@ def test_recent_projects_survive_controller_restart_without_changing_access(tmp_
|
||||
assert payload["recent_projects"] == [{"name": "project", "path": str(project)}]
|
||||
assert payload["default_scope"]["project_path"] == str(default)
|
||||
assert payload["default_scope"]["access_mode"] == "restricted"
|
||||
assert payload["controls"]["can_browse_directories"] is True
|
||||
assert payload["controls"]["can_change_project"] is True
|
||||
|
||||
|
||||
def test_favorites_keep_pin_order_across_restart_and_can_remove_deleted_folder(tmp_path, monkeypatch) -> None:
|
||||
|
||||
Reference in new issue
Block a user