Files

49 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""Verify wordcount.py output matches wc command."""
import json
import subprocess
import sys
from pathlib import Path
def verify_wordcount(filepath):
"""Run wordcount.py and verify against wc."""
# Run our script
result = subprocess.run(
["python3", "/root/.hermes/wizard-outputs/spark/wordcount.py", filepath],
capture_output=True, text=True
)
if result.returncode != 0:
return {"valid": False, "error": f"wordcount.py failed: {result.stderr}"}
our_stats = json.loads(result.stdout)
# Run wc for comparison
wc_result = subprocess.run(
["wc", filepath],
capture_output=True, text=True
)
if wc_result.returncode != 0:
return {"valid": False, "error": f"wc failed: {wc_result.stderr}"}
wc_parts = wc_result.stdout.strip().split()
wc_lines, wc_words, wc_bytes = int(wc_parts[0]), int(wc_parts[1]), int(wc_parts[2])
# Verify
issues = []
if our_stats["words"] != wc_words:
issues.append(f"words mismatch: {our_stats['words']} vs wc {wc_words}")
if our_stats["bytes"] != wc_bytes:
issues.append(f"bytes mismatch: {our_stats['bytes']} vs wc {wc_bytes}")
return {
"valid": len(issues) == 0,
"issues": issues if issues else None,
"stats": our_stats,
"wc_comparison": {"lines": wc_lines, "words": wc_words, "bytes": wc_bytes}
}
if __name__ == "__main__":
filepath = sys.argv[1] if len(sys.argv) > 1 else "/root/.hermes/wizard-outputs/alexander-reading.txt"
result = verify_wordcount(filepath)
print(json.dumps(result, indent=2))
sys.exit(0 if result["valid"] else 1)