fix(webui): allow switching Default permissions back to Full Access (#6175)

* fix(webui): allow authenticated access mode switching

* refactor(webui): remove constant full access eligibility helpers

* refactor(webui): remove obsolete full access policy parameter

* docs(webui): remove redundant access switching paragraph

* refactor(webui): remove obsolete full access capability
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-12 15:39:33 +08:00
1 parent ae186cb18d
commit 73af08efab
14 files changed
+87 -204

No files matched your search

-2
View File
@@ -176,8 +176,6 @@ The access control in the composer controls the local capability level for the c
In Restricted mode, ordinary file and shell work stays inside the selected project. To preserve agent continuity, filesystem/search tools receive narrow, read-only access to built-in skills, custom skills in the agent workspace, and the exact agent `memory/history.jsonl` file. This does not grant access to neighboring memory or profile files, and it does not allow writes outside the selected project. These tool exceptions do not broaden the browser's file preview boundary.
Remote WebUI connections may reduce access for the current workspace and may select a different workspace by browsing folders or entering its server-side path. A remote project change must use Restricted mode; enabling Full Access remains limited to local and native clients.
## Composer
With voice transcription configured, the idle composer uses one button for voice input when empty and Send when text or attachments are present; speech is transcribed into the draft before sending.
@@ -2117,7 +2117,7 @@ async def test_remote_webui_scope_allows_access_reduction(
@pytest.mark.asyncio
async def test_remote_access_reduction_rejects_stale_in_flight_message_scope(
async def test_in_flight_message_without_scope_uses_latest_access_mode(
bus: MagicMock,
tmp_path,
monkeypatch,
@@ -2154,10 +2154,6 @@ async def test_remote_access_reduction_rejects_stale_in_flight_message_scope(
"chat_id": chat_id,
"content": "hello",
"webui": True,
"workspace_scope": {
"project_path": str(default_workspace),
"access_mode": "full",
},
},
)
)
@@ -2178,18 +2174,16 @@ async def test_remote_access_reduction_rejects_stale_in_flight_message_scope(
release_hydrate.set()
await message_task
assert sessions.read_session_file(f"websocket:{chat_id}") is None
saved = sessions.read_session_file(f"websocket:{chat_id}")
assert saved["metadata"]["workspace_scope"]["access_mode"] == "restricted"
assert channel.gateway.workspaces.scope_for_session_key(
f"websocket:{chat_id}"
).access_mode == "restricted"
payload = json.loads(message_conn.send.await_args.args[0])
assert payload["event"] == "error"
assert payload["detail"] == "workspace_scope_rejected"
bus.publish_inbound.assert_not_awaited()
bus.publish_inbound.assert_awaited_once()
@pytest.mark.asyncio
async def test_remote_webui_scope_rejects_full_access_for_custom_scope(
async def test_remote_webui_scope_allows_full_access_for_custom_scope(
bus: MagicMock,
tmp_path,
) -> None:
@@ -2220,11 +2214,11 @@ async def test_remote_webui_scope_rejects_full_access_for_custom_scope(
)
payload = json.loads(conn.send.await_args.args[0])
assert payload["event"] == "error"
assert payload["detail"] == "workspace_scope_rejected"
assert payload["reason"] == "full workspace access is unavailable for this connection"
assert payload["chat_id"] == "chat-remote"
assert sessions.read_session_file("websocket:chat-remote") is None
assert payload["event"] == "session_updated"
assert payload["workspace_scope"]["access_mode"] == "full"
assert channel.gateway.workspaces.scope_for_session_key(
"websocket:chat-remote"
).project_path == project.resolve()
@pytest.mark.asyncio
@@ -6621,15 +6615,12 @@ def test_handle_webui_thread_get_does_not_backfill_hidden_subagent_result(
]
@pytest.mark.parametrize("headers,allowed", [
(None, False),
([], False),
({}, False),
({"Host": "localhost:8765"}, True),
({"Host": "remote.example"}, False),
({"Host": "localhost:8765", "X-Forwarded-For": "203.0.113.8"}, False),
@pytest.mark.parametrize("headers", [
{"Host": "localhost:8765"},
{"Host": "remote.example"},
{"Host": "localhost:8765", "X-Forwarded-For": "203.0.113.8"},
])
async def test_full_access_requires_local_handshake(bus, tmp_path, headers, allowed):
async def test_webui_access_mode_can_toggle_back_to_full(bus, tmp_path, headers):
sessions = SessionManager(tmp_path / "sessions")
channel = WebSocketChannel(
{"enabled": True, "allowFrom": ["*"], "host": "127.0.0.1"},
@@ -6639,17 +6630,17 @@ async def test_full_access_requires_local_handshake(bus, tmp_path, headers, allo
)
conn = AsyncMock()
conn.remote_address = ("127.0.0.1", 50123)
conn.request = SimpleNamespace(headers=headers) if headers is not None else None
await channel._dispatch_envelope(conn, "client", {
"type": "set_workspace_scope",
"chat_id": "handshake-scope",
"workspace_scope": {"project_path": str(tmp_path), "access_mode": "full"},
})
result = json.loads(conn.send.await_args.args[0])
if allowed:
conn.request = SimpleNamespace(headers=headers)
for mode in ("full", "restricted", "full"):
conn.send.reset_mock()
await channel._dispatch_envelope(conn, "client", {
"type": "set_workspace_scope",
"chat_id": "handshake-scope",
"workspace_scope": {"project_path": str(tmp_path), "access_mode": mode},
})
result = json.loads(conn.send.await_args.args[0])
assert result["event"] == "session_updated"
assert result["workspace_scope"]["access_mode"] == "full"
else:
assert result["event"] == "error"
assert result["reason"] == "full workspace access is unavailable for this connection"
assert sessions.read_session_file("websocket:handshake-scope") is None
assert result["workspace_scope"]["access_mode"] == mode
assert channel.gateway.workspaces.scope_for_session_key(
"websocket:handshake-scope"
).access_mode == mode
@@ -2531,7 +2531,7 @@ async def test_webui_automation_result_is_authenticated_and_returns_only_selecte
@pytest.mark.asyncio
async def test_remote_new_chat_accepts_server_project_path_but_rejects_remote_full_access(
async def test_remote_new_chat_accepts_server_project_path_and_full_access(
bus: MagicMock, tmp_path: Path
) -> None:
project = tmp_path / "remote-project"
@@ -2585,18 +2585,15 @@ async def test_remote_new_chat_accepts_server_project_path_but_rejects_remote_fu
},
)
rejected = [
json.loads(call.args[0])
for call in connection.send.await_args_list
if json.loads(call.args[0]).get("event") == "error"
]
assert rejected == [
{
"event": "error",
"detail": "workspace_scope_rejected",
"reason": "full workspace access is unavailable for this connection",
}
]
attached = next(
json.loads(call.args[0]) for call in connection.send.await_args_list
if json.loads(call.args[0]).get("event") == "attached"
)
scope = channel.gateway.workspaces.scope_for_session_key(
f"websocket:{attached['chat_id']}"
)
assert scope.project_path == other_project.resolve()
assert scope.access_mode == "full"
@pytest.mark.asyncio
@@ -3656,18 +3653,17 @@ async def test_recovery_mutation_uses_authenticated_websocket_action(bus: MagicM
@pytest.mark.parametrize(
("connection", "headers", "can_use_full_access"),
("connection", "headers"),
[
(_REMOTE, {"Host": "nas.example", "X-Forwarded-For": "203.0.113.42"}, False),
(_LOCAL, {"Host": "nas.example", "X-Forwarded-For": "203.0.113.42"}, False),
(_LOCAL, {"Host": "127.0.0.1:8765"}, True),
(_REMOTE, {"Host": "nas.example", "X-Forwarded-For": "203.0.113.42"}),
(_LOCAL, {"Host": "nas.example", "X-Forwarded-For": "203.0.113.42"}),
(_LOCAL, {"Host": "127.0.0.1:8765"}),
],
)
def test_workspace_payload_separates_remote_project_selection_from_full_access(
def test_workspace_payload_allows_access_selection_for_local_and_remote_clients(
bus: MagicMock,
connection: _FakeConn,
headers: dict[str, str],
can_use_full_access: bool,
) -> None:
channel = _ch(bus)
token = channel.gateway.tokens.issue_api_token(300)
@@ -3681,7 +3677,6 @@ def test_workspace_payload_separates_remote_project_selection_from_full_access(
assert response.status_code == 200
controls = json.loads(response.body.decode())["controls"]
assert controls["can_change_project"] is True
assert controls["can_use_full_access"] is can_use_full_access
assert controls["can_browse_directories"] is True
assert controls["can_resolve_project"] is True
assert controls["can_manage_favorites"] is True
@@ -4178,11 +4173,11 @@ async def test_project_selection_remembers_resolved_path_without_changing_access
assert response.status_code == 200
assert response.json() == {"name": "project", "path": str(project)}
assert channel.gateway.workspaces.default_scope() == scope
payload = channel.gateway.workspaces.payload(can_change_project=True, can_use_full_access=False)
payload = channel.gateway.workspaces.payload(can_change_project=True)
assert payload["recent_projects"] == [{"name": "project", "path": str(project)}]
rejected = await _webui_mutate(channel, "workspace.resolve_project", {"path": str(tmp_path / "missing")}, connection=connection)
assert rejected.status_code == 400
assert channel.gateway.workspaces.payload(can_change_project=True, can_use_full_access=False)["recent_projects"] == payload["recent_projects"]
assert channel.gateway.workspaces.payload(can_change_project=True)["recent_projects"] == payload["recent_projects"]
@pytest.mark.asyncio
@@ -4196,7 +4191,7 @@ async def test_project_favorites_mutation_persists_without_selecting_project(
response = await _webui_mutate(channel, "workspace.favorite", {"path": str(project), "pinned": True}, connection=connection)
assert response.status_code == 200
assert response.json() == {"favorite_projects": [{"name": "pinned", "path": str(project)}]}
payload = channel.gateway.workspaces.payload(can_change_project=True, can_use_full_access=False)
payload = channel.gateway.workspaces.payload(can_change_project=True)
assert payload["favorite_projects"] == response.json()["favorite_projects"]
assert payload["recent_projects"] == []
assert payload["default_scope"]["project_path"] == str(tmp_path)
-6
View File
@@ -164,9 +164,6 @@ class WebUICommandRouter:
def workspace_project_selection_available(self, connection: ServerConnection) -> bool:
return self._http_router.workspace_project_selection_available(connection)
def workspace_full_access_available(self, connection: ServerConnection) -> bool:
return self._http_router.workspace_full_access_available(connection)
async def send_webui_protocol_error(
self,
connection: ServerConnection,
@@ -310,7 +307,6 @@ class WebUICommandRouter:
lambda: self._workspaces.scope_for_new_chat(
envelope,
can_change_project=self.workspace_project_selection_available(connection),
can_use_full_access=self.workspace_full_access_available(connection),
),
)
if scope is None:
@@ -451,7 +447,6 @@ class WebUICommandRouter:
chat_id=chat_id,
chat_running=websocket_turn_wall_started_at(chat_id) is not None,
can_change_project=self.workspace_project_selection_available(connection),
can_use_full_access=self.workspace_full_access_available(connection),
),
chat_id=chat_id,
)
@@ -630,7 +625,6 @@ class WebUICommandRouter:
chat_id=chat_id,
chat_running=websocket_turn_wall_started_at(chat_id) is not None,
can_change_project=self.workspace_project_selection_available(connection),
can_use_full_access=self.workspace_full_access_available(connection),
)
),
chat_id=chat_id,
-23
View File
@@ -175,7 +175,6 @@ def workspaces_payload(
default_workspace: Path,
default_restrict_to_workspace: bool,
can_change_project: bool,
can_use_full_access: bool,
) -> dict[str, Any]:
state = read_webui_workspace_state()
default_access_mode = state["default_access_mode"]
@@ -203,7 +202,6 @@ def workspaces_payload(
],
"controls": {
"can_change_project": can_change_project,
"can_use_full_access": can_use_full_access,
"can_browse_directories": can_change_project,
"can_resolve_project": can_change_project,
"can_manage_favorites": can_change_project,
@@ -302,13 +300,11 @@ class WebUIWorkspaceController:
self,
*,
can_change_project: bool,
can_use_full_access: bool,
) -> dict[str, Any]:
return workspaces_payload(
default_workspace=self._default_workspace,
default_restrict_to_workspace=self._default_restrict_to_workspace,
can_change_project=can_change_project,
can_use_full_access=can_use_full_access,
)
def resolve_project(self, path: object) -> dict[str, str]:
@@ -358,7 +354,6 @@ class WebUIWorkspaceController:
*,
session_key: str | None,
can_change_project: bool,
can_use_full_access: bool,
) -> WorkspaceScope:
current = self.scope_for_session_key(session_key) if session_key else self.default_scope()
raw = envelope.get(WORKSPACE_SCOPE_METADATA_KEY)
@@ -376,18 +371,6 @@ class WebUIWorkspaceController:
"project selection is unavailable for this connection",
status=403,
)
if (
not can_use_full_access
and scope.access_mode == "full"
and (
current.access_mode != "full"
or scope.project_path != current.project_path
)
):
raise WorkspaceScopeError(
"full workspace access is unavailable for this connection",
status=403,
)
return scope
def scope_for_new_chat(
@@ -395,13 +378,11 @@ class WebUIWorkspaceController:
envelope: dict[str, Any],
*,
can_change_project: bool,
can_use_full_access: bool,
) -> WorkspaceScope:
return self.scope_from_envelope(
envelope,
session_key=None,
can_change_project=can_change_project,
can_use_full_access=can_use_full_access,
)
def scope_for_set_request(
@@ -411,7 +392,6 @@ class WebUIWorkspaceController:
chat_id: str,
chat_running: bool,
can_change_project: bool,
can_use_full_access: bool,
) -> WorkspaceScope:
if chat_running:
raise WorkspaceScopeError("chat_running", status=409)
@@ -419,7 +399,6 @@ class WebUIWorkspaceController:
envelope,
session_key=webui_session_key(chat_id),
can_change_project=can_change_project,
can_use_full_access=can_use_full_access,
)
def scope_for_message(
@@ -429,13 +408,11 @@ class WebUIWorkspaceController:
chat_id: str,
chat_running: bool,
can_change_project: bool,
can_use_full_access: bool,
) -> WorkspaceScope:
scope = self.scope_from_envelope(
envelope,
session_key=webui_session_key(chat_id),
can_change_project=can_change_project,
can_use_full_access=can_use_full_access,
)
if (
WORKSPACE_SCOPE_METADATA_KEY in envelope
-24
View File
@@ -446,26 +446,6 @@ class GatewayHTTPHandler:
"""
return True
def workspace_full_access_available(
self,
connection: Any,
headers: Any | None = None,
) -> bool:
"""Return whether this request may opt into Full Access.
A reverse proxy can make a remote browser look like a localhost TCP
peer. Inspect the original browser headers before granting this
capability so proxy-local requests keep the remote restriction.
"""
if self._runtime_surface == "native":
return True
if headers is None:
request = getattr(connection, "request", None)
headers = getattr(request, "headers", None)
if not isinstance(headers, Mapping):
return False
return _is_local_browser_request(connection, headers)
# -- Token management ---------------------------------------------------
def check_api_token(self, request: WsRequest) -> bool:
@@ -1679,10 +1659,6 @@ class GatewayHTTPHandler:
return _http_json_response(
self.workspaces.payload(
can_change_project=self.workspace_project_selection_available(connection),
can_use_full_access=self.workspace_full_access_available(
connection,
request.headers,
),
)
)
+20 -59
View File
@@ -36,7 +36,6 @@ def test_workspace_payload_is_config_data_dir_scoped(tmp_path, monkeypatch) -> N
default_workspace=default,
default_restrict_to_workspace=False,
can_change_project=True,
can_use_full_access=True,
)
assert payload["default_scope"]["project_path"] == str(default.resolve())
@@ -45,26 +44,6 @@ def test_workspace_payload_is_config_data_dir_scoped(tmp_path, monkeypatch) -> N
assert payload["controls"]["can_change_project"] is True
def test_workspace_payload_allows_remote_project_selection_without_full_access(
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=False,
)
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
def test_workspace_payload_hides_project_selection_when_unavailable(
tmp_path,
monkeypatch,
@@ -77,11 +56,9 @@ def test_workspace_payload_hides_project_selection_when_unavailable(
default_workspace=default,
default_restrict_to_workspace=False,
can_change_project=False,
can_use_full_access=False,
)
assert payload["controls"]["can_change_project"] is False
assert payload["controls"]["can_use_full_access"] is False
def test_workspace_payload_uses_webui_default_access_mode(tmp_path, monkeypatch) -> None:
@@ -96,7 +73,6 @@ def test_workspace_payload_uses_webui_default_access_mode(tmp_path, monkeypatch)
default_workspace=default,
default_restrict_to_workspace=True,
can_change_project=True,
can_use_full_access=True,
)
assert payload["default_access_mode"] == "full"
@@ -128,7 +104,6 @@ def test_webui_default_access_applies_to_unscoped_old_sessions(tmp_path, monkeyp
new_scope = controller.scope_for_new_chat(
{},
can_change_project=True,
can_use_full_access=True,
)
assert scope.project_path == default.resolve()
@@ -311,7 +286,6 @@ def test_remote_existing_chat_can_reduce_its_workspace_access(tmp_path, monkeypa
chat_id="remote-chat",
chat_running=False,
can_change_project=True,
can_use_full_access=False,
)
assert scope.project_path == project.resolve()
@@ -319,21 +293,20 @@ def test_remote_existing_chat_can_reduce_its_workspace_access(tmp_path, monkeypa
@pytest.mark.parametrize(
("default_restricted", "project_name", "access_mode", "allowed"),
("default_restricted", "project_name", "access_mode"),
[
(False, "default", "restricted", True),
(True, "default", "full", False),
(False, "other", "restricted", True),
(False, "other", "full", False),
(False, "default", "restricted"),
(True, "default", "full"),
(False, "other", "restricted"),
(False, "other", "full"),
],
)
def test_remote_new_chat_allows_project_selection_only_in_restricted_mode(
def test_new_chat_allows_project_selection_in_either_access_mode(
tmp_path,
monkeypatch,
default_restricted: bool,
project_name: str,
access_mode: str,
allowed: bool,
) -> None:
monkeypatch.setattr("nanobot.webui.workspaces.get_webui_dir", lambda: tmp_path / "webui")
default = tmp_path / "default"
@@ -347,28 +320,17 @@ def test_remote_new_chat_allows_project_selection_only_in_restricted_mode(
)
requested_path = tmp_path / project_name
def resolve():
return controller.scope_for_new_chat(
{
"workspace_scope": {
"project_path": str(requested_path),
"access_mode": access_mode,
}
},
can_change_project=True,
can_use_full_access=False,
)
if allowed:
scope = resolve()
assert scope.project_path == requested_path.resolve()
assert scope.access_mode == access_mode
else:
with pytest.raises(
WorkspaceScopeError,
match="full workspace access is unavailable for this connection",
):
resolve()
scope = controller.scope_for_new_chat(
{
"workspace_scope": {
"project_path": str(requested_path),
"access_mode": access_mode,
}
},
can_change_project=True,
)
assert scope.project_path == requested_path.resolve()
assert scope.access_mode == access_mode
def test_project_selection_can_remain_disabled_for_untrusted_connections(
@@ -398,7 +360,6 @@ def test_project_selection_can_remain_disabled_for_untrusted_connections(
}
},
can_change_project=False,
can_use_full_access=False,
)
@@ -413,14 +374,14 @@ def test_recent_projects_survive_controller_restart_without_changing_access(tmp_
)
scope = controller.scope_for_new_chat(
{WORKSPACE_SCOPE_METADATA_KEY: {"project_path": str(project), "access_mode": "restricted"}},
can_change_project=True, can_use_full_access=False,
can_change_project=True,
)
controller.stage_scope("first", scope)
controller.stage_scope("second", scope)
restarted = WebUIWorkspaceController(
session_manager=None, default_workspace=default, default_restrict_to_workspace=True,
)
payload = restarted.payload(can_change_project=True, can_use_full_access=False)
payload = restarted.payload(can_change_project=True)
assert payload["recent_projects"] == [{"name": "project", "path": str(project)}]
assert payload["default_scope"]["project_path"] == str(default)
assert payload["default_scope"]["access_mode"] == "restricted"
@@ -442,7 +403,7 @@ def test_favorites_keep_pin_order_across_restart_and_can_remove_deleted_folder(t
restarted = WebUIWorkspaceController(
session_manager=None, default_workspace=default, default_restrict_to_workspace=True,
)
payload = restarted.payload(can_change_project=True, can_use_full_access=False)
payload = restarted.payload(can_change_project=True)
assert [item["path"] for item in payload["favorite_projects"]] == [str(beta), str(alpha)]
assert [item["path"] for item in payload["recent_projects"]] == [str(alpha)]
assert payload["default_scope"]["project_path"] == str(default)
@@ -2386,7 +2386,6 @@ export function ThreadComposer({
<WorkspaceAccessToggle
scope={workspaceScope}
disabled={interactionDisabled || workspaceScopeDisabled}
canUseFullAccess={workspaceControls?.can_use_full_access !== false}
isHero={isHero}
onChange={onWorkspaceScopeChange}
/>
@@ -421,11 +421,10 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
const trimmed = path.trim();
if (!base || !onChange) return;
if (!trimmed || !isAbsoluteWorkspacePath(trimmed)) { setPathError(t("workspace.dialog.absolutePathRequired")); return; }
const accessMode = controls?.can_use_full_access === false && !sameWorkspacePath(trimmed, base.project_path) ? "restricted" : base.access_mode;
onChange({ ...base, project_path: trimmed, project_name: name || projectNameFromPath(trimmed), access_mode: accessMode, restrict_to_workspace: accessMode === "restricted" });
onChange({ ...base, project_path: trimmed, project_name: name || projectNameFromPath(trimmed) });
setPathError(null);
setOpen(false);
}, [controls?.can_use_full_access, defaultScope, onChange, scope, t]);
}, [defaultScope, onChange, scope, t]);
const chooseProject = useCallback(async (path: string, name?: string) => {
const session = pickerSession.current;
@@ -683,13 +682,11 @@ export function WorkspaceProjectPicker({ isHero, disabled, scope, defaultScope,
export function WorkspaceAccessToggle({
scope,
disabled,
canUseFullAccess,
isHero,
onChange,
}: {
scope: WorkspaceScopePayload;
disabled?: boolean;
canUseFullAccess: boolean;
isHero: boolean;
onChange?: (scope: WorkspaceScopePayload) => void;
}) {
@@ -712,7 +709,7 @@ export function WorkspaceAccessToggle({
variant={null}
aria-label={accessAriaLabel}
aria-pressed={isFull}
disabled={disabled || !onChange || (!isFull && !canUseFullAccess)}
disabled={disabled || !onChange}
onClick={() => onChange?.(scopeWithAccessMode(scope, isFull ? "restricted" : "full"))}
className={cn(
"settings-hover thread-composer-access touch-target min-w-0 max-w-[min(12.5rem,42vw)] whitespace-nowrap rounded-control border border-transparent font-semibold shadow-none",
-1
View File
@@ -497,7 +497,6 @@ export interface WorkspacesPayload {
host?: { name: string; platform: string };
controls: {
can_change_project: boolean;
can_use_full_access: boolean;
can_browse_directories?: boolean;
can_resolve_project?: boolean;
can_manage_favorites?: boolean;
-1
View File
@@ -1218,7 +1218,6 @@ describe("webui API helpers", () => {
},
controls: {
can_change_project: true,
can_use_full_access: true,
},
};
vi.mocked(fetch).mockResolvedValueOnce({
+3 -3
View File
@@ -1077,7 +1077,7 @@ describe("App layout", () => {
schema_version: 1,
default_access_mode: "full",
default_scope: { ...projectScope, project_path: "/tmp/workspace", project_name: "workspace" },
controls: { can_change_project: true, can_use_full_access: true },
controls: { can_change_project: true },
},
});
window.history.replaceState(null, "", "/#/chat/websocket%3Aexisting-chat");
@@ -1108,7 +1108,7 @@ describe("App layout", () => {
access_mode: "full",
restrict_to_workspace: false,
},
controls: { can_change_project: true, can_use_full_access: true },
controls: { can_change_project: true },
},
});
render(<App />);
@@ -1162,7 +1162,7 @@ describe("App layout", () => {
access_mode: "restricted",
restrict_to_workspace: true,
},
controls: { can_change_project: true, can_use_full_access: true, can_browse_directories: true, can_resolve_project: true },
controls: { can_change_project: true, can_browse_directories: true, can_resolve_project: true },
},
[directoryUrl("C:\\workspace")]: directory("C:\\workspace"),
[directoryUrl("C:\\workspace\\")]: directory("C:\\workspace"),
+13 -16
View File
@@ -17,7 +17,7 @@ function workspacePickerProps(scope: WorkspaceScopePayload) {
default_scope: scope,
recent_projects: [],
favorite_projects: [],
controls: { can_change_project: true, can_use_full_access: true },
controls: { can_change_project: true },
}),
onBrowseWorkspaceDirectories: async (path: string) => ({
path: resolvePath(path), parent: null, entries: [], partial: false,
@@ -1415,10 +1415,10 @@ describe("ThreadComposer", () => {
project_path: "/tmp/project", project_name: "project",
access_mode: "restricted", restrict_to_workspace: true,
};
const composer = (workspaceScope: WorkspaceScopePayload, canUseFullAccess = true) => (
const composer = (workspaceScope: WorkspaceScopePayload) => (
<ThreadComposer onSend={vi.fn()} placeholder="Type your message..."
workspaceScope={workspaceScope}
workspaceControls={{ can_change_project: true, can_use_full_access: canUseFullAccess }}
workspaceControls={{ can_change_project: true }}
onWorkspaceScopeChange={onWorkspaceScopeChange} />
);
const { rerender } = render(composer(restricted));
@@ -1434,11 +1434,10 @@ describe("ThreadComposer", () => {
expect(access).toHaveFocus();
await user.keyboard("{Enter}");
expect(onWorkspaceScopeChange).toHaveBeenLastCalledWith(restricted);
rerender(composer(restricted, false));
expect(access).toBeDisabled();
onWorkspaceScopeChange.mockClear();
rerender(composer(restricted));
expect(access).toBeEnabled();
await user.click(access);
expect(onWorkspaceScopeChange).not.toHaveBeenCalled();
expect(onWorkspaceScopeChange).toHaveBeenLastCalledWith(full);
});
it("exposes full and compact workspace labels for container-driven compression", () => {
@@ -1453,7 +1452,7 @@ describe("ThreadComposer", () => {
access_mode: "full",
restrict_to_workspace: false,
}}
workspaceControls={{ can_change_project: true, can_use_full_access: true }}
workspaceControls={{ can_change_project: true }}
onWorkspaceScopeChange={vi.fn()}
/>,
);
@@ -1490,7 +1489,7 @@ describe("ThreadComposer", () => {
}}
workspaceDefaultScope={defaultScope}
{...workspacePickerProps(defaultScope)}
workspaceControls={{ can_change_project: true, can_use_full_access: true, can_browse_directories: true, can_resolve_project: true }}
workspaceControls={{ can_change_project: true, can_browse_directories: true, can_resolve_project: true }}
onWorkspaceScopeChange={onWorkspaceScopeChange}
/>,
);
@@ -1555,7 +1554,7 @@ describe("ThreadComposer", () => {
workspaceScope={defaultScope}
workspaceDefaultScope={defaultScope}
{...workspacePickerProps(defaultScope)}
workspaceControls={{ can_change_project: true, can_use_full_access: true }}
workspaceControls={{ can_change_project: true }}
onWorkspaceScopeChange={onWorkspaceScopeChange}
/>,
);
@@ -1584,7 +1583,7 @@ describe("ThreadComposer", () => {
workspaceScope={defaultScope}
workspaceDefaultScope={defaultScope}
{...workspacePickerProps(defaultScope)}
workspaceControls={{ can_change_project: true, can_use_full_access: true }}
workspaceControls={{ can_change_project: true }}
onWorkspaceScopeChange={vi.fn()}
/>
);
@@ -1663,7 +1662,6 @@ describe("ThreadComposer", () => {
{...workspacePickerProps(defaultScope)}
workspaceControls={{
can_change_project: true,
can_use_full_access: true,
can_browse_directories: true,
can_resolve_project: true,
}}
@@ -1689,7 +1687,7 @@ describe("ThreadComposer", () => {
}));
});
it("selects an entered host path in Restricted mode when Full Access is unavailable", async () => {
it("preserves Full Access when selecting an entered host path", async () => {
const user = userEvent.setup();
const onWorkspaceScopeChange = vi.fn();
const defaultScope = {
@@ -1708,7 +1706,6 @@ describe("ThreadComposer", () => {
{...workspacePickerProps(defaultScope)}
workspaceControls={{
can_change_project: true,
can_use_full_access: false,
}}
onWorkspaceScopeChange={onWorkspaceScopeChange}
/>,
@@ -1726,8 +1723,8 @@ describe("ThreadComposer", () => {
expect(onWorkspaceScopeChange).toHaveBeenCalledWith(expect.objectContaining({
project_path: "/srv/nas-project",
access_mode: "restricted",
restrict_to_workspace: true,
access_mode: "full",
restrict_to_workspace: false,
}));
});
+2 -2
View File
@@ -13,7 +13,7 @@ const catalog: WorkspacesPayload = {
default_scope: scope,
recent_projects: [{ name: "alpha", path: "/srv/alpha" }, { name: "beta", path: "/srv/beta" }],
host: { name: "dev-server", platform: "Linux" },
controls: { can_change_project: true, can_use_full_access: false, can_browse_directories: true },
controls: { can_change_project: true, can_browse_directories: true },
};
const directory: WorkspaceDirectoriesPayload = {
path: "/srv/workspace", parent: "/srv", entries: [{ name: "alpha", path: "/srv/workspace/alpha" }],
@@ -419,7 +419,7 @@ describe("Workspace project picker", () => {
const onChange = vi.fn();
const onBrowse = vi.fn();
const onResolve = vi.fn();
render(<WorkspaceProjectPicker isHero scope={scope} defaultScope={scope} controls={{ can_change_project: true, can_use_full_access: false }} onBrowseDirectories={onBrowse} onResolveProject={onResolve} onChange={onChange} />);
render(<WorkspaceProjectPicker isHero scope={scope} defaultScope={scope} controls={{ can_change_project: true }} onBrowseDirectories={onBrowse} onResolveProject={onResolve} onChange={onChange} />);
await user.click(screen.getByRole("button", { name: "Switch directory" }));
expect(screen.queryByRole("option", { name: "Browse folders…" })).not.toBeInTheDocument();
await user.type(screen.getByRole("combobox"), "relative-path");