Skip to content

refactor: reduce SonarQube cognitive complexity - #11

Merged
Jonathan0823 merged 2 commits into
masterfrom
refactor/sonar-complexity
Aug 21, 2026
Merged

Jonathan0823 merged 2 commits into
masterfrom
refactor/sonar-complexity

Conversation

@Jonathan0823

@Jonathan0823 Jonathan0823 commented Aug 21, 2026 •

Copy link
Copy Markdown
Owner

Related issue

  • SonarQube cognitive-complexity findings in authentication refresh and platform configuration validation.

Summary

  • Extract refresh-token transaction handling to reduce service complexity.
  • Split configuration validation into focused helpers.
  • Add coverage for configuration validation edge cases.

Scope

  • In scope: behavior-preserving refactoring and tests.
  • Out of scope: authentication policy changes, rate-limit behavior, migrations, and dependency changes.

Testing

  • go test ./...
  • go vet ./...
  • gofmt
  • git diff --check
  • Coverage-focused tests; local coverage reached 65.2%.

Reviewer focus

  • Refresh-token rotation, replay detection, and transaction behavior remain unchanged.
  • Configuration validation order and error messages remain unchanged.

Risks

  • Low; changes are limited to extracting existing logic and adding tests.

Summary by CodeRabbit

  • Bug Fixes

    • Improved token refresh processing and error handling while preserving token rotation, revocation, and account validation behavior.
    • Strengthened configuration validation for environment settings, allowed origins, OAuth credentials, production secrets, and rate-limit options.
    • Invalid or incomplete configuration now fails with clearer validation errors.
  • Tests

    • Added coverage for invalid environments, missing allowed origins, incomplete OAuth settings, and valid production rate-limit configurations.

@coderabbitai

coderabbitai Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b807bb10-93e7-4da1-966b-321b900939ae

📥 Commits

Reviewing files that changed from the base of the PR and between eca131c and f7f8539.

📒 Files selected for processing (3)
  • internal/core/service/auth.go
  • internal/platform/config.go
  • internal/platform/config_test.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change extracts refresh-token transaction handling and configuration validation into dedicated helpers. Configuration tests add coverage for invalid environment values, nil allowed origins, partial OAuth settings, and production memory rate limiting.

Changes

Refresh-token flow

Layer / File(s) Summary
Refresh-token transaction handling
internal/core/service/auth.go
refreshTokensInTransaction returns tokens, reuse status, and errors. RefreshTokens handles transaction errors and maps reused tokens to ErrRefreshTokenReused with an unauthenticated error.

Configuration validation

Layer / File(s) Summary
Configuration validation helpers and coverage
internal/platform/config.go, internal/platform/config_test.go
Config.Validate delegates origin, required-setting, OAuth, and production-secret checks to helpers. Tests cover invalid environments, nil allowed origins, partial Google settings, and production memory rate limiting.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to f7f85

This refactoring is merge-ready after normal checks and review; no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main refactoring objective: reducing SonarQube cognitive complexity in authentication and configuration validation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/sonar-complexity

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.

@Jonathan0823
Jonathan0823 merged commit a4e4dd0 into master Aug 21, 2026
11 checks passed
@Jonathan0823
Jonathan0823 deleted the refactor/sonar-complexity branch August 21, 2026 03:19
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