fix(ci): green main — pyvis.shiny unit guard + de-flake leverage/simulation e2e#10
Conversation
test_cld.py and test_cld_filter.py import sespy.modules.cld_visualization / analysis_* at module top, which import the pyvis fork (`pyvis.shiny`) at load. In the stock-pyvis unit-CI jobs (py3.11 + py3.12) that raised ModuleNotFoundError at collection, failing the whole job. The other fork tests (test_network, test_report) already skip cleanly via importorskip; these two missed the guard. Add a module-level importorskip so they skip when the fork is absent and still run for real in the conda full-app/e2e jobs. E402 is already ignored for tests/ for exactly this idiom. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…eeps) The trajectory and final-state plot checks did wait_for_timeout(...) then asserted the <img> was present, so a render slower than the guessed delay (under full-suite / CI load) failed the assert prematurely — it flaked on a slower machine, failing at 3 different lines across reruns. Replace the sleep-then-assert pairs with wait_for_selector on the plot images (and the run button), matching the Monte-Carlo poll already used lower in the same file. Verified 3/3 green locally. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ace) Two timing races made this the CI-red e2e: 1. It hard-asserted it *caught* the transient "Computing…" caption by polling. The MC run on the 17-node/n=50 sample can finish between polls (esp. on a fast CI runner), so the sighting is inherently racy. Downgrade to best-effort (log on miss); the load-bearing guarantee is the 95% CI column appearing, which is already polled and still hard-asserted. 2. It read window.pyvisNetworks['leverage-leverage_network'].nodes after a fixed 2.5s sleep; when the network hadn't registered yet it crashed on undefined.nodes. Replace the sleep with wait_for_function on nav-active and on the network object existing. Verified 4/4 green locally (was ~1/2). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughTest modules ChangesTest Robustness Updates
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/test_leverage_e2e.py (1)
17-27: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMinor redundancy: double-checking nav activation.
wait_for_function(Line 18-23) already asserts the exact same condition (.sespy-nav-btn.activehas exactly one match equal tosespy_nav_leverage) that the follow-upeval_on_selector_all+assert(Line 24-27) re-verifies. Not incorrect, just a redundant round trip.♻️ Optional simplification
- await page.wait_for_function( - "() => { const a = Array.from(document.querySelectorAll(" - "'.sespy-nav-btn.active')).map(e => e.id);" - " return a.length === 1 && a[0] === 'sespy_nav_leverage'; }", - timeout=15000, - ) - nav_active = await page.eval_on_selector_all( - ".sespy-nav-btn.active", "els => els.map(e => e.id)" - ) - assert nav_active == ["sespy_nav_leverage"], f"unexpected: {nav_active}" + nav_active = await page.wait_for_function( + "() => { const a = Array.from(document.querySelectorAll(" + "'.sespy-nav-btn.active')).map(e => e.id);" + " return (a.length === 1 && a[0] === 'sespy_nav_leverage') ? a : null; }", + timeout=15000, + ) + assert (await nav_active.json_value()) == ["sespy_nav_leverage"]🤖 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 `@tests/test_leverage_e2e.py` around lines 17 - 27, The nav activation check in the leverage e2e test is duplicated: wait_for_function already verifies that .sespy-nav-btn.active contains exactly sespy_nav_leverage, so the follow-up eval_on_selector_all and assert in the same test are redundant. Simplify the test by keeping the wait_for_function in the leverage flow and removing the extra selector readback/assert, or otherwise consolidate the check into a single validation using the existing page wait logic.
🤖 Prompt for all review comments with 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.
Nitpick comments:
In `@tests/test_leverage_e2e.py`:
- Around line 17-27: The nav activation check in the leverage e2e test is
duplicated: wait_for_function already verifies that .sespy-nav-btn.active
contains exactly sespy_nav_leverage, so the follow-up eval_on_selector_all and
assert in the same test are redundant. Simplify the test by keeping the
wait_for_function in the leverage flow and removing the extra selector
readback/assert, or otherwise consolidate the check into a single validation
using the existing page wait logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: dd351d48-0603-4a48-86f0-8cbef7a4ed1c
📒 Files selected for processing (4)
tests/test_cld.pytests/test_cld_filter.pytests/test_leverage_e2e.pytests/test_simulation_e2e.py
Why
mainCI has been red on every push since ~2026-07-01. Two independent causes:ModuleNotFoundError: No module named 'pyvis.shiny'ontests/test_cld.pyandtests/test_cld_filter.py. Those modules importsespy.modules.cld_visualization/analysis_*at top level, which import the pyvis fork at load. The unit jobs installstock pyvis from PyPI (by design — fork tests belong in the conda jobs), so collection
crashes. The two files simply missed the
importorskipguard thattest_network/test_reportalready use.test_leverage_e2ehard-asserted it caught atransient "Computing…" caption (racy), and separately read
window.pyvisNetworks[...]after a fixed 2.5s sleep (crashed on
undefined.nodeswhen the network hadn'tregistered).
test_simulation_e2ehad the same arbitrary-timeout-then-assert pattern.What
test_cld.py/test_cld_filter.py: add module-levelpytest.importorskip("pyvis.shiny").Skips cleanly in the stock-pyvis unit jobs; still runs for real in the conda full-app/e2e jobs.
test_simulation_e2e.py: replacewait_for_timeout→assert withwait_for_selectoron theplot images (and run button), matching the Monte-Carlo poll already in the file.
test_leverage_e2e.py: downgrade the transient-caption sighting to best-effort (log on miss;the load-bearing 95% CI-column assertion is kept and already polled), and replace the pyvis
network sleep with
wait_for_functionwaits.Verification (local)
pyvis.shiny→ 2 skipped, not errored;fork present → 5 passed; ruff clean.
Not reproducible locally: the exact CI unit env (ubuntu + stock pyvis) and the fast-runner e2e
timing — this PR exists to confirm those go green.
🤖 Generated with Claude Code
Summary by CodeRabbit