"""Tests for workspace manager.""" import pytest from ai_orchestrator.workspace import ( WorkspacePathError, get_workspace_path, sanitize_workspace_key, ) class TestSanitizeWorkspaceKey: """Tests for workspace key sanitization.""" def test_simple_identifier(self): assert sanitize_workspace_key("ABC-123") == "ABC-123" def test_special_characters_replaced(self): assert sanitize_workspace_key("ABC/123") == "ABC_123" assert sanitize_workspace_key("my project!") == "my_project_" def test_dots_and_underscores_preserved(self): assert sanitize_workspace_key("v1.0_release") == "v1.0_release" def test_unicode_replaced(self): assert sanitize_workspace_key("café-123") == "caf_-123" class TestGetWorkspacePath: """Tests for workspace path computation.""" def test_deterministic_path(self, tmp_path): root = str(tmp_path) path1 = get_workspace_path(root, "ABC-123") path2 = get_workspace_path(root, "ABC-123") assert path1 == path2 def test_path_inside_root(self, tmp_path): root = str(tmp_path) path = get_workspace_path(root, "ABC-123") assert str(path).startswith(str(tmp_path)) def test_path_traversal_blocked(self, tmp_path): # The sanitizer replaces .. with __ so this is safe root = str(tmp_path) path = get_workspace_path(root, "../escape") # Should be sanitized to __escape and stay inside root assert str(path).startswith(str(tmp_path))