#!/usr/bin/env python3
"""
test_reality_api.py - Verify helix64_reality_api works as expected

This demonstrates the MANDATORY bootstrap snippet agents must use.
"""

# ═══════════════════════════════════════════════════════════════════════
# AGENT BOOTSTRAP - DO NOT SKIP
# ═══════════════════════════════════════════════════════════════════════
# Before doing ANYTHING, import and use the reality API:

import sys
from pathlib import Path

# Add tools to path
sys.path.insert(0, str(Path.home() / "helix-cdc" / "tools"))

from helix64_reality_api import (
    get_substrate_driver,
    get_runtime_driver_main,
    get_helix_infer,
    get_encoding_components,
    dump_summary,
)

# Print once for logging
print("=" * 80)
print("HELIX64 REALITY CHECK (from helix64_reality_api.py)")
print("=" * 80)
import json
print(json.dumps(dump_summary(), indent=2)[:1000] + "...")  # Truncate for brevity
print("=" * 80)
print()

# Example: Use existing substrate driver instead of creating new one
try:
    substrate_path = get_substrate_driver()
    print(f"✅ Using existing substrate driver: {substrate_path}")
except FileNotFoundError as e:
    print(f"❌ substrate_driver missing: {e}")

# Example: Use existing runtime driver
try:
    runtime_path = get_runtime_driver_main()
    print(f"✅ Using existing runtime driver: {runtime_path}")
except FileNotFoundError as e:
    print(f"❌ runtime_driver missing: {e}")

# Example: Get helix_infer.py
try:
    helix_infer_path = get_helix_infer()
    print(f"✅ Using existing helix_infer: {helix_infer_path}")
except FileNotFoundError as e:
    print(f"❌ helix_infer missing: {e}")

# Example: Get all encoding components
try:
    encoding_comps = get_encoding_components()
    print(f"✅ Found {len(encoding_comps)} encoding components:")
    for comp in encoding_comps:
        print(f"   - {comp.name} ({comp.stat().st_size} bytes)")
except Exception as e:
    print(f"❌ encoding components error: {e}")

print()
print("RULES:")
print("  1. If get_*() returns a path → USE IT (don't rebuild)")
print("  2. If get_*() raises FileNotFoundError → OK to build new")
print("  3. Never create substrate/runtime/encoding if API returns path")
print("=" * 80)
print()

# ═══════════════════════════════════════════════════════════════════════
# END BOOTSTRAP - Continue with your task below
# ═══════════════════════════════════════════════════════════════════════

print("✅ Bootstrap test complete - all components found!")
print()
print("This demonstrates what EVERY agent should do BEFORE touching Helix64.")
print("The API prevents agents from rebuilding what already exists.")
