Files
felhom-controller/controller/internal/web/app_update_switch_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

116 lines
5.1 KiB
Go

package web
import (
"html"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"strings"
"testing"
)
// v0.271.0 — the per-box switch for AUTOMATIC app updates (`09` §3 decision 12: ON by default) on the
// settings page, in both languages, through the REAL router, handler and template; and the saved choice
// read back from settings.json's accessor the leg reads.
//
// COMPANION RED-PROOF (REPORT.md): make GetAppUpdateUnattended return false for an absent key — the
// first assertion fails at "a box that never saved the switch must show it ON".
func TestAppUpdateSwitch_DefaultOnAndSaved(t *testing.T) {
s := testPageServer(t)
hu := html.UnescapeString(getPage(t, s, "/settings").Body.String())
if !strings.Contains(hu, `data-app-update-unattended="true"`) || !strings.Contains(hu, "checked data-app-update-unattended") {
t.Fatal("a box that never saved the switch must show it ON (decision 12)")
}
if !strings.Contains(hu, "Alkalmazások automatikus frissítése") || !strings.Contains(hu, "kipróbált lépéssel") {
t.Error("the Hungarian page must carry the card's title and its one sentence")
}
en := html.UnescapeString(getPage(t, s, "/settings?lang=en").Body.String())
if !strings.Contains(en, "Automatic app updates") || !strings.Contains(en, "only with a tested step") {
t.Error("the English page must carry the card's title and its one sentence")
}
if strings.Contains(en, "kipróbált lépéssel") {
t.Error("the Hungarian sentence must be GONE from the English page")
}
// OFF: an unchecked box posts no field
rec := postForm(t, s, "/settings/app-update", url.Values{})
if rec.Code != 200 {
t.Fatalf("POST off = %d", rec.Code)
}
if s.settings.GetAppUpdateUnattended() {
t.Fatal("saving with the box unchecked must turn the switch OFF")
}
body := html.UnescapeString(rec.Body.String())
if !strings.Contains(body, "kikapcsolva") || !strings.Contains(body, `data-app-update-unattended="false"`) {
t.Error("the page after saving OFF must say so and show the box unchecked")
}
// ON again
postForm(t, s, "/settings/app-update", url.Values{"app_update_unattended": {"on"}})
if !s.settings.GetAppUpdateUnattended() {
t.Fatal("saving with the box checked must turn the switch back ON")
}
}
// TestAutoUpdateLine_PageSaysItOnce — a successful automatic step is told on the app page only, in the
// request's language, and only while the app still runs what that step installed.
//
// COMPANION RED-PROOF (REPORT.md): drop the AutoUpdateLine block from appCommonData — this fails at
// "the English page must carry the automatic-update line".
func TestAutoUpdateLine_PageSaysItOnce(t *testing.T) {
s, _ := credsHarness(t)
sd := filepath.Join(s.cfg.Paths.StacksDir, "crafty")
write := func(pin string) {
app := "deployed: true\npinned_images:\n web: " + pin + "\nlast_auto_update:\n at: \"2026-09-25T02:21:00Z\"\n outcome: done\n to:\n web: crafty:2.0.0\n"
if err := os.WriteFile(filepath.Join(sd, "app.yaml"), []byte(app), 0o644); err != nil {
t.Fatal(err)
}
_ = s.stackMgr.ScanStacks()
}
s.loadTemplates()
render := func(lang string) string {
rr := httptest.NewRecorder()
s.appPageHandler(rr, httptest.NewRequest("GET", "/apps/crafty?lang="+lang, nil), "crafty", "")
return html.UnescapeString(rr.Body.String())
}
write("crafty:2.0.0")
en, hu := render("en"), render("hu")
const enLine, huLine = "Automatic update at", "Automatikus frissítés"
if !strings.Contains(en, enLine) || !strings.Contains(en, "— done.") {
t.Fatalf("the English page must carry the automatic-update line")
}
if !strings.Contains(hu, huLine+" ") || !strings.Contains(hu, "— sikeres.") || strings.Contains(hu, enLine) {
t.Fatalf("the Hungarian page must carry its own line and not the English one")
}
if !strings.Contains(hu, `data-auto-update="done"`) {
t.Error("the line must render in its own marked alert")
}
// a later manual update moved the pin: the line is history and goes
write("crafty:2.1.0")
if strings.Contains(render("en"), enLine) {
t.Error("the line must go once the app no longer runs what the automatic step installed")
}
}
// R-498: the app page's „Első lépések" shows the household's address, never the catalog's wiki.DOMAIN.
func TestR498_AppPageFirstStepsShowTheRealAddress(t *testing.T) {
s, _ := credsHarness(t)
sd := filepath.Join(s.cfg.Paths.StacksDir, "crafty")
meta := "display_name: Crafty\nslug: crafty\nsubdomain: wiki\napp_info:\n first_steps:\n - 'Nyisd meg a wiki.DOMAIN címet a böngészőben'\n"
if err := os.WriteFile(filepath.Join(sd, ".felhom.yml"), []byte(meta), 0o644); err != nil {
t.Fatal(err)
}
_ = s.stackMgr.ScanStacks()
s.loadTemplates()
rr := httptest.NewRecorder()
// v0.315.0: „Elso lepesek" is the guide tab's content — the app's copy lives there now.
s.appPageHandler(rr, httptest.NewRequest("GET", "/apps/crafty/guide", nil), "crafty", appTabGuide)
page := html.UnescapeString(rr.Body.String())
if !strings.Contains(page, "Nyisd meg a wiki.example.hu c") {
t.Fatalf("the first step must name the real address wiki.example.hu (status %d)", rr.Code)
}
if strings.Contains(page, "wiki.DOMAIN") {
t.Error("the literal wiki.DOMAIN reached the page")
}
}