Skip to content

refactor: clear Sonar code smells in capture, the probe and the FastAPI adapter - #310

Draft
ffroliva wants to merge 1 commit into
mainfrom
refactor/sonar-src-capture
Draft

ffroliva wants to merge 1 commit into
mainfrom
refactor/sonar-src-capture

Conversation

@ffroliva

Copy link
Copy Markdown
Owner

Clears the 20 open SonarCloud code smells in engine/capture/, engine/probe.py, engine/daemon_executor.py and fastapi/ (outside the capture middleware's __call__), without changing behaviour.

  • Cognitive complexity (S3776): activity.py, sqltrace.py, probe.py (validators), introspector.py (providers becomes a _ProviderGraph with three collector methods). Extracted helpers keep the order of checks, messages and outputs. C901 pins in tests/complexity_baseline.json: activity.py 1 → 0, probe.py 2 → 1, introspector.py 1 → 0.
  • run_probe (probe.py) has helpers extracted but stays above Sonar's limit; it may still be reported.
  • S3358 nested conditionals: helpers or early returns. S7496: tuple(dict.fromkeys(...)), the same de-duplication with a stable order. S7632: # noqa: BLE001 # reason.
  • Kept with NOSONAR and the reason:
    • daemon_executor.py broad catch: the future carries the exception, so the worker thread does not die.
    • probe.py asyncio.wait(timeout=): asyncio.timeout() would cancel the task, which must keep running.
    • list() snapshots in fastapi/capture.py and introspector.py: host threads can mutate loggerDict and the route and middleware lists during iteration.
    • exchange_row (17 parameters): it is called from the capture hot path.

sonar-baseline.txt is lowered once the scan reports this pull request's fixed count (after #307).

Verified: ruff check, pyright clean; pytest -n 2 over tests/engine/capture, test_probe.py, tests/fastapi, test_code_shape.py, test_import_boundary.py: 3328 passed, 14 skipped; overhead budget tests alone at -n 0: 30 passed.

…dapter

Extract helpers from the cognitive-complexity hot spots (activity report, SQL
record, probe validation and run, provider discovery), replace nested
conditional expressions with explicit statements, and annotate the deliberate
patterns (worker catch-all, snapshot copies, probe timeout parameter, flat
exchange row signature) with their reason. Pinned C901 counts are lowered.

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>

This branch has not been deployed

No deployments
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.

1 participant