"""Check assets in the authored local exercise; does not open or restore an editor.
Run: python verify_session.py
Reads manifest.json next to this file. It never edits assets or follows outside paths.
"""
from pathlib import Path
import hashlib,json,sys
root=Path(__file__).resolve().parent
manifest=json.loads((root/'manifest.json').read_text(encoding='utf-8'))
rows=[]
for item in manifest['assets']:
 path=(root/item['path']).resolve()
 if not path.is_relative_to(root):raise ValueError('Asset path must stay inside the exercise folder')
 if not path.is_file():status='missing';actual=None
 else:
  actual=hashlib.sha256(path.read_bytes()).hexdigest()
  status='present_and_matches' if actual==item['sha256'] else 'changed'
 rows.append({'path':item['path'],'status':status,'expected_sha256':item['sha256'],'actual_sha256':actual})
ok=all(x['status']=='present_and_matches' for x in rows)
print(json.dumps({'exercise':'authored local manifest, not a vendor recovery test','assets_verified':ok,'asset_results':rows,'recorded_state':manifest['recorded_state'],'editor_reopened':False},indent=2))
sys.exit(0 if ok else 1)
