Files
felhom-controller/controller/internal/web/backup_page_state.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

85 lines
4.3 KiB
Go

package web
// backup_page_state holds the small pure state-pick helpers that drive the honest
// per-app / whole-page messaging on the /backups page. They are pure (no *Server,
// no I/O) so the truth-table can be unit-tested directly without a fixture Server.
// dbSectionState decides how the "Adatbázisok" section (and the "Adatbázis mentve"
// stat card) should read, given how many databases were discovered live at render
// time and how many dump files exist on disk:
// - "dumps" — dump files exist → show the real dump table / count.
// - "pending" — a database was discovered but no dump written yet → "first run tonight".
// - "embedded" — neither: the deployed apps carry embedded DBs (e.g. SQLite) that ride
// the file/volume backup; no separate dump is expected, so a bare "0" would lie.
//
// dumps wins over discovered: stale dumps from a since-removed DB app are still a real,
// restorable artifact and must be shown normally (see the §8 edge-case table).
func dbSectionState(discovered, dumps int) string {
switch {
case dumps > 0:
return "dumps"
case discovered > 0:
return "pending"
default:
return "embedded"
}
}
// tier3State decides the per-app "3. mentés" (off-box / off-site) row state:
// - "unconfigured" — no off-box target set (configured wins over a stale per-app toggle).
// - "off" — target set but this app is not toggled for off-box backup.
// - "escrow_pending" — toggled, but the repo password is not yet escrowed (fork-4 gate):
// runs are paused, so we must NOT imply a successful run.
// - "active" — toggled and escrowed: the app is included in the off-box runs.
//
// Precedence is strict: configured → toggle → escrow. Anything other than "escrowed"
// while toggled is treated as escrow-pending (never "active"), so a pre-pending LastStatus
// of "ok" can never surface a false "Sikeres".
func tier3State(configured, toggled bool, escrowState string) string {
switch {
case !configured:
return "unconfigured"
case !toggled:
return "off"
case escrowState != "escrowed":
return "escrow_pending"
default:
return "active"
}
}
// driveFilesNoteFor is the one sentence under a class-A app's Tier-1 row: where the household's own
// FILES are protected, said in the state the box is actually in.
//
// R-543. v0.244.0 shipped this sentence in one form — „a távoli másolat … védi" — and it was true of
// the design and false of a fresh box: off-site is ON by default (hub v0.116.0) but PAUSED until the
// household performs the escrow ceremony, which nothing asked them to do. A sentence that promises a
// copy which is not running is the same class of lie R-537 and R-538 were filed for, committed by the
// fix for them.
//
// It is pure, and it takes tier3State's OWN vocabulary rather than re-deriving the state, so the row
// and the sentence can never disagree:
//
// "active" → the copy exists and runs → „védi"
// "escrow_pending" → enabled, paused for the code → „védené … szünetel" + the route to fix it
// "off"/"unconfig" → no off-site at all → say so, and name both ways out
//
// The link is returned separately so the template renders a real anchor and the copy gate sees plain
// text; empty note means render nothing (an app whose data is in its volumes needs no sentence).
func driveFilesNoteFor(hasDriveFileLegs bool, tier3State string, tier2Configured bool) (note, linkHref, linkText string) {
if !hasDriveFileLegs {
return "", "", ""
}
switch tier3State {
case "active":
return "Az alkalmazás fájljait a távoli másolat (és a második meghajtó) védi — ez a helyi mentés a beállításokat és az adatbázist tartalmazza.", "", ""
case "escrow_pending":
return "Az alkalmazás fájljait a távoli másolat védené — a távoli mentés a helyreállítási kód létrehozásáig szünetel.", "/backup/escrow", "Helyreállítási kód létrehozása"
default:
if tier2Configured {
return "Az alkalmazás fájljait a második meghajtóra készülő másolat védi — ez a helyi mentés a beállításokat és az adatbázist tartalmazza.", "", ""
}
return "Az alkalmazás fájljairól jelenleg nincs másolat — kapcsold be a távoli mentést vagy adj hozzá második meghajtót.", "/backups/remote", "Távoli mentés beállítása"
}
}