[hermes] metis: go:S3776 #210

Open
opened 2026-09-28 03:31:23 +00:00 by hermes-automation · 0 comments

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

What is wrong

collectUSBScratch mixes three independent concerns (mount health, device identity via blkid, and bind-target health) in one method, and the accumulated nested ifs and loop push its cognitive complexity to 17. Extracting each concern into a small helper keeps the exact same behaviour while dropping the method well under the threshold.

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 — Replace the body of collectUSBScratch with three sequential helper calls, moving the mount-health block, the device/blkid block (with device resolution order source -> UUID -> label preserved), and the bind-target loop into dedicated functions. Each helper performs exactly the statements the original method did, in the same order and with the same conditions, so the produced facts.USBScratch is identical; only the complexity accounting changes because the nesting now lives in small single-purpose functions.

func collectUSBScratch() *facts.USBScratch {
	cfg, ok := loadNodeConfig()
	if !ok || cfg.USBScratch == nil {
		return nil
	}
	desired := cfg.USBScratch
	scratch := &facts.USBScratch{
		Mountpoint: desired.Mountpoint,
		UUID:       desired.UUID,
		Label:      desired.Label,
		FS:         desired.FS,
	}

	source := applyMountFacts(scratch, desired)
	applyDeviceFacts(scratch, desired, source)
	applyBindFacts(scratch, desired)
	return scratch
}

func applyMountFacts(scratch *facts.USBScratch, desired *usbScratchConfig) string {
	source, fsType, mounted := mountInfo(desired.Mountpoint)
	scratch.MountHealthy = mounted && strings.TrimSpace(source) != ""
	if scratch.MountHealthy && desired.FS != "" && fsType != "" {
		scratch.MountHealthy = strings.EqualFold(fsType, desired.FS)
	}
	if scratch.FS == "" && fsType != "" {
		scratch.FS = fsType
	}
	return source
}

func applyDeviceFacts(scratch *facts.USBScratch, desired *usbScratchConfig, source string) {
	device := resolveDevice(desired, source)
	if device == "" {
		return
	}
	export := blkidExport(device)
	if desired.UUID != "" {
		scratch.UUIDHealthy = export["UUID"] == desired.UUID
	}
	if desired.Label != "" {
		scratch.LabelHealthy = export["LABEL"] == desired.Label
	}
	if scratch.FS == "" {
		scratch.FS = export["TYPE"]
	}
}

func resolveDevice(desired *usbScratchConfig, source string) string {
	device := source
	if device == "" && desired.UUID != "" {
		device = resolveDeviceByUUID(desired.UUID)
	}
	if device == "" && desired.Label != "" {
		device = resolveDeviceByLabel(desired.Label)
	}
	return device
}

func applyBindFacts(s
... (truncated)

Filed automatically by Ariadne from a Hermes Agent diagnosis (run run_48ec45dee2f341e4b202aa4beabfb6d7). 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 collectUSBScratch mixes three independent concerns (mount health, device identity via blkid, and bind-target health) in one method, and the accumulated nested ifs and loop push its cognitive complexity to 17. Extracting each concern into a small helper keeps the exact same behaviour while dropping the method well under the threshold. 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`** — Replace the body of collectUSBScratch with three sequential helper calls, moving the mount-health block, the device/blkid block (with device resolution order source -> UUID -> label preserved), and the bind-target loop into dedicated functions. Each helper performs exactly the statements the original method did, in the same order and with the same conditions, so the produced facts.USBScratch is identical; only the complexity accounting changes because the nesting now lives in small single-purpose functions. ``` func collectUSBScratch() *facts.USBScratch { cfg, ok := loadNodeConfig() if !ok || cfg.USBScratch == nil { return nil } desired := cfg.USBScratch scratch := &facts.USBScratch{ Mountpoint: desired.Mountpoint, UUID: desired.UUID, Label: desired.Label, FS: desired.FS, } source := applyMountFacts(scratch, desired) applyDeviceFacts(scratch, desired, source) applyBindFacts(scratch, desired) return scratch } func applyMountFacts(scratch *facts.USBScratch, desired *usbScratchConfig) string { source, fsType, mounted := mountInfo(desired.Mountpoint) scratch.MountHealthy = mounted && strings.TrimSpace(source) != "" if scratch.MountHealthy && desired.FS != "" && fsType != "" { scratch.MountHealthy = strings.EqualFold(fsType, desired.FS) } if scratch.FS == "" && fsType != "" { scratch.FS = fsType } return source } func applyDeviceFacts(scratch *facts.USBScratch, desired *usbScratchConfig, source string) { device := resolveDevice(desired, source) if device == "" { return } export := blkidExport(device) if desired.UUID != "" { scratch.UUIDHealthy = export["UUID"] == desired.UUID } if desired.Label != "" { scratch.LabelHealthy = export["LABEL"] == desired.Label } if scratch.FS == "" { scratch.FS = export["TYPE"] } } func resolveDevice(desired *usbScratchConfig, source string) string { device := source if device == "" && desired.UUID != "" { device = resolveDeviceByUUID(desired.UUID) } if device == "" && desired.Label != "" { device = resolveDeviceByLabel(desired.Label) } return device } func applyBindFacts(s ... (truncated) ``` ## 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_48ec45dee2f341e4b202aa4beabfb6d7](https://triage.bstein.dev/chat?resume=run_48ec45dee2f341e4b202aa4beabfb6d7)). 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#210
No description provided.