Files
felhom-controller/controller/internal/web/r553_alert_placement_test.go
T
admin c00fed6db3 R-553: four decisions stop reading their own Hungarian words (sites 1-4)
Every Hungarian sentence is byte-identical; each decision now reads a signal set where the message is
made. util.KindErrorf builds the same bytes fmt.Errorf did while carrying a sentinel for errors.Is.

- Deploy status (api/router.go): deployStatusFor() by kind — stacks.ErrAlreadyDeployed (409),
  ErrRequiredField / ErrPathMissing / ErrNotEnoughMemory (400). The „kötelező" / „memória" /
  "does not exist" / "already deployed" text chain is gone.
- Off-site failure class (backup/offbox.go): ErrOffsiteQuota replaces the „tárhelykeretet" match. The
  restic/ssh signatures stay text matches on purpose — that output is not ours and is not translated.
- Alert placement (web/alerts.go): monitor.HealthReport carries WarningKinds parallel to Warnings;
  the "not on a separate drive" warning is inline by KIND. The hub report is untouched (builder.go
  copies Status/Issues/Warnings only) — pinned by a wire test.
- Stale off-site note (web/handlers.go): settings LastWarningKind + backup.OffboxWarnNoAppsSelected.
  The text test survives ONLY for kind == "" (a box whose last run predates 0.251.0) and is removed
  when R-570 closes; slice 2 must not translate that producer before then.

Tests (all red-proofed by restoring the pre-fix predicate — see the audit's redproofs.txt):
TestR553_Deploy_DecisionSurvivesWordingChange, TestR553_DeployHandlerUsesTheKind,
TestR553_DeployProducersCarryKindAndKeepTheirWords (through the real DeployStack),
TestR553_OffsiteQuota_{Decision,HeadLine}SurvivesWordingChange, TestR553_OffboxRunRecordsTheKind,
TestR553_StorageWarningsCarryKindsAndKeepTheirWords, TestR553_DiskWarningPlacementSurvivesWordingChange,
TestR553_HubReportWarningsAreUnchangedOnTheWire, TestR553_StaleNote*, TestR553_WarningKindIsPersistedAndCopied.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
2026-09-17 20:58:45 +02:00

106 lines
4.3 KiB
Go

package web
import (
"encoding/json"
"io"
"log"
"reflect"
"strings"
"testing"
"gitea.dooplex.hu/admin/felhom-controller/internal/config"
"gitea.dooplex.hu/admin/felhom-controller/internal/monitor"
"gitea.dooplex.hu/admin/felhom-controller/internal/report"
)
// R-553 — the „your data is not on a separate drive" warning is shown quietly, inline under the
// storage bars on two pages. Which warning that is used to be decided by looking for „meghajtó" in
// the sentence; slice 2 translates it, and from that day the warning appears in the RED BANNER on
// every page of the dashboard instead — a household that changed nothing suddenly reads an alarm.
//
// RED-PROOF (REPORT): put the strings.Contains(w, "meghajtón"/"adattároló"/"meghajtó") test back in
// alerts.go and the TRANSLATED row below fails (Inline=false, no PageOnly).
func TestR553_DiskWarningPlacementSurvivesWordingChange(t *testing.T) {
cases := []struct {
name string
text, kind string
wantInline bool
}{
{"as shipped", "Az adattároló (/mnt/hdd) nem külön meghajtón van — az adatok a rendszermeghajtóra íródnak",
monitor.WarnKindStorageNotSeparate, true},
{"TRANSLATED", "The data storage (/mnt/hdd) is not on a separate drive — the data is written to the system drive",
monitor.WarnKindStorageNotSeparate, true},
{"a CPU warning stays in the banner", "CPU usage high: 91%", "", false},
{"a disconnected drive stays in the banner (its own alert covers it)",
"Meghajtó leválasztva: Külső (/mnt/usb)", monitor.WarnKindStorageDisconnected, false},
{"a warning that merely CONTAINS the old words is not moved",
"A meghajtó ellenőrzése nem futott le", "", false},
}
for _, c := range cases {
am := NewAlertManager(log.New(io.Discard, "", 0))
hr := &monitor.HealthReport{Status: "warn", Warnings: []string{c.text}, WarningKinds: []string{c.kind}}
cfg := &config.Config{}
cfg.Hub.Enabled = false
am.Refresh(hr, cfg, nil, false, "")
var found *Alert
for i, a := range am.GetAlerts() {
if a.Message == c.text {
found = &am.GetAlerts()[i]
}
}
if found == nil {
t.Fatalf("%s: the warning did not reach the alerts at all", c.name)
}
if found.Inline != c.wantInline {
t.Errorf("%s: Inline = %v, want %v (message %q)", c.name, found.Inline, c.wantInline, c.text)
}
wantPages := 0
if c.wantInline {
wantPages = 2
}
if len(found.PageOnly) != wantPages {
t.Errorf("%s: PageOnly = %v, want %d page(s)", c.name, found.PageOnly, wantPages)
}
if c.wantInline && (found.ID != "disk-not-separate" ||
strings.Join(found.PageOnly, ",") != "dashboard,monitoring") {
t.Errorf("%s: id/pages changed: %q %v", c.name, found.ID, found.PageOnly)
}
}
}
// THE WIRE IS SACRED — the kinds are an internal field and must not reach the hub. The report's
// health block is its own struct; this pins that it carries exactly three fields, their JSON names,
// and that a health report WITH kinds marshals to the same bytes as one without.
//
// RED-PROOF (REPORT): add `WarningKinds []string \`json:"warning_kinds"\`` to report.HealthReport and
// both halves fail.
func TestR553_HubReportWarningsAreUnchangedOnTheWire(t *testing.T) {
rt := reflect.TypeOf(report.HealthReport{})
var names []string
for i := 0; i < rt.NumField(); i++ {
names = append(names, rt.Field(i).Tag.Get("json"))
}
if got, want := strings.Join(names, ","), "status,issues,warnings"; got != want {
t.Errorf("the hub's health block changed shape: %q, want %q", got, want)
}
// The same warnings, one report built the way builder.go builds it (Status/Issues/Warnings only).
src := &monitor.HealthReport{
Status: "warn",
Issues: []string{},
Warnings: []string{"CPU usage high: 91%", "Az adattároló (/mnt/hdd) nem külön meghajtón van"},
WarningKinds: []string{"", monitor.WarnKindStorageNotSeparate},
}
wire := report.HealthReport{Status: src.Status, Issues: src.Issues, Warnings: src.Warnings}
b, err := json.Marshal(wire)
if err != nil {
t.Fatal(err)
}
const want = `{"status":"warn","issues":[],"warnings":["CPU usage high: 91%","Az adattároló (/mnt/hdd) nem külön meghajtón van"]}`
if string(b) != want {
t.Errorf("the hub report's health bytes CHANGED:\n got %s\nwant %s", b, want)
}
if strings.Contains(string(b), "kind") {
t.Error("a warning KIND reached the wire — the hub contract gained a field nobody agreed to")
}
}