From a641ef9dc5dc9646621a596c1baf220bfd8238da Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 26 Nov 2026 23:55:14 -0400 Subject: [PATCH 1/2] fix: keep sanitized project paths inside the workspace A path component made only of forbidden characters, spaces or periods sanitized to an empty string. As the first component that made the local path absolute, so cloud push failed with ValueError. Name such components "_" and skip empty components between separators. Co-Authored-By: Claude Sonnet 5.5 --- lean/components/util/project_manager.py | 7 ++++++- tests/components/util/test_project_manager.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lean/components/util/project_manager.py b/lean/components/util/project_manager.py index 73156b41..812e64f3 100644 --- a/lean/components/util/project_manager.py +++ b/lean/components/util/project_manager.py @@ -459,6 +459,10 @@ def _format_local_path(self, cloud_path: str) -> str: new_components = [] for component in cloud_path.split("/"): + # Leading, trailing and repeated separators don't name a directory + if not component: + continue + # Some names are reserved for reserved_name in reserved_names: # If the component is a reserved name, we add an underscore to it so it can be used @@ -471,7 +475,8 @@ def _format_local_path(self, cloud_path: str) -> str: # Components cannot end with a period component = component.rstrip(".") - new_components.append(component) + # An empty component would be dropped from the path or make it absolute, outside the workspace + new_components.append(component or "_") cloud_path = "/".join(new_components) diff --git a/tests/components/util/test_project_manager.py b/tests/components/util/test_project_manager.py index d59b5391..73c7b2c4 100644 --- a/tests/components/util/test_project_manager.py +++ b/tests/components/util/test_project_manager.py @@ -721,3 +721,18 @@ def test_get_cloud_projects_libraries_filters_libraries_that_cannot_be_accessed( assert _lists_are_equal(libraries, own_project_libraries) assert _lists_are_equal(libraries_not_found, collab_libraries) + + +@pytest.mark.parametrize("cloud_name,expected_name", [(":/Strategy", "_/Strategy"), + ("Folder/ /Strategy", "Folder/_/Strategy"), + ("../Strategy", "_/Strategy"), + ("::", "_"), + ("/Strategy", "Strategy"), + ("Folder/Strategy/", "Folder/Strategy")]) +def test_get_local_project_path_stays_inside_workspace_when_a_component_sanitizes_to_nothing(cloud_name: str, + expected_name: str) -> None: + project_manager = _create_project_manager() + + local_path = project_manager.get_local_project_path(cloud_name, cloud_id=1) + + assert local_path == Path.cwd() / expected_name From e381c365ff9d318ea5cdb29eeb7583af5f9806c9 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 29 Nov 2026 08:52:37 -0400 Subject: [PATCH 2/2] fix: keep empty cloud project paths inside the workspace --- lean/components/util/project_manager.py | 6 ++---- tests/components/util/test_project_manager.py | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lean/components/util/project_manager.py b/lean/components/util/project_manager.py index 812e64f3..75f3cb88 100644 --- a/lean/components/util/project_manager.py +++ b/lean/components/util/project_manager.py @@ -442,7 +442,7 @@ def _format_local_path(self, cloud_path: str) -> str: """Converts the given cloud path into a local path which is valid for the current operating system. :param cloud_path: the path of the project in the cloud - :return: the converted cloud_path so that it is valid locally + :return: a valid relative local path, or "_" if the cloud path names no components """ # Remove forbidden characters and OS-specific path separator that are not path separators on QuantConnect # Windows, \":*?"<>| are forbidden @@ -478,9 +478,7 @@ def _format_local_path(self, cloud_path: str) -> str: # An empty component would be dropped from the path or make it absolute, outside the workspace new_components.append(component or "_") - cloud_path = "/".join(new_components) - - return cloud_path + return "/".join(new_components) or "_" def _generate_python_library_projects_config(self) -> None: diff --git a/tests/components/util/test_project_manager.py b/tests/components/util/test_project_manager.py index 73c7b2c4..c8d7a48a 100644 --- a/tests/components/util/test_project_manager.py +++ b/tests/components/util/test_project_manager.py @@ -728,7 +728,9 @@ def test_get_cloud_projects_libraries_filters_libraries_that_cannot_be_accessed( ("../Strategy", "_/Strategy"), ("::", "_"), ("/Strategy", "Strategy"), - ("Folder/Strategy/", "Folder/Strategy")]) + ("Folder/Strategy/", "Folder/Strategy"), + ("", "_"), + ("///", "_")]) def test_get_local_project_path_stays_inside_workspace_when_a_component_sanitizes_to_nothing(cloud_name: str, expected_name: str) -> None: project_manager = _create_project_manager()