Skip to content

feat: overload monitoring tests and frontend fixes#37

Merged
marota merged 7 commits into
mainfrom
feat/overload-monitoring-tests-and-fixes
Mar 7, 2026
Merged

feat: overload monitoring tests and frontend fixes#37
marota merged 7 commits into
mainfrom
feat/overload-monitoring-tests-and-fixes

Conversation

@marota

@marota marota commented Mar 7, 2026

Copy link
Copy Markdown
Collaborator

feat: Overload Monitoring Refinement and Comprehensive Testing

This PR consolidates several improvements to the N-1 overload monitoring flow and introduces a robust testing suite for both backend logic and frontend integration.

🚀 Key Improvements

1. Focused Analysis & Action Cards

  • Deselecting Overloads: Users can now double-click specific N-1 overloads to deselect them, focusing the analysis on the most critical issues.
  • Improved Resolution Logic: Restored action cards when "Monitor deselected" is checked. The system now correctly monitors all overloads while only attempting to resolve those currently selected.
  • Backend Filtering: The backend now correctly excludes deselected overloads from the resolution mask (when not monitoring deselected), ensuring they don't impact the "Max loading" metrics in action cards.

2. Dynamic Monitoring Warning

  • Real-time Updates: The warning banner in the Overloads panel now dynamically reflects the count of monitored lines, including those effectively monitored even if deselected.
  • Informative Labels: Added detailed labels like (effective count) ... incl. X deselected to provide better context.

3. UI/UX Optimizations

  • Horizontal Panel Layout: Refactored the N-1 Overloads list from a vertical stack to a horizontal flow, significantly reducing the vertical footprint and improving information density.
  • Synced Interfaces: Synchronized the React frontend with the standalone HTML interface to ensure consistency across all access methods.

🧪 Comprehensive Testing Suite

Introduced a suite of API and service-level tests to ensure stability and correctness of the split analysis flow:

  • API Integration Tests:
    • Coverage for /api/run-analysis-step1 and step2.
    • Verification of streaming response events (pdf, result).
    • Validation of parameter propagation (selected_overloads, monitor_deselected, all_overloads).
  • Service & Filtering Tests:
    • Edge case handling for empty or invalid overload selections.
    • Robustness checks for the new split analysis orchestration.

🛠 Technical Changes

  • Backend: Updated expert_backend/main.py and recommender_service.py to support the refined analysis flow and fixed PDF path resolution.
  • Frontend: Significant refactor of App.tsx, OverloadPanel.tsx, and ActionFeed.tsx for better state management and UI performance.
  • New Tests: Added test_overload_filtering.py, test_recommender_simulation.py, and test_split_analysis.py.

Based on work from conversations 1cff2d49-4df1-4b36-ab6c-0577cf9248dd and f046a5e1-7850-4f96-ada9-b7656b533402.

marota and others added 7 commits March 7, 2026 13:21
- Add comprehensive API and service tests for overload monitoring
- Fix PDF result display and merge analysis steps in frontend
- Add support for monitoring deselected overloads
- Improve OverloadPanel and ActionFeed components
- Keep 'without permanent limits' count static
- Show deselected count separately as requested
- Import and call enrich_actions_lazy after load_actions in update_config
  so that action 'content'/set_bus is computed on demand from 'switches'
  (PR marota/Expert_op4grid_recommender#49 compatibility)
- Auto-generated disco_ actions now only store description fields; their
  content is derived lazily by LazyActionDict._build_disco_content
- Rewrite test_recommender_simulation.py to load and verify the new
  lazy-format action dictionary (reduced_model_actions_test_pypowsybl.json):
  tests for absence of pre-computed content, LazyActionDict 'content'
  availability, and correct variant management during simulate_manual_action
- Patch enrich_actions_lazy in test_recommender_service.py to keep those
  unit tests isolated from the real library

https://claude.ai/code/session_01HfipZethVhYX7gQJ92oEEr
…e_ids, fix sanitize_for_json recursion

Three root causes fixed:

1. conftest.py: now tries importlib.import_module() before installing a
   MagicMock stub, so real packages (pypowsybl, expert_op4grid_recommender
   and its submodules) are used when available.  Mocks are only installed
   for packages that genuinely cannot be imported (e.g. alphaDeesp, which
   is not in the test environment).  This makes TestRecommenderSimulationRealData
   run against the real pypowsybl network and real data_loader instead of
   opaque MagicMock objects.

2. recommender_service._get_base_network: adds a get_line_ids() convenience
   method to the returned pypowsybl Network object (Network.get_lines()
   returns a DataFrame; the tests and some service helpers need a plain list
   of IDs via get_line_ids()).

3. sanitize_for_json: the else-branch called obj.to_dict() and recursed
   unconditionally.  For MagicMock objects (and any object whose to_dict()
   returns a non-dict), this caused infinite recursion and an eventual OOM
   kill.  Now the result of to_dict() is checked with isinstance(d, dict)
   before recursing; otherwise str(obj) is returned immediately.

4. test_simulate_manual_action_sets_correct_variant: the _variant_id
   assertion referenced mock_get_obs.return_value (the auto-generated mock
   return-value, which is distinct from mock_obs returned by the side_effect
   function) instead of mock_obs directly.  Corrected to assert
   mock_obs._variant_id.

https://claude.ai/code/session_01HfipZethVhYX7gQJ92oEEr
Implement lazy-loading for action content in recommender service
@marota marota merged commit 248ed14 into main Mar 7, 2026
2 checks passed
@marota marota mentioned this pull request Mar 8, 2026
27 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants