"""A workspace path that merely starts with the workspace path still resolves. `_remote_path` spells a local workspace path in the remote root, and its docstring promises anything else passes through. `str.startswith` accepted a sibling directory (`-sibling/file.txt`), then `relative_to` raised ValueError, so a remote command crashed instead of passing the path through. e2e drives remote commands with real sessions and never names a sibling of the workspace, so the prefix/subpath mismatch stays invisible there. """ from __future__ import annotations import sys import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(ROOT / "python")) from albedo_plugins.remote import RemoteConnection, _remote_path # noqa: E402 class RemotePathTest(unittest.TestCase): def test_a_workspace_file_maps_into_the_remote_root(self) -> None: under = Path.cwd() / "notes" / "todo.md" self.assertEqual( _remote_path(RemoteConnection({"remote_cwd": "/remote/root"}), str(under)), "/remote/root/notes/todo.md", ) def test_a_sibling_of_the_workspace_passes_through(self) -> None: sibling = str(Path.cwd()) + "-sibling/file.txt" self.assertEqual( _remote_path(RemoteConnection({"remote_cwd": "/remote/root"}), sibling), sibling, ) def test_an_unrelated_path_passes_through(self) -> None: self.assertEqual( _remote_path( RemoteConnection({"remote_cwd": "/remote/root"}), "/etc/hostname" ), "/etc/hostname", ) if __name__ == "__main__": unittest.main()