Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/cli/audit_cross_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func buildCrossRunAuditReport(inputs []crossRunInput) *CrossRunAuditReport {
agg.totalBlocked += stats.Blocked
agg.perRun = append(agg.perRun, DomainRunStatus{
RunID: in.RunID,
Status: domainStatus(stats),
Status: classifyFirewallDomainStatus(stats),
Allowed: stats.Allowed,
Blocked: stats.Blocked,
})
Expand Down Expand Up @@ -354,7 +354,7 @@ func buildCrossRunAuditReport(inputs []crossRunInput) *CrossRunAuditReport {
SeenInRuns: len(agg.perRun),
TotalAllowed: agg.totalAllowed,
TotalBlocked: agg.totalBlocked,
OverallStatus: domainStatus(DomainRequestStats{Allowed: agg.totalAllowed, Blocked: agg.totalBlocked}),
OverallStatus: classifyFirewallDomainStatus(DomainRequestStats{Allowed: agg.totalAllowed, Blocked: agg.totalBlocked}),
PerRunStatus: fullPerRun,
}
report.DomainInventory = append(report.DomainInventory, entry)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/audit_cross_run_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func renderCrossRunReportMarkdown(report *CrossRunAuditReport) {
fmt.Printf("| Domain | Status | Seen In | Allowed | Blocked |\n")
fmt.Printf("|--------|--------|---------|---------|--------|\n")
for _, entry := range report.DomainInventory {
icon := statusEmoji(entry.OverallStatus)
icon := firewallStatusEmoji(entry.OverallStatus)
fmt.Printf("| `%s` | %s %s | %d/%d runs | %d | %d |\n",
entry.Domain, icon, entry.OverallStatus, entry.SeenInRuns, report.RunsAnalyzed,
entry.TotalAllowed, entry.TotalBlocked)
Expand Down Expand Up @@ -289,7 +289,7 @@ func renderCrossRunReportPretty(report *CrossRunAuditReport) {
if len(report.DomainInventory) > 0 {
fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Domain Inventory (%d domains)", len(report.DomainInventory))))
for _, entry := range report.DomainInventory {
icon := statusEmoji(entry.OverallStatus)
icon := firewallStatusEmoji(entry.OverallStatus)
fmt.Fprintf(os.Stderr, " %s %-45s %s seen=%d/%d allowed=%d blocked=%d\n",
icon, entry.Domain, entry.OverallStatus, entry.SeenInRuns, report.RunsAnalyzed,
entry.TotalAllowed, entry.TotalBlocked)
Expand Down
12 changes: 6 additions & 6 deletions pkg/cli/audit_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func computeFirewallDiff(run1ID, run2ID int64, run1, run2 *FirewallAnalysis) *Fi
Status: "new",
Run2Allowed: stats2.Allowed,
Run2Blocked: stats2.Blocked,
Run2Status: domainStatus(stats2),
Run2Status: classifyFirewallDomainStatus(stats2),
}
// Anomaly: new denied domain
if stats2.Blocked > 0 {
Expand All @@ -125,13 +125,13 @@ func computeFirewallDiff(run1ID, run2ID int64, run1, run2 *FirewallAnalysis) *Fi
Status: "removed",
Run1Allowed: stats1.Allowed,
Run1Blocked: stats1.Blocked,
Run1Status: domainStatus(stats1),
Run1Status: classifyFirewallDomainStatus(stats1),
}
diff.RemovedDomains = append(diff.RemovedDomains, entry)
} else {
// Domain exists in both runs - check for changes
status1 := domainStatus(stats1)
status2 := domainStatus(stats2)
status1 := classifyFirewallDomainStatus(stats1)
status2 := classifyFirewallDomainStatus(stats2)

if status1 != status2 {
// Status changed
Expand Down Expand Up @@ -198,8 +198,8 @@ func computeFirewallDiff(run1ID, run2ID int64, run1, run2 *FirewallAnalysis) *Fi
return diff
}

// domainStatus returns "allowed", "denied", or "mixed" based on request stats
func domainStatus(stats DomainRequestStats) string {
// classifyFirewallDomainStatus returns "allowed", "denied", or "mixed" based on request stats
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

The doc comment says this returns only "allowed", "denied", or "mixed", but the implementation can also return "unknown" (e.g., when Allowed==0 && Blocked==0). Please update the comment to include "unknown" so it matches actual behavior.

Suggested change
// classifyFirewallDomainStatus returns "allowed", "denied", or "mixed" based on request stats
// classifyFirewallDomainStatus returns "allowed", "denied", "mixed", or "unknown" based on request stats

Copilot uses AI. Check for mistakes.
func classifyFirewallDomainStatus(stats DomainRequestStats) string {
if stats.Allowed > 0 && stats.Blocked == 0 {
return "allowed"
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/cli/audit_diff_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func renderFirewallDiffMarkdownSection(diff *FirewallDiff) {
fmt.Printf("**New domains (%d)**\n", len(diff.NewDomains))
for _, entry := range diff.NewDomains {
total := entry.Run2Allowed + entry.Run2Blocked
statusIcon := statusEmoji(entry.Run2Status)
statusIcon := firewallStatusEmoji(entry.Run2Status)
anomalyTag := ""
if entry.IsAnomaly {
anomalyTag = " ⚠️"
Expand All @@ -171,8 +171,8 @@ func renderFirewallDiffMarkdownSection(diff *FirewallDiff) {
if len(diff.StatusChanges) > 0 {
fmt.Printf("**Status changes (%d)**\n", len(diff.StatusChanges))
for _, entry := range diff.StatusChanges {
icon1 := statusEmoji(entry.Run1Status)
icon2 := statusEmoji(entry.Run2Status)
icon1 := firewallStatusEmoji(entry.Run1Status)
icon2 := firewallStatusEmoji(entry.Run2Status)
anomalyTag := ""
if entry.IsAnomaly {
anomalyTag = " ⚠️"
Expand Down Expand Up @@ -324,7 +324,7 @@ func renderFirewallDiffPrettySection(diff *FirewallDiff) {
}
config.Rows = append(config.Rows, []string{
entry.Domain,
statusEmoji(entry.Run2Status) + " " + entry.Run2Status,
firewallStatusEmoji(entry.Run2Status) + " " + entry.Run2Status,
strconv.Itoa(total),
anomalyNote,
})
Expand All @@ -342,7 +342,7 @@ func renderFirewallDiffPrettySection(diff *FirewallDiff) {
total := entry.Run1Allowed + entry.Run1Blocked
config.Rows = append(config.Rows, []string{
entry.Domain,
statusEmoji(entry.Run1Status) + " " + entry.Run1Status,
firewallStatusEmoji(entry.Run1Status) + " " + entry.Run1Status,
strconv.Itoa(total),
})
}
Expand All @@ -362,8 +362,8 @@ func renderFirewallDiffPrettySection(diff *FirewallDiff) {
}
config.Rows = append(config.Rows, []string{
entry.Domain,
statusEmoji(entry.Run1Status) + " " + entry.Run1Status,
statusEmoji(entry.Run2Status) + " " + entry.Run2Status,
firewallStatusEmoji(entry.Run1Status) + " " + entry.Run1Status,
firewallStatusEmoji(entry.Run2Status) + " " + entry.Run2Status,
anomalyNote,
})
}
Expand Down Expand Up @@ -583,8 +583,8 @@ func renderTokenUsageDiffPrettySection(run1ID, run2ID int64, diff *TokenUsageDif
}
}

// statusEmoji returns the status emoji for a domain status
func statusEmoji(status string) string {
// firewallStatusEmoji returns the status emoji for a domain status
func firewallStatusEmoji(status string) string {
switch status {
case "allowed":
return "✅"
Expand Down
12 changes: 6 additions & 6 deletions pkg/cli/audit_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func TestDomainStatus(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := domainStatus(tt.stats)
result := classifyFirewallDomainStatus(tt.stats)
Comment on lines 244 to +246
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

This test is still named TestDomainStatus, but it now exercises classifyFirewallDomainStatus. Renaming the test to match the function name would make it easier to discover/grep and avoids confusion when the old symbol no longer exists.

This issue also appears on line 299 of the same file.

Copilot uses AI. Check for mistakes.
assert.Equal(t, tt.expected, result, "Domain status should match")
})
}
Expand Down Expand Up @@ -297,11 +297,11 @@ func TestFirewallDiffJSONSerialization(t *testing.T) {
}

func TestStatusEmoji(t *testing.T) {
assert.Equal(t, "✅", statusEmoji("allowed"), "Allowed should show checkmark")
assert.Equal(t, "❌", statusEmoji("denied"), "Denied should show X")
assert.Equal(t, "⚠️", statusEmoji("mixed"), "Mixed should show warning")
assert.Equal(t, "❓", statusEmoji("unknown"), "Unknown should show question mark")
assert.Equal(t, "❓", statusEmoji(""), "Empty should show question mark")
assert.Equal(t, "✅", firewallStatusEmoji("allowed"), "Allowed should show checkmark")
assert.Equal(t, "❌", firewallStatusEmoji("denied"), "Denied should show X")
assert.Equal(t, "⚠️", firewallStatusEmoji("mixed"), "Mixed should show warning")
assert.Equal(t, "❓", firewallStatusEmoji("unknown"), "Unknown should show question mark")
assert.Equal(t, "❓", firewallStatusEmoji(""), "Empty should show question mark")
}

func TestIsEmptyDiff(t *testing.T) {
Expand Down
Loading