Files
felhom.eu/hub/internal/configgen/language_test.go
T
admin 9167cf53af
gates / gates (push) Successful in 23s
hub v0.118.0: the household's e-mails follow the household's language (R-558 Part A)
The hub has written every customer e-mail in Hungarian whatever the box was set
to. The box has published its language since controller v0.247.0; nothing read
it. Now it does.

Nothing an operator reads changes. The Hungarian mails are byte-identical, and
that is a diff rather than a reading: 56 goldens per language captured from
v0.117.0 BEFORE any string moved, and all 56 Hungarian ones pass unchanged after
every sentence was routed through the new bundle.

- internal/i18n: flat bundle, 79 keys, hu authoritative + hu fallback, ceiling 0.
- customerMessages/severityLabels are DERIVED from the bundle, so a sentence is
  written in one place and all 40+ tests that read those maps still work.
- Language order: last reported -> created-with -> hu. reports.language defaults
  to EMPTY, never hu: "never told us" is not "chose Hungarian".
- message_customer on POST /api/v1/event, additive and optional forever, for the
  sentences the box composes and the hub cannot translate.
- The bind page is per-language, and its `expired` state stays Hungarian: it is
  the state an unknown token lands in, so rendering a real English customer's
  token in English would make the LANGUAGE answer what the TEXT refuses to.

Two defects found inside the release:
- R-581: the newest report was picked by received_at, which has SECOND
  granularity, so same-second reports tied and the winner was arbitrary. Ordered
  by the autoincrement id now. GetCustomers() still has the shape - row open.
- R-582: the English copy-guard stems, ported word for word from Hungarian,
  convicted 141 honest sentences. The English claim is a phrase with a modal.

R-555 closed: the language allowlist entry is out of wire_contract_gate.py.
hub_copy_gate.py follows the sentences into the bundle - without that it would
have scanned four files that no longer hold any customer text and reported
success. Three new decoys incl. an innocent control.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
2026-09-18 16:20:11 +02:00

94 lines
3.1 KiB
Go

package configgen
import (
"strings"
"testing"
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
)
// S4/S6 (R-558) — `customer.language` reaches controller.yaml, and it is the ONLY thing that moved.
//
// The controller reads it to decide what language a box STARTS in, before anyone has touched the
// dashboard switch. It has to arrive, and nothing else may arrive with it: a config pull restarts
// the box, so an unintended second change would ride out to the whole fleet on the same wire.
func TestGenerate_CustomerLanguage(t *testing.T) {
const tmpl = "customer:\n id: \"\"\n name: \"\"\nlogging:\n level: info\n"
base := &store.CustomerConfig{CustomerID: "c1", CustomerName: "Acme", ConfigJSON: "{}"}
withEN := &store.CustomerConfig{CustomerID: "c1", CustomerName: "Acme", ConfigJSON: "{}", Language: "en"}
huYAML, err := Generate(tmpl, base, nil)
if err != nil {
t.Fatal(err)
}
enYAML, err := Generate(tmpl, withEN, nil)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(enYAML, "language: en") {
t.Fatalf("customer.language did not reach controller.yaml:\n%s", enYAML)
}
// THE DIFF IS EXACTLY ONE LINE. Compared line by line after dropping the fields that are
// regenerated on every call — a session secret and a timestamp differ between any two renders,
// so counting them would make this test pass no matter what else changed.
huLines := stableLines(huYAML)
enLines := stableLines(enYAML)
var onlyInEN, onlyInHU []string
for _, l := range enLines {
if !contains(huLines, l) {
onlyInEN = append(onlyInEN, l)
}
}
for _, l := range huLines {
if !contains(enLines, l) {
onlyInHU = append(onlyInHU, l)
}
}
if len(onlyInEN) != 1 || !strings.Contains(onlyInEN[0], "language: en") {
t.Errorf("the English config differs from the Hungarian one by %d line(s), want exactly the "+
"language line: %v", len(onlyInEN), onlyInEN)
}
if len(onlyInHU) != 1 || !strings.Contains(onlyInHU[0], "language:") {
t.Errorf("the Hungarian config has %d line(s) the English one lacks, want exactly the "+
"language line: %v", len(onlyInHU), onlyInHU)
}
}
// An empty creation language still writes a line — the box is told "Hungarian" explicitly rather
// than being left to guess from an absent key.
func TestGenerate_EmptyLanguageStillWritesTheKey(t *testing.T) {
const tmpl = "customer:\n id: \"\"\n"
y, err := Generate(tmpl, &store.CustomerConfig{CustomerID: "c1", ConfigJSON: "{}"}, nil)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(y, "language:") {
t.Errorf("no language key at all — the box cannot tell a default from a missing field:\n%s", y)
}
}
// stableLines drops the lines that are regenerated on every call, so two renders are comparable.
func stableLines(y string) []string {
var out []string
for _, l := range strings.Split(y, "\n") {
t := strings.TrimSpace(l)
if t == "" || strings.HasPrefix(t, "session_secret:") || strings.HasPrefix(t, "generated_at:") {
continue
}
out = append(out, l)
}
return out
}
func contains(ls []string, want string) bool {
for _, l := range ls {
if l == want {
return true
}
}
return false
}