"""Actual browser only: flexible human points in new namespace, temporary stores."""
from pathlib import Path
import sys

PROJECT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(PROJECT));sys.path.insert(0,str(PROJECT/'scripts'))
from scripts import check_mask_model_requests_ui as checks
from pallet.mask_annotation_update_v2_review import Updated2041KeypointGallery
from pallet.mask_annotation_update_v2_requests import ROOT,DRAFT_PREFIX
from pallet.pose_review_geometry import canonical
import json

if __name__=='__main__':
    checks.ROOT=ROOT;checks.REVIEWS=PROJECT/'outputs/pallet_mask_model_reviews_v5'
    checks.OUT=PROJECT/'outputs/pallet_mask_annotation_update_checks_v2/ui_acceptance';checks.OUT.parent.mkdir(mode=0o700,exist_ok=True)
    props=[json.loads(s) for s in (ROOT/'proposals.jsonl').read_text().splitlines()];first=props[0]['class_id'];second=next(p['class_id'] for p in props if p['target_key']!=props[0]['target_key'])
    try:checks.check(Updated2041KeypointGallery,keypoint_mode=True,allow_human_keypoint_edits=True,local_draft_prefix=DRAFT_PREFIX,editing_class=first,image_retry_class=second)
    except Exception as error:
        if checks.OUT.exists() and not (checks.OUT/'failure.json').exists():
            secret=(PROJECT/'outputs/pallet_pose_human_review_v1/access_key.txt').read_text().strip()
            (checks.OUT/'failure.json').write_bytes(canonical(dict(state='failed_new2041_UI_not_deployed',
                error=(type(error).__name__+': '+str(error)).replace(secret,'[redacted]'),production_annotation_writes=0))+b'\n')
        raise
