Files
felhom-controller/controller/internal/web/r2_media_recreate_wiring_test.go
T

50 lines
1.6 KiB
Go

package web
import (
"go/ast"
"go/parser"
"go/token"
"os"
"strings"
"testing"
)
// Review round 2 (2026-10-24, DOC-D2 U2): both web paths that recreate the media apps must take their list from
// mediaAppsToRecreate (which leaves out the apps the household stopped, R-721), never from mediaApps(). A source pin:
// the decision itself is tested in stacks (TestMediaAppsToRecreate_SkipsAppsTheHouseholdStopped); this pins the
// WIRING, the half a seam test cannot see. COMPANION RED-PROOF: put `s.mediaApps()` back in either loop → this fails.
func TestR2_MediaRecreateLoopsSkipStoppedApps(t *testing.T) {
src, err := os.ReadFile("media_events.go")
if err != nil {
t.Fatal(err)
}
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "media_events.go", src, 0)
if err != nil {
t.Fatal(err)
}
want := map[string]bool{"restartMediaApps": false, "mediaSafeRemoval": false}
for _, d := range f.Decls {
fn, ok := d.(*ast.FuncDecl)
if !ok {
continue
}
if _, tracked := want[fn.Name.Name]; !tracked {
continue
}
body := string(src[fset.Position(fn.Body.Pos()).Offset:fset.Position(fn.Body.End()).Offset])
if strings.Contains(body, "range s.mediaApps()") {
t.Errorf("%s ranges over s.mediaApps(): it would recreate (start) an app the household stopped", fn.Name.Name)
}
if !strings.Contains(body, "s.mediaAppsToRecreate(") || !strings.Contains(body, "RestartStack(") {
t.Errorf("%s no longer recreates from s.mediaAppsToRecreate", fn.Name.Name)
}
want[fn.Name.Name] = true
}
for name, seen := range want {
if !seen {
t.Errorf("function %s not found in media_events.go — the pin is stale", name)
}
}
}