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
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/backup"
|
||||
"gitea.dooplex.hu/admin/felhom-controller/internal/settings"
|
||||
)
|
||||
|
||||
// R-553 — the Távoli mentés page replaces a stale „nothing was selected" run note once apps HAVE been
|
||||
// selected. It used to find that note by searching the sentence for „nincs mentésre jelölt alkalmazás";
|
||||
// slice 2 translates the sentence, and the stale note would then come back and stay — telling a
|
||||
// household that has selected apps that nothing is covered.
|
||||
//
|
||||
// RED-PROOF (REPORT): make offboxWarningDisplay decide by the marker again (drop the kind arm) and
|
||||
// the TRANSLATED row fails: the stale sentence is shown verbatim.
|
||||
func TestR553_StaleNoteDecisionSurvivesWordingChange(t *testing.T) {
|
||||
const hu = "Sikeres — nincs mentésre jelölt alkalmazás"
|
||||
const en = "Success — no app is selected for backup"
|
||||
cases := []struct {
|
||||
name, warning, kind string
|
||||
toggled int
|
||||
want string
|
||||
}{
|
||||
{"as shipped, apps now selected", hu, backup.OffboxWarnNoAppsSelected, 1, offboxSelectionChangedLine},
|
||||
{"TRANSLATED, apps now selected", en, backup.OffboxWarnNoAppsSelected, 2, offboxSelectionChangedLine},
|
||||
{"still nothing selected → the honest note stays", hu, backup.OffboxWarnNoAppsSelected, 0, hu},
|
||||
{"a quota note passes through", "A tároló a keret 84%-át használja (42/50 GB).", "", 3,
|
||||
"A tároló a keret 84%-át használja (42/50 GB)."},
|
||||
// LEGACY: a box upgraded to v0.251.0 still carries the OLD text with no kind until its next
|
||||
// off-site run rewrites it. Until then the text test is what it has.
|
||||
{"legacy persisted text, no kind", hu, "", 1, offboxSelectionChangedLine},
|
||||
{"legacy: any other text without a kind is shown verbatim", "Valami más történt.", "", 1, "Valami más történt."},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := offboxWarningDisplay(c.warning, c.kind, c.toggled); got != c.want {
|
||||
t.Errorf("%s:\n got %q\nwant %q", c.name, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The consequence on the page itself: with a TRANSLATED warning that carries the kind, the rendered
|
||||
// Távoli mentés page shows the selection-changed note and not the stale sentence.
|
||||
func TestR553_StaleNoteOnTheRenderedPage(t *testing.T) {
|
||||
const en = "Success — no app is selected for backup"
|
||||
data := appRowSplitData()
|
||||
data["Offbox"] = &settings.OffboxTarget{
|
||||
Enabled: true, Host: "nas.local", LastStatus: "ok", EscrowState: "escrowed",
|
||||
LastWarning: en, LastWarningKind: backup.OffboxWarnNoAppsSelected,
|
||||
}
|
||||
data["OffboxWarningDisplay"] = offboxWarningDisplay(en, backup.OffboxWarnNoAppsSelected, 1)
|
||||
html := renderBackupPage(t, "backups_remote", data)
|
||||
if !strings.Contains(html, offboxSelectionChangedLine) {
|
||||
t.Error("the selection-changed note is missing for a translated warning that carries its kind")
|
||||
}
|
||||
if strings.Contains(html, en) {
|
||||
t.Error("the stale note is still on the page beside its replacement")
|
||||
}
|
||||
}
|
||||
|
||||
// The kind has to be PERSISTED beside the text and survive an edit of the target, or the page falls
|
||||
// back to the legacy text test on the next render (settings.json is the only carrier between runs).
|
||||
func TestR553_WarningKindIsPersistedAndCopied(t *testing.T) {
|
||||
tgt := settings.OffboxTarget{
|
||||
Enabled: true, Host: "nas.local", User: "felhom", RepoPath: "/srv/repo",
|
||||
LastWarning: "Sikeres — nincs mentésre jelölt alkalmazás", LastWarningKind: backup.OffboxWarnNoAppsSelected,
|
||||
}
|
||||
dir := t.TempDir()
|
||||
load := func() *settings.Settings {
|
||||
s, err := settings.Load(filepath.Join(dir, "settings.json"), log.New(io.Discard, "", 0))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return s
|
||||
}
|
||||
if err := load().SetOffboxTarget(&tgt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reloaded := load().GetOffboxTarget()
|
||||
if reloaded == nil {
|
||||
t.Fatal("the target did not survive the reload")
|
||||
}
|
||||
if reloaded.LastWarningKind != backup.OffboxWarnNoAppsSelected {
|
||||
t.Errorf("the warning kind was not persisted: %q", reloaded.LastWarningKind)
|
||||
}
|
||||
if reloaded.LastWarning != tgt.LastWarning {
|
||||
t.Errorf("the warning text changed across the reload: %q", reloaded.LastWarning)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user