"""Schema-level path validation (P2).""" import pytest from pydantic import ValidationError from server.api.schemas import ( FileDecompress, FileOperation, ServerCreate, ServerUpdate, SyncFiles, SyncBrowse, ) def test_server_create_target_path_normalizes(): m = ServerCreate( name="s1", domain="1.2.3.4", target_path="/www/wwwroot/foo/", ) assert m.target_path == "/www/wwwroot/foo" def test_server_create_rejects_backslash(): with pytest.raises(ValidationError): ServerCreate(name="s1", domain="1.2.3.4", target_path=r"\www\site") def test_server_update_optional_target_path(): m = ServerUpdate(target_path=None) assert m.target_path is None def test_sync_browse_root(): m = SyncBrowse(server_id=1, path="/") assert m.path == "/" def test_sync_files_source_nexus_path(): m = SyncFiles( server_ids=[1], source_path="/tmp/nexus_upload_abc", target_path="/www/wwwroot/site", ) assert m.source_path == "/tmp/nexus_upload_abc" assert m.target_path == "/www/wwwroot/site" def test_file_operation_paths(): m = FileOperation( server_id=1, operation="mkdir", path="/www/wwwroot/newdir", ) assert m.path == "/www/wwwroot/newdir" def test_file_decompress_rejects_dot_dest(): with pytest.raises(ValidationError): FileDecompress(server_id=1, path="/tmp/a.tar.gz", dest=".")