From 959c386d8d1d64183613e7be7efefef2b0d774ca Mon Sep 17 00:00:00 2001 From: Nathan Esquenazi Date: Fri, 3 Apr 2026 14:23:50 +0000 Subject: [PATCH] fix: test_send_pop_in keyframe parser hit wrong @keyframes block rfind('@keyframes') searched backward from 'send-pop-in' but with both keyframes on the same CSS line, it landed on mic-pulse instead. Fix: use find('@keyframes send-pop-in') directly (forward search) via a shared _extract_keyframe() helper. Same fix applied to both test_send_pop_in_uses_scale and test_send_pop_in_uses_opacity. --- tests/test_sprint20b.py | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/tests/test_sprint20b.py b/tests/test_sprint20b.py index 5aa70bf..3cfaecb 100644 --- a/tests/test_sprint20b.py +++ b/tests/test_sprint20b.py @@ -178,12 +178,12 @@ def test_send_pop_in_keyframes_defined(): assert '@keyframes' in css -def test_send_pop_in_uses_scale(): - """send-pop-in keyframe must animate from a scaled-down state.""" - css, _ = get_text("/static/style.css") - kf_idx = css.find('send-pop-in') - kf_start = css.rfind('@keyframes', 0, kf_idx) - # Find matching closing brace (simple scan) +def _extract_keyframe(css, name): + """Extract the full @keyframes block for the given animation name.""" + # Find '@keyframes ' directly (forward search) to avoid hitting + # an earlier keyframe when multiple are defined on the same line. + kf_start = css.find('@keyframes ' + name) + assert kf_start != -1, f"@keyframes {name} not found in CSS" depth = 0 kf_end = kf_start for i, ch in enumerate(css[kf_start:], kf_start): @@ -194,26 +194,20 @@ def test_send_pop_in_uses_scale(): if depth == 0: kf_end = i break - kf_rule = css[kf_start:kf_end] + return css[kf_start:kf_end] + + +def test_send_pop_in_uses_scale(): + """send-pop-in keyframe must animate from a scaled-down state.""" + css, _ = get_text("/static/style.css") + kf_rule = _extract_keyframe(css, 'send-pop-in') assert 'scale' in kf_rule def test_send_pop_in_uses_opacity(): """send-pop-in keyframe must fade in (opacity transition).""" css, _ = get_text("/static/style.css") - kf_idx = css.find('send-pop-in') - kf_start = css.rfind('@keyframes', 0, kf_idx) - depth = 0 - kf_end = kf_start - for i, ch in enumerate(css[kf_start:], kf_start): - if ch == '{': - depth += 1 - elif ch == '}': - depth -= 1 - if depth == 0: - kf_end = i - break - kf_rule = css[kf_start:kf_end] + kf_rule = _extract_keyframe(css, 'send-pop-in') assert 'opacity' in kf_rule