package web import ( "context" "encoding/json" "net/http" "net/http/httptest" "testing" "gitea.dooplex.hu/admin/felhom-controller/internal/agentapi" ) // R-574 — handler_debug.go's literals, classified once: 38 are PAGE COPY (every writeDebugJSON // message/error, which debug.html prints into the result line, plus the pre-0.83 agent `notice`, // which it prints into the log viewer) and were moved to the bundle (debug.api.*); ONE is PAYLOAD — // the `Teszt esemény: %s (%s)` text handed to PushTestEventSync, which travels to the hub as the // test event's own message — and stays a literal on purpose. The diagnostic dump carries no // Hungarian. // // The consequence pinned here: the Hungarian page is byte-for-byte what it was (the parity gate // proves the bundle text; this proves the handler reads it), and an English page is English. // RED-PROOF (REPORT): put either producer back to its literal and the English rows fail. func TestR574_DebugPageCopyFollowsTheLanguage(t *testing.T) { type debugResp struct { OK bool `json:"ok"` Error string `json:"error"` Data struct { Notice string `json:"notice"` } `json:"data"` } run := func(t *testing.T, lang string, call func(s *Server, w http.ResponseWriter, r *http.Request)) debugResp { t.Helper() s := testServer(t) if s.settings == nil { t.Fatal("testServer has no settings — the language cannot be set") } s.settings.SetConfigLanguage(lang) w := httptest.NewRecorder() call(s, w, httptest.NewRequest(http.MethodPost, "/api/debug/x", nil)) var resp debugResp if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil { t.Fatalf("decode: %v (%s)", err, w.Body.String()) } return resp } dbDump := func(s *Server, w http.ResponseWriter, r *http.Request) { s.backupMgr = nil s.debugTriggerDBDump(w, r) } notice := func(s *Server, w http.ResponseWriter, r *http.Request) { s.agentLogsFn = func(context.Context) (agentapi.AgentLogsResponse, error) { return agentapi.AgentLogsResponse{}, &agentapi.StatusError{Path: "/debug/logs", Code: http.StatusNotFound} } s.debugAgentLogs(w, r) } if got := run(t, "hu", dbDump).Error; got != "Backup manager nincs konfigurálva" { t.Errorf("hu error = %q — the Hungarian bytes moved", got) } if got := run(t, "en", dbDump).Error; got != "Backup manager is not configured" { t.Errorf("en error = %q — the handler does not read the bundle", got) } if got := run(t, "hu", notice).Data.Notice; got != "Az ügynök naplónézete az ügynök következő frissítése után érhető el." { t.Errorf("hu notice = %q — the Hungarian bytes moved", got) } if got := run(t, "en", notice).Data.Notice; got != "The agent’s log view becomes available after the agent’s next update." { t.Errorf("en notice = %q — the handler does not read the bundle", got) } }