Skip to content

ci: enable ruff EM rules on durable code, ignore in private models#961

Draft
bluetoothbot wants to merge 2 commits into
uilibs:mainfrom
bluetoothbot:koan/fix-issue-957
Draft

ci: enable ruff EM rules on durable code, ignore in private models#961
bluetoothbot wants to merge 2 commits into
uilibs:mainfrom
bluetoothbot:koan/fix-issue-957

Conversation

@bluetoothbot

@bluetoothbot bluetoothbot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Enables the ruff EM family (EM101/EM102) so exceptions raised across durable/public code extract their message into a variable, while per-file-ignoring the three private device-model files slated for removal in the public-API migration to avoid churning dying code.

Closes #957

Changes

  • Add EM to [tool.ruff.lint] select; per-file-ignore EM101/EM102 for data/devices.py, data/nvr.py, data/user.py (private models) and for tests/** (inline messages are fine in assertions).
  • Autofix message extraction across src/uiprotect/ and scripts/ (mechanical — msg = …; raise X(msg)).
  • Keep two defensive branches inline with # noqa (base.py .api, stream.py run_until_complete) — mypy reports the extracted msg = line as unreachable there.
  • Add tests covering the now two-line raise paths (device adopt/unadopt/reboot permission errors, read-only save guard, get_field_type, ModelType immutability, WS frame encoding, profile_ws, CLI relative_datetime); mark genuinely-unreachable guards # pragma: no cover.

Test plan

  • ruff check green across src/, tests/, scripts/.
  • bin/run-mypy introduces no new errors (message-extraction only).
  • poetry run pytest green; new error-path tests give 100% patch coverage on the diff (no changed/added line shows as missing in term-missing).
  • No behavioral changes — message-extraction only.

Quality Report

Changes: 15 files changed, 407 insertions(+), 100 deletions(-)

Code scan: clean

Tests: failed (FAILED)

Branch hygiene: clean

Generated by Kōan

Add the EM family (EM101/EM102) to the ruff select. Private device-model
files slated for removal in the public-API migration (data/devices.py,
data/nvr.py, data/user.py) are per-file-ignored to avoid churn; tests get
the same ignore since inline messages are fine in assertions.

Autofix extracts exception messages into a msg variable across durable
src/ and scripts/. Two defensive branches (base.py .api, stream.py
run_until_complete) keep inline messages with a noqa because mypy reports
the extracted msg= line as unreachable.

Cover the newly two-line raise paths with tests for the device adopt/
unadopt/reboot permission errors, read-only save guard, type helpers,
WS frame encoding, profiling, and CLI datetime parsing; genuinely
unreachable guards are marked no cover.
@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 20f3b2de-b635-4a70-84f7-35646fbce0df

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codspeed-hq

codspeed-hq Bot commented Jun 7, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 4 untouched benchmarks


Comparing bluetoothbot:koan/fix-issue-957 (c8bb404) with main (16f0cfe)

Open in CodSpeed

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.

Tier 3 (#872): enable ruff EM (public/durable code) + ignore in private models

1 participant