c00fed6db3
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
75 lines
3.1 KiB
Go
75 lines
3.1 KiB
Go
package monitor
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"gitea.dooplex.hu/admin/felhom-controller/internal/settings"
|
|
)
|
|
|
|
// R-553 — the storage warnings carry a KIND, and their sentences are byte-for-byte unchanged.
|
|
//
|
|
// checkStoragePaths is the real producer the health check folds into the report. The kinds are what
|
|
// the dashboard reads to decide WHERE a warning is shown; the sentence is what the household reads.
|
|
//
|
|
// RED-PROOF (REPORT): drop the `kinds = append(…, WarnKindStorageNotSeparate)` line and the
|
|
// placement test in internal/web fails with the warning back in the top banner.
|
|
func TestR553_StorageWarningsCarryKindsAndKeepTheirWords(t *testing.T) {
|
|
dir := t.TempDir()
|
|
present := filepath.Join(dir, "data")
|
|
if err := os.MkdirAll(present, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
paths := []settings.StoragePath{
|
|
{Path: filepath.Join(dir, "gone"), Label: "Leválasztott", Disconnected: true},
|
|
{Path: filepath.Join(dir, "nem-letezik")},
|
|
{Path: present},
|
|
{Path: filepath.Join(dir, "kihagyott"), Decommissioned: true},
|
|
}
|
|
_, warnings, kinds := checkStoragePaths(paths)
|
|
if len(warnings) != len(kinds) {
|
|
t.Fatalf("a warning without its kind (or the reverse): %d warnings, %d kinds", len(warnings), len(kinds))
|
|
}
|
|
want := []struct{ text, kind string }{
|
|
{"Meghajtó leválasztva: Leválasztott (" + filepath.Join(dir, "gone") + ")", WarnKindStorageDisconnected},
|
|
{"Adattároló nem elérhető: " + filepath.Join(dir, "nem-letezik"), WarnKindStorageUnavailable},
|
|
{"Az adattároló (" + present + ") nem külön meghajtón van — az adatok a rendszermeghajtóra íródnak", WarnKindStorageNotSeparate},
|
|
}
|
|
if len(warnings) != len(want) {
|
|
t.Fatalf("warnings = %q, want %d of them", warnings, len(want))
|
|
}
|
|
for i, w := range want {
|
|
if warnings[i] != w.text {
|
|
t.Errorf("warning %d CHANGED:\n got %q\nwant %q", i, warnings[i], w.text)
|
|
}
|
|
if kinds[i] != w.kind {
|
|
t.Errorf("warning %d has kind %q, want %q", i, kinds[i], w.kind)
|
|
}
|
|
}
|
|
// The decommissioned path is skipped entirely — it must not appear with an empty kind either.
|
|
for i, w := range warnings {
|
|
if kinds[i] == "" {
|
|
t.Errorf("storage warning %q carries no kind — the dashboard would fall back to placing it in the banner", w)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A warning and its kind can never drift apart, because every warning goes through addWarning.
|
|
func TestR553_WarningKindsStayParallel(t *testing.T) {
|
|
r := &HealthReport{}
|
|
r.addWarning("CPU usage high: 91%", "")
|
|
r.addWarning("Az adattároló (/mnt/x) nem külön meghajtón van", WarnKindStorageNotSeparate)
|
|
if len(r.Warnings) != 2 || len(r.WarningKinds) != 2 {
|
|
t.Fatalf("lengths drifted: %d warnings, %d kinds", len(r.Warnings), len(r.WarningKinds))
|
|
}
|
|
if r.WarningKindAt(0) != "" || r.WarningKindAt(1) != WarnKindStorageNotSeparate {
|
|
t.Errorf("kinds read back wrong: %q, %q", r.WarningKindAt(0), r.WarningKindAt(1))
|
|
}
|
|
// A report built by hand (an older caller, a test fixture) answers "" instead of panicking.
|
|
old := &HealthReport{Warnings: []string{"x"}}
|
|
if old.WarningKindAt(0) != "" || old.WarningKindAt(9) != "" {
|
|
t.Error("a report with no kinds must answer \"\", never index out of range")
|
|
}
|
|
}
|