R-575: the overcommit warning follows the reader's language

memoryVerdict returns the warning's bundle KEY (KeyMemoryOvercommitWarning)
and DeployStack hands it on; the API renders it per request
(deployWarningData). msgHU, whose only use this was, is gone.

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-05 22:42:21 +02:00
parent b36a85ac04
commit b05be0ac11
5 changed files with 81 additions and 26 deletions
@@ -0,0 +1,32 @@
package api
import (
"net/http/httptest"
"strings"
"testing"
"gitea.dooplex.hu/admin/felhom-controller/internal/stacks"
)
// R-575: the deploy answer renders the overcommit warning in the reader's language — English for an
// English request (it used to be Hungarian on every page), Hungarian by default.
func TestR575_OvercommitWarningFollowsTheLanguage(t *testing.T) {
r := &Router{}
en := r.deployWarningData(httptest.NewRequest("POST", "/api/stacks/x/deploy?lang=en", nil), stacks.KeyMemoryOvercommitWarning)
hu := r.deployWarningData(httptest.NewRequest("POST", "/api/stacks/x/deploy?lang=hu", nil), stacks.KeyMemoryOvercommitWarning)
if en == nil || hu == nil {
t.Fatal("a warning key must produce a warning")
}
if !strings.Contains(en["warning"], "memory") || strings.Contains(en["warning"], "memóri") {
t.Errorf("English page got %q", en["warning"])
}
if !strings.Contains(hu["warning"], "memóri") {
t.Errorf("Hungarian page got %q", hu["warning"])
}
if strings.Contains(en["warning"], "err.stacks.") || strings.Contains(hu["warning"], "err.stacks.") {
t.Error("a raw key reached the page")
}
if d := r.deployWarningData(httptest.NewRequest("POST", "/", nil), ""); d != nil {
t.Errorf("no warning -> no data, got %v", d)
}
}
+12 -2
View File
@@ -544,8 +544,8 @@ func (r *Router) deployStack(w http.ResponseWriter, req *http.Request, name stri
// was true — misleading for API/script consumers. Report that the deploy STARTED, not that it
// finished. 202 Accepted reflects "accepted, processing"; ok:true is preserved for the UI.
resp := apiResponse{OK: true, Message: r.msg(req, "api.deploy.started")}
if warning != "" {
resp.Data = map[string]string{"warning": warning}
if d := r.deployWarningData(req, warning); d != nil {
resp.Data = d
}
writeJSON(w, http.StatusAccepted, resp)
@@ -1651,3 +1651,13 @@ func startAnswer(name, action, state string) apiResponse {
Message: "Stack " + name + " " + action + " requested — state now: " + state,
Data: map[string]interface{}{"state": state}}
}
// deployWarningData renders the deploy's soft warning for the answer. R-575: DeployStack hands back the
// warning's bundle KEY, never a sentence, so it is rendered here in the reader's language. nil = none.
// Pinned by TestR575_OvercommitWarningFollowsTheLanguage.
func (r *Router) deployWarningData(req *http.Request, warningKey string) map[string]string {
if warningKey == "" {
return nil
}
return map[string]string{"warning": r.msg(req, warningKey)}
}