Files
felhom-controller/controller/internal/stacks/captureset_wiring_test.go
T
admin 2958946517 v0.172.0 — R-75: canonical import root, catalog-derived skeleton, import surfaces
${IMPORT_PATH} = <system namespace root>/userdata/import — ONE drop-zone per box,
on the system drive, injected at BOTH compose-env builders with NO per-drive
fallback (unresolvable leaves it unset so compose fails loudly rather than
quietly building a second, dead drop-zone).

Third BindRoot (RootImport) + Import list in BackupSpec, extended through
ValidateBackupSpec/ClassifyBinds. Load-bearing: a stale `userdata: import/<app>`
entry against the moved bind would be a WHOLE-BLOCK reject, taking the app's
mandatory hdd classification with it.

Exhaustive-root audit: resolveAbs/structuralGuard/ComputeCaptureSet/
ComputeFabBuckets now take importRoot explicitly (an import bind resolved
against hddPath would name a directory on the wrong drive); unresolvable is
refused loudly into Skipped. GetImportRoot added to both provider interfaces.

Catalog-derived skeleton: UserdataSkeleton() -> UserdataSkeletonCarry() +
BuildUserdataSkeleton(), SORTED. The carry-list makes zero-removals true by
construction (`documents` is in no catalog app but on both boxes) and is the
fresh-box floor. The sort is not tidiness: the naive map-order derivation
measured 20 distinct outputs from 20 identical runs, which with fbNeedsRecreate
is a fleet-wide FileBrowser restart loop.

One authoritative compose parser: ParseComposeUserdataMounts now delegates to
ParseComposeClassifiableBinds. Import root excluded from per-app migration.

Surfaces: FileBrowser /srv/beolvasas source; app-page "Hova tegyem a fajlokat?"
with PathEscape deep links (never QueryEscape) and class-driven copy;
data_paths: annotation with the Fork-3 asymmetry; system-owned beolvasas SMB
share refused server-side at handler AND store, button omitted in template.

Caught on the way: the sharing template's row struct was function-local, so
adding {{if .System}} would have 500'd every share row. ShareRow is now
package-level and the render test uses the handler's own type.

Tests 915 -> 949, all green. MinAgent unchanged.
2026-07-26 08:12:57 +02:00

69 lines
2.6 KiB
Go

package stacks
import (
"path"
"reflect"
"testing"
"gitea.dooplex.hu/admin/felhom-controller/internal/appbackup"
)
// absSet returns the sorted Abs slice of a CaptureSet's Paths (helper for exact assertions).
func absSet(cs appbackup.CaptureSet) []string {
out := make([]string, 0, len(cs.Paths))
for _, p := range cs.Paths {
out = append(out, p.Abs)
}
return out
}
// TestCaptureSet_Wiring (Scenario G, F-S3 no-seam): a real .felhom.yml backup block + real compose,
// loaded through a REAL stacks.Manager, must produce the exact per-tier capture sets end-to-end —
// ClassifiedBinds → ComputeCaptureSet — with no fake between the parser, validator, classifier, and
// the capture computation (the wiring is where a class-constant typo would otherwise hide).
func TestCaptureSet_Wiring(t *testing.T) {
felhom := `display_name: Wiretest
backup:
userdata:
- path: media/photos
class: optional
`
// appdata/wiretest is UNLISTED + writable → default mandatory; media/photos is :ro but EXPLICIT
// optional (explicit beats the :ro reader-default).
compose := `services:
wiretest:
volumes:
- ${HDD_PATH}/appdata/wiretest:/data
- ${USERDATA_PATH}/media/photos:/external/photos:ro
`
m := newClassifyManager(t, felhom, compose)
cbs, has := m.ClassifiedBinds("app")
if !has {
t.Fatal("valid block must classify end-to-end (hasClassification=true)")
}
const hddPath = "/mnt/drv"
wantWiretest := path.Join(hddPath, "appdata/wiretest")
wantPhotos := path.Join(hddPath, "userdata", "media/photos")
// Secondary: mandatory + optional, sorted by Abs.
sec := appbackup.ComputeCaptureSet(cbs, has, appbackup.TierSecondary, hddPath, "")
if got, want := absSet(sec), []string{wantWiretest, wantPhotos}; !reflect.DeepEqual(got, want) {
t.Errorf("secondary Paths = %v, want %v", got, want)
}
// Offsite: mandatory only — the explicit-optional :ro library must NOT appear.
off := appbackup.ComputeCaptureSet(cbs, has, appbackup.TierOffsite, hddPath, "")
if got, want := absSet(off), []string{wantWiretest}; !reflect.DeepEqual(got, want) {
t.Errorf("offsite Paths = %v, want %v (optional :ro must not ship offsite)", got, want)
}
// classes ride through end-to-end
for _, p := range sec.Paths {
if p.Abs == wantPhotos && p.Class != appbackup.ClassOptional {
t.Errorf("media/photos class = %q, want optional (explicit beats :ro default, through the real Manager)", p.Class)
}
if p.Abs == wantWiretest && p.Class != appbackup.ClassMandatory {
t.Errorf("appdata/wiretest class = %q, want mandatory (unlisted writable default)", p.Class)
}
}
}