@@ -309,6 +309,72 @@ run_test_no_pattern "label-actions-all-refused-no-reason" \
309309 ' {"action":"sufficient","reasoning":"all clear","clarity_scores":{"symptom":0.9,"cause":0.85,"reproduction":0.9,"impact":0.8,"overall":0.87},"triage_summary":{"title":"Fix crash","severity":"high","category":"bug","problem":"Crash","root_cause_hypothesis":"Buffer overflow","reproduction_steps":["step 1"],"environment":"Linux","impact":"All users","recommended_fix":"Fix buffer","proposed_test_case":"test_crash"},"comment":"## Triage Summary\n\nReady.","label_actions":{"reason":"Should not appear.","actions":[{"action":"add","label":"ready-to-code"}]}}' \
310310 " Should not appear."
311311
312+ # run_test_label_order verifies that a pattern appears AFTER another pattern
313+ # in the gh call log (i.e., ordering of API calls).
314+ run_test_label_order () {
315+ local test_name=" $1 "
316+ local json_content=" $2 "
317+ local before_pattern=" $3 "
318+ local after_pattern=" $4 "
319+
320+ local run_dir=" ${TMPDIR} /run-${test_name} "
321+ mkdir -p " ${run_dir} /iteration-1/output"
322+ echo " ${json_content} " > " ${run_dir} /iteration-1/output/agent-result.json"
323+ : > " ${GH_LOG} "
324+
325+ local exit_code=0
326+ (cd " ${run_dir} " && bash " ${POST_SCRIPT} " ) > " ${TMPDIR} /stdout.log" 2>&1 || exit_code=$?
327+
328+ if [[ ${exit_code} -ne 0 ]]; then
329+ echo " FAIL: ${test_name} — exit code ${exit_code} "
330+ cat " ${TMPDIR} /stdout.log"
331+ FAILURES=$(( FAILURES + 1 ))
332+ return
333+ fi
334+
335+ local before_line after_line
336+ before_line=$( grep -nF " ${before_pattern} " " ${GH_LOG} " | head -1 | cut -d: -f1)
337+ after_line=$( grep -nF " ${after_pattern} " " ${GH_LOG} " | head -1 | cut -d: -f1)
338+
339+ if [[ -z " ${before_line} " ]]; then
340+ echo " FAIL: ${test_name} — before pattern '${before_pattern} ' not found"
341+ echo " Actual calls:"
342+ cat " ${GH_LOG} "
343+ FAILURES=$(( FAILURES + 1 ))
344+ return
345+ fi
346+
347+ if [[ -z " ${after_line} " ]]; then
348+ echo " FAIL: ${test_name} — after pattern '${after_pattern} ' not found"
349+ echo " Actual calls:"
350+ cat " ${GH_LOG} "
351+ FAILURES=$(( FAILURES + 1 ))
352+ return
353+ fi
354+
355+ if [[ " ${before_line} " -ge " ${after_line} " ]]; then
356+ echo " FAIL: ${test_name} — '${before_pattern} ' (line ${before_line} ) should appear before '${after_pattern} ' (line ${after_line} )"
357+ echo " Actual calls:"
358+ cat " ${GH_LOG} "
359+ FAILURES=$(( FAILURES + 1 ))
360+ return
361+ fi
362+
363+ echo " PASS: ${test_name} "
364+ }
365+
366+ # Verify ready-to-code is applied AFTER informational labels from label_actions
367+ # to prevent the ready-to-code webhook event from being superseded (#1752).
368+ run_test_label_order " ready-to-code-applied-after-label-actions" \
369+ ' {"action":"sufficient","reasoning":"all clear","clarity_scores":{"symptom":0.9,"cause":0.85,"reproduction":0.9,"impact":0.8,"overall":0.87},"triage_summary":{"title":"Fix crash","severity":"high","category":"bug","problem":"Crash","root_cause_hypothesis":"Buffer overflow","reproduction_steps":["step 1"],"environment":"Linux","impact":"All users","recommended_fix":"Fix buffer","proposed_test_case":"test_crash"},"comment":"## Triage Summary\n\nReady.","label_actions":{"reason":"Component label.","actions":[{"action":"add","label":"area/api"},{"action":"add","label":"priority/high"}]}}' \
370+ " labels[]=priority/high" \
371+ " labels[]=ready-to-code"
372+
373+ # Verify ready-to-code is still applied when there are no label_actions.
374+ run_test " ready-to-code-applied-without-label-actions" \
375+ ' {"action":"sufficient","reasoning":"all clear","clarity_scores":{"symptom":0.9,"cause":0.85,"reproduction":0.9,"impact":0.8,"overall":0.87},"triage_summary":{"title":"Fix crash","severity":"high","category":"bug","problem":"Crash","root_cause_hypothesis":"Buffer overflow","reproduction_steps":["step 1"],"environment":"Linux","impact":"All users","recommended_fix":"Fix buffer","proposed_test_case":"test_crash"},"comment":"## Triage Summary\n\nReady."}' \
376+ " gh api repos/test-org/test-repo/issues/42/labels -f labels[]=ready-to-code --silent"
377+
312378# --- Summary ---
313379
314380echo " "
0 commit comments