[hermes] metis: go:S3776 #4

Open
opened 2026-08-11 01:22:44 +00:00 by bstein · 0 comments
Owner

SonarQube reports go:S3776 in pkg/sentinel/collector.go. The build is green; this is a standing finding, not a failure.

What is wrong

The cognitive complexity is mainly due to nested conditionals and loops inside collectUSBScratch, especially the bind‑target health checks and the multiple device resolution steps.

Ariadne opened no pull request for it: no automated patch was possible for this finding.

Facts

  • gitea — Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. (CRITICAL, 7min estimated) (pkg/sentinel/collector.go:131)

Suggested fix (not applied)

Hermes could not open a pull request for this, so the change below was not written, validated, or pushed anywhere. It is a starting point for whoever picks this up, not a reviewed patch.

pkg/sentinel/collector.go — Extract the bind‑target health loop and related state updates into a helper function to flatten collectUSBScratch. This reduces nesting and keeps the original logic intact.

// helper to evaluate bind targets and return slice and overall healthy flag
func processBindTargets(desired *usbScratchConfig, scratch *facts.USBScratch) (bool, []facts.USBBindTarget) {
    var bTargets []facts.USBBindTarget
    healthy := true
    for _, target := range desired.BindTargets {
        ok := bindHealthy(target, desired.Mountpoint)
        if !ok {
            healthy = false
        }
        bTargets = append(bTargets, facts.USBBindTarget{Path: target, Healthy: ok})
    }
    return healthy, bTargets
}

// In collectUSBScratch replace the original bind‑target loop and flags:
//    if len(desired.BindTargets) > 0 {
//        scratch.BindTargets = make([]facts.USBBindTarget, 0, len(desired.BindTargets))
//        for _, target := range desired.BindTargets { … }
//        scratch.BindHealthy = healthy
//    } else {
//        scratch.BindHealthy = true
//    }
// with:
//    healthy, bTargets := processBindTargets(desired, scratch)
//    scratch.BindTargets = bTargets
//    scratch.BindHealthy = healthy
// This reduces nested nesting and keeps behavior identical.

Filed automatically by Ariadne from a Hermes Agent diagnosis (run run_213c42165ee74502b1b579125e93d9c8). Hermes has no write access to this repository; no files or infrastructure were changed.

SonarQube reports **go:S3776** in `pkg/sentinel/collector.go`. The build is green; this is a standing finding, not a failure. ## What is wrong The cognitive complexity is mainly due to nested conditionals and loops inside collectUSBScratch, especially the bind‑target health checks and the multiple device resolution steps. Ariadne opened no pull request for it: no automated patch was possible for this finding. ## Facts - **gitea** — Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. (CRITICAL, 7min estimated) (`pkg/sentinel/collector.go:131`) ## Suggested fix (not applied) Hermes could not open a pull request for this, so the change below was not written, validated, or pushed anywhere. It is a starting point for whoever picks this up, not a reviewed patch. **`pkg/sentinel/collector.go`** — Extract the bind‑target health loop and related state updates into a helper function to flatten collectUSBScratch. This reduces nesting and keeps the original logic intact. ``` // helper to evaluate bind targets and return slice and overall healthy flag func processBindTargets(desired *usbScratchConfig, scratch *facts.USBScratch) (bool, []facts.USBBindTarget) { var bTargets []facts.USBBindTarget healthy := true for _, target := range desired.BindTargets { ok := bindHealthy(target, desired.Mountpoint) if !ok { healthy = false } bTargets = append(bTargets, facts.USBBindTarget{Path: target, Healthy: ok}) } return healthy, bTargets } // In collectUSBScratch replace the original bind‑target loop and flags: // if len(desired.BindTargets) > 0 { // scratch.BindTargets = make([]facts.USBBindTarget, 0, len(desired.BindTargets)) // for _, target := range desired.BindTargets { … } // scratch.BindHealthy = healthy // } else { // scratch.BindHealthy = true // } // with: // healthy, bTargets := processBindTargets(desired, scratch) // scratch.BindTargets = bTargets // scratch.BindHealthy = healthy // This reduces nested nesting and keeps behavior identical. ``` ## Links - SonarQube finding: https://quality.bstein.dev/project/issues?resolved=false&id=metis&open=AZ2z_XbbKy9i4pkIqvM9 - Full evidence bundle and audit trail live in Ariadne at `/api/admin/audit/events`, event types `hermes_autotriage_incident` and `hermes_autotriage_diagnosis`. Filed automatically by Ariadne from a Hermes Agent diagnosis (run [run_213c42165ee74502b1b579125e93d9c8](https://triage.hermes.bstein.dev/chat?resume=run_213c42165ee74502b1b579125e93d9c8)). Hermes has no write access to this repository; no files or infrastructure were changed. <!-- hermes-triage job=metis classification=go:S3776 incident=sonar/metis/go:S3776/AZ2z_XbbKy9i4pkIqvM9 -->
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: titan/metis#4
No description provided.