Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Move policy count formatting into unified resources

rcourtman401e2c0df487
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index feb84fd0a5..5916af61d4 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -188,9 +188,9 @@ That posture snapshot must render redaction labels through the canonical
unified-resource hint order, not alphabetically, so the AI summary, drawer,
and any future policy surfaces all present the same redaction precedence.
Its sensitivity and routing counts must also follow the canonical
-unified-resource order and shared human-readable labels, so both the backend
-summary and the frontend policy card stay aligned on the same presentation
-sequence.
+unified-resource order and shared human-readable count summaries, so both the
+backend summary and the frontend policy card stay aligned on the same
+presentation sequence.
The resource-intelligence payload used by the resource drawer also carries
the same canonical policy posture snapshot, so the detail surface can show
governed posture context without inventing a second posture contract.
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 706f836997..5fda9d6ce0 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -405,9 +405,9 @@ Those helpers now own the canonical redaction-hint order and count-to-label
projection, so the AI summary and any other backend policy posture surface do
not re-sort redaction labels locally.
They also own the canonical sensitivity and routing order used to format
-policy-posture counts and human-readable labels, so the AI summary and
-frontend policy card both read the same presentation sequence from the shared
-resource model.
+policy-posture count summaries with human-readable labels, so the AI summary
+and frontend policy card both read the same presentation sequence from the
+shared resource model.
Canonical resources now carry first-class graph-expansion fields: `Capabilities`
(bounded action definitions with approval levels), `Relationships` (typed
inter-resource links with direction and confidence), and `RecentChanges` (typed
diff --git a/internal/ai/resource_context.go b/internal/ai/resource_context.go
index 11e11e07e3..d7f1b1b2b6 100644
--- a/internal/ai/resource_context.go
+++ b/internal/ai/resource_context.go
@@ -123,18 +123,10 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
if policyPosture != nil && policyPosture.TotalResources > 0 {
sections = append(sections, "\n### Data Governance")
- sensitivityParts := make([]string, 0, len(unifiedresources.ResourceSensitivityOrder))
- for _, sensitivity := range unifiedresources.ResourceSensitivityOrder {
- sensitivityParts = append(sensitivityParts, fmt.Sprintf("%d %s",
- sensitivityCounts[sensitivity], unifiedresources.ResourceSensitivityLabel(sensitivity)))
- }
+ sensitivityParts := unifiedresources.ResourcePolicySensitivitySummaryFromCounts(sensitivityCounts)
sections = append(sections, fmt.Sprintf("- Sensitivity: %s", strings.Join(sensitivityParts, ", ")))
- routingParts := make([]string, 0, len(unifiedresources.ResourceRoutingScopeOrder))
- for _, scope := range unifiedresources.ResourceRoutingScopeOrder {
- routingParts = append(routingParts, fmt.Sprintf("%d %s",
- routingCounts[scope], unifiedresources.ResourceRoutingScopeLabel(scope)))
- }
+ routingParts := unifiedresources.ResourcePolicyRoutingSummaryFromCounts(routingCounts)
sections = append(sections, fmt.Sprintf("- Routing: %s", strings.Join(routingParts, ", ")))
sections = append(sections, fmt.Sprintf("- Local-only resources: %d", localOnlyCount))
if redactionLabels := policyPostureRedactionLabels(policyPosture); len(redactionLabels) > 0 {
diff --git a/internal/ai/resource_context_test.go b/internal/ai/resource_context_test.go
index 939be2f3a2..692887a184 100644
--- a/internal/ai/resource_context_test.go
+++ b/internal/ai/resource_context_test.go
@@ -222,8 +222,19 @@ func TestBuildUnifiedResourceContext_FullContext(t *testing.T) {
assertContains("## Unified Infrastructure View")
assertContains("Total resources: 11 (Infrastructure: 5, Workloads: 6)")
assertContains("Data Governance")
- assertContains("Sensitivity: 0 Public, 5 Internal, 6 Sensitive, 0 Restricted")
- assertContains("Routing: 5 Cloud Summary, 6 Local First, 0 Local Only")
+ expectedSensitivity := strings.Join(unifiedresources.ResourcePolicySensitivitySummaryFromCounts(map[unifiedresources.ResourceSensitivity]int{
+ unifiedresources.ResourceSensitivityPublic: 0,
+ unifiedresources.ResourceSensitivityInternal: 5,
+ unifiedresources.ResourceSensitivitySensitive: 6,
+ unifiedresources.ResourceSensitivityRestricted: 0,
+ }), ", ")
+ assertContains("Sensitivity: " + expectedSensitivity)
+ expectedRouting := strings.Join(unifiedresources.ResourcePolicyRoutingSummaryFromCounts(map[unifiedresources.ResourceRoutingScope]int{
+ unifiedresources.ResourceRoutingScopeCloudSummary: 5,
+ unifiedresources.ResourceRoutingScopeLocalFirst: 6,
+ unifiedresources.ResourceRoutingScopeLocalOnly: 0,
+ }), ", ")
+ assertContains("Routing: " + expectedRouting)
assertContains("Policy Redaction Hints")
assertContains("Redactions in use: Hostname, IP Address, Platform ID, Alias")
assertContains("Proxmox VE Nodes")
diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.go
index fd13c6be7f..219ebbaeb6 100644
--- a/internal/unifiedresources/code_standards_test.go
+++ b/internal/unifiedresources/code_standards_test.go
@@ -280,6 +280,8 @@ func TestResourcePolicyPresentationUsesCanonicalLabels(t *testing.T) {
"ResourceRedactionHintLabel(",
"ResourcePolicyRedactionLabels(",
"ResourcePolicyRedactionLabelsFromCounts(",
+ "ResourcePolicySensitivitySummaryFromCounts(",
+ "ResourcePolicyRoutingSummaryFromCounts(",
}
for _, snippet := range requiredSnippets {
if !strings.Contains(source, snippet) {
diff --git a/internal/unifiedresources/policy_metadata_test.go b/internal/unifiedresources/policy_metadata_test.go
index 999e14c3e0..bda401a766 100644
--- a/internal/unifiedresources/policy_metadata_test.go
+++ b/internal/unifiedresources/policy_metadata_test.go
@@ -128,6 +128,27 @@ func TestResourcePolicyRedactionLabelsUseCanonicalOrder(t *testing.T) {
}
}
+func TestResourcePolicyCountSummariesUseCanonicalOrder(t *testing.T) {
+ sensitivityCounts := map[ResourceSensitivity]int{
+ ResourceSensitivityRestricted: 1,
+ ResourceSensitivityPublic: 2,
+ ResourceSensitivitySensitive: 3,
+ ResourceSensitivityInternal: 4,
+ }
+ if got := ResourcePolicySensitivitySummaryFromCounts(sensitivityCounts); len(got) != 4 || got[0] != "2 Public" || got[1] != "4 Internal" || got[2] != "3 Sensitive" || got[3] != "1 Restricted" {
+ t.Fatalf("sensitivity summary = %#v, want [2 Public 4 Internal 3 Sensitive 1 Restricted]", got)
+ }
+
+ routingCounts := map[ResourceRoutingScope]int{
+ ResourceRoutingScopeLocalOnly: 5,
+ ResourceRoutingScopeCloudSummary: 6,
+ ResourceRoutingScopeLocalFirst: 7,
+ }
+ if got := ResourcePolicyRoutingSummaryFromCounts(routingCounts); len(got) != 3 || got[0] != "6 Cloud Summary" || got[1] != "7 Local First" || got[2] != "5 Local Only" {
+ t.Fatalf("routing summary = %#v, want [6 Cloud Summary 7 Local First 5 Local Only]", got)
+ }
+}
+
func containsRedactionHint(hints []ResourceRedactionHint, want ResourceRedactionHint) bool {
for _, hint := range hints {
if hint == want {
diff --git a/internal/unifiedresources/policy_presentation.go b/internal/unifiedresources/policy_presentation.go
index 5432fa0a0f..bf1ecff3bc 100644
--- a/internal/unifiedresources/policy_presentation.go
+++ b/internal/unifiedresources/policy_presentation.go
@@ -1,6 +1,9 @@
package unifiedresources
-import "sort"
+import (
+ "fmt"
+ "sort"
+)
// ResourceSensitivityOrder captures the canonical presentation order for
// sensitivity counts across policy surfaces.
@@ -128,3 +131,33 @@ func ResourcePolicyRedactionLabelsFromCounts(counts map[ResourceRedactionHint]in
sort.Strings(remaining)
return append(labels, remaining...)
}
+
+// ResourcePolicySensitivitySummaryFromCounts returns the canonical
+// human-readable count summary for sensitivity posture.
+func ResourcePolicySensitivitySummaryFromCounts(counts map[ResourceSensitivity]int) []string {
+ if len(counts) == 0 {
+ return nil
+ }
+
+ parts := make([]string, 0, len(ResourceSensitivityOrder))
+ for _, sensitivity := range ResourceSensitivityOrder {
+ parts = append(parts, fmt.Sprintf("%d %s",
+ counts[sensitivity], ResourceSensitivityLabel(sensitivity)))
+ }
+ return parts
+}
+
+// ResourcePolicyRoutingSummaryFromCounts returns the canonical human-readable
+// count summary for routing posture.
+func ResourcePolicyRoutingSummaryFromCounts(counts map[ResourceRoutingScope]int) []string {
+ if len(counts) == 0 {
+ return nil
+ }
+
+ parts := make([]string, 0, len(ResourceRoutingScopeOrder))
+ for _, scope := range ResourceRoutingScopeOrder {
+ parts = append(parts, fmt.Sprintf("%d %s",
+ counts[scope], ResourceRoutingScopeLabel(scope)))
+ }
+ return parts
+}