Skip to content

refactor(sonar): extract helpers to reduce main() complexity (python:S3776) - #6

Merged
setchy merged 1 commit into
mainfrom
refactor/extract-live-test-helpers
Oct 8, 2026
Merged

setchy merged 1 commit into
mainfrom
refactor/extract-live-test-helpers

Conversation

@setchy

@setchy setchy commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Summary

SonarCloud issue — python:S3776

python:S3776 flags main() in scripts/test-live.py for a cognitive complexity of 28 (threshold: 15). Sonar's Python analyzer counts the bodies of nested functions toward the enclosing function, so the helper closures defined inside main() (inspect, visible, tray_item, beside_panel, activate, …) were all inflating it.

This PR extracts those helpers to module level, dropping main() to a cognitive complexity of 9 with every extracted helper well under the threshold.

Changes

  • start_gitify(temporary) — launch Gitify against isolated XDG dirs, return (process, log)
  • inspect(process, temporary, probe_name, mutation="") — write and load the KWin probe script
  • visible(...) — first visible Gitify window
  • tray_item(process) / activate_tray(service, path) — StatusNotifier look-up and activation
  • beside_panel(...) / has_8px_gap(frame, panel) — 8px panel-gap placement check
  • inspector_endpoint(temporary) / resize_expression(frame) / resize_window(endpoint, expression) — CDP resize against the inspector

No behavior is changed: same DBus calls, same script, same output, same cleanup in finally.

Rebased onto latest main to pick up chore(sonar): document loopback-only inspector connection (python:S5332) (#7). The moved ws:// regex in inspector_endpoint() keeps the # NOSONAR(S5332) suppression, so the previous "Security Rating on New Code" quality-gate failure is resolved (the insecure-transport rule is expected and documented for the loopback-only DevTools endpoint).

Validation

  • node --check gitify/contents/code/main.js — passes
  • bash -n scripts/install.sh scripts/bundle.sh — passes
  • python3 -m py_compile scripts/test-live.py — passes
  • npm test — 13/13 pass
  • Cognitive complexity re-computed with the cognitive-complexity package: main 9, next highest helper 8 (all ≤ 15)

@setchy
setchy marked this pull request as ready for review October 4, 2026 02:46
@setchy
setchy force-pushed the refactor/extract-live-test-helpers branch from b4bb0b2 to e5ff502 Compare October 8, 2026 13:11
@sonarqubecloud

sonarqubecloud Bot commented Oct 8, 2026

Copy link
Copy Markdown

@setchy
setchy merged commit ff196cd into main Oct 8, 2026
2 checks passed
@setchy
setchy deleted the refactor/extract-live-test-helpers branch October 8, 2026 13:13
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