Files
felhom-controller/controller/internal/web/r553_alert_placement_test.go
T
admin 7c05b59708
gates / gates (push) Successful in 24s
v0.253.0 — errors carry the key of the sentence they are (R-557 slice 2 release B)
179 Hungarian sentences were built deep inside a package with fmt.Errorf and printed by
whoever caught them: too late to translate where they are shown, too early where they are
made. Every one now carries its key across that gap. ZERO Hungarian error literals remain.

util.MsgError does three things at once, each earned:
  - Error() is the Hungarian, byte for byte, so every un-converted printer is unchanged;
  - errors.Is answers for the kind AND for a wrapped cause (KindErrorf dropped the cause);
  - an error ARGUMENT renders recursively, so "formázás sikertelen: %w" translates whole.
A foreign error — restic, docker, ssh, the stdlib — prints verbatim. It is not ours.

76 display sites go through errText, and TestNoErrErrorInPageOutput convicts any that do
not. memoryVerdict returns an error rather than a sentence, so the deploy's 409 and the
household's language come from one value; UpdateRefusal gained a Cause to carry it.

Plurals, one rule, stated once: a key with .one/.other takes its COUNT first. Not a
per-call-site flag — the producer somebody forgot would read "3 app is not running". The
guard caught a real key collision (alert.deadapp.one) the day the rule landed.

TWO DEFECTS FOUND IN MY OWN TOOLING, recorded rather than quietly fixed. The bulk converter
silently dropped multi-line concatenations, damaging 7 producers — and the parity gate could
not see it, because every surviving fragment WAS a real base literal while the CALL had lost
text; two behaviour tests caught it. And the counting script was case-sensitive, so it said
"0 left" while five remained.

MinAgent: 0.131.0 (unchanged). No hub release needed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
2026-09-18 11:44:30 +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("hu") {
if a.Message == c.text {
found = &am.GetAlerts("hu")[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")
}
}