@@ -84,10 +84,38 @@ if [ "${run_frontend}" = true ]; then
8484 build_pid=$!
8585fi
8686
87+ # CI-reuse: when HEAD is exactly what's pushed (clean backend/ worktree, local
88+ # tip == remote tip) and the test-backend workflow already completed for that
89+ # SHA, reuse CI's verdict instead of a duplicate multi-minute local run. One
90+ # gh call inside this script — no extra agent round-trips. Any doubt (dirty
91+ # tree, unpushed commits, gh missing, run still in progress) falls through to
92+ # a normal local run.
93+ ci_verdict=" "
94+ if [ " ${run_backend} " = true ] && command -v gh > /dev/null 2>&1 \
95+ && [ -z " $( git status --porcelain -- backend/ 2> /dev/null) " ]; then
96+ head_sha=" $( git rev-parse HEAD) "
97+ branch_name=" $( git rev-parse --abbrev-ref HEAD) "
98+ remote_sha=" $( git ls-remote origin " refs/heads/${branch_name} " 2> /dev/null | cut -f1) "
99+ if [ " ${remote_sha} " = " ${head_sha} " ]; then
100+ ci_verdict=" $( gh run list --commit " ${head_sha} " --workflow test-backend.yml \
101+ --json status,conclusion --jq \
102+ ' first(.[] | select(.status == "completed")) | .conclusion // empty' \
103+ 2> /dev/null || true) "
104+ fi
105+ fi
106+
87107pytest_status=0
88108pytest_pid=" "
89109pytest_ran=false
90- if [ " ${run_backend} " = true ]; then
110+ if [ " ${run_backend} " = true ] && [ " ${ci_verdict} " = " success" ]; then
111+ pytest_ran=true
112+ echo " backend pytest: PASS (reusing CI test-backend run for pushed HEAD $( git rev-parse --short HEAD) ; local run skipped)"
113+ echo " CI verdict reused; see: gh run list --commit $( git rev-parse HEAD) " > " ${pytest_log} "
114+ elif [ " ${run_backend} " = true ]; then
115+ if [ " ${ci_verdict} " = " failure" ]; then
116+ echo " note: CI test-backend FAILED for this exact commit — check the CI record" \
117+ " (gh run list --commit $( git rev-parse HEAD) ); running locally anyway for a fresh log."
118+ fi
91119 pytest_ran=true
92120 echo " Starting backend pytest in background..."
93121 docker-compose exec -T backend pytest > " ${pytest_log} " 2>&1 &
0 commit comments