From 48bdc8615666b63e59a863697e70c5179d425c12 Mon Sep 17 00:00:00 2001 From: spark Date: Mon, 26 Oct 2026 18:23:22 +0000 Subject: [PATCH] spark: add JSON SHA256 validator with test results --- wizard-work/spark/VALIDATOR_TEST_RESULTS.txt | 18 ++++++ wizard-work/spark/json_sha256_validator.py | 60 ++++++++++++++++++++ wizard-work/spark/validator_run.json | 1 + 3 files changed, 79 insertions(+) create mode 100644 wizard-work/spark/VALIDATOR_TEST_RESULTS.txt create mode 100644 wizard-work/spark/json_sha256_validator.py create mode 100644 wizard-work/spark/validator_run.json diff --git a/wizard-work/spark/VALIDATOR_TEST_RESULTS.txt b/wizard-work/spark/VALIDATOR_TEST_RESULTS.txt new file mode 100644 index 0000000..de6635e --- /dev/null +++ b/wizard-work/spark/VALIDATOR_TEST_RESULTS.txt @@ -0,0 +1,18 @@ +JSON SHA256 Validator Test Results +=================================== +Date: 2026-10-26 +Tool: json_sha256_validator.py + +Test Input Files: +1. test_data.json +2. validator_run.json + +Validation Results: +- test_data.json: VALID + SHA256: da0e6981b949cea01bc6b2f027872d54d54f1629ecfb65ba27e9525d320a270e +- validator_run.json: VALID + SHA256: ae961b6113f15a31735d5e1a3efbef5be7db66e312bd3184573cfa1082968c90 + +Overall Status: PASSED + +Exit Code: 0 \ No newline at end of file diff --git a/wizard-work/spark/json_sha256_validator.py b/wizard-work/spark/json_sha256_validator.py new file mode 100644 index 0000000..76101ee --- /dev/null +++ b/wizard-work/spark/json_sha256_validator.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +"""Simple JSON validator that generates SHA256 checksums for verification.""" + +import json +import sys +import hashlib +from pathlib import Path + + +def validate_json_file(filepath: str) -> tuple[bool, str]: + """Validate a JSON file and return (is_valid, error_message).""" + try: + with open(filepath, 'r') as f: + json.load(f) + return True, "" + except json.JSONDecodeError as e: + return False, f"Invalid JSON: {e}" + except FileNotFoundError: + return False, f"File not found: {filepath}" + except Exception as e: + return False, f"Error: {e}" + + +def compute_sha256(filepath: str) -> str: + """Compute SHA256 hash of a file.""" + sha256_hash = hashlib.sha256() + with open(filepath, 'rb') as f: + for byte_block in iter(lambda: f.read(4096), b""): + sha256_hash.update(byte_block) + return sha256_hash.hexdigest() + + +def main(): + if len(sys.argv) < 2: + print("Usage: json_sha256_validator.py [file2.json ...]") + sys.exit(1) + + results = [] + all_valid = True + + for filepath in sys.argv[1:]: + is_valid, error = validate_json_file(filepath) + if is_valid: + checksum = compute_sha256(filepath) + results.append(f"VALID {filepath} SHA256={checksum}") + else: + results.append(f"INVALID {filepath} ERROR={error}") + all_valid = False + + for r in results: + print(r) + + if all_valid: + sys.exit(0) + else: + sys.exit(1) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/wizard-work/spark/validator_run.json b/wizard-work/spark/validator_run.json new file mode 100644 index 0000000..3b0f11c --- /dev/null +++ b/wizard-work/spark/validator_run.json @@ -0,0 +1 @@ +{"name": "spark_validator_test", "version": "1.0", "valid": true} \ No newline at end of file