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
test(notifications): cover SMTP transaction retry replies
pulse-triage[bot]ad0a70bc75ef
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex d1179a7234..367f921c15 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -10681,3 +10681,7 @@ Its returned failure retains the structured cause and actual attempt count;this does not change report API schemas or prove recipient acceptance.`internal/notifications/email_retry_class_test.go` verifies the shared transportfailure boundary with in-memory SMTP replies, not end-to-end report delivery.+The transaction-stage regression matrix additionally checks MAIL, RCPT, DATA+command and completed-message rejections, including transient-then-accepted+termination. It exercises the shared sender with plain SMTP and no attachments;+it is not separate qualification of report rendering, TLS or report receipt.diff --git a/docs/release-control/v6/internal/subsystems/notifications.md b/docs/release-control/v6/internal/subsystems/notifications.mdindex a18ef9ae86..fead8f181b 100644--- a/docs/release-control/v6/internal/subsystems/notifications.md+++ b/docs/release-control/v6/internal/subsystems/notifications.md@@ -653,3 +653,14 @@ email, webhook and Apprise, firing and recovery, and global versus destinationdisablement. This corrects false successful queue/audit records; it does notestablish maintenance-window expiry, stop an already-started provider request,or repair historical false-success records.++### SMTP transaction-stage retry regression coverage++`TestEmailRetryRespectsSMTPTransactionReplies` extends the greeting-failure+fixture through MAIL, RCPT, DATA command and completed-message replies. At each+stage, structured 550 replies stop after one attempt despite temporary prose;+451 replies retain the three-attempt configured budget, and a 451 followed by+acceptance stops after the second attempt. This checks the sender's wrapped+errors and retry termination, not only the failure classifier. The in-memory+plain-SMTP fixture sends no external mail and does not qualify TLS, installed+recipient receipt or queue persistence.diff --git a/internal/notifications/email_retry_class_test.go b/internal/notifications/email_retry_class_test.goindex a3e49d75b7..361498fecb 100644--- a/internal/notifications/email_retry_class_test.go+++ b/internal/notifications/email_retry_class_test.go@@ -3,6 +3,7 @@ package notificationsimport ("fmt""net"+ "net/textproto""strings""sync""testing"@@ -62,3 +63,119 @@ func TestEmailRetryRespectsSMTPFailureClass(t *testing.T) {})}}++// A provider may accept the greeting and reject the envelope or the completed+// message. Keep those wrapped replies authoritative too, and ensure a later+// successful attempt ends retries rather than exhausting the budget.+func TestEmailRetryRespectsSMTPTransactionReplies(t *testing.T) {+ for _, stage := range []string{"MAIL", "RCPT", "DATA", "message"} {+ for _, tc := range []struct {+ name string+ code int+ recover bool+ wantAttempts int+ }{+ {"permanent", 550, false, 1},+ {"temporary", 451, false, 3},+ {"recovery", 451, true, 2},+ } {+ t.Run(stage+"/"+tc.name, func(t *testing.T) {+ var servers sync.WaitGroup+ originalDial := smtpDialTimeout+ t.Cleanup(func() { smtpDialTimeout = originalDial; servers.Wait() })+ attempts := 0+ smtpDialTimeout = func(string, string, time.Duration) (net.Conn, error) {+ attempts+++ fail := !tc.recover || attempts == 1+ client, server := net.Pipe()+ servers.Add(1)+ go func() {+ defer servers.Done()+ defer server.Close()+ _ = server.SetDeadline(time.Now().Add(5 * time.Second))+ conn := textproto.NewConn(server)+ if err := conn.PrintfLine("220 smtp.example.test"); err != nil {+ t.Error(err)+ return+ }+ for {+ line, err := conn.ReadLine()+ if err != nil {+ t.Error(err)+ return+ }+ command := strings.Fields(line)[0]+ if fail && command == stage {+ if err := conn.PrintfLine("%d temporary authentication timeout", tc.code); err != nil {+ t.Error(err)+ }+ return+ }+ switch command {+ case "EHLO", "HELO", "MAIL", "RCPT":+ err = conn.PrintfLine("250 OK")+ case "DATA":+ if err = conn.PrintfLine("354 Send message"); err != nil {+ t.Error(err)+ return+ }+ if _, err = conn.ReadDotBytes(); err != nil {+ t.Error(err)+ return+ }+ if fail && stage == "message" {+ if err := conn.PrintfLine("%d temporary authentication timeout", tc.code); err != nil {+ t.Error(err)+ }+ return+ }+ err = conn.PrintfLine("250 Accepted")+ case "QUIT":+ if err := conn.PrintfLine("221 Bye"); err != nil {+ t.Error(err)+ }+ return+ default:+ t.Errorf("unexpected SMTP command %q", command)+ return+ }+ if err != nil {+ t.Error(err)+ return+ }+ }+ }()+ return client, nil+ }+ manager := NewEnhancedEmailManager(EmailProviderConfig{+ EmailConfig: EmailConfig{SMTPHost: "smtp.example.test", SMTPPort: 25, From: "[email protected]", To: []string{"[email protected]"}},+ MaxRetries: 2,+ })+ err := manager.SendEmailWithRetry("test", "<p>test</p>", "test")+ if tc.recover {+ if err != nil {+ t.Fatalf("recovery failed: %v", err)+ }+ } else {+ if err == nil {+ t.Fatal("expected SMTP failure")+ }+ wantClass := NotificationFailureRejected+ if tc.code == 451 {+ wantClass = NotificationFailureServerError+ }+ if got := ClassifyNotificationFailureError(err); got != wantClass {+ t.Errorf("class = %q, want %q", got, wantClass)+ }+ if !strings.Contains(err.Error(), fmt.Sprintf("email failed after %d attempts:", tc.wantAttempts)) {+ t.Errorf("incorrect attempt count: %v", err)+ }+ }+ if attempts != tc.wantAttempts {+ t.Errorf("attempts = %d, want %d", attempts, tc.wantAttempts)+ }+ servers.Wait()+ })+ }+ }+}