package provision import ( "slices" "testing" "time" "amadan.net/oficina/alta/homeop" ) // Base joins canonical adoption as Equipo did: adoption-only, env prefix // BASE (Base reads BASE_HOME_ISSUER and BASE_HOME_CONSUMER_ID), and the // label was already reserved. func TestBaseAdoptionRegistry(t *testing.T) { app, ok := AppBySlug("base") if !ok || app.Prefix != "BASE" || app.Name != "Base" { t.Fatalf("Base registry: %+v %v", app, ok) } if app.AdoptionOnly || !app.Seeded || !app.OwnOnly || app.Roster { t.Fatalf("Base is seeded and own-only (team-bundle spec): %+v", app) } if !ReservedLabels["base"] { t.Fatal("Base label is not reserved") } if homeop.CanonicalOrigin("base") != "https://base.oficina.works" || !slices.Equal(SortApps([]string{"base"}), []string{"base"}) { t.Fatal("Base adoption mapping missing") } } // A completed seven-app adoption is extended without reseeding the team or // touching existing registrations. Both Home confirmations remain required. func TestBaseJoinsExistingAdoption(t *testing.T) { saved := Apps t.Cleanup(func() { Apps = saved }) Apps = slices.DeleteFunc(slices.Clone(saved), func(a App) bool { return a.Slug == "base" }) a := newAdoption(t) e := a.adopter(nil, newObserver()) a.planA(e) oldTeam, _ := a.store.Team(a.ctx(), AdoptionLabel) Apps = saved a.home.AddEnvConsumer("base", "https://base.oficina.works") a.tick(homeop.WindowLifetime * time.Second) run, err := e.ContinueAdoption(a.ctx()) if err != nil { t.Fatal(err) } r, _ := a.store.Run(a.ctx(), run) if !slices.Equal(r.Apps, []string{"base"}) { t.Fatalf("continuation: %v", r.Apps) } for role, p := range a.plans(run) { if p.Kind != homeop.KindAddApps || p.ExistingTeam != oldTeam.TeamSQID || !slices.Equal(p.Apps, []string{"base"}) { t.Fatalf("%s plan: %+v", role, p) } } a.confirm(homeop.KindAddApps) if r := a.drive(e, run, 10); r.State != "done" || r.Code != "awaiting-configuration" { t.Fatalf("registration: %s %s", r.State, r.Code) } team, _ := a.store.Team(a.ctx(), AdoptionLabel) if team.Apps["base"] != "active" { t.Fatal("Base missing from existing local team") } var environments int if err := a.store.DB().QueryRow("SELECT count(*) FROM environments").Scan(&environments); err != nil || environments != 0 { t.Fatalf("adoption reserved environments: %d %v", environments, err) } if a.home.InstanceState("base") != "pending" { t.Fatal("Base must stay pending before activation") } run = a.activate(e, "base") if r := a.drive(e, run, 10); r.State != "done" || a.home.InstanceState("base") != "live" { t.Fatalf("activation: %s %s", r.State, r.Code) } if a.home.TeamCount() != 1 || a.home.ConsumerCount() != 0 || a.home.Calls[homeop.DirectorySeedTeam] != 1 || a.home.Calls[homeop.CredentialOwnerSeed] != 1 || a.net.count() != 0 { t.Fatal("adoption changed existing team, registry, or instances") } } // A fresh Base is offered only under profile own (team-bundle spec ยง5.1 // rule 3), never under outside, and never by an ordinary run under the // adoption label. func TestBaseFreshInstancesAreOwnOnly(t *testing.T) { h := newHarness(t) h.initialized() e := h.engine(nil) _, err := e.CreateTeam(h.ctx(), NewTeam{Label: "new-team", Name: "New", Owner: ownerCanary, Apps: []string{"docs", "sheets", "slides", "calendar", "calls", "memoria", "equipo", "base"}}) failCode(t, err, "app-own-only") if err := h.store.CreateTeam(h.ctx(), "existing", "Existing", "existing", false, ownerCanary, []string{"docs"}); err != nil { t.Fatal(err) } _, err = e.AddApps(h.ctx(), "existing", []string{"base"}, RunOptions{Profile: ProfileOutside}) failCode(t, err, "app-own-only") }