#!/bin/bash
# VERIFICATION CHECK: verify the line counter produces correct output
# Exit 0 = correct, nonzero = wrong

set -e

SCRIPT="/root/.hermes/wizard-outputs/spark/python_line_counter.py"
REPORT="/root/.hermes/wizard-outputs/spark/VERIFICATION_REPORT.json"

# Verify script exists
if [ ! -f "$SCRIPT" ]; then
    echo "FAIL: Script not found"
    exit 1
fi

# Verify report exists
if [ ! -f "$REPORT" ]; then
    echo "FAIL: Report not found"
    exit 1
fi

# Run line count on a known file and verify it matches
ACTUAL=$(python3 "$SCRIPT" /etc/hosts count 2>/dev/null || python3 -c "
import sys
sys.path.insert(0, '/root/.hermes/wizard-outputs/spark')
from python_line_counter import count_python_lines
print(count_python_lines('/etc/hosts')['total_lines'])
")

EXPECTED=16

if [ "$ACTUAL" = "$EXPECTED" ]; then
    echo "PASS: Line count verified (got $ACTUAL, expected $EXPECTED)"
    exit 0
else
    echo "FAIL: Line count mismatch (got $ACTUAL, expected $EXPECTED)"
    exit 1
fi