@@ -1408,3 +1408,166 @@ setup() {
14081408 assert_success
14091409 assert_output --partial " (DRY RUN) PR merged: <commit title would appear here>"
14101410}
1411+
1412+ @test " wait_for_pr_checks prints initial waiting message once" {
1413+ source " $SCRIPT_PATH "
1414+
1415+ # Mock gh to return empty checks array (waiting for checks to start)
1416+ function gh() {
1417+ if [ " $1 " = " pr" ] && [ " $2 " = " checks" ]; then
1418+ echo " []"
1419+ return 0
1420+ elif [ " $1 " = " pr" ] && [ " $2 " = " view" ]; then
1421+ echo ' {"reviewDecision": null, "reviewRequests": []}'
1422+ return 0
1423+ fi
1424+ return 1
1425+ }
1426+
1427+ # Mock sleep to avoid actual waiting
1428+ function sleep() {
1429+ return 0
1430+ }
1431+
1432+ export -f gh sleep
1433+
1434+ # Run with a short timeout to capture initial output
1435+ run timeout 1 bash -c "
1436+ source '$SCRIPT_PATH '
1437+ wait_for_pr_checks 123 'owner' 'repo' '(1/1)' 2>&1
1438+ " || true
1439+
1440+ # Should contain the initial waiting message
1441+ assert_output --partial " ⏳ Waiting for checks to start"
1442+ # Should contain at least one dot
1443+ assert_output --partial " ."
1444+ }
1445+
1446+ @test " wait_for_pr_checks prints dots on each waiting iteration" {
1447+ source " $SCRIPT_PATH "
1448+
1449+ # Use a counter that persists across function calls
1450+ echo " 0" > " $BATS_TEST_TMPDIR /gh_call_count"
1451+
1452+ # Mock gh to return empty checks for first few calls, then checks appear
1453+ function gh() {
1454+ if [ " $1 " = " pr" ] && [ " $2 " = " checks" ]; then
1455+ local count=$( cat " $BATS_TEST_TMPDIR /gh_call_count" )
1456+ count=$(( count + 1 ))
1457+ echo " $count " > " $BATS_TEST_TMPDIR /gh_call_count"
1458+
1459+ if [ $count -lt 3 ]; then
1460+ echo " []"
1461+ else
1462+ # Return checks after 3 iterations
1463+ echo ' [{"state": "completed", "bucket": "success"}]'
1464+ fi
1465+ return 0
1466+ elif [ " $1 " = " pr" ] && [ " $2 " = " view" ]; then
1467+ echo ' {"reviewDecision": "APPROVED", "reviewRequests": []}'
1468+ return 0
1469+ fi
1470+ return 1
1471+ }
1472+
1473+ # Mock sleep to avoid actual waiting
1474+ function sleep() {
1475+ return 0
1476+ }
1477+
1478+ export -f gh sleep
1479+
1480+ # Capture stderr output
1481+ run bash -c "
1482+ source '$SCRIPT_PATH '
1483+ wait_for_pr_checks 123 'owner' 'repo' '(1/1)' 2>&1
1484+ "
1485+
1486+ # Should contain multiple dots (at least 2)
1487+ local dot_count=$( echo " $output " | grep -o ' \.' | wc -l | tr -d ' ' )
1488+ assert [ " $dot_count " -ge 2 ]
1489+
1490+ rm -f " $BATS_TEST_TMPDIR /gh_call_count"
1491+ }
1492+
1493+ @test " wait_for_pr_checks prints newline when checks are found after waiting" {
1494+ source " $SCRIPT_PATH "
1495+
1496+ # Use a counter that persists across function calls
1497+ echo " 0" > " $BATS_TEST_TMPDIR /gh_call_count"
1498+
1499+ # Mock gh to return empty checks first, then checks appear
1500+ function gh() {
1501+ if [ " $1 " = " pr" ] && [ " $2 " = " checks" ]; then
1502+ local count=$( cat " $BATS_TEST_TMPDIR /gh_call_count" )
1503+ count=$(( count + 1 ))
1504+ echo " $count " > " $BATS_TEST_TMPDIR /gh_call_count"
1505+
1506+ if [ $count -le 2 ]; then
1507+ echo " []"
1508+ else
1509+ # Return checks after 2 iterations
1510+ echo ' [{"state": "completed", "bucket": "success"}]'
1511+ fi
1512+ return 0
1513+ elif [ " $1 " = " pr" ] && [ " $2 " = " view" ]; then
1514+ echo ' {"reviewDecision": "APPROVED", "reviewRequests": []}'
1515+ return 0
1516+ fi
1517+ return 1
1518+ }
1519+
1520+ # Mock sleep to avoid actual waiting
1521+ function sleep() {
1522+ return 0
1523+ }
1524+
1525+ export -f gh sleep
1526+
1527+ # Capture stderr output
1528+ run bash -c "
1529+ source '$SCRIPT_PATH '
1530+ wait_for_pr_checks 123 'owner' 'repo' '(1/1)' 2>&1
1531+ "
1532+
1533+ # Should contain the waiting message followed by dots
1534+ assert_output --partial " ⏳ Waiting for checks to start"
1535+ # Should eventually show check status (indicating newline was printed)
1536+ assert_output --partial " Found"
1537+
1538+ rm -f " $BATS_TEST_TMPDIR /gh_call_count"
1539+ }
1540+
1541+ @test " wait_for_pr_checks does not print waiting message when checks found immediately" {
1542+ source " $SCRIPT_PATH "
1543+
1544+ # Mock gh to return checks immediately (no waiting)
1545+ function gh() {
1546+ if [ " $1 " = " pr" ] && [ " $2 " = " checks" ]; then
1547+ echo ' [{"state": "completed", "bucket": "success"}]'
1548+ return 0
1549+ elif [ " $1 " = " pr" ] && [ " $2 " = " view" ]; then
1550+ echo ' {"reviewDecision": "APPROVED", "reviewRequests": []}'
1551+ return 0
1552+ fi
1553+ return 1
1554+ }
1555+
1556+ # Mock sleep to avoid actual waiting
1557+ function sleep() {
1558+ return 0
1559+ }
1560+
1561+ export -f gh sleep
1562+
1563+ # Capture stderr output
1564+ run bash -c "
1565+ source '$SCRIPT_PATH '
1566+ wait_for_pr_checks 123 'owner' 'repo' '(1/1)' 2>&1
1567+ "
1568+
1569+ # Should NOT contain waiting message when checks are found immediately
1570+ refute_output --partial " ⏳ Waiting for checks to start"
1571+ # Should show check status instead
1572+ assert_output --partial " Found"
1573+ }
0 commit comments