| |
| """ |
| Verification script for Directory Structure Mirroring with Smart Placeholders Task |
| """ |
|
|
| import sys |
| from pathlib import Path |
| import os |
|
|
| def get_test_directory() -> Path: |
| """Get the test directory from FILESYSTEM_TEST_DIR env var.""" |
| test_root = os.environ.get("FILESYSTEM_TEST_DIR") |
| if not test_root: |
| raise ValueError("FILESYSTEM_TEST_DIR environment variable is required") |
| return Path(test_root) |
|
|
| def verify_mirror_directory_exists(test_dir: Path, mirror_path: Path) -> bool: |
| """Verify that a mirror directory exists.""" |
| if not mirror_path.exists(): |
| print(f"β Mirror directory not found: {mirror_path.relative_to(test_dir)}") |
| return False |
| |
| if not mirror_path.is_dir(): |
| print(f"β Mirror path exists but is not a directory: {mirror_path.relative_to(test_dir)}") |
| return False |
| |
| print(f"β
Mirror directory exists: {mirror_path.relative_to(test_dir)}") |
| return True |
|
|
| def verify_placeholder_file_exists(mirror_path: Path, test_dir: Path) -> bool: |
| """Verify that placeholder.txt exists in the mirror directory.""" |
| placeholder_file = mirror_path / "placeholder.txt" |
| |
| if not placeholder_file.exists(): |
| print(f"β placeholder.txt not found in: {mirror_path.relative_to(test_dir)}") |
| return False |
| |
| if not placeholder_file.is_file(): |
| print(f"β placeholder.txt exists but is not a file in: {mirror_path.relative_to(test_dir)}") |
| return False |
| |
| print(f"β
placeholder.txt exists in: {mirror_path.relative_to(test_dir)}") |
| return True |
|
|
| def verify_placeholder_content(mirror_path: Path, test_dir: Path) -> bool: |
| """Verify that placeholder.txt contains the correct path ending with complex_structure_mirror/...""" |
| placeholder_file = mirror_path / "placeholder.txt" |
| |
| try: |
| content = placeholder_file.read_text().strip() |
| |
| |
| if not content: |
| print(f"β placeholder.txt is empty in: {mirror_path.relative_to(test_dir)}") |
| return False |
| |
| |
| expected_ending = f"complex_structure_mirror/{mirror_path.relative_to(test_dir / 'complex_structure_mirror')}" |
| if not content.endswith(expected_ending): |
| print(f"β placeholder.txt content incorrect in: {mirror_path.relative_to(test_dir)}") |
| print(f" Expected ending: {expected_ending}") |
| print(f" Found: {content}") |
| return False |
| |
| print(f"β
placeholder.txt content is correct in: {mirror_path.relative_to(test_dir)}") |
| return True |
| |
| except Exception as e: |
| print(f"β Error reading placeholder.txt in {mirror_path.relative_to(test_dir)}: {e}") |
| return False |
|
|
| def verify_no_files_copied(test_dir: Path) -> bool: |
| """Verify that no file contents were copied, only directory structure.""" |
| source_dir = test_dir / "complex_structure" |
| mirror_dir = test_dir / "complex_structure_mirror" |
| |
| if not mirror_dir.exists(): |
| print("β Mirror directory 'complex_structure_mirror' not found") |
| return False |
| |
| |
| for source_file in source_dir.rglob("*"): |
| if source_file.is_file(): |
| |
| relative_path = source_file.relative_to(source_dir) |
| mirror_file = mirror_dir / relative_path |
| |
| |
| if mirror_file.name == "placeholder.txt": |
| continue |
| |
| if mirror_file.exists(): |
| print(f"β File was copied when it shouldn't be: {relative_path}") |
| return False |
| |
| print("β
No file contents were copied, only directory structure") |
| return True |
|
|
| def verify_mirror_structure_completeness(test_dir: Path) -> bool: |
| """Verify that the mirror structure is complete and matches expected structure.""" |
| mirror_dir = test_dir / "complex_structure_mirror" |
| |
| if not mirror_dir.exists(): |
| print("β Mirror directory 'complex_structure_mirror' not found") |
| return False |
| |
| |
| expected_dirs = [ |
| "deeply", |
| "deeply/nested", |
| "deeply/nested/folder", |
| "deeply/nested/folder/structure", |
| "empty_folder", |
| "folder_lxkHt_0_1_processed", |
| "folder_QdTAj_0_2_processed", |
| "folder_xtgyi_0_0_processed", |
| "mixed_content", |
| "mixed_content/images_and_text", |
| "project", |
| "project/docs", |
| "project/docs/archive", |
| "project/docs/archive/2023_processed", |
| "project/src", |
| "project/src/main", |
| "project/src/main/resources" |
| ] |
| |
| |
| placeholder_dirs = [ |
| "deeply/nested/folder/structure", |
| "empty_folder", |
| "folder_lxkHt_0_1_processed", |
| "folder_QdTAj_0_2_processed", |
| "folder_xtgyi_0_0_processed", |
| "mixed_content/images_and_text", |
| "project/docs/archive/2023_processed", |
| "project/src/main/resources" |
| ] |
| |
| all_passed = True |
| |
| |
| for expected_dir in expected_dirs: |
| mirror_path = mirror_dir / expected_dir |
| if not verify_mirror_directory_exists(test_dir, mirror_path): |
| all_passed = False |
| elif expected_dir in placeholder_dirs: |
| |
| if not verify_placeholder_file_exists(mirror_path, test_dir): |
| all_passed = False |
| elif not verify_placeholder_content(mirror_path, test_dir): |
| all_passed = False |
| |
| |
| for mirror_subdir in mirror_dir.rglob("*"): |
| if mirror_subdir.is_dir(): |
| relative_path = mirror_subdir.relative_to(mirror_dir) |
| if str(relative_path) not in expected_dirs and str(relative_path) != ".": |
| print(f"β Unexpected directory found: {relative_path}") |
| all_passed = False |
| |
| return all_passed |
|
|
| def main(): |
| """Main verification function.""" |
| try: |
| test_dir = get_test_directory() |
| print(f"π Verifying Directory Structure Mirroring with Smart Placeholders in: {test_dir}") |
| |
| |
| verification_steps = [ |
| ("No files copied", verify_no_files_copied), |
| ("Mirror structure completeness", verify_mirror_structure_completeness), |
| ] |
| |
| |
| all_passed = True |
| for step_name, verify_func in verification_steps: |
| print(f"\nπ Checking: {step_name}") |
| if not verify_func(test_dir): |
| all_passed = False |
| |
| |
| print("\n" + "="*50) |
| if all_passed: |
| print("β
Directory structure mirroring completed correctly!") |
| print("π Structure Mirror verification: PASS") |
| sys.exit(0) |
| else: |
| print("β Structure Mirror verification: FAIL") |
| sys.exit(1) |
| |
| except Exception as e: |
| print(f"β Verification failed with error: {e}") |
| sys.exit(1) |
|
|
| if __name__ == "__main__": |
| main() |