#!/usr/bin/env python3 """Test suite for fs-report.py - verifies the script produces valid sorted JSON output.""" import subprocess import json import sys def test_fs_report(): # Run the script result = subprocess.run( ['python3', '/root/.hermes/wizard-outputs/spark/fs-report.py', '/tmp'], capture_output=True, text=True ) if result.returncode != 0: print(f'FAIL: Script returned non-zero exit code: {result.returncode}') print(f'stderr: {result.stderr}') return False # Parse JSON output try: report = json.loads(result.stdout) except json.JSONDecodeError as e: print(f'FAIL: Invalid JSON output: {e}') return False # Verify structure if 'files' not in report: print('FAIL: Missing "files" key in output') return False if 'total' not in report: print('FAIL: Missing "total" key in output') return False if 'directory' not in report: print('FAIL: Missing "directory" key in output') return False files = report['files'] if len(files) < 2: print('FAIL: Need at least 2 files') return False # Check descending order by size for i in range(len(files) - 1): if files[i]['size'] < files[i + 1]['size']: print(f'FAIL: Not sorted by size at position {i}: {files[i]["size"]} < {files[i+1]["size"]}') return False # Verify all files have required keys for f in files: for key in ['name', 'size', 'path']: if key not in f: print(f'FAIL: Missing key "{key}" in file entry') return False # Verify total matches if report['total'] != len(files): print(f'FAIL: total ({report["total"]}) != len(files) ({len(files)})') return False print(f'PASS: {len(files)} files correctly sorted and structured') print(f'PASS: All required keys present') print(f'PASS: total count matches: {report["total"]}') print('All tests passed') return True if __name__ == '__main__': success = test_fs_report() sys.exit(0 if success else 1)