Skip to content

[duplicate-code] Duplicate Code Pattern: tagsToStrings duplicates difc.TagsToStrings #2087

@github-actions

Description

@github-actions

Part of duplicate code analysis: #2085

Summary

internal/server/difc_log.go defines a private tagsToStrings helper that is functionally identical to the already-exported difc.TagsToStrings in internal/difc/tags.go. Notably, internal/server/unified.go already calls difc.TagsToStrings directly — so the server package already imports and uses the canonical function. The new tagsToStrings in difc_log.go is therefore an unnecessary duplicate.

Duplication Details

Pattern: Duplicate tag-to-string conversion utility

  • Severity: Low

  • Occurrences: 2 implementations of the same function

  • Locations:

    • internal/difc/tags.go (line 19): difc.TagsToStrings — canonical, exported
    • internal/server/difc_log.go (line 93): tagsToStrings — private duplicate
  • Canonical implementation (internal/difc/tags.go):

    func TagsToStrings(tags []Tag) []string {
        values := make([]string, 0, len(tags))
        for _, tag := range tags {
            values = append(values, string(tag))
        }
        return values
    }
  • Duplicate implementation (internal/server/difc_log.go):

    func tagsToStrings(tags []difc.Tag) []string {
        s := make([]string, len(tags))
        for i, t := range tags {
            s[i] = string(t)
        }
        return s
    }
  • Existing usage of canonical function in the same package (internal/server/unified.go lines 884–885):

    Secrecy:   difc.TagsToStrings(agentLabels.GetSecrecyTags()),
    Integrity: difc.TagsToStrings(agentLabels.GetIntegrityTags()),

Impact Analysis

  • Maintainability: Two implementations of identical logic in the same package hierarchy; if semantics ever change (e.g., filtering empty tags), only one copy may be updated.
  • Bug Risk: Low for now, but divergence becomes possible over time.
  • Code Bloat: 7 lines of redundant code.

Refactoring Recommendations

Replace with the canonical difc.TagsToStrings

In internal/server/difc_log.go:

  1. Delete the tagsToStrings function (lines 92–99).
  2. Replace the two call sites with difc.TagsToStrings:
    // Before:
    entry.SecrecyTags  = tagsToStrings(detail.Item.Labels.Secrecy.Label.GetTags())
    entry.IntegrityTags = tagsToStrings(detail.Item.Labels.Integrity.Label.GetTags())
    
    // After:
    entry.SecrecyTags  = difc.TagsToStrings(detail.Item.Labels.Secrecy.Label.GetTags())
    entry.IntegrityTags = difc.TagsToStrings(detail.Item.Labels.Integrity.Label.GetTags())

The difc package is already imported in difc_log.go, so no new import is needed.

  • Estimated effort: ~10 minutes
  • Benefits: Single implementation; consistent with how unified.go already calls this helper

Implementation Checklist

  • Delete tagsToStrings from internal/server/difc_log.go
  • Update the two call sites to use difc.TagsToStrings
  • Run make agent-finished to confirm all tests pass

Parent Issue

See parent analysis report: #2085
Related to #2085

Generated by Duplicate Code Detector ·

  • expires on Mar 25, 2026, 3:05 AM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions