package provision import ( "crypto/sha256" "encoding/hex" "encoding/json" "errors" "maps" "slices" "testing" "time" "amadan.net/oficina/alta/homeop" ) // The ruled list (Paul, 2026-11-12), in one place: ReservedLabels. func TestReservedLabelsAreTheRuledList(t *testing.T) { want := []string{ "oficina", "docs", "sheets", "slides", "calendar", "calls", "memoria", "equipo", "fichas", "mapa", "api", "auth", "healthz", "static", "www", "id", "admin", "portero", "home", "alta", "base", "forget", } got := slices.Sorted(maps.Keys(ReservedLabels)) slices.Sort(want) if !slices.Equal(got, want) { t.Fatalf("reserved labels\n got %v\nwant %v", got, want) } for _, a := range Apps { if !ReservedLabels[a.Slug] { t.Fatalf("registry app %s is not a reserved label", a.Slug) } } for label, code := range map[string]string{ "lagged": "", "lag-ged": "", "a-b-c": "", "xn--bcher": "label-double-hyphen", "lag--ged": "label-double-hyphen", "docs": "label-reserved", "oficina": "label-reserved", "forget": "label-reserved", "Docs": "label-shape", "ab": "label-shape", } { if got := LabelRefusal(label); got != code { t.Fatalf("LabelRefusal(%q) = %q, want %q", label, got, code) } } } func TestReservedAndPunycodeLabelsRefusedBeforeAnythingIsRecorded(t *testing.T) { h := newHarness(t) h.initialized() e := h.engine(nil) var fl *Fail for _, label := range append(slices.Sorted(maps.Keys(ReservedLabels)), "xn--lagged", "lag--ged") { want := "label-reserved" switch { case !LabelPattern.MatchString(label): want = "label-shape" // "id": under three characters already case !ReservedLabels[label]: want = "label-double-hyphen" } if _, err := e.CreateTeam(h.ctx(), NewTeam{Label: label, Name: "x", Owner: ownerCanary, Apps: []string{"docs"}}); !errors.As(err, &fl) || fl.Code != want { t.Fatalf("label %q: %v", label, err) } if used, err := h.store.LabelUsed(h.ctx(), label); err != nil || used { t.Fatalf("refused label %q was recorded: %v %v", label, used, err) } } } var goldenInputs = Inputs{Label: "lagged", Owner: "o@x.test", TeamSQID: "Uk", Record: []byte("{}"), Home: HomeConfig{Issuer: "https://id.oficina.works", Directory: "https://oficina.works", KeysBase64: "S0VZUw==", Provisioner: "AQ"}, CallsZone: "Europe/Dublin"} // outsideGolden is SHA-256 over the JSON of every app's recipe, in // registry order, for goldenInputs, as origin/main 2637793 (before // profiles existed) computes it. outside is that, byte for byte. const outsideGolden = "3836921a89ecd9942eead9b48db0609ed5509586348231bb1c3608112ce38405" func recipesDigest(in Inputs) string { var all [][]Key for _, a := range ProvisioningApps() { if a.OwnOnly { // Never written under outside (step 0 refuses it), so not // part of today's outside recipes. continue } all = append(all, Recipe(a, in)) } b, _ := json.Marshal(all) s := sha256.Sum256(b) return hex.EncodeToString(s[:]) } func TestOutsideIsTodaysRecipes(t *testing.T) { for _, opt := range []RunOptions{{}, {Profile: ProfileOutside}} { in := goldenInputs in.RunOptions = opt if got := recipesDigest(in); got != outsideGolden { t.Fatalf("outside recipes (%+v) moved: %s", opt, got) } } } // keyMap is a recipe by name. func keyMap(keys []Key) map[string]Key { out := map[string]Key{} for _, k := range keys { out[k.Name] = k } return out } // recipeDiff is what b adds or changes against a, by name; removed names // are reported with an empty Key. func recipeDiff(a, b []Key) map[string]Key { am, bm := keyMap(a), keyMap(b) out := map[string]Key{} for n, k := range bm { if old, ok := am[n]; !ok || old != k { out[n] = k } } for n := range am { if _, ok := bm[n]; !ok { out[n] = Key{} } } return out } // own differs from outside only in the listed keys, and samples only in // Docs' DOCS_SAMPLE_DOCUMENTS, in either profile. func TestOwnDiffersOnlyInTheRuledKeys(t *testing.T) { dash := Key{Name: "OFICINA_DASHBOARD_TEAM", Class: Set, Value: "lagged"} wantOwn := map[string]map[string]Key{ "docs": {dash.Name: dash}, "sheets": {dash.Name: dash}, "slides": {dash.Name: dash}, "calendar": {dash.Name: dash}, "calls": {"CALLS_QUALITY_REPORTS": {Name: "CALLS_QUALITY_REPORTS", Class: Set, Value: "on"}}, "memoria": {}, } samples := Key{Name: "DOCS_SAMPLE_DOCUMENTS", Class: Set, Value: "1"} for _, app := range ProvisioningApps() { outside, own := goldenInputs, goldenInputs outside.Profile, own.Profile = ProfileOutside, ProfileOwn if d := recipeDiff(Recipe(app, outside), Recipe(app, own)); !maps.Equal(d, wantOwn[app.Slug]) { t.Fatalf("%s: own against outside\n got %v\nwant %v", app.Slug, d, wantOwn[app.Slug]) } for _, p := range Profiles { without, with := goldenInputs, goldenInputs without.Profile, with.Profile, with.Samples = p, p, true want := map[string]Key{} if app.Slug == "docs" { want[samples.Name] = samples } if d := recipeDiff(Recipe(app, without), Recipe(app, with)); !maps.Equal(d, want) { t.Fatalf("%s %s: samples\n got %v\nwant %v", app.Slug, p, d, want) } } } } // Alta never holds or writes Memoria's TensorX key, nor turns AI on: in // any profile the key is only ever Paul's, admitted by the audit. func TestNoProfileWritesMemoriaAI(t *testing.T) { app, _ := AppBySlug("memoria") for _, p := range Profiles { in := goldenInputs in.Profile, in.Samples = p, true for _, k := range Recipe(app, in) { if k.Name == "MEMORIA_AI" || k.Name == "MEMORIA_TENSORX_KEY" { t.Fatalf("%s recipe writes %s", p, k.Name) } } } outside, own := goldenInputs, goldenInputs outside.Profile, own.Profile = ProfileOutside, ProfileOwn if len(OperatorKeys(app, outside)) != 0 { t.Fatal("an outside team admits Memoria AI") } got := OperatorKeys(app, own) if len(got) != 2 || got[0] != (OperatorKey{Name: "MEMORIA_AI", Value: "on"}) || got[1] != (OperatorKey{Name: "MEMORIA_TENSORX_KEY", Secret: true}) { t.Fatalf("own memoria operator keys %v", got) } for _, a := range ProvisioningApps() { if a.Slug != "memoria" && a.Slug != "equipo" && len(OperatorKeys(a, own)) != 0 { t.Fatalf("%s has operator keys", a.Slug) } } } // An own run with samples, end to end: recorded on the run, written into // each environment, audited against the profile the environment was // written with, and continued with the same choice. func TestOwnRunWritesAndAuditsItsProfile(t *testing.T) { h := newHarness(t) h.initialized() e := h.engine(nil) run, err := e.CreateTeam(h.ctx(), NewTeam{Label: "sample", Name: "Sample", Owner: ownerCanary, Apps: allApps, Options: RunOptions{Profile: ProfileOwn, Samples: true}}) if err != nil { t.Fatal(err) } if r, _ := h.store.Run(h.ctx(), run); r.Options != (RunOptions{Profile: ProfileOwn, Samples: true}) { t.Fatalf("run options %+v", r.Options) } h.confirm(homeop.KindCreateTeam) if r := h.drive(e, run, 40); r.State != "done" { t.Fatalf("%s %s", r.State, r.Code) } val := func(app, key string) (string, bool) { vars, _, _ := h.con.Env(app, "sample") v, ok := vars[key] return v.Value, ok } for _, app := range []string{"docs", "sheets", "slides", "calendar"} { if v, _ := val(app, "OFICINA_DASHBOARD_TEAM"); v != "sample" { t.Fatalf("%s dashboard team %q", app, v) } } for _, app := range []string{"calls", "memoria"} { if _, ok := val(app, "OFICINA_DASHBOARD_TEAM"); ok { t.Fatalf("%s got a dashboard team it does not read", app) } } if v, _ := val("calls", "CALLS_QUALITY_REPORTS"); v != "on" { t.Fatalf("quality reports %q", v) } if v, _ := val("docs", "DOCS_SAMPLE_DOCUMENTS"); v != "1" { t.Fatalf("samples %q", v) } if _, ok := val("memoria", "MEMORIA_AI"); ok { t.Fatal("Alta turned Memoria AI on") } // Paul's post-run step: the AI pair, together, is admitted; either // alone, or a value memoria would refuse, is not. memoria, _ := AppBySlug("memoria") base, owner, _ := h.con.Env("memoria", "sample") with := func(extra map[string]fakeVar) { vars := maps.Clone(base) maps.Copy(vars, extra) h.con.SetEnv("memoria", "sample", owner, vars) } key := fakeVar{Kind: "secret", Envelope: sealFor(t, h, "memoria", "tensorx-canary")} var fl *Fail for _, c := range []struct { extra map[string]fakeVar code string }{ {map[string]fakeVar{}, ""}, {map[string]fakeVar{"MEMORIA_AI": {Kind: "env", Value: "on"}, "MEMORIA_TENSORX_KEY": key}, ""}, {map[string]fakeVar{"MEMORIA_AI": {Kind: "env", Value: "on"}}, "audit-operator-partial"}, {map[string]fakeVar{"MEMORIA_TENSORX_KEY": key}, "audit-operator-partial"}, {map[string]fakeVar{"MEMORIA_AI": {Kind: "env", Value: "yes"}, "MEMORIA_TENSORX_KEY": key}, "operator-keys-invalid"}, {map[string]fakeVar{"MEMORIA_AI": {Kind: "env", Value: "on"}, "MEMORIA_TENSORX_KEY": {Kind: "env", Value: "plain"}}, "operator-keys-invalid"}, {map[string]fakeVar{"MEMORIA_AI": {Kind: "env", Value: "on"}, "MEMORIA_TENSORX_KEY": key, "MEMORIA_SIBLINGS": {Kind: "env", Value: "x"}}, "audit-extra-key"}, } { with(c.extra) err := e.AuditEnvironment(h.ctx(), "sample", memoria) if c.code == "" && err != nil || c.code != "" && (!errors.As(err, &fl) || fl.Code != c.code) { t.Fatalf("audit with %v: %v, want %q", slices.Sorted(maps.Keys(c.extra)), err, c.code) } } if h.scan("tensorx-canary") { t.Fatal("Paul's TensorX key reached Alta's database") } // Continue without a fresh choice keeps own and samples. h.tick(homeop.WindowLifetime * time.Second) next, err := e.AddApps(h.ctx(), "sample", allApps, RunOptions{}) if err != nil { t.Fatal(err) } if r, _ := h.store.Run(h.ctx(), next); r.Options != (RunOptions{Profile: ProfileOwn, Samples: true}) { t.Fatalf("continued run options %+v", r.Options) } } // The outside team's audit refuses the AI pair: AI stays off for anyone // else's team. func TestOutsideAuditRefusesMemoriaAI(t *testing.T) { h := newHarness(t) h.initialized() e := h.engine(nil) run, err := e.CreateTeam(h.ctx(), NewTeam{Label: "beta", Name: "Beta", Owner: ownerCanary, Apps: []string{"memoria"}}) if err != nil { t.Fatal(err) } h.confirm(homeop.KindCreateTeam) if r := h.drive(e, run, 20); r.State != "done" { t.Fatalf("%s %s", r.State, r.Code) } vars, owner, _ := h.con.Env("memoria", "beta") vars["MEMORIA_AI"] = fakeVar{Kind: "env", Value: "on"} vars["MEMORIA_TENSORX_KEY"] = fakeVar{Kind: "secret", Envelope: sealFor(t, h, "memoria", "k")} h.con.SetEnv("memoria", "beta", owner, vars) memoria, _ := AppBySlug("memoria") var fl *Fail if err := e.AuditEnvironment(h.ctx(), "beta", memoria); !errors.As(err, &fl) || fl.Code != "audit-extra-key" { t.Fatalf("outside audit admitted Memoria AI: %v", err) } } // An environment written under one run's choice and continued under // another's: Alta takes its own profile keys back out (unforked, where any // other extra key refuses) and audits the result as the later choice. func TestLaterRunTakesItsOwnProfileKeysBackOut(t *testing.T) { h := newHarness(t) h.initialized() e := h.engine(nil) run, err := e.CreateTeam(h.ctx(), NewTeam{Label: "gamma", Name: "Gamma", Owner: ownerCanary, Apps: []string{"docs"}, Options: RunOptions{Profile: ProfileOwn, Samples: true}}) if err != nil { t.Fatal(err) } h.confirm(homeop.KindCreateTeam) // No walk yet: the environment is written and parks for its mail. if err := e.Advance(h.ctx(), run); err != nil { t.Fatal(err) } vars, _, _ := h.con.Env("docs", "gamma") if _, ok := vars["OFICINA_DASHBOARD_TEAM"]; !ok { t.Fatalf("own keys not written before the park") } if _, ok, _ := h.store.Done(h.ctx(), "gamma", "docs", StepEnv); ok { t.Fatal("env step done without platform keys") } h.tick(homeop.WindowLifetime * time.Second) next, err := e.AddApps(h.ctx(), "gamma", []string{"docs"}, RunOptions{Profile: ProfileOutside}) if err != nil { t.Fatal(err) } h.confirm(homeop.KindAddApps) if r := h.drive(e, next, 30); r.State != "done" { t.Fatalf("%s %s", r.State, r.Code) } vars, _, _ = h.con.Env("docs", "gamma") for _, k := range []string{"OFICINA_DASHBOARD_TEAM", "DOCS_SAMPLE_DOCUMENTS"} { if _, ok := vars[k]; ok { t.Fatalf("%s survived the outside run", k) } } docs, _ := AppBySlug("docs") if err := e.AuditEnvironment(h.ctx(), "gamma", docs); err != nil { t.Fatalf("audit: %v", err) } } // A forked stopgap moved under own: the fork's blanked MEMORIA_AI is not // Paul's post-run pair, so it goes like any Track 1 extra. func TestOwnForkDropsABlankedMemoriaAI(t *testing.T) { h := newHarness(t) h.initialized() h.con.SetEnv("memoria", "delta-team", "alta", map[string]fakeVar{ "MEMORIA_DEK": {Kind: "secret", Envelope: sealFor(t, h, "memoria", "data-key")}, "MEMORIA_INSTANCE_KEY": {Kind: "secret", Envelope: sealFor(t, h, "memoria", "instance")}, "MEMORIA_AI": {Kind: "env", Value: ""}, }) h.con.AddInstance("memoria", RouteHost("delta", "memoria", account), "delta-team") h.con.AddClaim("memoria", PublicHost("delta", "memoria"), RouteHost("delta", "memoria", account), "live") e := h.engine(nil) run, err := e.CreateTeam(h.ctx(), NewTeam{Label: "delta", Name: "Delta", Owner: ownerCanary, Apps: []string{"memoria"}, Forked: true, Options: RunOptions{Profile: ProfileOwn}}) if err != nil { t.Fatal(err) } h.confirm(homeop.KindCreateTeam) if r := h.drive(e, run, 20); r.State != "done" { t.Fatalf("%s %s", r.State, r.Code) } if vars, _, _ := h.con.Env("memoria", "delta-team"); vars["MEMORIA_AI"] != (fakeVar{}) { t.Fatal("the fork's blanked MEMORIA_AI survived") } } // driveOne creates label with apps under opt and drives it to done. func driveOne(t *testing.T, h *harness, e *Engine, label string, apps []string, opt RunOptions) { t.Helper() run, err := e.CreateTeam(h.ctx(), NewTeam{Label: label, Name: "Team", Owner: ownerCanary, Apps: apps, Options: opt}) if err != nil { t.Fatal(err) } h.confirm(homeop.KindCreateTeam) if r := h.drive(e, run, 30); r.State != "done" { t.Fatalf("%s %s", r.State, r.Code) } h.tick(homeop.WindowLifetime * time.Second) } // A written environment keeps its choice: a run under another choice // would finish having changed nothing, so it is refused, either way. func TestProfileChangeOverAWrittenEnvironmentIsRefused(t *testing.T) { h := newHarness(t) h.initialized() e := h.engine(nil) own := RunOptions{Profile: ProfileOwn, Samples: true} driveOne(t, h, e, "omega", []string{"docs", "memoria"}, own) driveOne(t, h, e, "sigma", []string{"docs", "memoria"}, RunOptions{Profile: ProfileOutside}) var fl *Fail for _, c := range []struct { label string apps []string opt RunOptions code string }{ {"omega", []string{"docs"}, RunOptions{Profile: ProfileOutside}, "profile-differs-docs"}, {"omega", []string{"docs"}, RunOptions{Profile: ProfileOwn}, "profile-differs-docs"}, {"omega", []string{"memoria"}, RunOptions{Profile: ProfileOutside, Samples: true}, "profile-differs-memoria"}, {"sigma", []string{"memoria"}, RunOptions{Profile: ProfileOwn}, "profile-differs-memoria"}, {"sigma", []string{"docs"}, RunOptions{Profile: ProfileOutside, Samples: true}, "profile-differs-docs"}, } { before, _ := h.store.Runs(h.ctx(), c.label) if _, err := e.AddApps(h.ctx(), c.label, c.apps, c.opt); !errors.As(err, &fl) || fl.Code != c.code { t.Fatalf("%s %v %+v: %v, want %s", c.label, c.apps, c.opt, err, c.code) } if after, _ := h.store.Runs(h.ctx(), c.label); len(after) != len(before) { t.Fatal("a refused profile change recorded a run") } } // The same choice, or Continue, is admitted and keeps what was written. for label, want := range map[string]RunOptions{"omega": own, "sigma": {Profile: ProfileOutside}} { for _, opt := range []RunOptions{{}, want} { next, err := e.AddApps(h.ctx(), label, []string{"docs", "memoria"}, opt) if err != nil { t.Fatalf("%s %+v: %v", label, opt, err) } if r, _ := h.store.Run(h.ctx(), next); r.Options != want { t.Fatalf("%s continued as %+v", label, r.Options) } } } } // "Alta's own keys" is by value too: a foreign OFICINA_DASHBOARD_TEAM or // DOCS_SAMPLE_DOCUMENTS in an unforked environment is an extra key. func TestForeignProfileValuesAreExtraKeys(t *testing.T) { for _, foreign := range []fakeVar{{Kind: "env", Value: "oficina"}, {Kind: "env", Value: "yes"}, {Kind: "secret", Envelope: "x"}} { for _, name := range []string{"OFICINA_DASHBOARD_TEAM", "DOCS_SAMPLE_DOCUMENTS"} { h := newHarness(t) h.initialized() e := h.engine(nil) run, err := e.CreateTeam(h.ctx(), NewTeam{Label: "kappa", Name: "Kappa", Owner: ownerCanary, Apps: []string{"docs"}}) if err != nil { t.Fatal(err) } h.confirm(homeop.KindCreateTeam) if err := e.Advance(h.ctx(), run); err != nil { t.Fatal(err) } vars, owner, _ := h.con.Env("docs", "kappa") vars[name] = foreign h.con.SetEnv("docs", "kappa", owner, vars) if r := h.drive(e, run, 10); r.State != "failed" || r.Code != "extra-key" { t.Fatalf("%s=%+v: %s %s", name, foreign, r.State, r.Code) } if vars, _, _ := h.con.Env("docs", "kappa"); vars[name] != foreign { t.Fatalf("%s was taken out", name) } } } } // Step 7 keeps Paul's AI pair only as memoria reads it. func TestInvalidMemoriaAIPairFailsAtStep7(t *testing.T) { h := newHarness(t) h.initialized() e := h.engine(nil) run, err := e.CreateTeam(h.ctx(), NewTeam{Label: "theta", Name: "Theta", Owner: ownerCanary, Apps: []string{"memoria"}, Options: RunOptions{Profile: ProfileOwn}}) if err != nil { t.Fatal(err) } h.confirm(homeop.KindCreateTeam) if err := e.Advance(h.ctx(), run); err != nil { t.Fatal(err) } if _, ok, _ := h.store.Done(h.ctx(), "theta", "memoria", StepEnv); ok { t.Fatal("env step done before its platform keys") } vars, owner, _ := h.con.Env("memoria", "theta") vars["MEMORIA_AI"] = fakeVar{Kind: "env", Value: "1"} vars["MEMORIA_TENSORX_KEY"] = fakeVar{Kind: "secret", Envelope: sealFor(t, h, "memoria", "k")} h.con.SetEnv("memoria", "theta", owner, vars) if r := h.drive(e, run, 10); r.State != "failed" || r.Code != "operator-keys-invalid" { t.Fatalf("%s %s", r.State, r.Code) } if st, _, _ := h.store.Step(h.ctx(), "theta", "memoria", StepEnv); st.State != "failed" { t.Fatalf("step 7 %s", st.State) } } // Fable's N1 and N2: Docs written own, Calls then added outside and parked // before step 7 recorded. Continue takes only the unfinished app (Calls), // under its own run's choice, never Docs' written own; continuing both // together is refused, naming the app that disagrees. func TestContinueTakesUnfinishedAppsUnderTheirOwnChoice(t *testing.T) { h := newHarness(t) h.initialized() e := h.engine(nil) driveOne(t, h, e, "mixed", []string{"docs"}, RunOptions{Profile: ProfileOwn}) add, err := e.AddApps(h.ctx(), "mixed", []string{"calls"}, RunOptions{Profile: ProfileOutside}) if err != nil { t.Fatal(err) } h.confirm(homeop.KindAddApps) if err := e.Advance(h.ctx(), add); err != nil { t.Fatal(err) } if st, ok, _ := h.store.Step(h.ctx(), "mixed", "calls", StepEnv); !ok || st.State != "parked" || st.Code != "awaiting-platform-keys" { t.Fatalf("calls step 7: %+v %v", st, ok) } h.tick(homeop.WindowLifetime * time.Second) var fl *Fail if _, err := e.AddApps(h.ctx(), "mixed", []string{"docs", "calls"}, RunOptions{}); !errors.As(err, &fl) || fl.Code != "profile-differs-calls" { t.Fatalf("continue over both: %v", err) } apps, _, err := e.ContinueApps(h.ctx(), "mixed") if err != nil || !slices.Equal(apps, []string{"calls"}) { t.Fatalf("continue apps %v %v", apps, err) } next, err := e.AddApps(h.ctx(), "mixed", apps, RunOptions{}) if err != nil { t.Fatal(err) } if r, _ := h.store.Run(h.ctx(), next); r.Options != (RunOptions{Profile: ProfileOutside}) || !slices.Equal(r.Apps, []string{"calls"}) { t.Fatalf("continued run %+v %v", r.Options, r.Apps) } h.confirm(homeop.KindAddApps) if r := h.drive(e, next, 30); r.State != "done" { t.Fatalf("%s %s", r.State, r.Code) } vars, _, _ := h.con.Env("calls", "mixed") if v := vars["CALLS_QUALITY_REPORTS"].Value; v != "off" { t.Fatalf("outside Calls written with quality reports %q", v) } if opt, ok, _ := h.store.WrittenOptions(h.ctx(), "mixed", "docs"); !ok || opt.Profile != ProfileOwn { t.Fatalf("docs written %+v", opt) } // Everything finished: Continue covers every active app, whose // written choices disagree, and says so rather than guessing. apps, finished, _ := e.ContinueApps(h.ctx(), "mixed") if !finished { t.Fatal("a finished team has apps to continue") } if _, err := e.ContinuedOptions(h.ctx(), "mixed", apps); !errors.As(err, &fl) || fl.Code != "profile-differs-calls" { t.Fatalf("finished mixed team: %v", err) } } // Fable's L5: a wrong choice on an app not yet written is corrected by // continuing under an explicit one, for a seeded team and for a // create-team run that never reached Home (whose label is already spent). func TestContinueUnderAnExplicitChoiceCorrectsAnUnwrittenApp(t *testing.T) { h := newHarness(t) h.initialized() e := h.engine(nil) outside := RunOptions{Profile: ProfileOutside} // Seeded: Calls created own, parked before step 7 recorded. run, err := e.CreateTeam(h.ctx(), NewTeam{Label: "fix", Name: "Fix", Owner: ownerCanary, Apps: []string{"calls"}, Options: RunOptions{Profile: ProfileOwn}}) if err != nil { t.Fatal(err) } h.confirm(homeop.KindCreateTeam) if err := e.Advance(h.ctx(), run); err != nil { t.Fatal(err) } if _, ok, _ := h.store.WrittenOptions(h.ctx(), "fix", "calls"); ok { t.Fatal("calls written before its platform keys") } h.tick(homeop.WindowLifetime * time.Second) apps, _, _ := e.ContinueApps(h.ctx(), "fix") next, err := e.AddApps(h.ctx(), "fix", apps, outside) if err != nil { t.Fatal(err) } h.confirm(homeop.KindAddApps) if r := h.drive(e, next, 30); r.State != "done" { t.Fatalf("%s %s", r.State, r.Code) } if vars, _, _ := h.con.Env("calls", "fix"); vars["CALLS_QUALITY_REPORTS"].Value != "off" { t.Fatalf("calls quality reports %q", vars["CALLS_QUALITY_REPORTS"].Value) } if opt, ok, _ := h.store.WrittenOptions(h.ctx(), "fix", "calls"); !ok || opt != outside { t.Fatalf("calls written %+v", opt) } // Now written: the same correction the other way is refused. var fl *Fail if _, err := e.AddApps(h.ctx(), "fix", []string{"calls"}, RunOptions{Profile: ProfileOwn}); !errors.As(err, &fl) || fl.Code != "profile-differs-calls" { t.Fatalf("written calls: %v", err) } // Unseeded: a create-team plan never confirmed. Continue under an // explicit choice resubmits the create-team plan under it. if _, err := e.CreateTeam(h.ctx(), NewTeam{Label: "spent", Name: "Spent", Owner: ownerCanary, Apps: []string{"docs"}, Options: RunOptions{Profile: ProfileOwn, Samples: true}}); err != nil { t.Fatal(err) } h.tick(homeop.WindowLifetime * time.Second) apps, _, _ = e.ContinueApps(h.ctx(), "spent") again, err := e.AddApps(h.ctx(), "spent", apps, outside) if err != nil { t.Fatal(err) } r, _ := h.store.Run(h.ctx(), again) if r.Kind != homeop.KindCreateTeam || r.Options != outside || !slices.Equal(r.Apps, []string{"docs"}) { t.Fatalf("resumed create %s %+v %v", r.Kind, r.Options, r.Apps) } }