#!/usr/bin/env bash
set -euo pipefail
umask 077
E="/home/cube/projects/richard/traning coach/.omo/evidence/task26/task26-certification-deployment-4a8627af8f9b931d537e17dbd3e357b7a0f2b2abffdbf28f6ad19a8d32893ec0-gate20-corrected-v2-st_01a00b39"
C="/home/cube/projects/richard/traning coach/.omo/evidence/task26/task26-token-rotation-successor-4a8627af8f9b931d537e17dbd3e357b7a0f2b2abffdbf28f6ad19a8d32893ec0";S="/home/cube/.hermes/profiles/dualcoachtest/workspace/checkin_cli";PY=/home/cube/miniconda3/bin/python;W="$C/artifacts/physique_checkin_cli-0.1.0-py3-none-any.whl";D=4a8627af8f9b931d537e17dbd3e357b7a0f2b2abffdbf28f6ad19a8d32893ec0
mkdir -p "$E/artifacts" "$E/receipts";chmod 700 "$E" "$E/artifacts" "$E/receipts"
record(){ local n="$1";shift;local o="$E/artifacts/$n" s e rc;mkdir -p "$o";printf '%q ' "$@">"$o/command.txt";echo>>"$o/command.txt";env -0|sort -z>"$o/launcher-environment.nul";date -u +%Y-%m-%dT%H:%M:%S.%NZ>"$o/started-at-utc.txt";s=$(date +%s%N);set +e;"$@">"$o/stdout.txt" 2>"$o/stderr.txt";rc=$?;set -e;e=$(date +%s%N);date -u +%Y-%m-%dT%H:%M:%S.%NZ>"$o/ended-at-utc.txt";echo "$rc">"$o/exit-code.txt";echo "$(((e-s)/1000000))">"$o/duration-ms.txt";(cd "$o"&&sha256sum command.txt launcher-environment.nul started-at-utc.txt ended-at-utc.txt exit-code.txt duration-ms.txt stdout.txt stderr.txt>files.sha256);return "$rc";}
record corrected-source-package env -C "$S" -u TMPDIR HOME=/home/cube PYTHONPATH="$S" PYTHONDONTWRITEBYTECODE=1 PYTHONPYCACHEPREFIX=/tmp/task26-cert-pyc-source "$PY" -B -m pytest -q -p no:cacheprovider --junitxml="$E/artifacts/corrected-source-package.junit.xml" tests
I="$E/artifacts/installed-profile-wheel-root";mkdir -p "$I";record corrected-wheel-install "$PY" -m pip install --no-deps --no-compile --target "$I" "$W";cp -a "$S/tests" "$E/artifacts/installed-profile-tests"
record corrected-installed-package env -C /tmp -u TMPDIR HOME=/home/cube PYTHONPATH="$I" PYTHONDONTWRITEBYTECODE=1 PYTHONPYCACHEPREFIX=/tmp/task26-cert-pyc-installed "$PY" -B -m pytest -q -p no:cacheprovider --junitxml="$E/artifacts/corrected-installed-package.junit.xml" "$E/artifacts/installed-profile-tests"
record corrected-installed-imports env -C /tmp -u TMPDIR HOME=/home/cube PYTHONPATH="$I" PYTHONDONTWRITEBYTECODE=1 "$PY" -B - "$I" "$D" <<'PY'
import hashlib,importlib,json,sys
from pathlib import Path
r=Path(sys.argv[1]).resolve();rows=[]
for n in ['checkin_cli.customer_admin','checkin_cli.activation_token_rotation_policy']:
 m=importlib.import_module(n);p=Path(m.__file__).resolve();rows.append({'module':n,'path':str(p),'inside_wheel':p.is_relative_to(r),'sha256':hashlib.sha256(p.read_bytes()).hexdigest()})
o={'candidate_digest':sys.argv[2],'modules':rows,'status':'PASS' if all(x['inside_wheel'] for x in rows) else 'FAIL'};print(json.dumps(o,sort_keys=True,separators=(',',':')));raise SystemExit(o['status']!='PASS')
PY
record corrected-candidate-reverify /home/cube/projects/richard/hermes-agent/.venv/bin/python "$C/verify_candidate.py" "$C"
