Refactor tests and code styling using RUFF and bandit#268
Merged
Conversation
…ed Python 3.9 support
- Updated byte representations in tests to use lowercase hex format for consistency. - Reformatted code for better readability, including line breaks and indentation adjustments. - Consolidated multiple lines into single lines where appropriate to enhance clarity. - Ensured that all test cases maintain consistent formatting and style across the test suite.
…e, and update_endpoints modules
Contributor
There was a problem hiding this comment.
Pull request overview
This PR modernizes the repo’s Python linting/formatting and tightens a few security-related behaviors while reformatting a large portion of the codebase and tests to match the new tooling.
Changes:
- Replaced Black/isort/flake8 pre-commit setup with Ruff (+ Bandit) and added a pytest pre-commit gate plus a GitHub Actions “PR Checks” workflow.
- Applied wide formatting and cleanup changes across tests and runtime code (imports, line wrapping, logging, minor refactors).
- Introduced/adjusted several security-leaning behaviors (e.g., safer subprocess annotations, URL validation, replacing
randomusage withsecretsin a few places).
Reviewed changes
Copilot reviewed 79 out of 88 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_update_endpoints_unit.py | Test refactors/formatting; adjusts mocked URL input. |
| tests/test_tx_lock.py | Formatting-only refactors in async TX lock tests. |
| tests/test_storage_collector_ws_stats_throttle.py | Import ordering cleanup. |
| tests/test_sqlite_handler_easy.py | Adds unit test for MeshCore transport key derivation path; formatting cleanups. |
| tests/test_service_utils.py | Formatting-only updates. |
| tests/test_sensors.py | Formatting-only updates in sensor tests. |
| tests/test_radio_config.py | Formatting-only update. |
| tests/test_path_hash_protocol.py | Import/order cleanup and formatting of path-hash protocol tests. |
| tests/test_path_hash_mode_advert.py | Removes unused mocks import. |
| tests/test_packet_router.py | Formatting-only refactors in router tests. |
| tests/test_packet_duration.py | Formatting-only tweak (operator spacing). |
| tests/test_mqtt_publish_integration.py | Removes unused import + formatting. |
| tests/test_main_py_more.py | Formatting + byte literal normalization. |
| tests/test_main_py_coverage.py | Formatting + byte literal normalization. |
| tests/test_keygen_local_cli.py | Removes unused imports + formatting; byte literal normalization. |
| tests/test_identity_manager_and_repeater_cli.py | Removes unused imports + formatting fixes. |
| tests/test_http_server_unit.py | Formatting + string literal normalization in assertions. |
| tests/test_handler_helpers_trace_discovery_login.py | Formatting-only refactors. |
| tests/test_handler_helpers_room_server.py | Formatting + byte literal normalization. |
| tests/test_handler_helpers_path_protocol_text.py | Formatting + byte literal normalization. |
| tests/test_handler_helpers_mesh_cli.py | Removes unused import + formatting. |
| tests/test_handler_helpers_acl_advert.py | Byte literal normalization + formatting. |
| tests/test_gps_service.py | Formatting-only refactors. |
| tests/test_glass_handler.py | Formatting-only refactors. |
| tests/test_flood_loop_dedup.py | Removes unused imports/constants + formatting/byte literal normalization. |
| tests/test_config_manager.py | Formatting-only update. |
| tests/test_companion_ws_proxy.py | Formatting-only updates. |
| tests/test_companion_bridge_frame_utils.py | Formatting-only updates. |
| tests/test_auth_endpoints.py | Formatting-only updates. |
| tests/test_auth_components.py | Formatting-only updates. |
| tests/test_airtime.py | Formatting-only tweak (operator spacing). |
| scripts/precommit-pytest.sh | Adds a robust pytest runner script for pre-commit. |
| repeater/web/http_server.py | Auth tool registration refactor; formatting and small routing readability changes. |
| repeater/web/companion_ws_proxy.py | Improves teardown exception logging; formatting changes. |
| repeater/web/companion_endpoints.py | Formatting-only change to loop destructuring. |
| repeater/web/cad_calibration_engine.py | Logs exceptions instead of swallowing them; typing cleanup. |
| repeater/web/auth/jwt_handler.py | Whitespace/formatting cleanup. |
| repeater/web/auth/cherrypy_tool.py | Moves tool registration behind an explicit function; formatting cleanup. |
| repeater/web/auth/api_tokens.py | Formatting/whitespace cleanup. |
| repeater/service_utils.py | Adds Bandit suppressions and refactors restart command invocation. |
| repeater/sensors/waveshare_ups_e.py | Formatting/readability refactor in sensor implementation. |
| repeater/sensors/waveshare_ups_d.py | Formatting/readability refactor; expands one-line returns. |
| repeater/sensors/shtc3.py | Formatting/readability refactor. |
| repeater/sensors/registry.py | Formatting-only change to method signature wrapping. |
| repeater/sensors/manager.py | Whitespace cleanup. |
| repeater/sensors/lafvin_ups_3s.py | Formatting/readability refactor; expands one-line returns. |
| repeater/sensors/ens210.py | Formatting-only change; wraps long assignment. |
| repeater/sensors/base.py | Adds package-name validation before pip install; Bandit suppressions; formatting changes. |
| repeater/packet_router.py | Formatting-only cleanup; wraps long conditionals. |
| repeater/main.py | Import reordering and formatting updates; minor log string cleanup. |
| repeater/local_cli.py | Adds HTTP URL validation before urlopen; typing/import cleanup; formatting. |
| repeater/keygen.py | Formatting-only cleanup of comments/spacing. |
| repeater/identity_manager.py | Removes stray blank line/formatting. |
| repeater/handler_helpers/trace.py | Formatting + logging line wrapping. |
| repeater/handler_helpers/text.py | Removes unused imports; formatting; callback lambda refactor. |
| repeater/handler_helpers/room_server.py | Uses secrets for randomized startup delay; formatting. |
| repeater/handler_helpers/repeater_cli.py | Removes unused imports; formatting/whitespace cleanup. |
| repeater/handler_helpers/protocol_request.py | Removes unused import; formatting cleanup. |
| repeater/handler_helpers/path.py | Logging f-string cleanup. |
| repeater/handler_helpers/mesh_cli.py | Removes unused imports; formatting cleanup. |
| repeater/handler_helpers/login.py | Changes default password handling for repeaters; formatting cleanup. |
| repeater/handler_helpers/advert.py | Formatting cleanup + minor readability refactors. |
| repeater/handler_helpers/acl.py | Changes password fields to Optional[str]; formatting cleanup. |
| repeater/engine.py | Uses secrets instead of random; logging improvements; formatting refactors. |
| repeater/data_acquisition/websocket_handler.py | Logs malformed messages instead of swallowing; formatting cleanup. |
| repeater/data_acquisition/storage_collector.py | Removes unused imports; formatting cleanup. |
| repeater/data_acquisition/sqlite_handler.py | Refactors some SQL execution; transport key derivation defaults adjusted; formatting cleanup. |
| repeater/data_acquisition/rrdtool_handler.py | Removes unused typing imports; logging string cleanup. |
| repeater/data_acquisition/mqtt_handler.py | Removes unused imports; formatting cleanup; improves exception logging in a few places. |
| repeater/data_acquisition/hardware_stats.py | Formatting/whitespace cleanup. |
| repeater/data_acquisition/gps_service.py | Formatting-only changes to wrap long lines. |
| repeater/data_acquisition/glass_handler.py | Adds URL validation and tweaks TLS context creation; formatting cleanup. |
| repeater/data_acquisition/init.py | Trailing newline/formatting cleanup. |
| repeater/config.py | Updates defaults (e.g., secure placeholders); formatting cleanup. |
| repeater/config_manager.py | Formatting cleanup; quoting and list literal normalization. |
| repeater/companion/frame_server.py | Formatting-only comment spacing change. |
| repeater/companion/bridge.py | Formatting-only refactor of one call site. |
| repeater/airtime.py | Formatting + small simplification of bandwidth assignment. |
| README.md | Updates dev tooling documentation to reflect Ruff-based workflow. |
| pyproject.toml | Raises minimum Python to 3.9; replaces Black/isort config with Ruff config; adds Ruff dev dependency. |
| debian/control | Bumps declared Python version to >= 3.9. |
| .pre-commit-config.yaml | Replaces Black/isort/flake8 hooks with Ruff + Bandit; adds pytest hook; updates pre-commit-hooks rev. |
| .github/workflows/pr-checks.yml | Adds CI workflow running pre-commit on PRs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+17
to
+19
| _SH_BIN = "/bin/sh" | ||
| _SYSTEMCTL_BIN = "/bin/systemctl" | ||
| _SUDO_BIN = "/usr/bin/sudo" |
Comment on lines
29
to
+33
| if not jwt_handler or not token_manager: | ||
| logger.error("Auth handlers not initialized in cherrypy.config") | ||
| cherrypy.response.status = 500 | ||
| return {"success": False, "error": "Authentication system not configured"} | ||
|
|
Comment on lines
40
to
44
| max_clients: int = 50, | ||
| admin_password: str = "admin123", | ||
| guest_password: str = "guest123", | ||
| admin_password: Optional[str] = None, | ||
| guest_password: Optional[str] = None, | ||
| allow_read_only: bool = True, | ||
| ): |
| # Fallback to a transport-compatible random 16-byte key if derivation fails. | ||
| try: | ||
| random_bytes = secrets.token_bytes(key_length_bytes) | ||
| random_bytes = secrets.token_bytes(16) |
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.
No description provided.