import os
import sys
import logging

logging.basicConfig(level=logging.DEBUG)

lab = r"C:\Users\intel\AppData\Local\OptimusRuntime\Labs\AR74\12_ar88_authority_operational_closure"
candidate_ws = os.path.join(lab, "candidate_workspace")
sys.path.insert(0, candidate_ws)

import artifacts.brain_host.brain_host_tls as bh
from app.remediation.self_repair.live_shadow_hook import dispatch_live_shadow_hook

print("BH dispatch_live_shadow_hook object:", bh.dispatch_live_shadow_hook)
print("Module dispatch_live_shadow_hook object:", dispatch_live_shadow_hook)

# Setup dummy task
tid = "test_task_debug"
bh.OPERATIONAL_TASKS[tid] = {
    "task_id": tid,
    "mission_id": tid,
    "status": "FAILED",
    "task_status": "FAILED",
    "activity": []
}

snap = dict(bh.OPERATIONAL_TASKS[tid])
snap["operational_tasks"] = bh.OPERATIONAL_TASKS

print("\n--- Calling dispatch_live_shadow_hook(async_dispatch=False) ---")
res = dispatch_live_shadow_hook(snap, async_dispatch=False)
print("Sync result:", res)
print("Task status after sync:", bh.OPERATIONAL_TASKS[tid].get("status"))
print("Activities after sync:", [a.get("event") or a.get("message") for a in bh.OPERATIONAL_TASKS[tid].get("activity", [])])

