Skip to content

[Code Quality] Extract DiffEntryBase embed to reduce anomaly-field repetition in audit_diff.go #46945

Description

@github-actions

Description

Three nearly-identical entry types in pkg/cli/audit_diff.go each repeat the same anomaly-flagging fields inline:

  • DomainDiffEntry (line ~24)
  • MCPToolDiffEntry (line ~224)
  • ToolCallDiffEntry (line ~282)

All three follow the same pattern: Status string, IsAnomaly bool, AnomalyNote string. The run1/run2 count pairs differ per type (intentionally), but the anomaly fields are identical copy-pastes.

Suggested Changes

  1. Define a new DiffEntryBase struct in pkg/cli/audit_diff.go with fields:
    • Status string json:"status"``
    • IsAnomaly bool json:"is_anomaly"``
    • AnomalyNote string json:"anomaly_note"``
  2. Replace the inline copies of those fields in DomainDiffEntry, MCPToolDiffEntry, and ToolCallDiffEntry with an embedded DiffEntryBase
  3. Verify JSON serialization is unchanged (json:",inline" or direct embedding preserves flat JSON keys)

Files Affected

  • pkg/cli/audit_diff.goDomainDiffEntry, MCPToolDiffEntry, ToolCallDiffEntry (lines ~24, ~224, ~282)

Success Criteria

  • DiffEntryBase struct defined and embedded in all three types
  • JSON output for audit diff is unchanged (field names preserved)
  • make build and make test pass

Source

Extracted from Typist Go Type Consistency Analysis discussion #46823

Priority

Low — reduces copy-paste drift; effort ~1–2 hours

🔍 Task mining by Discussion Task Miner - Code Quality Improvement Agent · 46.7 AIC · ⌖ 7.94 AIC · ⊞ 7K ·

  • expires on Jul 21, 2026, 5:17 PM UTC-08:00

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions