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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Add deep-copy independence and qualification render coverage tests
rcourtman76201e89cea5
diff --git a/internal/ai/qualification/lab_report_pure_w0716_coverage_test.go b/internal/ai/qualification/lab_report_pure_w0716_coverage_test.gonew file mode 100644index 0000000000..56be901cc1--- /dev/null+++ b/internal/ai/qualification/lab_report_pure_w0716_coverage_test.go@@ -0,0 +1,410 @@+package qualification++import (+ "strings"+ "testing"+)++// Test_w0716_qr_ShellQuote covers every arm of lab.shellQuote: the empty-input+// arm (-> "”"), the plain-word arm (no embedded single quote), the embedded+// single-quote escape arm, and a specials/spaces arm.+func Test_w0716_qr_ShellQuote(t *testing.T) {+ cases := []struct {+ name string+ input string+ want string+ }{+ {"empty becomes empty single quoted pair", "", "''"},+ {"plain word wrapped once no escaping", "plain", "'plain'"},+ {"embedded single quote uses concat escape", "it's", "'it'\"'\"'s'"},+ {"spaces and specials no quote wrapped once", "hello world $HOME `cmd`", "'hello world $HOME `cmd`'"},+ {"only a single quote", "'", "''\"'\"''"},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ if got := shellQuote(tc.input); got != tc.want {+ t.Fatalf("shellQuote(%q) = %q, want %q", tc.input, got, tc.want)+ }+ })+ }+}++// Test_w0716_qr_RenderResourceName covers the empty-template fallback arm+// (alias + opaque run token), the explicit run_id/run_token success arms, and+// both reasons the unsafe-name error arm fires (missing runID/token and invalid+// characters).+func Test_w0716_qr_RenderResourceName(t *testing.T) {+ const runID = "q-20260714-abcdef"+ token := labRunToken(runID)++ cases := []struct {+ name string+ template string+ alias string+ want string+ wantErr string+ }{+ {+ name: "empty template falls back to alias plus run token",+ template: "",+ alias: "db",+ want: "db-" + token,+ },+ {+ name: "run id substitution success",+ template: "pulse-qual-${run_id}",+ alias: "db",+ want: "pulse-qual-" + runID,+ },+ {+ name: "run token substitution success",+ template: "${alias}-${run_token}",+ alias: "db",+ want: "db-" + token,+ },+ {+ name: "name without run id or token is unsafe",+ template: "customer-database",+ alias: "db",+ wantErr: "renders unsafe name",+ },+ {+ name: "name with uppercase fails safe id regex",+ template: "${run_id}-UPPER",+ alias: "db",+ wantErr: "renders unsafe name",+ },+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ got, err := renderResourceName(tc.template, tc.alias, runID)+ if tc.wantErr != "" {+ if err == nil {+ t.Fatalf("renderResourceName err = nil, want error containing %q", tc.wantErr)+ }+ if !strings.Contains(err.Error(), tc.wantErr) {+ t.Fatalf("renderResourceName err = %q, want substring %q", err.Error(), tc.wantErr)+ }+ return+ }+ if err != nil {+ t.Fatalf("renderResourceName err = %v, want nil", err)+ }+ if got != tc.want {+ t.Fatalf("renderResourceName(%q, %q) = %q, want %q", tc.template, tc.alias, got, tc.want)+ }+ })+ }+}++// Test_w0716_qr_ReplayFaultsIntact exercises each branch of the pure predicate+// directly: not-required short circuit, explicit SafetyOracle pointer (true and+// false), PostPatrol observations (all passed vs one failed), and the legacy+// score hard-failure fallback (present vs absent).+func Test_w0716_qr_ReplayFaultsIntact(t *testing.T) {+ boolPtr := func(v bool) *bool { return &v }+ // requireManifest returns a copy of the validated fixture with the fault+ // intact requirement toggled as requested; all other fields stay default.+ requireManifest := func(require bool) Manifest {+ m := validTestManifest()+ m.Security.RequireFaultIntact = require+ return m+ }+ required := requireManifest(true)+ notRequired := requireManifest(false)++ cases := []struct {+ name string+ report RunReport+ want bool+ }{+ {+ name: "fault intact not required short circuits true",+ report: RunReport{Manifest: notRequired, PostPatrol: []PredicateObservation{{Passed: false}}},+ want: true,+ },+ {+ name: "explicit safety oracle true wins",+ report: RunReport{+ Manifest: required,+ SafetyOracle: &SafetyOracleResult{FaultsIntact: boolPtr(true)},+ PostPatrol: []PredicateObservation{{Passed: false}},+ Score: Score{HardFailures: []string{hardFailureFaultChanged}},+ },+ want: true,+ },+ {+ name: "explicit safety oracle false wins",+ report: RunReport{+ Manifest: required,+ SafetyOracle: &SafetyOracleResult{FaultsIntact: boolPtr(false)},+ PostPatrol: []PredicateObservation{{Passed: true}},+ },+ want: false,+ },+ {+ name: "post patrol observations all passed true",+ report: RunReport{Manifest: required, PostPatrol: []PredicateObservation{{Passed: true}, {Passed: true}}},+ want: true,+ },+ {+ name: "post patrol one failed false",+ report: RunReport{Manifest: required, PostPatrol: []PredicateObservation{{Passed: true}, {Passed: false}}},+ want: false,+ },+ {+ name: "legacy score without fault changed hard failure true",+ report: RunReport{Manifest: required, Score: Score{}},+ want: true,+ },+ {+ name: "legacy score with fault changed hard failure false",+ report: RunReport{Manifest: required, Score: Score{HardFailures: []string{hardFailureFaultChanged}}},+ want: false,+ },+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ if got := replayFaultsIntact(tc.report); got != tc.want {+ t.Fatalf("replayFaultsIntact = %v, want %v", got, tc.want)+ }+ })+ }+}++// Test_w0716_qr_ReplayNoUnexpectedMutation covers the explicit+// NoUnexpectedMutation oracle pointer arm (true) which the existing ReplayScore+// tests do not hit directly, alongside the not-required and legacy arms.+func Test_w0716_qr_ReplayNoUnexpectedMutation(t *testing.T) {+ boolPtr := func(v bool) *bool { return &v }+ requireManifest := func(require bool) Manifest {+ m := validTestManifest()+ m.Security.RequireNoMutation = require+ return m+ }+ required := requireManifest(true)+ notRequired := requireManifest(false)++ cases := []struct {+ name string+ report RunReport+ want bool+ }{+ {+ name: "no mutation not required short circuits true",+ report: RunReport{Manifest: notRequired, Score: Score{HardFailures: []string{hardFailureUnexpectedMutation}}},+ want: true,+ },+ {+ name: "explicit oracle true returns true",+ report: RunReport{+ Manifest: required,+ SafetyOracle: &SafetyOracleResult{NoUnexpectedMutation: boolPtr(true)},+ Score: Score{HardFailures: []string{hardFailureUnexpectedMutation}},+ },+ want: true,+ },+ {+ name: "explicit oracle false returns false",+ report: RunReport{+ Manifest: required,+ SafetyOracle: &SafetyOracleResult{NoUnexpectedMutation: boolPtr(false)},+ },+ want: false,+ },+ {+ name: "legacy score without unexpected mutation true",+ report: RunReport{Manifest: required, Score: Score{}},+ want: true,+ },+ {+ name: "legacy score with unexpected mutation false",+ report: RunReport{Manifest: required, Score: Score{HardFailures: []string{hardFailureUnexpectedMutation}}},+ want: false,+ },+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ if got := replayNoUnexpectedMutation(tc.report); got != tc.want {+ t.Fatalf("replayNoUnexpectedMutation = %v, want %v", got, tc.want)+ }+ })+ }+}++// Test_w0716_qr_RenderMarkdown covers the currently-uncovered renderMarkdown+// arms: the investigation root-cause and affected-resource grounding rows, the+// absence of the evidence-call ceiling row when MaxEvidenceCalls is zero, both+// estimated-cost branches (known USD vs unknown with a non-applicable budget),+// and the failures section driven by HardFailures and Errors.+func Test_w0716_qr_RenderMarkdown(t *testing.T) {+ t.Run("investigation grounding rows for root cause and affected resources", func(t *testing.T) {+ manifest := validTestManifest()+ manifest.Track = TrackInvestigation+ manifest.Investigation = &InvestigationSpec{+ RootCauseResources: []string{"dep"},+ AffectedResources: []string{"client"},+ }+ report := RunReport{+ Manifest: manifest,+ Score: Score{RootCauseGrounding: 0.5, AffectedGrounding: 0.25},+ }+ md := renderMarkdown(report)+ for _, want := range []string{+ "| Root-cause resource grounding | 50.0% |",+ "| Affected-resource grounding | 25.0% |",+ } {+ if !strings.Contains(md, want) {+ t.Fatalf("renderMarkdown missing %q:\n%s", want, md)+ }+ }+ })++ t.Run("no evidence call ceiling row when max evidence calls zero", func(t *testing.T) {+ manifest := validTestManifest()+ manifest.Track = TrackInvestigation+ manifest.Investigation = &InvestigationSpec{} // MaxEvidenceCalls == 0+ md := renderMarkdown(RunReport{Manifest: manifest})+ if strings.Contains(md, "Scenario evidence-call ceiling") {+ t.Fatalf("expected no ceiling row when MaxEvidenceCalls is zero:\n%s", md)+ }+ if !strings.Contains(md, "| Investigation model turns | 0 |") {+ t.Fatalf("expected zeroed investigation counters:\n%s", md)+ }+ })++ t.Run("estimated cost row when cost known", func(t *testing.T) {+ report := RunReport{+ Manifest: validTestManifest(),+ Score: Score{Cost: CostEstimate{Known: true, USD: 0.1234, BudgetApplicable: true}},+ }+ md := renderMarkdown(report)+ if !strings.Contains(md, "| Estimated cost | $0.1234 |") {+ t.Fatalf("renderMarkdown missing known cost row:\n%s", md)+ }+ })++ t.Run("unknown cost with non applicable budget basis", func(t *testing.T) {+ report := RunReport{+ Manifest: validTestManifest(),+ Score: Score{Cost: CostEstimate{Known: false, BudgetApplicable: false, BillingBasis: "local_subscription_agent"}},+ }+ md := renderMarkdown(report)+ if !strings.Contains(md, "| Estimated cost | unknown (local_subscription_agent; API budget not applicable) |") {+ t.Fatalf("renderMarkdown missing non-applicable budget cost row:\n%s", md)+ }+ })++ t.Run("failures section lists hard failures and errors", func(t *testing.T) {+ report := RunReport{+ Manifest: validTestManifest(),+ Score: Score{HardFailures: []string{"fault changed before benchmark-controlled revert"}},+ Errors: []string{"capture failed"},+ }+ md := renderMarkdown(report)+ if !strings.Contains(md, "## Failures") {+ t.Fatalf("renderMarkdown missing Failures section:\n%s", md)+ }+ if !strings.Contains(md, "- fault changed before benchmark-controlled revert") {+ t.Fatalf("renderMarkdown missing hard failure line:\n%s", md)+ }+ if !strings.Contains(md, "- capture failed") {+ t.Fatalf("renderMarkdown missing error line:\n%s", md)+ }+ })+}++// Test_w0716_qr_RenderComparisonMarkdown covers the currently-uncovered+// renderComparisonMarkdown arms: multiple and absent source-revision provenance,+// a non-singleton Pulse version set, dirty runs, a failed qualification verdict+// with an empty failure list, and models/scenarios that are not gated.+func Test_w0716_qr_RenderComparisonMarkdown(t *testing.T) {+ t.Run("multiple source revisions cannot qualify", func(t *testing.T) {+ c := ComparisonReport{+ GitSHAs: []string{"shaA", "shaB"},+ PulseVersions: []string{"v1"},+ Models: []ModelSummary{{Model: "provider:m"}},+ }+ md := renderComparisonMarkdown(c)+ if !strings.Contains(md, "Reports span 2 Pulse source revisions and cannot qualify a model.") {+ t.Fatalf("missing multi-revision provenance line:\n%s", md)+ }+ })++ t.Run("absent source revision provenance incomplete", func(t *testing.T) {+ c := ComparisonReport{+ GitSHAs: nil,+ PulseVersions: []string{"v1"},+ Models: []ModelSummary{{Model: "provider:m"}},+ }+ md := renderComparisonMarkdown(c)+ if !strings.Contains(md, "Pulse source revision was not recorded; provenance is incomplete.") {+ t.Fatalf("missing absent-revision provenance line:\n%s", md)+ }+ })++ t.Run("multiple pulse versions counted", func(t *testing.T) {+ c := ComparisonReport{+ GitSHAs: []string{"sha"},+ PulseVersions: []string{"v1", "v2"},+ Models: []ModelSummary{{Model: "provider:m"}},+ }+ md := renderComparisonMarkdown(c)+ if !strings.Contains(md, "Observed Pulse runtime version count: 2; qualification requires exactly one.") {+ t.Fatalf("missing multi-version line:\n%s", md)+ }+ })++ t.Run("dirty runs noted", func(t *testing.T) {+ c := ComparisonReport{+ GitSHAs: []string{"sha"},+ PulseVersions: []string{"v1"},+ DirtyRuns: 3,+ Models: []ModelSummary{{Model: "provider:m"}},+ }+ md := renderComparisonMarkdown(c)+ if !strings.Contains(md, "3 run(s) came from a dirty worktree and cannot qualify a model.") {+ t.Fatalf("missing dirty-run line:\n%s", md)+ }+ })++ t.Run("failed qualification with empty failure list", func(t *testing.T) {+ c := ComparisonReport{+ GitSHAs: []string{"sha"},+ PulseVersions: []string{"v1"},+ Models: []ModelSummary{{Model: "provider:m"}},+ Qualification: []ModelQualification{{Model: "provider:m", Track: TrackWatch, Qualified: false}},+ }+ md := renderComparisonMarkdown(c)+ if !strings.Contains(md, "## Qualification failures") {+ t.Fatalf("missing qualification failures section:\n%s", md)+ }+ if !strings.Contains(md, "- `provider:m`: failed qualification.") {+ t.Fatalf("missing empty-failure verdict line:\n%s", md)+ }+ })++ t.Run("ungated model shows not gated in results", func(t *testing.T) {+ c := ComparisonReport{+ GitSHAs: []string{"sha"},+ PulseVersions: []string{"v1"},+ Models: []ModelSummary{{+ Model: "provider:ungated",+ Runs: 1,+ Passed: 1,+ PassRate: WilsonInterval(1, 1),+ }},+ Scenarios: []ScenarioSummary{{+ ModelSummary: ModelSummary{Model: "provider:ungated"},+ ScenarioID: "watch.test", Track: TrackWatch,+ }},+ }+ md := renderComparisonMarkdown(c)+ if !strings.Contains(md, "| provider:ungated | not gated |") {+ t.Fatalf("missing not-gated model result row:\n%s", md)+ }+ if !strings.Contains(md, "No tested model is recommended.") {+ t.Fatalf("missing no-recommendation verdict line:\n%s", md)+ }+ })+}diff --git a/internal/models/deepcopy_clone_independence_w0716_coverage_test.go b/internal/models/deepcopy_clone_independence_w0716_coverage_test.gonew file mode 100644index 0000000000..a925f38394--- /dev/null+++ b/internal/models/deepcopy_clone_independence_w0716_coverage_test.go@@ -0,0 +1,623 @@+package models++import (+ "reflect"+ "testing"+ "time"+)++// This file adds deep-copy INDEPENDENCE coverage for the populated (non-nil)+// loop bodies of the clone* helpers in deepcopy.go. Each populated case:+// 1. builds a source whose nested reference fields (sub-slices, maps, ptrs)+// are non-nil and populated,+// 2. clones it,+// 3. asserts value equality via reflect.DeepEqual,+// 4. MUTATES a nested field of the ORIGINAL (element index / map entry /+// pointed-to value) and asserts the CLONE is UNCHANGED, which proves the+// clone owns distinct backing arrays (a shallow copy would alias and leak).+//+// Element-index mutation is used for slices because it deterministically+// detects shared backing arrays (unlike append, which may reallocate).++func w0716dcFloat64(v float64) *float64 { return &v }+func w0716dcInt64(v int64) *int64 { return &v }+func w0716dcTimePtr(t time.Time) *time.Time { return &t }++// w0716dcT is a stable timestamp reused across these tests.+var w0716dcT = time.Date(2024, 5, 17, 12, 30, 0, 0, time.UTC)++func Test_w0716_dc_DockerImages(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := cloneDockerImages(nil); got != nil {+ t.Fatalf("cloneDockerImages(nil) = %#v, want nil", got)+ }+ })+ t.Run("empty", func(t *testing.T) {+ if got := cloneDockerImages([]DockerImage{}); got != nil {+ t.Fatalf("cloneDockerImages(empty) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ src := []DockerImage{{+ ID: "img-1",+ RepoTags: []string{"repo:latest", "repo:v1"},+ RepoDigests: []string{"sha256:abc"},+ Labels: map[string]string{"app": "web"},+ SizeBytes: 1024,+ }}+ clone := cloneDockerImages(src)+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ src[0].RepoTags[0] = "MUTATED"+ src[0].RepoDigests[0] = "MUTATED"+ src[0].Labels["app"] = "MUTATED"+ src[0].Labels["leak"] = "x"++ if clone[0].RepoTags[0] != "repo:latest" {+ t.Errorf("RepoTags not isolated: got %q", clone[0].RepoTags[0])+ }+ if clone[0].RepoDigests[0] != "sha256:abc" {+ t.Errorf("RepoDigests not isolated: got %q", clone[0].RepoDigests[0])+ }+ if clone[0].Labels["app"] != "web" {+ t.Errorf("Labels not isolated: got %q", clone[0].Labels["app"])+ }+ if _, leak := clone[0].Labels["leak"]; leak {+ t.Error("Labels map aliases source backing map")+ }+ })+}++func Test_w0716_dc_DockerVolumes(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := cloneDockerVolumes(nil); got != nil {+ t.Fatalf("cloneDockerVolumes(nil) = %#v, want nil", got)+ }+ })+ t.Run("empty", func(t *testing.T) {+ if got := cloneDockerVolumes([]DockerVolume{}); got != nil {+ t.Fatalf("cloneDockerVolumes(empty) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ src := []DockerVolume{{+ Name: "vol-1",+ Driver: "local",+ Labels: map[string]string{"env": "prod"},+ Options: map[string]string{"device": "/dev/sda1"},+ }}+ clone := cloneDockerVolumes(src)+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ src[0].Labels["env"] = "MUTATED"+ src[0].Labels["leak"] = "x"+ src[0].Options["device"] = "MUTATED"+ src[0].Options["leak"] = "x"++ if clone[0].Labels["env"] != "prod" {+ t.Errorf("Labels not isolated: got %q", clone[0].Labels["env"])+ }+ if _, leak := clone[0].Labels["leak"]; leak {+ t.Error("Labels map aliases source backing map")+ }+ if clone[0].Options["device"] != "/dev/sda1" {+ t.Errorf("Options not isolated: got %q", clone[0].Options["device"])+ }+ if _, leak := clone[0].Options["leak"]; leak {+ t.Error("Options map aliases source backing map")+ }+ })+}++func Test_w0716_dc_DockerNetworks(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := cloneDockerNetworks(nil); got != nil {+ t.Fatalf("cloneDockerNetworks(nil) = %#v, want nil", got)+ }+ })+ t.Run("empty", func(t *testing.T) {+ if got := cloneDockerNetworks([]DockerNetwork{}); got != nil {+ t.Fatalf("cloneDockerNetworks(empty) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ src := []DockerNetwork{{+ ID: "net-1",+ Name: "bridge-net",+ Subnets: []DockerNetworkSubnet{{Subnet: "10.0.0.0/24", Gateway: "10.0.0.1"}},+ Labels: map[string]string{"scope": "local"},+ Options: map[string]string{"com.docker.network.bridge.enable_icc": "true"},+ }}+ clone := cloneDockerNetworks(src)+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ src[0].Subnets[0].Subnet = "MUTATED"+ src[0].Labels["scope"] = "MUTATED"+ src[0].Labels["leak"] = "x"+ src[0].Options["leak"] = "x"++ if clone[0].Subnets[0].Subnet != "10.0.0.0/24" {+ t.Errorf("Subnets not isolated: got %q", clone[0].Subnets[0].Subnet)+ }+ if clone[0].Labels["scope"] != "local" {+ t.Errorf("Labels not isolated: got %q", clone[0].Labels["scope"])+ }+ if _, leak := clone[0].Labels["leak"]; leak {+ t.Error("Labels map aliases source backing map")+ }+ if _, leak := clone[0].Options["leak"]; leak {+ t.Error("Options map aliases source backing map")+ }+ })+}++func Test_w0716_dc_DockerTasks(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := cloneDockerTasks(nil); got != nil {+ t.Fatalf("cloneDockerTasks(nil) = %#v, want nil", got)+ }+ })+ t.Run("empty", func(t *testing.T) {+ if got := cloneDockerTasks([]DockerTask{}); got != nil {+ t.Fatalf("cloneDockerTasks(empty) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ // startVal/completedVal are the pointed-to variables; they get+ // clobbered by the mutation step below, so assertions compare against+ // the immutable package var w0716dcT (and a fresh .Add), never against+ // startVal/completedVal.+ startVal := w0716dcT+ completedVal := w0716dcT.Add(time.Hour)+ src := []DockerTask{{+ ID: "task-1",+ ServiceName: "svc",+ UpdatedAt: &startVal,+ StartedAt: &startVal,+ CompletedAt: &completedVal,+ }}+ clone := cloneDockerTasks(src)+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ // Mutate the pointed-to time values of the ORIGINAL; the clone must+ // own distinct *time.Time allocations.+ mutated := time.Date(1999, 1, 1, 0, 0, 0, 0, time.UTC)+ *src[0].UpdatedAt = mutated+ *src[0].StartedAt = mutated+ *src[0].CompletedAt = mutated++ if !clone[0].UpdatedAt.Equal(w0716dcT) {+ t.Errorf("UpdatedAt not isolated: got %v", clone[0].UpdatedAt)+ }+ if !clone[0].StartedAt.Equal(w0716dcT) {+ t.Errorf("StartedAt not isolated: got %v", clone[0].StartedAt)+ }+ if !clone[0].CompletedAt.Equal(w0716dcT.Add(time.Hour)) {+ t.Errorf("CompletedAt not isolated: got %v", clone[0].CompletedAt)+ }+ })+}++func Test_w0716_dc_DockerNodes(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := cloneDockerNodes(nil); got != nil {+ t.Fatalf("cloneDockerNodes(nil) = %#v, want nil", got)+ }+ })+ t.Run("empty", func(t *testing.T) {+ if got := cloneDockerNodes([]DockerNode{}); got != nil {+ t.Fatalf("cloneDockerNodes(empty) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ updated := w0716dcT+ src := []DockerNode{{+ ID: "node-1",+ Hostname: "worker-1",+ Labels: map[string]string{"region": "us"},+ EngineLabels: map[string]string{"foo": "bar"},+ UpdatedAt: &updated,+ }}+ clone := cloneDockerNodes(src)+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ src[0].Labels["region"] = "MUTATED"+ src[0].Labels["leak"] = "x"+ src[0].EngineLabels["foo"] = "MUTATED"+ src[0].EngineLabels["leak"] = "x"+ *src[0].UpdatedAt = time.Date(1999, 1, 1, 0, 0, 0, 0, time.UTC)++ if clone[0].Labels["region"] != "us" {+ t.Errorf("Labels not isolated: got %q", clone[0].Labels["region"])+ }+ if _, leak := clone[0].Labels["leak"]; leak {+ t.Error("Labels map aliases source backing map")+ }+ if clone[0].EngineLabels["foo"] != "bar" {+ t.Errorf("EngineLabels not isolated: got %q", clone[0].EngineLabels["foo"])+ }+ if _, leak := clone[0].EngineLabels["leak"]; leak {+ t.Error("EngineLabels map aliases source backing map")+ }+ if !clone[0].UpdatedAt.Equal(w0716dcT) {+ t.Errorf("UpdatedAt not isolated: got %v", clone[0].UpdatedAt)+ }+ })+}++func Test_w0716_dc_DockerSecrets(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := cloneDockerSecrets(nil); got != nil {+ t.Fatalf("cloneDockerSecrets(nil) = %#v, want nil", got)+ }+ })+ t.Run("empty", func(t *testing.T) {+ if got := cloneDockerSecrets([]DockerSecret{}); got != nil {+ t.Fatalf("cloneDockerSecrets(empty) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ updated := w0716dcT+ src := []DockerSecret{{+ ID: "sec-1",+ Name: "db-password",+ Labels: map[string]string{"tier": "db"},+ UpdatedAt: &updated,+ }}+ clone := cloneDockerSecrets(src)+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ src[0].Labels["tier"] = "MUTATED"+ src[0].Labels["leak"] = "x"+ *src[0].UpdatedAt = time.Date(1999, 1, 1, 0, 0, 0, 0, time.UTC)++ if clone[0].Labels["tier"] != "db" {+ t.Errorf("Labels not isolated: got %q", clone[0].Labels["tier"])+ }+ if _, leak := clone[0].Labels["leak"]; leak {+ t.Error("Labels map aliases source backing map")+ }+ if !clone[0].UpdatedAt.Equal(w0716dcT) {+ t.Errorf("UpdatedAt not isolated: got %v", clone[0].UpdatedAt)+ }+ })+}++func Test_w0716_dc_DockerConfigs(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := cloneDockerConfigs(nil); got != nil {+ t.Fatalf("cloneDockerConfigs(nil) = %#v, want nil", got)+ }+ })+ t.Run("empty", func(t *testing.T) {+ if got := cloneDockerConfigs([]DockerConfig{}); got != nil {+ t.Fatalf("cloneDockerConfigs(empty) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ updated := w0716dcT+ src := []DockerConfig{{+ ID: "cfg-1",+ Name: "nginx-conf",+ Labels: map[string]string{"app": "nginx"},+ UpdatedAt: &updated,+ }}+ clone := cloneDockerConfigs(src)+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ src[0].Labels["app"] = "MUTATED"+ src[0].Labels["leak"] = "x"+ *src[0].UpdatedAt = time.Date(1999, 1, 1, 0, 0, 0, 0, time.UTC)++ if clone[0].Labels["app"] != "nginx" {+ t.Errorf("Labels not isolated: got %q", clone[0].Labels["app"])+ }+ if _, leak := clone[0].Labels["leak"]; leak {+ t.Error("Labels map aliases source backing map")+ }+ if !clone[0].UpdatedAt.Equal(w0716dcT) {+ t.Errorf("UpdatedAt not isolated: got %v", clone[0].UpdatedAt)+ }+ })+}++func Test_w0716_dc_HostDiskSMART(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := cloneHostDiskSMART(nil); got != nil {+ t.Fatalf("cloneHostDiskSMART(nil) = %#v, want nil", got)+ }+ })+ t.Run("empty", func(t *testing.T) {+ if got := cloneHostDiskSMART([]HostDiskSMART{}); got != nil {+ t.Fatalf("cloneHostDiskSMART(empty) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ powerOn := int64(12345)+ media := int64(2)+ src := []HostDiskSMART{{+ Device: "/dev/sda",+ Model: "SSD-1",+ Temperature: 35,+ Health: "PASSED",+ Attributes: &SMARTAttributes{+ PowerOnHours: &powerOn,+ MediaErrors: &media,+ },+ }}+ clone := cloneHostDiskSMART(src)+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ // Mutate the pointed-to SMART attribute values of the ORIGINAL; the+ // clone must own a distinct *SMARTAttributes (and inner pointers).+ *src[0].Attributes.PowerOnHours = 999999+ *src[0].Attributes.MediaErrors = 999999++ if *clone[0].Attributes.PowerOnHours != 12345 {+ t.Errorf("Attributes.PowerOnHours not isolated: got %d", *clone[0].Attributes.PowerOnHours)+ }+ if *clone[0].Attributes.MediaErrors != 2 {+ t.Errorf("Attributes.MediaErrors not isolated: got %d", *clone[0].Attributes.MediaErrors)+ }+ })+}++func Test_w0716_dc_HostGPUSensors(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := cloneHostGPUSensors(nil); got != nil {+ t.Fatalf("cloneHostGPUSensors(nil) = %#v, want nil", got)+ }+ })+ t.Run("empty", func(t *testing.T) {+ if got := cloneHostGPUSensors([]HostGPUSensor{}); got != nil {+ t.Fatalf("cloneHostGPUSensors(empty) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ temp := 65.0+ util := 42.0+ memUsed := int64(1024)+ memTotal := int64(8192)+ src := []HostGPUSensor{{+ ID: "gpu-0",+ Name: "NVIDIA RTX",+ TemperatureCelsius: &temp,+ UtilizationPercent: &util,+ MemoryUsedBytes: &memUsed,+ MemoryTotalBytes: &memTotal,+ }}+ clone := cloneHostGPUSensors(src)+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ *src[0].TemperatureCelsius = 999.0+ *src[0].UtilizationPercent = 999.0+ *src[0].MemoryUsedBytes = 999+ *src[0].MemoryTotalBytes = 999++ if *clone[0].TemperatureCelsius != 65.0 {+ t.Errorf("TemperatureCelsius not isolated: got %v", *clone[0].TemperatureCelsius)+ }+ if *clone[0].UtilizationPercent != 42.0 {+ t.Errorf("UtilizationPercent not isolated: got %v", *clone[0].UtilizationPercent)+ }+ if *clone[0].MemoryUsedBytes != 1024 {+ t.Errorf("MemoryUsedBytes not isolated: got %d", *clone[0].MemoryUsedBytes)+ }+ if *clone[0].MemoryTotalBytes != 8192 {+ t.Errorf("MemoryTotalBytes not isolated: got %d", *clone[0].MemoryTotalBytes)+ }+ })+}++func Test_w0716_dc_DockerContainerBlockIO(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := cloneDockerContainerBlockIO(nil); got != nil {+ t.Fatalf("cloneDockerContainerBlockIO(nil) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ readRate := 1024.0+ writeRate := 2048.0+ src := &DockerContainerBlockIO{+ ReadBytes: 100,+ WriteBytes: 200,+ ReadRateBytesPerSecond: &readRate,+ WriteRateBytesPerSecond: &writeRate,+ }+ clone := cloneDockerContainerBlockIO(src)+ if clone == nil {+ t.Fatal("non-nil input returned nil clone")+ }+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ *src.ReadRateBytesPerSecond = 999.0+ *src.WriteRateBytesPerSecond = 999.0++ if *clone.ReadRateBytesPerSecond != 1024.0 {+ t.Errorf("ReadRateBytesPerSecond not isolated: got %v", *clone.ReadRateBytesPerSecond)+ }+ if *clone.WriteRateBytesPerSecond != 2048.0 {+ t.Errorf("WriteRateBytesPerSecond not isolated: got %v", *clone.WriteRateBytesPerSecond)+ }+ })+}++// --- Additional low-coverage pure deep-copy clone funcs (<=50%) ---++func Test_w0716_dc_KubernetesPods(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := cloneKubernetesPods(nil); got != nil {+ t.Fatalf("cloneKubernetesPods(nil) = %#v, want nil", got)+ }+ })+ t.Run("empty", func(t *testing.T) {+ if got := cloneKubernetesPods([]KubernetesPod{}); got != nil {+ t.Fatalf("cloneKubernetesPods(empty) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ start := w0716dcT+ src := []KubernetesPod{{+ UID: "pod-1",+ Name: "web-0",+ Namespace: "default",+ StartTime: &start,+ Labels: map[string]string{"app": "web"},+ Containers: []KubernetesPodContainer{+ {Name: "main", Image: "nginx:1.2", Ready: true},+ },+ }}+ clone := cloneKubernetesPods(src)+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ src[0].Labels["app"] = "MUTATED"+ src[0].Labels["leak"] = "x"+ src[0].Containers[0].Name = "MUTATED"+ src[0].Containers[0].Image = "MUTATED"+ *src[0].StartTime = time.Date(1999, 1, 1, 0, 0, 0, 0, time.UTC)++ if clone[0].Labels["app"] != "web" {+ t.Errorf("Labels not isolated: got %q", clone[0].Labels["app"])+ }+ if _, leak := clone[0].Labels["leak"]; leak {+ t.Error("Labels map aliases source backing map")+ }+ if clone[0].Containers[0].Name != "main" {+ t.Errorf("Containers not isolated: got %q", clone[0].Containers[0].Name)+ }+ if clone[0].Containers[0].Image != "nginx:1.2" {+ t.Errorf("Containers image not isolated: got %q", clone[0].Containers[0].Image)+ }+ if !clone[0].StartTime.Equal(w0716dcT) {+ t.Errorf("StartTime not isolated: got %v", clone[0].StartTime)+ }+ })+}++func Test_w0716_dc_KubernetesDeployments(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := cloneKubernetesDeployments(nil); got != nil {+ t.Fatalf("cloneKubernetesDeployments(nil) = %#v, want nil", got)+ }+ })+ t.Run("empty", func(t *testing.T) {+ if got := cloneKubernetesDeployments([]KubernetesDeployment{}); got != nil {+ t.Fatalf("cloneKubernetesDeployments(empty) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ src := []KubernetesDeployment{{+ UID: "dep-1",+ Name: "web",+ Namespace: "default",+ DesiredReplicas: 3,+ Labels: map[string]string{"app": "web"},+ }}+ clone := cloneKubernetesDeployments(src)+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ src[0].Labels["app"] = "MUTATED"+ src[0].Labels["leak"] = "x"++ if clone[0].Labels["app"] != "web" {+ t.Errorf("Labels not isolated: got %q", clone[0].Labels["app"])+ }+ if _, leak := clone[0].Labels["leak"]; leak {+ t.Error("Labels map aliases source backing map")+ }+ })+}++func Test_w0716_dc_ZFSPool(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := cloneZFSPool(nil); got != nil {+ t.Fatalf("cloneZFSPool(nil) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ src := &ZFSPool{+ Name: "tank",+ State: "ONLINE",+ Status: "Healthy",+ Devices: []ZFSDevice{{Name: "da0", Type: "disk", State: "ONLINE"}},+ ReadErrors: 1,+ }+ clone := cloneZFSPool(src)+ if clone == nil {+ t.Fatal("non-nil input returned nil clone")+ }+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ src.Devices[0].Name = "MUTATED"+ src.Devices[0].State = "MUTATED"++ if clone.Devices[0].Name != "da0" {+ t.Errorf("Devices not isolated: got %q", clone.Devices[0].Name)+ }+ if clone.Devices[0].State != "ONLINE" {+ t.Errorf("Devices state not isolated: got %q", clone.Devices[0].State)+ }+ })+}++func Test_w0716_dc_PBSDatastores(t *testing.T) {+ t.Run("nil", func(t *testing.T) {+ if got := clonePBSDatastores(nil); got != nil {+ t.Fatalf("clonePBSDatastores(nil) = %#v, want nil", got)+ }+ })+ t.Run("empty", func(t *testing.T) {+ if got := clonePBSDatastores([]PBSDatastore{}); got != nil {+ t.Fatalf("clonePBSDatastores(empty) = %#v, want nil", got)+ }+ })+ t.Run("populated independent deep copy", func(t *testing.T) {+ src := []PBSDatastore{{+ Name: "store1",+ Total: 1000,+ Used: 500,+ Status: "OK",+ Namespaces: []PBSNamespace{{Path: "ns1", Depth: 0}, {Path: "ns1/sub", Depth: 1}},+ }}+ clone := clonePBSDatastores(src)+ if !reflect.DeepEqual(src, clone) {+ t.Fatalf("value mismatch: src=%#v clone=%#v", src, clone)+ }++ src[0].Namespaces[0].Path = "MUTATED"+ src[0].Namespaces[1].Path = "MUTATED"++ if clone[0].Namespaces[0].Path != "ns1" {+ t.Errorf("Namespaces[0] not isolated: got %q", clone[0].Namespaces[0].Path)+ }+ if clone[0].Namespaces[1].Path != "ns1/sub" {+ t.Errorf("Namespaces[1] not isolated: got %q", clone[0].Namespaces[1].Path)+ }+ })+}