v0.309.0: the fill warning reaches the household in its own language; the root-filesystem disk event pinned end to end (R-521 F7)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
2026-10-12 17:11:53 +02:00
parent 402fa41e45
commit 7626a28de3
14 changed files with 290 additions and 53 deletions
+61 -27
View File
@@ -27,6 +27,8 @@ import (
"sort"
"strings"
"sync"
"gitea.dooplex.hu/admin/felhom-controller/internal/i18n"
)
// ── Thresholds ───────────────────────────────────────────────────────────────────────────────────
@@ -120,6 +122,11 @@ type Usage struct {
type Target struct {
Path string
Label string
// LabelKey, when set, names the target in the household's language from the bundle (the two
// built-in areas: „Alkalmazások területe", „Rendszer- és mentési terület"). Label stays the
// Hungarian name for the log and the event details. A household's own drive label has no key —
// the household named it, in whatever language it wished.
LabelKey string
}
// Event is one crossing, handed to the notify seam.
@@ -127,7 +134,10 @@ type Event struct {
Target Target
Band Band
Usage Usage
Message string // the Hungarian customer text, already rendered
Message string // the Hungarian customer text, already rendered (the wire's `message`)
// MessageHousehold is the same sentence in the household's language (the wire's
// `message_customer`, R-558); "" for a Hungarian household, which sends nothing extra.
MessageHousehold string
}
// Watcher holds the persisted per-filesystem band and emits on escalation only.
@@ -142,9 +152,12 @@ type Watcher struct {
usage func(path string) *Usage
// notify pushes the customer event. Nil-safe.
notify func(Event)
// extra appends a sentence to the warning for one target — the kept folders on it the household
// can delete (`09` §3 decision 36). Nil-safe; "" appends nothing.
extra func(Target) string
// extra appends a sentence to the warning for one target, in a language — the kept folders on it
// the household can delete (`09` §3 decision 36). Nil-safe; "" appends nothing.
extra func(t Target, lang string) string
// lang returns the household's language (R-521 F7: the warning reaches an English household in
// English). Nil-safe: nil means Hungarian only.
lang func() string
mu sync.Mutex
bands map[string]Band
@@ -168,7 +181,10 @@ func New(statePath string, logger *log.Logger, targets func() []Target, usage fu
func (w *Watcher) SetNotify(fn func(Event)) { w.notify = fn }
// SetExtra wires the kept-data sentence (main.go). INIT-ONLY.
func (w *Watcher) SetExtra(fn func(Target) string) { w.extra = fn }
func (w *Watcher) SetExtra(fn func(t Target, lang string) string) { w.extra = fn }
// SetLang wires the household's language (main.go: settings.GetLanguage). INIT-ONLY.
func (w *Watcher) SetLang(fn func() string) { w.lang = fn }
// classify decides the band from a reading AND the previous band, which is what makes the hysteresis
// work: between the clear and warn thresholds the previous band is HELD rather than recomputed.
@@ -236,17 +252,18 @@ func (w *Watcher) Check() error {
continue
}
msg := Message(t, *u, next)
if w.extra != nil {
if x := w.extra(t); x != "" {
msg += " " + x
msg := w.messageWithExtra(i18n.Default, t, *u, next)
household := ""
if w.lang != nil {
if lang := i18n.Normalize(w.lang()); lang != i18n.Default {
household = w.messageWithExtra(lang, t, *u, next)
}
}
w.logger.Printf("[WARN] [fillwatch] %s (%q): %s → %s — %.0f%% used, %.1f GB free of %.1f GB; notifying the customer",
t.Path, t.Label, prev, next, u.UsedPercent, u.AvailGB, u.TotalGB)
emitted++
if w.notify != nil {
w.notify(Event{Target: t, Band: next, Usage: *u, Message: msg})
w.notify(Event{Target: t, Band: next, Usage: *u, Message: msg, MessageHousehold: household})
}
}
@@ -273,6 +290,17 @@ func (w *Watcher) Check() error {
return w.saveLocked()
}
// messageWithExtra is the warning in one language, with the kept-data sentence when there is one.
func (w *Watcher) messageWithExtra(lang string, t Target, u Usage, band Band) string {
msg := MessageLang(lang, t, u, band)
if w.extra != nil {
if x := w.extra(t, lang); x != "" {
msg += " " + x
}
}
return msg
}
// bandSummaryLocked renders the current per-path bands for the run summary, deterministically. Caller
// holds w.mu.
func (w *Watcher) bandSummaryLocked() string {
@@ -376,35 +404,41 @@ func (w *Watcher) saveLocked() error {
// these two types: `FormatCustomerEmail` PREFERS the entry over the message, so a static template
// would discard the label and the figures — exactly why `offbox_enlarge_blocked` and
// `disk_health_degraded` have none either.
func Message(t Target, u Usage, band Band) string {
func Message(t Target, u Usage, band Band) string { return MessageLang(i18n.Default, t, u, band) }
// MessageLang is Message in a language, from the bundle keys `event.fill.critical` /
// `event.fill.warning` (R-521 F7). The Hungarian is the literal these keys replaced minus its formal
// „Kérjük," opening (the R-516 te-form gate); TestMessageHungarianWireText pins the exact bytes.
func MessageLang(lang string, t Target, u Usage, band Band) string {
b, err := i18n.Shared()
if err != nil {
// The bundle is embedded: this is a broken build. Say it in the log and send the figures bare
// rather than nothing — an event with a visible fault reaches the operator and gets fixed.
return fmt.Sprintf("%s: %s, %s (%v)", t.Path, gbIn(lang, u.AvailGB), percent(u.UsedPercent), err)
}
name := t.Label
if t.LabelKey != "" && b.Has(i18n.Normalize(lang), t.LabelKey) {
name = b.Msg(lang, t.LabelKey)
}
if name == "" {
name = t.Path
}
if band == BandCritical {
return fmt.Sprintf(
"A(z) „%s” tároló kritikusan megtelt: %s szabad hely maradt (%s foglalt). "+
"A biztonsági mentések és az alkalmazások írásai bármikor meghiúsulhatnak. "+
"Kérjük, mielőbb szabadíts fel helyet: törölj felesleges fájlokat, vagy csatlakoztass új meghajtót.",
name, hunGB(u.AvailGB), hunPercent(u.UsedPercent))
return b.Msgf(lang, "event.fill.critical", name, gbIn(lang, u.AvailGB), percent(u.UsedPercent))
}
return fmt.Sprintf(
"A(z) „%s” tároló %s foglalt — %s szabad hely maradt. "+
"Kérjük, szabadíts fel helyet, mielőtt megtelik: törölj felesleges fájlokat, vagy csatlakoztass új meghajtót. "+
"Ha megtelik, a biztonsági mentések meghiúsulnak.",
name, hunPercent(u.UsedPercent), hunGB(u.AvailGB))
return b.Msgf(lang, "event.fill.warning", name, percent(u.UsedPercent), gbIn(lang, u.AvailGB))
}
// hunGB formats a GB figure the Hungarian way — decimal COMMA, one decimal place. A "4.2 GB" in a
// Hungarian sentence reads as a typo to the customer.
func hunGB(gb float64) string {
// gbIn formats a GB figure with lang's decimal separator, one decimal place — a "4.2 GB" in a
// Hungarian sentence reads as a typo to the customer, and "4,2 GB" in an English one.
func gbIn(lang string, gb float64) string {
if gb >= 1024 {
return strings.Replace(fmt.Sprintf("%.1f TB", gb/1024), ".", ",", 1)
return i18n.FormatDecimal(lang, gb/1024, 1) + " TB"
}
return strings.Replace(fmt.Sprintf("%.1f GB", gb), ".", ",", 1)
return i18n.FormatDecimal(lang, gb, 1) + " GB"
}
func hunPercent(p float64) string { return fmt.Sprintf("%.0f%%", p) }
func percent(p float64) string { return fmt.Sprintf("%.0f%%", p) }
// SortTargets gives Check a deterministic order, so a multi-filesystem crossing produces its events
// in a stable sequence (tests, and a readable log).
@@ -273,7 +273,7 @@ func TestCustomerMessageNamesTheDriveTheSpaceAndTheAction(t *testing.T) {
if !strings.Contains(msg, "87%") {
t.Fatalf("the message does not give the fill percentage. Got: %s", msg)
}
if !strings.Contains(msg, "szabadíts fel helyet") && !strings.Contains(msg, "szabadíts fel helyet:") {
if !strings.Contains(strings.ToLower(msg), "szabadíts fel helyet") { // v0.309.0: the sentence may open with it (R-516 dropped „Kérjük,")
t.Fatalf("the message does not tell the customer WHAT TO DO. Got: %s", msg)
}
// Design-system rule: no emoji in customer copy.
@@ -15,7 +15,7 @@ func TestFillwatch_ExtraSentenceRidesTheWarning(t *testing.T) {
func() []Target { return []Target{{Path: "/mnt/d", Label: "HDD"}} },
func(string) *Usage { return &Usage{UsedPercent: 97, AvailGB: 3, UsedGB: 97, TotalGB: 100} })
w.SetNotify(func(e Event) { got = append(got, e) })
w.SetExtra(func(tg Target) string {
w.SetExtra(func(tg Target, _ string) string {
if tg.Path == "/mnt/d" {
return "KEPT: Nextcloud (126.0 MB)."
}
@@ -0,0 +1,76 @@
package fillwatch
import (
"io"
"log"
"path/filepath"
"strings"
"testing"
)
// R-521 F7 — the fill warning moved from a Go literal to the bundle (`event.fill.*`) so an English
// household is told in English. The Hungarian wire text is pinned to the byte: it is the pre-bundle
// literal (this test ran green against 68294ec's fillwatch.go with these strings carrying „Kérjük, ")
// minus that one formal opening, which the R-516 te-form gate refuses in the bundle.
func TestMessageHungarianWireText(t *testing.T) {
cases := []struct {
name string
got string
want string
}{
{"warning", Message(photos, Usage{UsedPercent: 87, AvailGB: 4.2, TotalGB: 100}, BandWarning),
"A(z) „Fotók” tároló 87% foglalt — 4,2 GB szabad hely maradt. Szabadíts fel helyet, mielőtt megtelik: törölj felesleges fájlokat, vagy csatlakoztass új meghajtót. Ha megtelik, a biztonsági mentések meghiúsulnak."},
{"critical", Message(photos, Usage{UsedPercent: 96, AvailGB: 1.4, TotalGB: 100}, BandCritical),
"A(z) „Fotók” tároló kritikusan megtelt: 1,4 GB szabad hely maradt (96% foglalt). A biztonsági mentések és az alkalmazások írásai bármikor meghiúsulhatnak. Szabadíts fel helyet mielőbb: törölj felesleges fájlokat, vagy csatlakoztass új meghajtót."},
{"terabytes", Message(Target{Path: "/mnt/big", Label: "Média"}, Usage{UsedPercent: 88, AvailGB: 2048, TotalGB: 16000}, BandWarning),
"A(z) „Média” tároló 88% foglalt — 2,0 TB szabad hely maradt. Szabadíts fel helyet, mielőtt megtelik: törölj felesleges fájlokat, vagy csatlakoztass új meghajtót. Ha megtelik, a biztonsági mentések meghiúsulnak."},
{"no label", Message(Target{Path: "/mnt/sys_drive"}, Usage{UsedPercent: 90, AvailGB: 1.5}, BandWarning),
"A(z) „/mnt/sys_drive” tároló 90% foglalt — 1,5 GB szabad hely maradt. Szabadíts fel helyet, mielőtt megtelik: törölj felesleges fájlokat, vagy csatlakoztass új meghajtót. Ha megtelik, a biztonsági mentések meghiúsulnak."},
}
for _, c := range cases {
if c.got != c.want {
t.Errorf("%s: Hungarian changed.\n got: %q\n want: %q", c.name, c.got, c.want)
}
}
}
// The household half: an English household gets the same warning in English, the built-in area named
// in English, the figure with a decimal point; a Hungarian household sends nothing extra.
func TestR521F7_HouseholdLanguageRidesTheEvent(t *testing.T) {
root := Target{Path: "/", Label: "Alkalmazások területe", LabelKey: "event.fill.label_apps"}
for _, lang := range []string{"en", "hu"} {
t.Run(lang, func(t *testing.T) {
var got []Event
w := New(filepath.Join(t.TempDir(), "s.json"), log.New(io.Discard, "", 0),
func() []Target { return []Target{root} },
func(string) *Usage { return &Usage{UsedPercent: 95, AvailGB: 3.5, UsedGB: 65, TotalGB: 68.7} })
w.SetNotify(func(e Event) { got = append(got, e) })
w.SetLang(func() string { return lang })
w.SetExtra(func(_ Target, l string) string { return "EXTRA-" + l })
if err := w.Check(); err != nil {
t.Fatal(err)
}
if len(got) != 1 {
t.Fatalf("events = %d, want 1", len(got))
}
e := got[0]
if !strings.Contains(e.Message, "Alkalmaz") || !strings.Contains(e.Message, "3,5 GB") || !strings.HasSuffix(e.Message, " EXTRA-hu") {
t.Errorf("Hungarian message = %q", e.Message)
}
if lang == "hu" {
if e.MessageHousehold != "" {
t.Errorf("a Hungarian household sends nothing extra; got %q", e.MessageHousehold)
}
return
}
for _, want := range []string{"App area", "critically full", "3.5 GB", "95%", " EXTRA-en"} {
if !strings.Contains(e.MessageHousehold, want) {
t.Errorf("English message %q lacks %q", e.MessageHousehold, want)
}
}
if strings.Contains(e.MessageHousehold, "Alkalmaz") {
t.Errorf("English message carries the Hungarian area name: %q", e.MessageHousehold)
}
})
}
}
+4
View File
@@ -1444,6 +1444,10 @@
"event.health_recovered": "System health is back to normal: %s (was: %s)",
"event.storage_disconnected": "Drive disconnected unexpectedly: %s",
"event.storage_reconnected": "Drive reconnected: %s",
"event.fill.critical": "The storage “%s” is critically full: %s of free space is left (%s used). Backups and app writes can fail at any moment. Free up space soon: delete files you do not need, or connect a new drive.",
"event.fill.warning": "The storage “%s” is %s full — %s of free space is left. Free up space before it fills: delete files you do not need, or connect a new drive. If it fills, backups will fail.",
"event.fill.label_apps": "App area",
"event.fill.label_system": "System and backup area",
"flash.backup.not_configured": "Backup is not set up",
"flash.backup.window_invalid_time": "That is not a valid time. Use the HH:MM format (02:30, for example).",
"flash.backup.window_save_failed": "The backup window could not be saved.",
+4
View File
@@ -1435,6 +1435,10 @@
"event.health_recovered": "Rendszer állapot helyreállt: %s (volt: %s)",
"event.storage_disconnected": "Meghajtó váratlanul leválasztva: %s",
"event.storage_reconnected": "Meghajtó újra csatlakoztatva: %s",
"event.fill.critical": "A(z) „%s” tároló kritikusan megtelt: %s szabad hely maradt (%s foglalt). A biztonsági mentések és az alkalmazások írásai bármikor meghiúsulhatnak. Szabadíts fel helyet mielőbb: törölj felesleges fájlokat, vagy csatlakoztass új meghajtót.",
"event.fill.warning": "A(z) „%s” tároló %s foglalt — %s szabad hely maradt. Szabadíts fel helyet, mielőtt megtelik: törölj felesleges fájlokat, vagy csatlakoztass új meghajtót. Ha megtelik, a biztonsági mentések meghiúsulnak.",
"event.fill.label_apps": "Alkalmazások területe",
"event.fill.label_system": "Rendszer- és mentési terület",
"flash.backup.not_configured": "Mentés nincs beállítva",
"flash.backup.window_invalid_time": "Érvénytelen időpont. Használd az ÓÓ:PP formátumot (például 02:30).",
"flash.backup.window_save_failed": "A mentési időablak mentése nem sikerült.",
+7
View File
@@ -261,6 +261,13 @@ func (n *Notifier) PushEvent(eventType, severity, message string, details interf
n.pushEventBoth(eventType, severity, message, "", details)
}
// PushEventHousehold is PushEvent with the household's own rendering beside the Hungarian (R-558's
// `message_customer`), for a producer that renders both languages itself because the sentence carries
// figures it computed (fillwatch, R-521 F7). household "" = a Hungarian household: nothing extra.
func (n *Notifier) PushEventHousehold(eventType, severity, message, household string, details interface{}) {
n.pushEventBoth(eventType, severity, message, household, details)
}
func (n *Notifier) pushEventBoth(eventType, severity, message, messageCustomer string, details interface{}) {
// The test seam sits HERE, not only in emit (v0.252.0, R-557). Most producers call PushEvent
// directly, so a test that set pushFn saw nothing from them and the difference was invisible: a
@@ -57,6 +57,7 @@ var severityArg = map[string]int{
"pushEventMsg": 1, // (eventType, severity, key, details, args...)
"pushEventMsgSuffix": 1, // (eventType, severity, key, suffix, details, args...)
"pushEventBoth": 1, // (eventType, severity, message, messageCustomer, details)
"PushEventHousehold": 1, // (eventType, severity, message, household, details)
}
// knownDynamicSeveritySites are the call sites that pass a VARIABLE rather than a literal, so this
@@ -72,11 +73,12 @@ var knownDynamicSeveritySites = map[string]string{
"internal/notify/notifier.go:PushEvent": `pass-through of its own severity parameter to pushEventBoth — checked at PushEvent's callers`,
"internal/notify/notifier.go:pushEventMsg": `pass-through of its own severity parameter to pushEventBoth — checked at pushEventMsg's callers`,
"internal/notify/notifier.go:pushEventMsgSuffix": `pass-through of its own severity parameter to pushEventBoth — checked at pushEventMsgSuffix's callers`,
"internal/notify/notifier.go:PushEventHousehold": `pass-through of its own severity parameter to pushEventBoth — checked at PushEventHousehold's callers`,
"internal/notify/notifier.go:NotifyControllerUpdated": `local var: "info", or "error" when the update failed`,
"internal/notify/notifier.go:NotifyDRCompleted": `local var: "info", or "warning" when failCount > 0`,
"internal/notify/notifier.go:NotifyAgentChannelDown": `internal/channelhealth's classifier — every severity literal in checker.go is "warning" or "error"`,
"internal/notify/notifier.go:NotifyDiskHealthDegraded": `DiskAlertKind.Severity() — pinned behaviourally by TestR329_DiskAlertSeveritiesStillSatisfyTheContract`,
"cmd/controller/main.go:main": `fillwatch.Band.Severity() in the SetNotify closure — pinned by TestR329_FillwatchNeverEmitsTheEmptySeverity`,
"cmd/controller/main.go:fillEventPush": `fillwatch.Band.Severity() — pinned by TestR329_FillwatchNeverEmitsTheEmptySeverity`,
}
func walkControllerFiles(t *testing.T, fn func(path string, fset *token.FileSet, f *ast.File)) {