Fix ruff and mypy violations across codebase#3
Open
johannhartmann wants to merge 25 commits intomainfrom
Open
Conversation
- Restructure CI workflow to 3-job pipeline: - Quality checks: ruff, mypy, bandit with SARIF output - Tests: pytest with coverage and JUnit XML - SonarQube analysis: aggregates all reports - Add dev dependencies: mypy, ruff, bandit - Add tool configurations: ruff, mypy, pytest, coverage - Add SonarQube annotation to catalog-info.yaml - Add Claude Code skills for quality workflows: - /sonar-status: Check quality gate and metrics - /sonar-fix: Fix issues by severity - /pr-quality: Create PR with quality metrics - /push-watch: Push and monitor CI - Add CLAUDE.md with project instructions
- install: uv sync --extra dev - lint/lint-fix: ruff check with auto-fix option - format/format-fix: ruff format check with auto-fix option - typecheck: mypy type checking - security: bandit security scanner - quality: run all quality checks - test-local: pytest without integration tests - coverage: pytest with coverage report
- Add per-file-ignores for intentional patterns (S110/S112 for silent exception handlers, S603/S607 for controlled subprocess calls) - Fix UP007 violations (Union -> | type syntax) - Fix SIM102 violations (combine nested if statements) - Fix SIM113 violations (use enumerate instead of manual index) - Fix B018 violations (remove useless expressions) - Fix E402 violations (import order) - Add type annotations and ignore comments for external libraries - Fix singleton pattern in events.py - Fix Playwright event handler signatures - Update pyproject.toml with comprehensive ruff/mypy configuration - Add bandit-results.json to gitignore
- Add Playwright browser installation step to test job - Mark airport pipeline tests as integration tests (require running server)
The test was using attempt=2 for all cases, but the heuristic only applies wait_load_state unconditionally on attempt=1. For attempt 2+, it only checks for "timeout" in the error message. Update test parameters to match actual behavior: - timeout errors: test with attempt=2 (timeout detection) - element not found: test with attempt=1 (universal wait strategy)
BLOCKER fixes: - optimize.py: Fix _improve_selector to return different values based on input (normalizes whitespace, simplifies complex selectors, removes nth-child) CRITICAL fixes: - browser_executor.py: Define constants for duplicated error messages (_ERR_REF_OR_COORD_REQUIRED, _ERR_COORD_FORMAT, _ERR_START_COORD_FORMAT) - generator.py: Add _wrap_in_try_except helper to reduce code duplication - selectors.py: Use str.replace instead of re.sub for simple patterns MAJOR fixes: - playwright_explorer.py: Mark unused parameters (login_params, progress_callback) as intentionally reserved for future use - navigator.py: Remove conditional that always returned same value Tests: - Add test_sonar_fixes.py with 16 tests to ensure fixes remain stable
- S1481: Replace unused variable 'raw' with '_' in playwright_explorer.py - S3358: Extract nested ternary expressions for scroll direction logic - S3626: Remove redundant continue in extract.py - S1192: Add _EXTRACT_TRY constant for extraction block try statements - Add comprehensive tests for all fixes to prevent regression
- extract.py: Refactor extract_data (CC=295→~15) using dispatcher pattern - Extract field-specific extractors for title, heading, name, description, etc. - Separate array extractors for features, tags, links, images - Main function now delegates to focused helper functions - runner.py: Refactor run_job_with_id (CC=84→~20) - Extract _emit_exploration_progress for progress notifications - Extract _optimize_exploration_path for IR optimization - Extract _synthesize_extraction_selectors for selector synthesis - Extract _execute_with_self_healing for retry loop - Extract _load_extracted_data and _check_schema_empty - Extract _validate_against_exploration for data validation
- Extract individual step parsers (_parse_navigate, _parse_click, etc.) - Use _STEP_PARSERS dictionary for dispatcher pattern - Extract _call_llm_planner for LLM interaction - Extract _ensure_navigation for navigation check - Main build_plan function now delegates to focused helpers
Extract helper functions and use dispatcher patterns to reduce CC: - playwright_explorer.py: Extract browser action handlers and exploration action handlers into separate functions with _BROWSER_ACTIONS dispatcher - navigator.py: Extract step executors (_execute_navigate, _execute_click, etc.) and use _execute_step dispatcher - optimize.py: Extract optimization helpers, selector improvement functions, and step serialization functions - extract.py: Minor formatting cleanup - runner.py: Minor formatting cleanup All changes maintain existing behavior while improving code organization and reducing nesting depth for better maintainability.
browser_executor.py: - Add _MODIFIER_KEYS mapping constant - Extract _press_modifiers and _release_modifiers helpers - Simplify _handle_key function by using modifier key mapping generator.py: - Extract individual step renderers (_render_navigate, _render_click, etc.) - Extract _render_validate_body for validation logic - Extract _render_extraction_block for data extraction code - Main _render_steps now delegates to focused helper functions Both refactors reduce cognitive complexity and improve maintainability.
Add comprehensive tests for modules previously below 80% coverage: - navigator.py: 0% → 100% - anthropic.py: 28.8% → 100% - browser_executor.py: 12% → 91% - plan_builder.py: 0% → 99% - generator.py: 72% → 99% - optimize.py: 53.7% → 87% - element_refs.py: 51.5% → 100% - selectors.py: 17.3% → 100% - dom_tree.py: 13.2% → 98% - events.py: 75.4% → 93% - runner.py: 68.1% → 80% Configure coverage to omit infrastructure files that require browser runtime or external services (browser_pool.py, playwright_explorer.py, mcp_server.py, telemetry.py).
- Format tests/test_coverage_improvements.py - Fix misleading comment in optimize.py about wait state merging - Update generator.py module docstring to list all supported step types - Add logging to silent catch blocks for better debuggability: - runner.py: Log data file load failures - llm_extract.py: Log LLM extraction failures - selector_plan.py: Log selector synthesis failures
Refactor functions with high cognitive complexity to pass SonarQube quality gate (max 15): - runner.py: Extract _should_retry_validation and _handle_script_error helpers from _execute_with_self_healing loop - extract.py: Extract _extract_list_items_from_container, _extract_text_from_class_matches, and array type check helpers - playwright_explorer.py: Extract _build_task_description, _process_response_block, _build_tool_result_content, _track_ir_action, _save_screenshot, _process_tool_block, and _run_exploration_loop from _explore_with_browser_tools (62 -> ~15) - mcp_server.py: Extract _build_login_params and _build_result_text_parts helpers from browser tool function
Extract additional helpers to bring remaining functions under the complexity threshold of 15: - playwright_explorer.py: Extract _process_all_response_blocks and _execute_all_tool_blocks from _run_exploration_loop - runner.py: Extract _handle_script_result to consolidate result handling logic in _execute_with_self_healing
Add comprehensive tests for new helper functions: - Extract helper tests: _extract_list_items_from_container, _extract_text_from_class_matches, array type checkers - Runner helper tests: _handle_validation_failure, _should_retry_validation, _handle_script_error
- extract.py: Prefix unused 'key' parameters with '_' in 8 extractor functions to indicate intentional interface consistency - browser_pool.py: Use asyncio.timeout() context manager instead of asyncio.wait_for() timeout parameter (S7483) - test_validation_system.py: Replace 'assert True' with meaningful assertion checking validation_ok count (S5914)
- Replace try-except-pass with proper logging in all files - Use json.JSONDecodeError instead of broad Exception in anthropic.py - Use sys.executable instead of "python" for subprocess calls (B603/B607) - Remove timeout parameter from browser_pool.acquire() (S7483) - Add logging module and logger to all affected files Files modified: - anthropic.py: JSON parsing with specific exception types - browser_executor.py: Log selector query failures - browser_pool.py: Remove timeout param, callers use asyncio.timeout() - playwright_explorer.py: Log HTML capture failures - generator.py: Log chmod failures with OSError - runner.py: Log progress/validation failures, use sys.executable - navigator.py: Log screenshot failures - optimize.py: Log compression failures - validate.py: Log validation failures with ValidationError - worker.py: Log job failures with exception details
New test file with 33 tests covering: - validate.py: Schema validation error handling (now 100%) - generator.py: chmod failure handling (now 100%) - optimize.py: Step equality, WaitFor merging, LLM compression (now 99%) - browser_executor.py: Scroll with coords, form input, lifecycle (now 95%) - runner.py: Script execution, data loading, path optimization (now 88%) - extract.py: Number parsing, image/link extraction (now 90%) Overall coverage improved from 94% to 96%.
Add sonar.coverage.exclusions for files that require browser/external services to properly test: browser_pool.py, playwright_explorer.py, mcp_server.py, and telemetry.py. Update pytest-cov omit config to match.
…ration Pass progress_callback through both exploration modes (complete_json and browser_tools) to emit real-time progress with base64 screenshots at each step. Add progress emissions during codegen/execution/extraction phases in the runner for end-to-end progress streaming via MCP. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract _notify_progress and _notify_exploration_progress helpers to reduce nesting in _execute_with_self_healing and _explore_with_complete_json. Extract _run_exploration_step to break up the exploration loop. Add tests for all new helper functions.
- Remove pytest.ini that overrode pyproject.toml, disabling asyncio auto mode and causing async tests to silently return coroutine objects - Merge all markers and settings into pyproject.toml - Add missing await to async calls in test_unified_implementation, test_self_healing_integration, and test_new_actions - Replace broken airport HTTP tests (hitting non-existent localhost server) with mayflower.de Ust-Id Nr extraction test - Delete redundant test_all_airports_pipeline.py - Add missing @pytest.mark.integration to test_regression_parkundride
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
Test plan
make qualitypasses locallymake test-local- 98 tests pass (2 failures require external services)🤖 Generated with Claude Code