#!/usr/bin/env bash
# R1: identity parity, merge-base vs head, same fixture.
set -uo pipefail
C=/tmp/ev-23690/capture; D=$C/drivers; F=$C/fx-r1
HEADWT=$HOME/wt/pr-23690; BASEWT=$HOME/wt/pr-23690-before
echo "## R1 identity parity  $(date -u +%FT%TZ)"
echo "HEAD=$(git -C $HEADWT rev-parse HEAD) BASE=$(git -C $BASEWT rev-parse HEAD)"
echo "\$ bash fixture-r1.sh $F"; bash $D/fixture-r1.sh $F
for side in base head; do
  wt=$BASEWT; [ $side = head ] && wt=$HEADWT
  echo "\$ (cd $wt/apps/server && node $D/scan.ts $wt $F/claude $F/codex 1) > $C/r1-$side.json"
  (cd $wt/apps/server && node $D/scan.ts $wt $F/claude $F/codex 1) > $C/r1-$side.json
  echo "exit=$?"
done
echo "\$ jq '.[0].result' r1-head.json"; jq '.[0].result' $C/r1-head.json
echo "\$ diff <(jq -S '.[0].result' r1-base.json) <(jq -S '.[0].result' r1-head.json)"
diff <(jq -S '.[0].result' $C/r1-base.json) <(jq -S '.[0].result' $C/r1-head.json) && echo "IDENTICAL (diff exit 0)"
echo "candidate count and paths (normal-wt linked worktree and regular-file are expected to be absent):"
jq -r '.[0].result.candidates[].path' $C/r1-head.json | grep -c . ; jq -r '.[0].result.candidates[].path' $C/r1-head.json
