Skip to content

fix: Sonar follow-ups — ModuleDeps ordering, Express dead code, RepositoryIdentity env#60

Merged
aksOps merged 3 commits into
mainfrom
fix/sonar-followups
Apr 23, 2026
Merged

fix: Sonar follow-ups — ModuleDeps ordering, Express dead code, RepositoryIdentity env#60
aksOps merged 3 commits into
mainfrom
fix/sonar-followups

Conversation

@aksOps

@aksOps aksOps commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Changes (one commit each)

fix(detector): ModuleDepsDetector reaches settings.gradle branch

Real bug — .endsWith(".gradle") matched settings.gradle first, shadowing detectGradleSettings. Gradle multi-module include ':foo' entries were silently lost. Reordered the dispatch chain so the settings branch is evaluated before the generic .gradle branch. Added ModuleDepsDetectorTest (9 tests) to lock in the reachability contract plus a regression guard that build.gradle still routes to detectGradle.

refactor(detector): remove dead detectWithAst from ExpressRouteDetector

AbstractTypeScriptDetector#detect() unconditionally dispatches to detectWithRegex, and the detector is annotated @DetectorInfo(parser = REGEX), so the protected detectWithAst override (and its three private ANTLR helpers: extractIdentifierText, extractFirstStringArg, extractStringLiteral) was never invoked. Deleted the dead method, helpers, and the now-orphaned ANTLR / JavaScriptParser imports. All 28 existing ExpressRoute* tests stay green. (Verified the Python detectors' own extractFirstStringArg has a distinct signature and is unaffected.)

fix(test): RepositoryIdentityTest no longer depends on local git state

Root cause: the two failing tests (resolve_gitRepoWithCommit_commitShaPresent, resolve_detachedHead_branchIsNull) inherit the developer's global commit.gpgsign=true and fail silently when no signing key is available — the run() helper was ignoring non-zero exit codes, so git commit produced no commit and rev-parse HEAD returned null. Fix: inject repo-local config that disables GPG signing, hooks, autocrlf, and template dir; add --no-gpg-sign on the commit; scrub GIT_* env vars on every child; assert non-zero exit codes loudly (silent failures become loud failures); assumeTrue skip when git binary is absent. Verified by running the pre-fix test under a hostile HOME with forced GPG signing — reproduces the exact 2 failures; post-fix: 8/8 pass.

(skipped) chore: remove 4 unused private fields

No-op on current main: MODEL_INIT_RE, BATCH_MAPPING_RE, PROP_REQUESTMAPPING, and ENTITY_RE were already removed by merged PR #58 (chore(sonar): clean unused imports, suppressions, and private members, commit eaea1ff). Verified via grep in src/main — zero hits. No commit needed.

Test count: 3294 → 3303, all green (31 pre-existing env-gated E2E skips).

*/
private static void requireGit() {
try {
Process p = new ProcessBuilder("git", "--version")
aksOps and others added 3 commits April 23, 2026 15:09
The dispatch chain in detect() checked `.endsWith(".gradle")` before the
settings-specific branch, so any `settings.gradle` / `settings.gradle.kts`
path routed to detectGradle() and the specialised detectGradleSettings()
helper was never reached. Gradle multi-module `include ':foo'` entries
were silently lost.

Reordered the dispatch so settings files are matched first, and added
ModuleDepsDetectorTest to lock in the reachability contract (plus a
regression guard that `build.gradle` still routes to detectGradle).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
AbstractTypeScriptDetector#detect() unconditionally dispatches to
detectWithRegex, and the class is annotated @DetectorInfo(parser = REGEX),
so the protected detectWithAst override (and its three private ANTLR
helper methods: extractIdentifierText, extractFirstStringArg,
extractStringLiteral) were never invoked.

Removed the AST method + helpers and their now-orphaned ANTLR /
JavaScriptParser imports. The Python detectors define their own
extractFirstStringArg with a distinct signature — unaffected.

All 28 ExpressRoute* tests remain green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The two git-backed tests (resolve_gitRepoWithCommit_commitShaPresent,
resolve_detachedHead_branchIsNull) failed when the developer's global
gitconfig forced commit signing (commit.gpgsign=true, signingkey set) on
a machine without a usable signing key — git commit exited non-zero, the
original run() helper ignored the exit code, no commit was made, and
rev-parse HEAD returned null.

Made the git invocations hermetic:
  * repo-local config overrides commit.gpgsign / tag.gpgsign to false,
    unsets core.hooksPath, core.autocrlf, init.templateDir
  * explicit --no-gpg-sign on the commit (belt-and-braces)
  * scrub GIT_* env vars on every child process so no ambient CI /
    worktree state leaks in
  * run() now asserts the process exited 0 — silent failures become
    loud test failures
  * new requireGit() uses Assumptions.assumeTrue to skip cleanly when
    the git binary is absent (product still covered by non-git tests +
    RepositoryIdentity's own swallow-on-error path)

Verified by running the pre-fix test against a hostile HOME with forced
GPG signing — reproduces the 2 failures. Post-fix: 8/8 pass under the
same hostile environment.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@aksOps aksOps force-pushed the fix/sonar-followups branch from 92fd0de to 5646a92 Compare April 23, 2026 15:10
@sonarqubecloud

Copy link
Copy Markdown

@aksOps aksOps merged commit bfab2e7 into main Apr 23, 2026
9 checks passed
@aksOps aksOps deleted the fix/sonar-followups branch April 26, 2026 05:52
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.

2 participants