Repository navigation
style: adopt the shared ruff standard - #358
Conversation
- ruff: add S (bandit) and G (logging format); tests ignore S101 only; D (Google convention) now also applies to tests, docs and examples. - mypy: as in cloud-registry, check the package and the tests (files in pyproject.toml; CI runs plain mypy), with disallow_untyped_defs, disallow_any_generics and warn_unused_ignores. - Ignore the reformat with line length 88 (#353) in git blame. Refs #344 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Log with lazy %-style arguments instead of f-strings (G004); messages are unchanged. - Parametrize generic types and annotate the remaining functions (disallow_any_generics, disallow_untyped_defs). - Justify the default host 0.0.0.0 (S104) and a false positive for the invalid_token description (S105) inline. Refs #344 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Type and document the tests and examples for the shared ruff standard and strict mypy. Logger mocks format the lazy %-style arguments, the integration tests set request timeouts (S113), and deliberately invalid arguments carry type: ignore with error codes. No test was added or removed. Refs #344 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Give every type: ignore a reason and noqa comments their reason in parentheses, as elsewhere in FOCA; list error codes without spaces. - Define the invalid_token challenge and the type of the in-memory MongoDB clients once in tests/mock_data.py. Refs #344 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Use the MongoClients alias in the remaining tests and give the F401 noqa comments of re-exports their reason. Refs #344 Co-Authored-By: Claude Opus 5.5 <[email protected]>
semgrep's logger-credential-disclosure rule flags the debug message about validated tokens, which now uses lazy arguments; it logs the issuer and subject only, not the token. Refs #344 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThis PR applies the shared ELIXIR Cloud & AAI Ruff standard and strict package/test mypy configuration across the repository, then updates production code, examples, fixtures, mocks, and tests to satisfy those checks without changing application behavior; integration-test requests additionally gain finite timeouts. Flow diagram for the updated quality checksflowchart TD
Config[pyproject.toml shared Ruff and mypy settings] --> RuffRules[Ruff rules: B C4 D E F G I PL RUF S SIM UP W]
Config --> MypyRules[Strict mypy: foca and tests]
RuffRules --> SourceUpdates[Typed code, lazy logging, docstrings, justified ignores]
MypyRules --> SourceUpdates
SourceUpdates --> Validation[ruff, mypy, tests, documentation build]
Validation --> Result[Behavior unchanged; integration requests have timeouts]
File-Level Changes
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 #358 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 24 24
Lines 1786 1797 +11
=========================================
+ Hits 1786 1797 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/config/test_config_parser.py" line_range="300" />
<code_context>
-def test_no_flask_config_logged(monkeypatch):
+def test_no_flask_config_logged(monkeypatch: pytest.MonkeyPatch) -> None:
"""The Flask config, including secrets, is not logged."""
messages: list[str] = []
</code_context>
<issue_to_address>
**Secret logging goes undetected**
When the factory logs each app's Flask config during creation, in `test_no_flask_config_logged`, line 304 creates an app before line 305 adds `SECRET_KEY`, and line 306 creates a second app with a fresh `Config`; the assertion at line 307 therefore passes even if each app's config is logged, leaving a secret leak undetected.
Set the secret in the configuration before calling the factory, then assert it is absent from the captured logs.
</issue_to_address>
### Comment 2
<location path="tests/security/test_auth.py" line_range="179" />
<code_context>
+ monkeypatch.setattr(
+ auth.logger,
+ "debug",
+ lambda msg, *args: messages.append(msg % args),
+ )
token = make_token(email="[email protected]", name="Alice A.")
</code_context>
<issue_to_address>
**Missing token logs go undetected**
When `validate_token` emits no debug message, in `test_no_claims_logged`, the assertions at lines 185-186 only check that sensitive values are absent from the captured messages; an empty message list passes, so removing the validated-token debug log goes unnoticed.
Assert that the expected issuer and subject appear in the captured log, in addition to checking that sensitive values do not.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: tests/config/test_config_parser.py:300, tests/security/test_auth.py:179
The test set SECRET_KEY after the app was created, so it could not catch a logged Flask config. Check instead that no key of the created app's Flask config appears in the factory's debug messages, and that those messages were captured at all. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add docstrings and return types to the chart tests and justify the subprocess call, as the shared ruff standard (#358) requires. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Closes #344 (part 2; part 1, the reformat with line length 88, is #353)
S(bandit) andG(logging format). Onlytests/**ignoresS101(assert), andD(Google convention) now applies to tests, docs and examples too. The rules are nowB C4 D E F G I PL RUF S SIM UP Wwith FOCA's documented ignores.files = ["foca", "tests"], withdisallow_untyped_defs,disallow_any_genericsandwarn_unused_ignores; CI runs plainmypy. Examples are covered by ruff only, because mypy cannot check the two example apps together (both have top-levelapp/controllersmodules)..git-blame-ignore-revs: lists the squash commit of style: reformat with line length 88 #353 (8dfb0ca), which contains formatting only.0.0.0.0default host (S104) and a false positive on theinvalid_tokendescription (S105) are justified inline.type: ignore[<code>]with a reason.tests/mock_data.py.Behaviour is unchanged, apart from the request timeouts in the integration tests.
Release notes (0.16.0): none for users (internal style and type-checking change). Optionally: "FOCA now lints with the shared ruff standard of ELIXIR Cloud & AAI apps and is fully type-checked (package and tests)."
Verification
ruff check,ruff format --check: passmypy(68 files, package and tests, strict): no issuesmkdocs build --strict: passfoca: 100%type: ignore/noqa). Round 2: the adversarial review found nothing; the quality review found a medium (three tests still spelled out the client type), now fixed, and two lows: F401 re-export reasons were added, and a duplicated comment incelery_app.pypredates this PRlogger-credential-disclosureon the debug message about validated tokens (logs issuer and subject only) is suppressed inlineDeclined review findings
clientsfixtures intests/database/test_register_mongodb.pyandtests/security/access_control/test_register_casbin_enforcer.py: they predate this PR; removing them is test refactoring outside style: adopt the shared ruff standard #344.ContextTaskinfoca/factories/celery_app.py: predates this PR.test_no_claims_loggedpasses on an empty log (tests/security/test_auth.py): it does not; the test already asserts that the issuer/subject message is logged. (Sourcery's other finding, ontest_no_flask_config_logged, is fixed in f8149db.)Open questions
None.
🤖 Generated with Claude Code