Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PR 19 Sonar quality gate restoration

  • Status: Accepted
  • Date: 2026-04-12
  • Context:
    • PR 19’s SonarCloud quality gate failed on new-code security and duplication metrics even though the remaining non-Sonar CI checks were green.
    • The security failure came from unit tests in crates/revaer-test-support/src/postgres.rs that embedded Postgres credentials in parsed fixture URLs.
    • The duplication spike came from Rust test modules added in this branch, including crate-level tests/ trees and in-source tests.rs modules that Sonar was still treating as duplication-sensitive source files.
  • Decision:
    • Remove credentials from the postgres.rs fixture URLs because those tests only exercise database-path rewriting and do not need authentication fields.
    • Exclude Rust test modules from Sonar copy-paste detection in sonar-project.properties while keeping production Rust sources, workflows, and first-party application code inside the gate.
    • Record the Sonar-scoping rule in the Sonar instruction file so future changes preserve the same production-focused quality signal.
  • Consequences:
    • Positive outcomes:
      • Sonar no longer flags fixture URLs as hardcoded database passwords on new code.
      • PR duplication metrics stop being dominated by intentionally repetitive Rust test setup and assertion fixtures.
      • The Sonar gate remains strict on production code while matching Revaer’s library-first testing layout.
    • Risks or trade-offs:
      • Sonar will no longer report copy-paste findings inside excluded Rust test modules, so test-duplication hygiene relies on code review and local maintenance discipline instead of the PR gate.
  • Follow-up:
    • Implementation tasks:
      • Keep new Rust test-only paths added under src/**/tests* or crate-level tests/ aligned with the Sonar duplication exclusions when repository layout changes.
    • Review checkpoints:
      • Re-run the required local validation gates and let the PR’s SonarCloud analysis refresh on the pushed commit.

Task Record

  • Motivation:
    • The user asked to restore PR 19’s Sonar quality standards after the gate regressed to E security rating and 4.1% duplication on new code.
  • Design notes:
    • The postgres.rs tests now use password-free fixture URLs because the behavior under test only depends on path replacement and admin-database fallback handling.
    • sonar.cpd.exclusions now explicitly covers Rust test modules in both crate-level tests/ directories and in-source tests.rs or *_tests.rs files, which matches how this repository colocates test code.
    • The Sonar instruction file now documents that policy so future scope changes do not accidentally reintroduce test-only duplication into the gate.
  • Test coverage summary:
    • cargo test -p revaer-test-support postgres
    • just ci
    • just ui-e2e
  • Observability updates:
    • None. No runtime logging, tracing, metrics, or health behavior changed.
  • Status-doc validation:
    • No README or operator guide changes were required because this work only touches tests, Sonar scope, and ADR/policy documentation.
  • Risk & rollback plan:
    • Risk is limited to Sonar PR analysis scope and unit-test fixture strings.
    • Rollback is a straightforward revert of this commit if Sonar scoping needs to be reconsidered.
  • Dependency rationale:
    • No new dependencies were added.
  • Stale-policy check:
    • Reviewed:
      • AGENTS.md
      • .github/instructions/devops.instructions.md
      • .github/instructions/sonarqube_mcp.instructions.md
      • sonar-project.properties
      • docs/adr/template.md
    • Drift found:
      • sonar-project.properties excluded selected TypeScript/API duplication noise but not Rust test modules, even though this repository colocates substantial test-only code under source trees.
      • crates/revaer-test-support/src/postgres.rs used credential-bearing fixture URLs in tests that do not require authentication semantics.
    • Contradictions removed:
      • None.