Repository navigation
style: adopt the shared ruff rule set - #162
Conversation
Lint with the rule set shared with FOCA (B C4 D E F G I PL RUF S SIM UP W), ignoring FOCA's complexity limits and magic-value comparisons, each with its reason. Fix the new findings: single with statements, no reassigned loop variables, unpacking instead of list concatenation, and fullwidth digits in a test written as escapes. Describe the rules in the contributing guide. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Instead of suppressing mypy's optional-type errors, check the values: problem() rejects exceptions without a code or description, operations that need the request's subject raise Unauthorized without one, and the API base path requires a request routed through an API's blueprint. Behavior is unchanged for requests the API handles. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Requests without a subject no longer look up the subject "<prefix>None", which a user with that identifier could match; only their groups count. Also from the reviews: say how the rule set differs from FOCA's and why tests may assert, test all operations that require a subject and both cases of problem() without a code or description, match the error of the API base path, and list the Git options of the version test once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Grant the role admin to the user None in the test of requests without a subject, which passed with the previous is_admin(), too. Also rename the test of incomplete exceptions, avoid shadowing in is_admin(), and tidy the wording of the ruff comments. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR adopts the shared Ruff configuration and brings the codebase into compliance through targeted, behavior-preserving fixes. It also removes all Python type: ignore comments by adding explicit validation for incomplete exceptions, unauthenticated subjects, and non-API requests, with tests covering the new error paths and the corrected admin edge case. Sequence diagram for explicit authentication checkssequenceDiagram
participant Client
participant Permissions
participant Auth
participant Registry
Client->>Permissions: add_owner(serviceId)
Permissions->>Auth: get_current_subject()
alt subject is missing
Auth-->>Permissions: None
Permissions-->>Client: Unauthorized
else subject is present
Auth-->>Permissions: user_id
Permissions->>Registry: add_resource_role(user_id, owner)
Registry-->>Client: success
end
Sequence diagram for validated problem responsessequenceDiagram
participant Handler
participant Exceptions
participant Response
Handler->>Exceptions: problem(exc)
alt code or description is missing
Exceptions-->>Handler: ValueError
else exception is complete
Exceptions->>Response: _response(title, status, detail)
Response-->>Handler: Problem details response
end
Flow diagram for API base path validationflowchart LR
Request["Current request"] --> Blueprint{"request.blueprint is set?"}
Blueprint -->|No| RuntimeError["Raise RuntimeError"]
Blueprint -->|Yes| BasePath["Return blueprint URL prefix"]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #162 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 11 11
Lines 868 880 +12
=========================================
+ Hits 868 880 +12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_exceptions.py" line_range="131" />
<code_context>
+
+
[email protected](
+ "exc", [HTTPException(), _NoDescription()], ids=["no_code", "no_description"]
+)
+def test_problem_incomplete_exception(exc: HTTPException) -> None:
</code_context>
<issue_to_address>
**No-code exceptions evade test**
When the code check in `problem()` is removed while the description check remains, `test_problem_incomplete_exception` line 131 uses `HTTPException()` with both `code` and `description` absent, so a description-only check still raises `ValueError` and the test passes even though a no-code exception with a description would be accepted.
Give the no-code test case a nonempty description so it verifies that a missing code alone raises `ValueError`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and requests without a subject now receive Unauthorized for owner-management and getMe operations, and a missing subject can no longer match an admin role named with None. If that behavior is wrong, it can deny access to those operations; reverting restores the previous behavior, and the diff does not introduce an irreversible side effect.
Blocking findings: tests/test_exceptions.py:131
So that the test fails if problem() checks only the description (review finding of Sourcery). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
This PR adopts the ruff standard decided for all repos, so FOCA and its apps lint the same way.
[tool.ruff.lint]selectsB C4 D E F G I PL RUF S SIM UP W, which is FOCA's set plusGandS.Dapplies everywhere, including tests and the docs hooks. Line length stays 88.PLR0912,PLR0913,PLR0915,PLR0917) andPLR2004(HTTP status codes and other literals).B010isn't needed.S101in tests now has a reason too.SIM117: singlewithstatements intest_server.pyPLW2901: no reassigned loop variables indocs/hooks.pyandtest_app.pyRUF005: unpacking instead of list concatenation intest_chart.py, and aGIT_CONFIGlist intest_version.pyRUF001: fullwidth digits intest_utils.pywritten as escapestype: ignorecomments by adding explicit checks:exceptions.problem()raisesValueErrorfor exceptions without a code or description. All callers pass werkzeug exceptions that have both.permissions._require_subject()raisesUnauthorizedwithout a subject (inadd_owner,remove_owner,getMe)._api_base_path()raisesRuntimeErrorfor requests that aren't routed through an API blueprint; this was aKeyErrorbefore, and both end as a500.noqa: S108ingunicorn_config.pystays.is_admin()without a subject no longer checks the subject<prefix>None. Before, if a user namedNonewas an admin, requests without a subject counted as admin. There is a test for this.docs/contributing.mddescribes the rule set and prefers explicit checks to suppressions.Behaviour notes (edge cases only):
security.access_control.claim_identityto a claim its tokens lack,POST /servicesnow returns401instead of400(FOCA's "Subjects must not be empty"), andGET /mereturns401instead of looking up<prefix>None. The default config doesn't hit this, as FOCA's auth requires the identity claim.mypy compared with FOCA (for the FOCA follow-up "adopt the shared ruff standard"): cloud-registry checks
files = [cloud_registry, docs/hooks.py, tests]withdisallow_untyped_defs,disallow_any_genericsandwarn_unused_ignores, and ignores missing imports per module (Connexion, Gunicorn). FOCA sets onlyignore_missing_imports = trueglobally. FOCA also uses line length 79 and excludesDfor docs, examples and tests.Closes #149
Verification
coverage run --source=cloud_registry -m pytest -p no:warnings(with Helm): 766 passed; coverage 100%ruff check .(ruff 0.17.1, as pinned in pre-commit),ruff format --check .,mypy,ast-grep scan: passmkdocs build --strict: passgit grep "type: ignore" -- '*.py': no matchesDeclined review findings
exc.code or 500inproblem()instead of raising. Declined: an explicit error is preferred to a silent default, and production callers always pass complete exceptions.adapted/declaredrenames add indirection. Kept, since they are the minimal PLW2901 fixes.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Adopt the shared Ruff standard while replacing type suppressions with explicit validation and correcting authentication edge cases.
Bug Fixes:
Noneand return explicit authentication errors for protected operations.Enhancements:
Documentation:
Tests:
None-named user, invalid problem exceptions, and API base-path access outside an API request.