# retoor import pytest from devplacepy.services.jobs.isslop.acquisition.workspace import ( safe_relative_path, slugify, workspace_for, ) def test_workspace_for_stays_inside_root(tmp_path): workspace = workspace_for(tmp_path, "https://github.com/owner/repo", "abc123") assert workspace.parent == tmp_path.resolve() assert "github.com-owner-repo" in workspace.name assert workspace.name.endswith("abc123") def test_workspace_for_rejects_escaping_uid(tmp_path): with pytest.raises(ValueError): workspace_for(tmp_path, "https://example.com", "../../../outside/x") def test_safe_relative_path_rejects_traversal(tmp_path): resolved = safe_relative_path(tmp_path, "../../../etc/passwd") assert resolved.is_relative_to(tmp_path.resolve()) def test_safe_relative_path_keeps_nested_files(tmp_path): resolved = safe_relative_path(tmp_path, "assets/js/app.js") assert resolved == tmp_path.resolve() / "assets" / "js" / "app.js" def test_slugify_strips_scheme_and_specials(): assert slugify("https://Example.com/Owner/Repo.git") == "example.com-owner-repo.git" assert slugify("!!!") == "source"