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

84 lines
3.3 KiB
Go

package web
import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
"gitea.dooplex.hu/admin/felhom-controller/internal/stacks"
)
// R-1028: the claim box renders only when the household still has to give the code — render test
// per branch (the seam-wiring rule).
//
// v0.315.0: the box is no longer Plex-specific markup behind a `.PlexClaim` flag. It is the GENERIC
// after-start card, and the thing it branches on is whether afterStartFields put the field in the
// page data at all — which is where the „registered action AND Needed()" decision now lives.
// COMPANION RED-PROOF: render the card unconditionally (drop the range over .AfterStartFields) →
// the two negative cases fail. Restored.
func TestPlexClaimBox_RendersPerBranch(t *testing.T) {
st := lcStack("plex", "", true)
st.State = stacks.StateRunning
claimField := stacks.DeployField{EnvVar: "PLEX_CLAIM", Label: "Plex kod", AfterStart: true,
Placeholder: "claim-xxxxxxxxxxxxxxxxxxxx"}
for _, c := range []struct {
name string
fields []stacks.DeployField
want bool
}{
{"the code is still wanted", []stacks.DeployField{claimField}, true},
{"nothing is wanted", nil, false},
} {
d := appInfoData(st)
d["AfterStartFields"] = c.fields
h := renderBackupPage(t, "app_settings", d)
if got := strings.Contains(h, `data-afterstart="PLEX_CLAIM"`) && strings.Contains(h, `id="after-start-PLEX_CLAIM"`); got != c.want {
t.Errorf("%s: claim box shown=%v, want %v", c.name, got, c.want)
}
}
}
// The code is checked for its shape before any call: no call for something that is not a claim code.
func TestPlexClaimCodeShape(t *testing.T) {
for code, ok := range map[string]bool{"claim-AbCdEf123456789_-xyz": true, "claim-short": false, "claim-abcdefgh": true, "claim-": false,
"https://plex.tv/claim": false, "claim-abc def": false, "": false} {
if got := plexClaimCode.MatchString(code); got != ok {
t.Errorf("%q: accepted=%v, want %v", code, got, ok)
}
}
}
// R-1045: the household's „Kész" never opens an UNCLAIMED Plex (it answers everything to a private address with no
// token); once Plex says claimed, the press opens it. No template probe is needed (an old controller would refuse the
// press forever with one). COMPANION RED-PROOF: drop the plexClaimed check in appSetupGateOpenHandler → the first press
// opens the gate (200). Restored.
func TestPlexDonePress_RefusedWhileUnclaimed(t *testing.T) {
s := gateHarness(t)
app := filepath.Join(s.cfg.Paths.StacksDir, "gapp")
if err := os.WriteFile(filepath.Join(app, ".felhom.yml"), []byte("display_name: Plex\nslug: plex\nsetup_gate: true\n"), 0o644); err != nil {
t.Fatal(err)
}
if err := s.stackMgr.ScanStacks(); err != nil {
t.Fatal(err)
}
claimed := false
old := plexClaimed
plexClaimed = func() bool { return claimed }
defer func() { plexClaimed = old }()
press := func() int {
w := httptest.NewRecorder()
s.appSetupGateOpenHandler(w, httptest.NewRequest(http.MethodPost, "/apps/plex/setup-gate/open", nil), "plex")
return w.Code
}
if c := press(); c != http.StatusConflict {
t.Fatalf("„Kész” on an unclaimed Plex: HTTP %d, want 409 — the gate must stay closed", c)
}
claimed = true
if c := press(); c != http.StatusOK {
t.Fatalf("„Kész” on a claimed Plex: HTTP %d, want 200", c)
}
}