Files
felhom-controller/controller/internal/web/r625_r647_held_test.go
T
admin e66d4669d6
gates / gates (push) Failing after 47s
v0.315.0: one app page with four tabs; the guide the catalog can carry; no Raspberry Pi badge
An app was six pages — details, install/settings, logs, export, the per-app backup panel and a
details card for moving data — and every "Vissza" on them went to the app LIST, so there was no way
back to the app you were looking at. It is now ONE page with four tab URLs under /apps/{slug}/,
one shared header and one set of banners.

  settings  Mukodes (Start/Restart/Stop, Stop confirms) + the cards that want something from the
            household + the install-time and optional settings. The default for an installed app,
            RENDERED at the bare URL and never redirected to.
  data      the data folders, move to another drive, the nightly copy, the 2nd-copy setting, export
  guide     tagline, screenshots, use cases, first steps, the catalog's guide, the FAQ, the docs
            link — and the WHOLE page for an app that is not installed
  logs      the log, and the only tab whose poller runs

The tabs are links, not panels: a link in an alert has to land ON a tab, and the log poller must not
run on the other three. Start/Restart/Stop left the page header, where they read as menu buttons.

The old /stacks/{name}/{deploy,logs,export,backup} GETs answer 302 — never 301, which a browser
caches beyond anyone's reach — to the tab that now holds them, query string carried through, with
name->slug resolved through the stack list rather than assumed equal. Every POST on those paths is
untouched: the backup form, the app-email toggle and the reveal endpoints keep their URLs.

A value asked AFTER the app starts is now generic (D2). The catalog marks a field `after_start: true`
and supplies its label; the ACTION is Go, in a registry keyed by slug + env var. The catalog can
never declare what runs — a declared field with no registered action renders nothing, POSTs 404 and
logs one WARN with the env var KEY, never the value. A red-proof found the second half of that guard
unpinned: deleting the "the catalog must have DECLARED this field" check left the suite green, and a
POST for an undeclared field then reached Plex and opened the setup gate.
TestAfterStart_RegistryAloneIsNotAnInvitation pins it.

New catalog block app_info.guide (sections + faq + checked_version), parsed, localised field by
field and rendered with the household's own address filled in. It renders only when checked_version
names the image tag its author clicked through. No template carries one yet.

The Pi and "csak x86" badges are gone; PiCompatible and the catalog key stay this release, or a box
on 0.314.0 would read "csak x86" on every app (R-1067).

template_id_gate.py now follows {{template}} includes, with a scope decoy proving the walk did not
become vacuous.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0117kRTSgs3rJWUFGxyoWN6Y
2026-10-15 18:37:50 +02:00

137 lines
6.0 KiB
Go

package web
import (
"html"
"io"
"log"
"strings"
"testing"
"time"
"gitea.dooplex.hu/admin/felhom-controller/internal/backup"
"gitea.dooplex.hu/admin/felhom-controller/internal/i18n"
"gitea.dooplex.hu/admin/felhom-controller/internal/stacks"
)
// heldBehindStack is R-625's measured shape: HELD by a failed update, while the catalog has already
// published a newer version — the moment the page used to say „Frissítés elérhető".
func heldBehindStack(t *testing.T, s *Server, boxLang string) (stacks.Stack, *backup.Manager) {
t.Helper()
b := backup.NewManager(s.cfg, s.settings, log.New(io.Discard, "", 0))
s.backupMgr = b
if boxLang != "" {
if err := s.settings.SetLanguage(boxLang); err != nil {
t.Fatal(err)
}
}
at := time.Date(2026, 9, 23, 8, 0, 0, 0, time.UTC)
if err := b.HoldAfterFailedUpdateHolding("kimai", at, at.Add(-6*time.Hour), backup.UpdateTierLocal, b.UpdateCopyHolds("kimai", backup.UpdateTierLocal), ""); err != nil {
t.Fatal(err)
}
_, why := b.RestoreHoldFor("kimai") // in the BOX's language, as fillHoldReason stores it
st := i18nStack("kimai", "Kimai Time", stacks.StateStopped, true)
st.AppConfig = &stacks.AppConfig{Deployed: true, InstalledImages: map[string]stacks.InstalledImage{"web": {Ref: "kimai/kimai2:2.30.0"}}}
st.CatalogImages = map[string]string{"web": "kimai/kimai2:2.31.0"}
if compareInstalledToTemplate(st) != updateBehind {
t.Fatal("fixture: the held app must also be BEHIND the catalog (R-625's shape)")
}
st.HoldReason = why
st.UpdatePhase, st.UpdateErrorKey, st.UpdateError = stacks.UpdatePhaseFailed, stacks.UpdateErrorKeyHeld, why
return st, b
}
func renderHeld(t *testing.T, s *Server, st stacks.Stack, lang, tmpl string) string {
t.Helper()
c := i18nCase{"r625_" + tmpl, tmpl, func() map[string]interface{} {
if tmpl == "stacks" {
d := i18nLayoutData("stacks", "Alkalmazások")
d["Stacks"] = []stacks.Stack{st}
for _, k := range []string{"Subdomains", "MissingStorage", "NetworkStubs", "NetworkWarnings", "StorageLabels"} {
d[k] = map[string]string{}
}
return d
}
d := i18nLayoutData("stacks", "Kimai")
cp := st
d["Stack"], d["Meta"], d["AppInfo"] = &cp, cp.Meta, cp.Meta.AppInfo
return d
}}
return html.UnescapeString(renderI18nCase(t, s, lang, c))
}
// R-625 — a held app says it is stopped and needs a restore, in both languages, on the app page; and
// NEITHER page offers the Update button.
//
// COMPANION RED-PROOF (REPORT.md): remove the HoldReason branch from updateBadgeAt (v0.264.0's shape)
// — the Hungarian page says „Frissítés elérhető" and this fails.
func TestR625_AHeldAppSaysStoppedRestoreNeeded(t *testing.T) {
s := i18nTestServer(t)
st, _ := heldBehindStack(t, s, "")
for _, c := range []struct{ lang, badge, invite, title string }{
{"hu", "Megállítva — visszaállítás szükséges", "Frissítés elérhető", "A(z) kimai frissítése"},
{"en", "Stopped — restore needed", "Update available", "The update of kimai"},
} {
page := renderHeld(t, s, st, c.lang, "app_settings")
if !strings.Contains(page, `<span class="tag tag-error" title="`) || !strings.Contains(page, c.badge) {
t.Errorf("%s app page: the held badge %q (tag-error) is missing", c.lang, c.badge)
}
if strings.Contains(page, c.invite) {
t.Errorf("%s app page still invites an update (%q) on a HELD app — R-625", c.lang, c.invite)
}
if i := strings.Index(page, c.badge); i > 0 && !strings.Contains(page[max(0, i-400):i], c.title) {
t.Errorf("%s: the badge title must open with the hold sentence (%q)", c.lang, c.title)
}
for _, tmpl := range []string{"app_settings", "stacks"} {
if strings.Contains(renderHeld(t, s, st, c.lang, tmpl), `'kimai', 'update')`) {
t.Errorf("%s %s: the Update button is rendered for a HELD app", c.lang, tmpl)
}
}
}
// CONTROL: the same app, not held and running, DOES get the button on the list — so the check above
// can see a button when there is one.
free := st
free.HoldReason, free.UpdateError, free.UpdateErrorKey, free.State = "", "", "", stacks.StateRunning
if !strings.Contains(renderHeld(t, s, free, "hu", "stacks"), `'kimai', 'update')`) {
t.Fatal("control: a running, not-held app must show the Update button on the list")
}
}
// R-647 (1) — on an ENGLISH box, a Hungarian reader (`?lang=hu`, an operator) reads the hold and the
// held update's error in HUNGARIAN; the English reader reads English. Both ways, both pages.
//
// COMPANION RED-PROOF (REPORT.md): make readerFuncs return nil (v0.264.0: no Hungarian override) — the
// Hungarian page carries the English hold and this fails.
func TestR647_AReaderInTheOtherLanguageReadsTheHoldInTheirs(t *testing.T) {
s := i18nTestServer(t)
st, _ := heldBehindStack(t, s, "en")
if !strings.Contains(st.HoldReason, "The update of kimai") {
t.Fatalf("fixture: an English box must store the English hold, got %q", st.HoldReason)
}
const huWant, enWant = "A(z) kimai frissítése 2026-09-23 10:00-kor nem sikerült", "The update of kimai at 2026-09-23 10:00 did not succeed"
for _, tmpl := range []string{"app_settings", "stacks"} {
hu := renderHeld(t, s, st, "hu", tmpl)
if !strings.Contains(hu, huWant) || strings.Contains(hu, enWant) {
t.Errorf("%s: the Hungarian reader of an English box must read the hold in Hungarian only", tmpl)
}
en := renderHeld(t, s, st, "en", tmpl)
if !strings.Contains(en, enWant) || strings.Contains(en, huWant) {
t.Errorf("%s: the English reader must read the hold in English only", tmpl)
}
}
}
// The held badge's Hungarian literal and the bundle say the same thing (the parity rule for funcmap).
func TestR625_HeldBadgeHungarianMatchesTheBundle(t *testing.T) {
b, err := i18n.Shared()
if err != nil {
t.Fatal(err)
}
st := stacks.Stack{Name: "x", HoldReason: "Egy. Kettő."}
if got, want := b.Msg("hu", "badge.update.held"), updateBadgeAt(st, time.Now()).Label; got != want {
t.Fatalf("badge.update.held: hu.json %q, funcmap %q", got, want)
}
if got := updateBadgeAt(st, time.Now()).Title; got != "Egy." {
t.Fatalf("the title is the first sentence, got %q", got)
}
}