Skip to content

Refactor tests and code styling using RUFF and bandit#268

Merged
rightup merged 8 commits into
devfrom
refactor-add-fuff-bandit
May 27, 2026
Merged

Refactor tests and code styling using RUFF and bandit#268
rightup merged 8 commits into
devfrom
refactor-add-fuff-bandit

Conversation

@rightup
Copy link
Copy Markdown
Collaborator

@rightup rightup commented May 27, 2026

No description provided.

rightup added 7 commits May 27, 2026 14:27
- 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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 random usage with secrets in 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 thread repeater/service_utils.py Outdated
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)
@rightup rightup merged commit 723e912 into dev May 27, 2026
1 check passed
@rightup rightup deleted the refactor-add-fuff-bandit branch May 27, 2026 21:14
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