Skip to content
40 changes: 39 additions & 1 deletion riptide/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,50 @@ def get_companion():
app = FastAPI(title="Riptide Webhook Server")

# ── Synchronize rate limiting ───────────────────────────────────────────────
# Track last synchronize time per PR to avoid T0 flooding on frequent pushes
# Track last synchronize time per PR to avoid flooding on frequent pushes
_SYNCHRONIZE_TIMESTAMPS: dict[str, float] = {}
_SYNCHRONIZE_LOCK = threading.Lock()
_SYNCHRONIZE_MIN_INTERVAL = 60.0 # seconds between synchronize processing


def _sync_test_helper(items: list[dict]) -> list[str]:
"""Live-test helper (WS-3 sync path): deterministic finding fixture."""
keys = []
for item in items:
try:
keys.append(item["key"])
except Exception as e: # noqa: BLE001 - finding: silently ignored exception
pass
Comment on lines +114 to +117

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

configs="$(fd -HI -t f '^(pyproject\.toml|ruff\.toml|\.ruff\.toml|setup\.cfg)$' . || true)"
while IFS= read -r file; do
  [ -z "$file" ] && continue
  rg -n 'S110|select|extend-select|ignore|extend-ignore' "$file" || true
done <<< "$configs"

if command -v ruff >/dev/null 2>&1; then
  ruff check riptide/webhook.py --select S110
fi

Repository: ChonSong/riptide

Length of output: 2228


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== webhook.py relevant sections =="
sed -n '90,135p' riptide/webhook.py | nl -ba -v90

echo
echo "== function definitions / calls =="
rg -n "def .*sync|def .*fixture|fixtures\.|riptide\.webhook|webhook\." -S . | head -n 120

echo
echo "== tests mentioning webhook / fixtures / sync =="
rg -n "fixtures|sync|webhook|key|str\(item\)|riptide/webhook\|riptide\.webhook" -S tests . --glob '!__pycache__/**' | head -n 200

echo
echo "== pyproject ruff config =="
sed -n '1,80p' pyproject.toml | nl -ba -v1

Repository: ChonSong/riptide

Length of output: 229


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== webhook.py relevant sections =="
sed -n '90,135p' riptide/webhook.py | awk '{print NR+89 ":" $0}'

echo
echo "== function definitions / calls =="
rg -n "def .*sync|def .*fixture|fixtures\.|riptide\.webhook|webhook\." -S . | head -n 120

echo
echo "== tests mentioning webhook / fixtures / sync =="
rg -n "fixtures|sync|webhook|key|str\(item\)|riptide/webhook\|riptide\.webhook" -S tests . --glob '!__pycache__/**' | head -n 200

echo
echo "== pyproject ruff config =="
sed -n '1,80p' pyproject.toml | awk '{print NR ":" "$0"}'

Repository: ChonSong/riptide

Length of output: 26759


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== riptide/webhook.py lines 330-365 =="
sed -n '330,365p' riptide/webhook.py | awk '{print NR+329 ":" $0}'

echo
echo "== all helpers usages in webhook.py =="
rg -n "_sync_test_helper(_delta)?\(" riptide/webhook.py

echo
echo "== riptide/tests path =="
find riptide/tests -maxdepth 2 -type f -print | sort | awk '{print NR ":" $0}' | tail -n 80

echo
echo "== relevant pytest references =="
rg -n "_sync_test_helper(_delta)?\(|sync_test_helper|delta|fixture|synchronize|pull_request" riptide/tests riptide -S | head -n 200

echo
echo "== pyproject ruff config =="
sed -n '1,40p' pyproject.toml | awk '{print NR ":" "$0"}'

Repository: ChonSong/riptide

Length of output: 18817


Do not hide fixture parsing exceptions in the sync helpers.

These _sync_test_helper and _sync_test_helper_delta helpers catch every Exception and drop the item. An unexpected item["key"] or str(item) failure can make the live sync fixture produce fewer expected results while avoiding a visible failure. Catch only malformed-item exceptions that support the WS-3 fixture contract, or re-raise unexpected exceptions and add tests for the contract.

Also applies to: 126-129

🧰 Tools
🪛 Ruff (0.16.1)

[error] 116-117: try-except-pass detected, consider logging the exception

(S110)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@riptide/webhook.py` around lines 114 - 117, Update _sync_test_helper and
_sync_test_helper_delta to stop swallowing all exceptions while parsing fixture
items. Catch only the specific malformed-item exceptions allowed by the WS-3
fixture contract, and re-raise unexpected failures from item["key"] or
str(item); add or update tests covering both accepted malformed items and
propagated unexpected exceptions.

Source: Linters/SAST tools

keys.sort()
return keys


def _sync_test_helper_delta(items: list[dict]) -> list[str]:
"""WS-3 delta fixture: a NEW silently-ignored exception in the delta."""
result = []
for item in items:
try:
result.append(str(item))
except Exception as e: # noqa: BLE001 - finding: silently ignored exception
pass
return result


def _sync_test_helper_delta2(items: list[dict]) -> int:
"""WS-3 final thread-update fixture: finding in the live delta."""
total = 0
for item in items:
try:
total += int(item.get("qty", 0))
except Exception as e: # noqa: BLE001 - finding: silently ignored exception
pass
return total


# WS-3 live-test marker: final sync to exercise the canonical-thread PATCH path
# with the delta-mapping fix deployed. See PR #73 / commit 6130294.


def _should_process_synchronize(owner: str, repo: str, pr_number: int) -> bool:
"""Check if enough time has passed since the last synchronize for this PR."""
global _SYNCHRONIZE_TIMESTAMPS
Expand Down
Loading