Skip to content

Extract DiffEntryBase embed to reduce anomaly-field repetition in audit_diff.go#46972

Merged
pelikhan merged 2 commits into
mainfrom
copilot/extract-diffentrybase-embed
Jul 21, 2026
Merged

Extract DiffEntryBase embed to reduce anomaly-field repetition in audit_diff.go#46972
pelikhan merged 2 commits into
mainfrom
copilot/extract-diffentrybase-embed

Conversation

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

DomainDiffEntry, MCPToolDiffEntry, and ToolCallDiffEntry each duplicated the same three anomaly-flagging fields inline. This extracts them into a shared DiffEntryBase embed.

Changes

  • New DiffEntryBase struct — holds the common fields:
    type DiffEntryBase struct {
        Status      string `json:"status"`
        IsAnomaly   bool   `json:"is_anomaly,omitempty"`
        AnomalyNote string `json:"anomaly_note,omitempty"`
    }
  • Embed in all three entry typesDomainDiffEntry, MCPToolDiffEntry, and ToolCallDiffEntry each replace their inline copies with DiffEntryBase
  • Struct literal updates — all 8 construction sites updated to DiffEntryBase: DiffEntryBase{Status: "..."} syntax

Go struct embedding promotes fields inline in JSON output, so wire format is unchanged.

…it_diff.go

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Extract DiffEntryBase embed to reduce anomaly-field repetition Extract DiffEntryBase embed to reduce anomaly-field repetition in audit_diff.go Jul 21, 2026
Copilot AI requested a review from pelikhan July 21, 2026 05:03
@pelikhan
pelikhan marked this pull request as ready for review July 21, 2026 05:05
Copilot AI review requested due to automatic review settings July 21, 2026 05:05
@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped.

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #46972 does not have the 'implementation' label and has only 49 new lines of code in business logic directories (threshold: 100).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Extracts shared diff-entry fields to reduce duplication in audit output models.

Changes:

  • Adds DiffEntryBase.
  • Embeds it across three diff entry types.
  • Updates all construction sites.
Show a summary per file
File Description
pkg/cli/audit_diff.go Consolidates shared status and anomaly fields.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Medium

Comment thread pkg/cli/audit_diff.go
Comment on lines +32 to +33
Domain string `json:"domain"`
DiffEntryBase
@github-actions github-actions Bot mentioned this pull request Jul 21, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, correct refactor. Go struct embedding promotes Status, IsAnomaly, and AnomalyNote inline in JSON output, so wire format is unchanged. All 8 construction sites updated consistently. No issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · 16.8 AIC · ⌖ 4.32 AIC · ⊞ 5K

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /codebase-design — two observations, neither blocking.

📋 Key Themes & Highlights

Key Themes

  • Lost status-value documentation: the per-type Status field inline comments (e.g. // "new", "removed", "status_changed", "volume_changed") were dropped; DiffEntryBase has no equivalent — discoverability for new contributors suffers.
  • JSON field order changed: the PR claims the wire format is unchanged, but is_anomaly / anomaly_note now serialize between status and the type-specific fields rather than at the end. JSON key order does not affect encoding/json unmarshal, but it can break raw-string snapshot comparisons.

Positive Highlights

  • ✅ Clean, focused extraction — exactly the three fields that are duplicated, nothing more.
  • ✅ All 8 construction sites updated consistently.
  • ✅ Go embedding correctly promotes fields into the JSON flat structure as documented.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 26.8 AIC · ⌖ 4.61 AIC · ⊞ 6.7K
Comment /matt to run again

Comment thread pkg/cli/audit_diff.go

// DiffEntryBase holds common anomaly-flagging fields shared by all diff entry types.
type DiffEntryBase struct {
Status string `json:"status"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/codebase-design] The valid status values per entry type were documented as inline comments on the old Status fields (e.g. // "new", "removed", "status_changed", "volume_changed" on DomainDiffEntry) but were dropped during extraction — DiffEntryBase now carries no hint of what values are valid.

💡 Suggestion

Either add a comment to DiffEntryBase pointing readers to the per-type enum, or restore the per-type annotations on the embedding structs' doc comments:

// DiffEntryBase holds common anomaly-flagging fields shared by all diff entry types.
// Status values are entry-type specific; see DomainDiffEntry, MCPToolDiffEntry, ToolCallDiffEntry.
type DiffEntryBase struct {

This keeps discoverability intact without duplicating the value lists.

@copilot please address this.

Comment thread pkg/cli/audit_diff.go
Domain string `json:"domain"`
Status string `json:"status"` // "new", "removed", "status_changed", "volume_changed"
Domain string `json:"domain"`
DiffEntryBase

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/codebase-design] The PR says "wire format is unchanged" but the JSON field order has shifted: is_anomaly / anomaly_note now appear between status and the type-specific fields instead of at the end. Consumers relying on key ordering (snapshot tests, jq positional scripts) may see unexpected diffs.

💡 Suggestion

Clarify in the PR body that field order changed, and verify no existing snapshot tests compare raw JSON strings. If strict trailing order is needed, move the embed to the end of each struct.

@copilot please address this.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, mechanical refactor — no correctness issues.

### Review summary

The extraction of DiffEntryBase is correct:

  • Go struct embedding promotes Status, IsAnomaly, and AnomalyNote inline in JSON output, so the wire format is unchanged.
  • All 8 construction sites are updated consistently.
  • No logic paths were altered.

One non-blocking doc comment issue flagged inline.

🔎 Code quality review by PR Code Quality Reviewer · 27.4 AIC · ⌖ 4.43 AIC · ⊞ 5.6K
Comment /review to run again

Comments that could not be inline-anchored

pkg/cli/audit_diff.go:10

Misleading doc comment: DiffEntryBase is described as holding "anomaly-flagging fields" but Status is a general entry discriminator (&quot;new&quot;, &quot;removed&quot;, &quot;changed&quot;) unrelated to anomaly detection.

<details>
<summary>💡 Suggested fix</summary>

// DiffEntryBase holds common fields shared by all diff entry types.
type DiffEntryBase struct {

Status is the primary discriminator; the anomaly fields (IsAnomaly, AnomalyNote) are secondary. The current comment misrepresents…

@pelikhan
pelikhan merged commit 4a5e7df into main Jul 21, 2026
70 of 81 checks passed
@pelikhan
pelikhan deleted the copilot/extract-diffentrybase-embed branch July 21, 2026 05:15
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.82.15

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.

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

3 participants