oficina / alta Public

Labels, and a per-run profile (own/outside) with a samples flag

Paul's rulings, 2026-11-12. Labels: no '--' (refuses xn--), and one
reserved list (oficina, every app name, and the suite's own words).
Profiles: outside is byte-identical to 2637793's recipes (digest-pinned);
own adds CALLS_QUALITY_REPORTS=on and OFICINA_DASHBOARD_TEAM=<label>;
samples sets DOCS_SAMPLE_DOCUMENTS=1. Memoria AI stays off at run time:
Paul sets MEMORIA_AI and MEMORIA_TENSORX_KEY himself, the audit admits
the pair only for own teams, and PutConfig refuses Alta setting either.
A written app refuses a different choice (profile-differs-<app>);
Continue takes only unfinished apps, each under its own choice, and can
correct an unwritten app's choice.

Not done: Slides uploads (a team credential cannot declare a store) and
Calls push (cmd/calls reads no CALLS_APNS_*): both await Paul.

Reviewed by Claude Fable 5.2 (claude-fable-5-2): CHANGES REQUIRED at
1837630 (H1 profile change no-op, M1 take-back by name, L1-L4); APPROVE
at a1b06f4 after N1/N2 (Continue widening, dead end); final APPROVE at
45d1799 (L5/L7). make ci green at 45d1799.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from feat/own-profile into main.
claude agent, operated by paul@keymail.dev 9046cff86db4e73136f300d560b274637182ca1b parent 2637793
20 files changed, +1,271 −66
  • PRODUCT.md +5 −2
  • README.md +51 −2
  • console/client.go +12 −0
  • internal/web/app.go +80 −10
  • internal/web/static/alta.css +2 −0
  • internal/web/templates/layout.html +9 −0
  • internal/web/templates/run.html +9 −1
  • internal/web/templates/team.html +13 −3
  • internal/web/templates/team_new.html +2 −1
  • internal/web/web_test.go +23 −2
  • internal/web/words.go +8 −3
  • provision/apps.go +193 −14
  • provision/engine.go +100 −13
  • provision/engine_test.go +4 −4
  • provision/guard_test.go +14 −0
  • provision/migrations/0002_run_options.sql +5 −0
  • provision/profile_test.go +601 −0
  • provision/review_test.go +2 −2
  • provision/steps.go +64 −5
  • provision/store.go +74 −4

CI passed — run details

diff --git a/PRODUCT.md b/PRODUCT.md
index 8c7f3e8..f5a2a3f 100644
--- a/PRODUCT.md
+++ b/PRODUCT.md
@@ -30,8 +30,11 @@ pages, against Home's own copy of the plan, after a fresh sign-in.
- Creates a team for an owner who has already signed in at Home.
- Labels and retired hostnames are never reused.
-- Memoria AI is off; Slides ships without uploads; team dashboards are
- blank; Calls' quality reports are off.
+- Each run is **outside** (the default: Memoria AI off, team dashboards
+ blank, Calls' quality reports off) or **own** (Paul's own teams:
+ quality reports on, dashboards named, Memoria AI Paul's to turn on with
+ his own key after the run). Docs' sample documents are a separate
+ per-run choice. Slides ships without uploads either way.
- Alta never holds or writes Paul's SMTP or relay secrets: CARLOS mints
them per team environment.
- No live updates: refresh to see progress.
diff --git a/README.md b/README.md
index bc6557b..f3151cd 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,54 @@ platform `9bcbab0f5`, **not released**. Alta replaces
5. A run that outlives its window parks; **Continue under a new plan**
submits an `add-apps` plan for the same apps, confirmed again on Home.
+### Profiles and samples (Paul, 2026-11-12)
+
+Each create-team and add-apps run carries a **profile**, chosen on the run
+form, recorded on the run and shown with its plan on Alta's run page
+(Home's copy of the plan has no field for it):
+
+- **outside** (the default): the recipes below, unchanged. For anyone
+ else's team.
+- **own**: Paul's own teams. Differs only in `CALLS_QUALITY_REPORTS=on`,
+ `OFICINA_DASHBOARD_TEAM=<label>` on the apps that read it (Docs, Sheets,
+ Slides, Calendar), and Memoria's AI: the run leaves it off (memoria
+ refuses to boot with `MEMORIA_AI=on` and no key, and Alta never holds
+ the TensorX key); Paul sets `MEMORIA_TENSORX_KEY` (secret) and
+ `MEMORIA_AI=on` in the environment afterwards, and the audit admits the
+ two together and refuses either alone.
+- **samples**, a separate box: `DOCS_SAMPLE_DOCUMENTS=1`, for a sample
+ team only.
+
+Slides stays without uploads in both profiles: a team credential cannot
+declare an object store (CARLOS's store doors are Admin-only), and the
+only store a create provisions comes from the app-wide private-storage
+policy, which a run cannot choose. Step 7 records the choice each
+environment was written with (the team page shows it per app), and the
+audit checks against that. A written environment is never rewritten, so
+a run whose choice differs from an app's written one is refused
+(`profile-differs-<app>`). "Continue under a new plan" takes only the
+apps with steps still to do. Its form (on the team page) offers the
+profile and samples choice, defaulted to those apps' own (written, else
+the newest run naming them), so a wrong choice on an app not yet written
+— a create-team run's included, whose label is already spent — is
+corrected by continuing under the right one. A team whose apps are all
+finished, under choices that disagree, has nothing to continue and shows
+no Continue form.
+
+Known limit (left as ruled): Continue defaults to nothing when two
+unfinished apps' choices differ, and says `profile-differs-<app>`.
+Choosing one profile on the form continues both when at most one of
+them is written (the unwritten one takes the choice); two unfinished
+apps *written* under different choices cannot be continued from any
+form. A later run takes back out only a key
+exactly as Alta wrote it (`OFICINA_DASHBOARD_TEAM=<label>`,
+`DOCS_SAMPLE_DOCUMENTS=1`); the console guard refuses any set of
+`MEMORIA_AI` or `MEMORIA_TENSORX_KEY`.
+
+Labels: Alta's pattern, never `--` (`xn--` punycode), and never a reserved
+name (`ReservedLabels`: `oficina`, every app's name, and the suite's and
+platform's own names).
+
Retiring apps (`retire-apps`) disables the directory consumer, retires the
credential consumer, detaches the hostname and deletes the instance. The
parked database replica, the owned environment, and the team's label stay;
@@ -140,8 +188,9 @@ recorded here instead (Fable's rulings on oficina/alta #1):
- **Calls has no push**: `cmd/calls` does not read `CALLS_APNS_*` (on
main or team-mode), so a team's Calls sends no Apple notifications.
`CARLOS_RELAY` stays PLATFORM, minted per environment.
-- Memoria's AI stays off in team mode: no `MEMORIA_AI`, TensorX key,
- siblings or logged mail.
+- Memoria's AI is never turned on by Alta: no `MEMORIA_AI`, TensorX key,
+ siblings or logged mail in any recipe. An own team's audit admits the
+ pair Paul sets by hand (see Profiles).
- **§11, Help**: the account menu has no Help items yet (no Colophon page).
## Developing
diff --git a/console/client.go b/console/client.go
index 3b22fd9..70fc067 100644
--- a/console/client.go
+++ b/console/client.go
@@ -70,6 +70,15 @@ var managedKey = regexp.MustCompile(`^([A-Z][A-Z0-9_]*_SMTP_(HOST|PORT|USER|PASS
// PlatformManaged reports whether key is the platform's alone.
func PlatformManaged(key string) bool { return managedKey.MatchString(key) }
+// operatorOnly is the keys only Paul ever sets (Memoria's AI and his
+// TensorX key, Paul 2026-11-12): Alta never holds or writes them, so a set
+// of either is refused before it is sent. Unsetting (a fork's blanked
+// MEMORIA_AI) stays allowed.
+var operatorOnly = map[string]bool{"MEMORIA_AI": true, "MEMORIA_TENSORX_KEY": true}
+
+// OperatorOnly reports whether key is Paul's alone to set.
+func OperatorOnly(key string) bool { return operatorOnly[key] }
+
// Client is one console, one account, one credential per app.
type Client struct {
HTTP *http.Client
@@ -235,6 +244,9 @@ func (c *Client) PutConfig(ctx context.Context, app, env string, set map[string]
if PlatformManaged(k) {
return PutResult{}, c.guard(fmt.Errorf("set of platform-managed key %s", k))
}
+ if OperatorOnly(k) {
+ return PutResult{}, c.guard(fmt.Errorf("set of operator-only key %s", k))
+ }
}
for _, k := range unset {
if PlatformManaged(k) {
diff --git a/internal/web/app.go b/internal/web/app.go
index 954ef12..2a93a8a 100644
--- a/internal/web/app.go
+++ b/internal/web/app.go
@@ -11,6 +11,7 @@ import (
"net/http"
"net/mail"
"net/url"
+ "slices"
"strconv"
"strings"
"sync"
@@ -313,7 +314,38 @@ func (a *App) teamRow(ctx context.Context, t provision.Team) teamRow {
}
func (a *App) newTeamForm(w http.ResponseWriter, r *http.Request) {
- a.render(w, r, http.StatusOK, "team_new", page{Title: "New team", Data: map[string]any{"Apps": provision.Apps, "Checked": map[string]bool{}, "Form": map[string]string{}}})
+ a.render(w, r, http.StatusOK, "team_new", page{Title: "New team", Data: map[string]any{"Apps": provision.Apps, "Checked": map[string]bool{}, "Form": map[string]string{},
+ "Options": optionsView(provision.RunOptions{Profile: provision.ProfileOutside})}})
+}
+
+// formOptions is a run form's profile and samples choice. A form without
+// a profile field (Continue) answers the zero value: the engine continues
+// with the team's last choice.
+func formOptions(r *http.Request) provision.RunOptions {
+ return provision.RunOptions{Profile: provision.Profile(r.PostForm.Get("profile")), Samples: r.PostForm.Get("samples") == "1"}
+}
+
+// profileWords is each profile as the run form and the plan say it.
+var profileWords = map[provision.Profile]struct{ Name, Says string }{
+ provision.ProfileOutside: {"Outside", "Someone else's team. Calls' quality reports off, dashboards blank, Memoria AI off."},
+ provision.ProfileOwn: {"Own", "One of your own teams. Calls' quality reports on, each dashboard app names the team, and Memoria AI may be turned on after the run with your TensorX key."},
+}
+
+// profileChoice is one radio on a run form.
+type profileChoice struct {
+ Value, Name, Says string
+ Checked bool
+}
+
+// optionsView is a run's options for the form and the plan.
+func optionsView(o provision.RunOptions) map[string]any {
+ var choices []profileChoice
+ for _, p := range provision.Profiles {
+ w := profileWords[p]
+ choices = append(choices, profileChoice{Value: string(p), Name: w.Name, Says: w.Says, Checked: o.Profile == p})
+ }
+ w := profileWords[o.Profile]
+ return map[string]any{"Profile": string(o.Profile), "Name": w.Name, "Says": w.Says, "Samples": o.Samples, "Choices": choices}
}
func (a *App) createTeam(w http.ResponseWriter, r *http.Request) {
@@ -321,7 +353,8 @@ func (a *App) createTeam(w http.ResponseWriter, r *http.Request) {
a.plain(w, http.StatusBadRequest, "Bad form.")
return
}
- in := provision.NewTeam{Label: strings.TrimSpace(r.PostForm.Get("label")), Name: strings.TrimSpace(r.PostForm.Get("name")), Owner: strings.TrimSpace(r.PostForm.Get("owner")), Apps: r.PostForm["app"], Forked: r.PostForm.Get("forked") == "1"}
+ in := provision.NewTeam{Label: strings.TrimSpace(r.PostForm.Get("label")), Name: strings.TrimSpace(r.PostForm.Get("name")), Owner: strings.TrimSpace(r.PostForm.Get("owner")), Apps: r.PostForm["app"], Forked: r.PostForm.Get("forked") == "1",
+ Options: formOptions(r)} // no profile posted: outside, the default
if addr, err := mail.ParseAddress(in.Owner); err == nil && addr.Name == "" {
in.Owner = addr.Address
}
@@ -341,7 +374,8 @@ func (a *App) createTeam(w http.ResponseWriter, r *http.Request) {
// The owner's address is echoed back into the form it came from,
// never logged or stored on a refusal.
a.render(w, r, http.StatusUnprocessableEntity, "team_new", page{Title: "New team", Error: describe(errorCode(err)),
- Data: map[string]any{"Apps": provision.Apps, "Checked": checked, "Form": map[string]string{"label": in.Label, "name": in.Name, "owner": in.Owner}, "Forked": in.Forked}})
+ Data: map[string]any{"Apps": provision.Apps, "Checked": checked, "Form": map[string]string{"label": in.Label, "name": in.Name, "owner": in.Owner}, "Forked": in.Forked,
+ "Options": optionsView(in.Options)}})
return
}
http.Redirect(w, r, "/runs/"+strconv.FormatInt(id, 10), http.StatusSeeOther)
@@ -375,6 +409,9 @@ type appView struct {
Slug, Name, Host, State string
Steps []stepView
Pending bool
+ // Written is the profile (and samples) the app's environment was
+ // written with, from step 7's record; "" until step 7 is done.
+ Written string
}
type stepView struct {
@@ -391,6 +428,12 @@ func (a *App) appViews(ctx context.Context, t provision.Team, apps []string) []a
for _, slug := range provision.SortApps(apps) {
spec, _ := provision.AppBySlug(slug)
v := appView{Slug: slug, Name: spec.Name, Host: provision.PublicHost(t.Label, slug), State: t.Apps[slug], Pending: !spec.Roster}
+ if opt, ok, _ := a.cfg.Store.WrittenOptions(ctx, t.Label, slug); ok {
+ v.Written = profileWords[opt.Profile].Name
+ if opt.Samples {
+ v.Written += ", samples"
+ }
+ }
names := provision.AppSteps(spec)
if t.Apps[slug] == "retired" {
names = provision.RetireSteps
@@ -443,8 +486,26 @@ func (a *App) team(w http.ResponseWriter, r *http.Request) {
}
}
}
+ // What Continue would do: the unfinished apps, each under its own
+ // choice, or the refusal it would meet.
+ cont, finished, _ := a.cfg.Engine.ContinueApps(ctx, t.Label)
+ var contNames []string
+ for _, s := range cont {
+ spec, _ := provision.AppBySlug(s)
+ contNames = append(contNames, spec.Name)
+ }
+ contWords := ""
+ contOpt, err := a.cfg.Engine.ContinuedOptions(ctx, t.Label, cont)
+ if err != nil {
+ contWords = describe(errorCode(err))
+ contOpt, _ = a.cfg.Store.LastOptions(ctx, t.Label)
+ }
a.render(w, r, http.StatusOK, "team", page{Title: t.Name, Context: t.Label, Notice: notice,
- Data: map[string]any{"Team": t, "Apps": a.appViews(ctx, t, apps), "Addable": addable, "Runs": runs, "Audit": audit, "HoldsOwner": holdsOwner, "NeedsOwner": needsOwner, "Seeded": t.TeamSQID != ""}})
+ Data: map[string]any{"Team": t, "Apps": a.appViews(ctx, t, apps), "Addable": addable, "Runs": runs, "Audit": audit, "HoldsOwner": holdsOwner, "NeedsOwner": needsOwner, "Seeded": t.TeamSQID != "",
+ "Options": optionsView(contOpt), "Continue": strings.Join(contNames, ", "), "ContinueRefused": contWords,
+ // Every app finished, under choices that disagree: nothing to
+ // continue, and no one choice to continue it under.
+ "NothingToContinue": finished && contWords != ""}})
}
func (a *App) addApps(w http.ResponseWriter, r *http.Request) {
@@ -455,14 +516,16 @@ func (a *App) addApps(w http.ResponseWriter, r *http.Request) {
_ = r.ParseForm()
apps := r.PostForm["app"]
if len(apps) == 0 {
- // "Continue": every active app, under a new plan.
- for app, st := range t.Apps {
- if st == "active" {
- apps = append(apps, app)
- }
+ // "Continue": the apps with steps still to do, under the choice
+ // the form posts (defaulted to each app's own; an app already
+ // written refuses any other), under a new plan.
+ var err error
+ if apps, _, err = a.cfg.Engine.ContinueApps(r.Context(), t.Label); err != nil {
+ http.Redirect(w, r, "/teams/"+t.Label+"?audit="+url.QueryEscape(errorCode(err)), http.StatusSeeOther)
+ return
}
}
- id, err := a.cfg.Engine.AddApps(r.Context(), t.Label, apps)
+ id, err := a.cfg.Engine.AddApps(r.Context(), t.Label, apps, formOptions(r))
if err != nil {
http.Redirect(w, r, "/teams/"+t.Label+"?audit="+url.QueryEscape(errorCode(err)), http.StatusSeeOther)
return
@@ -593,6 +656,13 @@ func (a *App) run(w http.ResponseWriter, r *http.Request) {
}
data := map[string]any{"Run": run, "Roles": roles, "Prefix": homeop.PlanPrefix(run.PlanID), "Words": describe(run.Code),
"PlanExpires": time.Unix(run.PlanExpires, 0), "Live": run.State == "planned" || run.State == "running" || run.State == "parked"}
+ if run.Kind == homeop.KindCreateTeam || run.Kind == homeop.KindAddApps {
+ data["Options"] = optionsView(run.Options)
+ data["HasDocs"] = slices.Contains(run.Apps, "docs")
+ if run.Options.Profile == provision.ProfileOwn && slices.Contains(run.Apps, "memoria") {
+ data["MemoriaAI"] = true
+ }
+ }
title := "Initialize"
if run.Label != "" {
t, err := a.cfg.Store.Team(ctx, run.Label)
diff --git a/internal/web/static/alta.css b/internal/web/static/alta.css
index 6c20745..de4037c 100644
--- a/internal/web/static/alta.css
+++ b/internal/web/static/alta.css
@@ -19,3 +19,5 @@ section { margin-block: var(--rst-sp-5); }
.alta-roles li { margin-block: var(--rst-sp-2); }
.alta-roles a, .alta-grid small { overflow-wrap: anywhere; }
.alta-audit { list-style: none; padding: 0; font-size: var(--rst-fs-sm); }
+.alta-profile { border: 0; padding: 0; margin-block: var(--rst-sp-3); }
+.alta-profile legend { font-weight: 600; margin-block-end: var(--rst-sp-2); }
diff --git a/internal/web/templates/layout.html b/internal/web/templates/layout.html
index c5c3bc5..1e0524b 100644
--- a/internal/web/templates/layout.html
+++ b/internal/web/templates/layout.html
@@ -31,3 +31,12 @@
</body>
</html>
{{end}}
+{{define "run-options"}}
+{{/* run-options — a provisioning run's profile and samples choice
+ (Paul, 2026-11-12): recorded on the run, shown with its plan. */}}
+<fieldset class="alta-profile">
+ <legend>Profile</legend>
+ {{range .Choices}}<label class="alta-check"><input type="radio" name="profile" value="{{.Value}}"{{if .Checked}} checked{{end}} required> <strong>{{.Name}}</strong><br><small class="alta-quiet">{{.Says}}</small></label>{{end}}
+</fieldset>
+<label class="alta-check"><input type="checkbox" name="samples" value="1"{{if .Samples}} checked{{end}}> Docs sample documents: each new person's Docs starts with the sample documents</label>
+{{end}}
diff --git a/internal/web/templates/run.html b/internal/web/templates/run.html
index a4b2a9c..6de1fe8 100644
--- a/internal/web/templates/run.html
+++ b/internal/web/templates/run.html
@@ -12,6 +12,14 @@
{{end}}
</ol>
<p class="alta-quiet">The plan expires {{when .Data.PlanExpires}} unless confirmed; a window lasts 15 minutes and is never extended.</p>
+ {{with .Data.Options}}<p>Profile <strong>{{.Name}}</strong>: {{.Says}}{{if $.Data.HasDocs}} Docs sample documents {{if .Samples}}<strong>on</strong>{{else}}off{{end}}.{{end}} <small class="alta-quiet">Alta's own record: Home's copy of the plan does not carry it.</small></p>{{end}}
+</section>
+{{end}}
+{{if .Data.MemoriaAI}}
+<section class="alta-box">
+ <h2>After the run: Memoria AI</h2>
+ <p>Alta never holds your TensorX key, so Memoria starts with AI off. To turn it on, set the secret <span class="alta-label">MEMORIA_TENSORX_KEY</span> and the variable <span class="alta-label">MEMORIA_AI=on</span> in environment <span class="alta-label">{{with .Data.Team}}{{.Environment}}{{end}}</span> (<span class="alta-label">carlos secrets set</span> and <span class="alta-label">carlos env set</span>, each with <span class="alta-label">--environment</span>), then restart the instance.</p>
+ <p class="alta-quiet">The audit accepts the two together and refuses either alone; memoria refuses to start with one alone.</p>
</section>
{{end}}
{{with .Data.Apps}}
@@ -35,7 +43,7 @@
{{end}}
{{if or (eq $run.Code "plan-expired") (eq $run.Code "plan-refused-credential") (eq $run.Code "plan-refused-directory")}}<form method="post" action="/runs/{{$run.ID}}/plan"><button type="submit" rst-btn>Submit a new plan</button></form>{{end}}
{{if .Data.Live}}
- {{if and .Data.Team (or (eq $run.Code "window-expired") (eq $run.Code "window-closed"))}}<form method="post" action="/teams/{{$run.Label}}/apps"><button type="submit" rst-btn>Continue under a new plan</button></form>{{end}}
+ {{if and .Data.Team (or (eq $run.Code "window-expired") (eq $run.Code "window-closed"))}}<a rst-btn href="/teams/{{$run.Label}}#continue">Continue under a new plan…</a>{{end}}
{{end}}
{{with .Data.Team}}<a rst-btn href="/teams/{{.Label}}">Team</a>{{end}}
<p class="alta-quiet">Refresh to see progress.</p>
diff --git a/internal/web/templates/team.html b/internal/web/templates/team.html
index 5d03bc0..01db104 100644
--- a/internal/web/templates/team.html
+++ b/internal/web/templates/team.html
@@ -7,22 +7,32 @@
<thead><tr><th scope="col">App</th><th scope="col">Steps</th></tr></thead>
<tbody>
{{range .Data.Apps}}
- <tr><th scope="row">{{.Name}}{{if eq .State "retired"}} (retired){{end}}<br><small class="alta-quiet">{{.Host}}</small></th>
+ <tr><th scope="row">{{.Name}}{{if eq .State "retired"}} (retired){{end}}<br><small class="alta-quiet">{{.Host}}</small>{{with .Written}}<br><small class="alta-quiet">Written as {{.}}</small>{{end}}</th>
<td><ul class="alta-steps">{{range .Steps}}<li class="alta-step" data-state="{{.State}}"><span>{{if eq .State "done"}}✓{{else if eq .State "parked"}}◷{{else if eq .State "failed"}}✕{{else}}·{{end}} {{.Name}}</span>{{with .Words}} <small>{{.}}</small>{{end}}</li>{{end}}</ul></td></tr>
{{end}}
</tbody>
</table>
</section>
<section class="alta-actions">
- <form method="post" action="/teams/{{$t.Label}}/apps"><button type="submit" rst-btn="primary">Continue under a new plan</button></form>
<form method="post" action="/teams/{{$t.Label}}/audit"><button type="submit" rst-btn>Audit</button></form>
{{if .Data.Seeded}}<a rst-btn="danger" href="/teams/{{$t.Label}}/retire">Retire apps…</a>{{end}}
</section>
+{{if not .Data.NothingToContinue}}
+<section class="alta-box" id="continue">
+ <h2>Continue under a new plan</h2>
+ <p>{{if .Data.ContinueRefused}}{{.Data.ContinueRefused}}{{else}}Continues {{.Data.Continue}}.{{end}} An app whose environment is already written keeps the choice it was written with; one not yet written takes the choice made here.</p>
+ <form method="post" action="/teams/{{$t.Label}}/apps">
+ {{template "run-options" .Data.Options}}
+ <button type="submit" rst-btn="primary">Continue under a new plan</button>
+ </form>
+</section>
+{{end}}
{{if and .Data.Seeded .Data.Addable}}
<section class="alta-box">
<h2>Add apps</h2>
<form method="post" action="/teams/{{$t.Label}}/apps">
<fieldset class="alta-apps"><legend>Apps</legend>{{range .Data.Addable}}<label><input type="checkbox" name="app" value="{{.}}"> {{.}}</label>{{end}}</fieldset>
+ {{template "run-options" .Data.Options}}
<button type="submit" rst-btn>Submit plan to Home</button>
</form>
</section>
@@ -40,7 +50,7 @@
{{end}}
<section>
<h2>Runs</h2>
- {{if .Data.Runs}}<ul>{{range .Data.Runs}}<li><a href="/runs/{{.ID}}">Run {{.ID}}</a> · {{.Kind}} · {{.State}}{{with .Code}} · {{describe .}}{{end}}</li>{{end}}</ul>{{else}}<p>None.</p>{{end}}
+ {{if .Data.Runs}}<ul>{{range .Data.Runs}}<li><a href="/runs/{{.ID}}">Run {{.ID}}</a> · {{.Kind}}{{if or (eq .Kind "create-team") (eq .Kind "add-apps")}} · {{.Options.Profile}}{{if .Options.Samples}}, samples{{end}}{{end}} · {{.State}}{{with .Code}} · {{describe .}}{{end}}</li>{{end}}</ul>{{else}}<p>None.</p>{{end}}
</section>
<section>
<h2>Audit</h2>
diff --git a/internal/web/templates/team_new.html b/internal/web/templates/team_new.html
index c88eeb2..5fd7308 100644
--- a/internal/web/templates/team_new.html
+++ b/internal/web/templates/team_new.html
@@ -1,13 +1,14 @@
{{define "content"}}
{{template "page-header" dict "Title" "New team" "Sub" "Alta checks everything it can first, then submits a plan you confirm on Home."}}
<form rst-form method="post" action="/teams">
- {{template "field" dict "ID" "label" "Name" "label" "Label" "Label" "Value" (index .Data.Form "label") "Required" true "Autofocus" true "Autocomplete" "off" "Pattern" "[a-z][a-z0-9-]{1,30}[a-z0-9]" "Help" "Lower-case letters, digits and hyphens. The team's hosts are <label>.<app>.oficina.works. A label is never reused, even after its apps are retired."}}
+ {{template "field" dict "ID" "label" "Name" "label" "Label" "Label" "Value" (index .Data.Form "label") "Required" true "Autofocus" true "Autocomplete" "off" "Pattern" "(?!.*--)[a-z][a-z0-9\\-]{1,30}[a-z0-9]" "Help" "Lower-case letters, digits and hyphens, never two hyphens together. The team's hosts are <label>.<app>.oficina.works. A label is never reused, even after its apps are retired, and an app's name or one of the suite's own is never offered."}}
{{template "field" dict "ID" "name" "Name" "name" "Label" "Name" "Value" (index .Data.Form "name") "Required" true "Help" "What the team is called in Home."}}
{{template "field" dict "ID" "owner" "Name" "owner" "Label" "Owner email" "Type" "email" "Value" (index .Data.Form "owner") "Required" true "Autocomplete" "off" "Help" "They must already have signed in at oficina.works once."}}
<fieldset class="alta-apps">
<legend>Apps</legend>
{{range .Data.Apps}}<label><input type="checkbox" name="app" value="{{.Slug}}"{{if or (index $.Data.Checked .Slug) (not $.Data.Checked)}} checked{{end}}> {{.Name}}</label>{{end}}
</fieldset>
+ {{template "run-options" .Data.Options}}
<label class="alta-check"><input type="checkbox" name="forked" value="1"{{if .Data.Forked}} checked{{end}}> Moving a stopgap: use the environments you forked to <span class="alta-label">&lt;label&gt;-team</span></label>
<div rst-form-foot><button type="submit" rst-btn="primary">Submit plan to Home</button></div>
</form>
diff --git a/internal/web/web_test.go b/internal/web/web_test.go
index 7b5c254..688ad66 100644
--- a/internal/web/web_test.go
+++ b/internal/web/web_test.go
@@ -230,20 +230,38 @@ func TestInitializeThenNewTeamShowsTheConfirmCeremony(t *testing.T) {
t.Fatal(page.Code)
}
scriptless(t, page.Body.String())
+ // The profile is chosen per run: outside is the default; samples off.
+ if b := page.Body.String(); !strings.Contains(b, `name="profile" value="outside" checked`) || strings.Contains(b, `value="own" checked`) || strings.Contains(b, `name="samples" value="1" checked`) {
+ t.Fatal("the new team form does not default to outside without samples")
+ }
+ for label, want := range map[string]string{"docs": "reserved", "xn--lagged": "two hyphens"} {
+ w = f.do("POST", "/teams", url.Values{"label": {label}, "name": {"X"}, "owner": {owner}, "app": {"docs"}, "profile": {"outside"}}, sameOrigin)
+ if w.Code != 422 || !strings.Contains(w.Body.String(), want) {
+ t.Fatalf("label %q: %d", label, w.Code)
+ }
+ }
+ w = f.do("POST", "/teams", url.Values{"label": {"lagged"}, "name": {"X"}, "owner": {owner}, "app": {"docs"}, "profile": {"mine"}}, sameOrigin)
+ if w.Code != 422 || !strings.Contains(w.Body.String(), "Choose a profile") {
+ t.Fatalf("unknown profile: %d", w.Code)
+ }
// A label used before is refused on the form, and the address is
// echoed into the form only.
w = f.do("POST", "/teams", url.Values{"label": {"Bad Label"}, "name": {"Lagged"}, "owner": {owner}, "app": {"docs", "calls"}}, sameOrigin)
if w.Code != 422 || !strings.Contains(w.Body.String(), "lower-case") {
t.Fatalf("bad label: %d", w.Code)
}
- w = f.do("POST", "/teams", url.Values{"label": {"lagged"}, "name": {"Lagged"}, "owner": {owner}, "app": {"docs", "calls"}}, sameOrigin)
+ w = f.do("POST", "/teams", url.Values{"label": {"lagged"}, "name": {"Lagged"}, "owner": {owner}, "app": {"docs", "calls", "memoria"}, "profile": {"own"}, "samples": {"1"}}, sameOrigin)
if w.Code != 303 {
t.Fatalf("create: %d %s", w.Code, w.Body.String())
}
run := f.do("GET", w.Header().Get("Location"), nil, nil)
body := run.Body.String()
r, _ := f.store.Run(context.Background(), mustInt(t, strings.TrimPrefix(w.Header().Get("Location"), "/runs/")))
- for _, want := range []string{"https://oficina.works/operator/confirm", "https://id.oficina.works/operator/confirm", homeop.PlanPrefix(r.PlanID), "lagged.docs.oficina.works", "Resume"} {
+ if r.Options != (provision.RunOptions{Profile: provision.ProfileOwn, Samples: true}) {
+ t.Fatalf("run options %+v", r.Options)
+ }
+ for _, want := range []string{"https://oficina.works/operator/confirm", "https://id.oficina.works/operator/confirm", homeop.PlanPrefix(r.PlanID), "lagged.docs.oficina.works", "Resume",
+ "Profile <strong>Own</strong>", "Docs sample documents <strong>on</strong>", "After the run: Memoria AI"} {
if !strings.Contains(body, want) {
t.Fatalf("run page lacks %q", want)
}
@@ -256,6 +274,9 @@ func TestInitializeThenNewTeamShowsTheConfirmCeremony(t *testing.T) {
if team.Code != 200 || strings.Contains(team.Body.String(), owner) {
t.Fatalf("team page: %d", team.Code)
}
+ if b := team.Body.String(); !strings.Contains(b, "Continues Docs, Calls, Memoria.") || !strings.Contains(b, `id="continue"`) || !strings.Contains(b, `name="profile" value="own" checked`) || !strings.Contains(b, `name="samples" value="1" checked`) || !strings.Contains(b, "create-team · own, samples") {
+ t.Fatal("the team page does not show the run's profile")
+ }
retire := f.do("GET", "/teams/lagged/retire", nil, nil)
if retire.Code != 200 || !strings.Contains(retire.Body.String(), "Type lagged to confirm") {
t.Fatalf("retire page: %d", retire.Code)
diff --git a/internal/web/words.go b/internal/web/words.go
index 486a269..dfa1e0a 100644
--- a/internal/web/words.go
+++ b/internal/web/words.go
@@ -56,8 +56,12 @@ var words = map[string]string{
"transient": "Something went wrong. Alta will try again.",
"guard": "Alta's own guard refused a request",
"label-used": "That label has been used before. Labels are never reused.",
- "label-reserved": "That label is reserved for the suite's own apps.",
- "label-shape": "A label is 3–32 lower-case letters, digits and hyphens, starting with a letter",
+ "label-reserved": "That label is reserved: it names one of the suite's apps or its own services.",
+ "label-shape": "A label is 3–32 lower-case letters, digits and hyphens, starting with a letter and ending with a letter or digit",
+ "label-double-hyphen": "A label never has two hyphens together (that is how punycode names begin)",
+ "profile-unknown": "Choose a profile: own or outside",
+ "operator-keys-invalid": "Memoria's AI pair is not as memoria reads it: MEMORIA_AI must be the variable on, and MEMORIA_TENSORX_KEY a secret",
+ "audit-operator-partial": "Memoria's AI is half set: MEMORIA_AI=on and MEMORIA_TENSORX_KEY go together",
"name-shape": "Give the team a name",
"owner-shape": "That is not a plain email address",
"no-apps": "Choose at least one app",
@@ -95,6 +99,7 @@ var prefixes = map[string]string{
"domain-slow-": "Over 30 minutes and still ",
"roster-": "The app's roster says ",
"plan-": "Plan: ",
+ "profile-differs-": "That app's environment was written under another profile or samples choice, which a run never rewrites: ",
}
// knownCode admits only codes Alta itself produces, so a code typed into
@@ -103,7 +108,7 @@ func knownCode(code string) bool {
if _, ok := words[code]; ok {
return true
}
- for _, p := range []string{"mail-prefix-", "no-credential-", "environment-exists-", "fork-missing-", "instance-bound-elsewhere-", "console-"} {
+ for _, p := range []string{"mail-prefix-", "no-credential-", "environment-exists-", "fork-missing-", "instance-bound-elsewhere-", "console-", "profile-differs-"} {
if strings.HasPrefix(code, p) {
_, ok := provision.AppBySlug(strings.TrimPrefix(code, p))
return ok
diff --git a/provision/apps.go b/provision/apps.go
index 8c14c7d..a0d8cdd 100644
--- a/provision/apps.go
+++ b/provision/apps.go
@@ -18,12 +18,39 @@ import (
// Home's ValidLabel, so every derived host stays well inside DNS limits.
var LabelPattern = regexp.MustCompile(`^[a-z][a-z0-9-]{1,30}[a-z0-9]$`)
-// ReservedLabels are never offered to a new team. "oficina" names the
-// suite's own canonical apps (docs.oficina.works and the rest), which Home
-// adopts as an existing team on its own path (Home discussion 103), and is
-// the dashboard team the canonical apps already carry; a new team under it
-// would claim their name.
-var ReservedLabels = map[string]bool{"oficina": true}
+// ReservedLabels are never offered to a new team. This is the one list
+// (a test pins it): a label becomes the first DNS label of every team
+// host and the team's name at Home, so it must never collide with a name
+// the suite or the platform already answers to (Paul, 2026-11-12).
+var ReservedLabels = map[string]bool{
+ // The suite's own canonical apps (docs.oficina.works and the rest),
+ // which Home adopts as an existing team on its own path (Home
+ // discussion 103), and the dashboard team they already carry.
+ "oficina": true,
+ // Every app's name, provisioned by Alta or not yet: a team called
+ // "docs" would own docs.calls.oficina.works and read as an app.
+ "docs": true, "sheets": true, "slides": true, "calendar": true,
+ "calls": true, "memoria": true, "fichas": true, "mapa": true,
+ // The suite's and the platform's own hosts and paths.
+ "api": true, "auth": true, "healthz": true, "static": true, "www": true,
+ "id": true, "admin": true, "portero": true, "home": true, "alta": true,
+ "base": true, "forget": true,
+}
+
+// LabelRefusal is the code a label is refused with at step 0, or "" for a
+// label Alta will offer. A label never holds "--": that is the shape
+// of IDNA's xn-- (punycode) labels, which would render as another name.
+func LabelRefusal(label string) string {
+ switch {
+ case !LabelPattern.MatchString(label):
+ return "label-shape"
+ case strings.Contains(label, "--"):
+ return "label-double-hyphen"
+ case ReservedLabels[label]:
+ return "label-reserved"
+ }
+ return ""
+}
// PublicDomain is the only public suffix Home's directory admits for a
// team instance (internal/home directoryRouteAllowed).
@@ -46,14 +73,18 @@ type App struct {
MailPrefixes []string
// Relay is true when CARLOS_RELAY is a PLATFORM key (Calls).
Relay bool
+ // Dashboard is true for an app whose binary reads
+ // OFICINA_DASHBOARD_TEAM (internal/<app>/dashboard.go): the own
+ // profile names the team there.
+ Dashboard bool
}
// Apps is the compiled registry, in Home's order (directory_runtime.go).
var Apps = []App{
- {Slug: "docs", Name: "Docs", Prefix: "DOCS", Roster: true, MailPrefixes: []string{"DOCS_SMTP"}},
- {Slug: "sheets", Name: "Sheets", Prefix: "SHEETS", Roster: true, MailPrefixes: []string{"CARLOS_SMTP"}},
- {Slug: "slides", Name: "Slides", Prefix: "SLIDES", Roster: true, MailPrefixes: []string{"SLIDES_SMTP", "CARLOS_SMTP"}},
- {Slug: "calendar", Name: "Calendar", Prefix: "CALENDAR", Roster: true, MailPrefixes: []string{"CALENDAR_SMTP", "CARLOS_SMTP"}},
+ {Slug: "docs", Name: "Docs", Prefix: "DOCS", Roster: true, MailPrefixes: []string{"DOCS_SMTP"}, Dashboard: true},
+ {Slug: "sheets", Name: "Sheets", Prefix: "SHEETS", Roster: true, MailPrefixes: []string{"CARLOS_SMTP"}, Dashboard: true},
+ {Slug: "slides", Name: "Slides", Prefix: "SLIDES", Roster: true, MailPrefixes: []string{"SLIDES_SMTP", "CARLOS_SMTP"}, Dashboard: true},
+ {Slug: "calendar", Name: "Calendar", Prefix: "CALENDAR", Roster: true, MailPrefixes: []string{"CALENDAR_SMTP", "CARLOS_SMTP"}, Dashboard: true},
{Slug: "calls", Name: "Calls", Prefix: "CALLS", Roster: true, MailPrefixes: []string{"CALLS_SMTP", "CARLOS_SMTP"}, Relay: true},
{Slug: "memoria", Name: "Memoria", Prefix: "MEMORIA", Roster: true, MailPrefixes: []string{"CARLOS_SMTP"}},
}
@@ -131,6 +162,47 @@ type HomeConfig struct {
Provisioner string // the directory's provisioning public key, base64url
}
+// Profile is a run's recipe variant (Paul, 2026-11-12).
+type Profile string
+
+const (
+ // ProfileOutside is the recipes as the design has them: for anyone
+ // else's team (an outsider's), and the default.
+ ProfileOutside Profile = "outside"
+ // ProfileOwn is for Paul's own teams. It differs from outside only in
+ // Calls' quality reports (on), each dashboard app's
+ // OFICINA_DASHBOARD_TEAM (the label), and Memoria's AI pair, which the
+ // audit admits once Paul has set it by hand (OperatorKeys). Alta never
+ // holds or writes the TensorX key.
+ ProfileOwn Profile = "own"
+)
+
+// Profiles is every profile, in the order the run form offers them.
+var Profiles = []Profile{ProfileOutside, ProfileOwn}
+
+// RunOptions is what Paul chooses per run beside its apps, recorded on the
+// run and shown with its plan.
+type RunOptions struct {
+ Profile Profile
+ // Samples sets DOCS_SAMPLE_DOCUMENTS: a new person's Docs starts with
+ // the sample documents. Separate from the profile, because only a
+ // sample team gets it.
+ Samples bool
+}
+
+// Normal is o with an unset profile read as outside; ok is false for a
+// profile Alta does not know.
+func (o RunOptions) Normal() (RunOptions, bool) {
+ switch o.Profile {
+ case "":
+ o.Profile = ProfileOutside
+ case ProfileOutside, ProfileOwn:
+ default:
+ return o, false
+ }
+ return o, true
+}
+
// Inputs is what a recipe is built from.
type Inputs struct {
Label string
@@ -139,6 +211,9 @@ type Inputs struct {
Record []byte // step 5's signed record (Docs)
Home HomeConfig
CallsZone string
+ // RunOptions is the run's profile and samples choice. The zero value
+ // is the outside recipe without samples.
+ RunOptions
}
// Recipe is one app's GENERATED and SET keys. PLATFORM keys are added by
@@ -154,12 +229,23 @@ func Recipe(app App, in Inputs) []Key {
{Name: p + "_HOME_DEK_BASE64", Class: Generated, Secret: true},
{Name: "HOME_DIRECTORY_ORIGIN", Class: Set, Value: in.Home.Directory},
}
+ own := in.Profile == ProfileOwn
+ if own && app.Dashboard {
+ // The team's own dashboard feed in Home (home/dashboard): the
+ // provider answers only for this team's name.
+ keys = append(keys, Key{Name: "OFICINA_DASHBOARD_TEAM", Class: Set, Value: in.Label})
+ }
switch app.Slug {
case "docs":
keys = append(keys,
Key{Name: "DOCS_CONTENT_KEY", Class: Generated, Secret: true},
Key{Name: "DOCS_ALLOWED_ADDRESSES", Class: Set, Value: ""},
)
+ if in.Samples {
+ // cmd/docs reads it permissively ("1", "true", "yes"; anything
+ // else is off), and seeds each new person's list once.
+ keys = append(keys, Key{Name: "DOCS_SAMPLE_DOCUMENTS", Class: Set, Value: "1"})
+ }
keys = append(keys, teamKeys(p, in)...)
case "sheets":
// Team mode (oficina/sheets team-mode @ b0264ff): SHEETS_OWNERS is
@@ -167,7 +253,11 @@ func Recipe(app App, in Inputs) []Key {
keys = append(keys, Key{Name: "SHEETS_DEK", Class: Generated, Secret: true})
keys = append(keys, teamKeys(p, in)...)
case "slides":
- // No uploads (Paul): no CARLOS_STORE_*, so uploads answer 503.
+ // No uploads (Paul): no CARLOS_STORE_*, so uploads answer 503. The
+ // own profile would want a bucket, but a team credential cannot
+ // declare one: CARLOS's store doors are Admin-only, and the one
+ // path that provisions a store at instance create is the app-wide
+ // private-storage policy, which no run can choose.
// Team mode (oficina/slides team-mode @ 80fd3c9, through Home's
// teammode): SLIDES_ALLOWED_ADDRESSES is optional beside
// SLIDES_TEAM_*, so the owner is not written.
@@ -188,14 +278,18 @@ func Recipe(app App, in Inputs) []Key {
Key{Name: "CALLS_DEK", Class: Generated, Secret: true},
Key{Name: "CALLS_ZONE", Class: Set, Value: in.CallsZone},
// A team's call-quality logs would land in the operator's
- // `carlos logs`; off until that team's owner and Paul agree.
- Key{Name: "CALLS_QUALITY_REPORTS", Class: Set, Value: "off"},
+ // `carlos logs`; off until that team's owner and Paul agree,
+ // and on for Paul's own teams.
+ Key{Name: "CALLS_QUALITY_REPORTS", Class: Set, Value: qualityReports(own)},
)
keys = append(keys, teamKeys(p, in)...)
case "memoria":
// AI off: MEMORIA_AI, _TENSORX_KEY, _SIBLINGS, _SIBLING_TOKEN_*
// and _ALLOW_LOGGED_MAIL are simply absent (Paul: AI is off, and
- // his key is never used).
+ // his key is never used). In both profiles: memoria refuses to
+ // boot with MEMORIA_AI=on and no MEMORIA_TENSORX_KEY, and Alta
+ // never holds the key, so an own team's AI is Paul's post-run
+ // step (OperatorKeys).
// Team mode (oficina/memoria #32, team-mode @ 88f6cec, through
// Home's teammode): MEMORIA_OWNERS is optional beside
// MEMORIA_TEAM_*, so the owner is not written. MEMORIA_TEAM is the
@@ -211,6 +305,91 @@ func Recipe(app App, in Inputs) []Key {
return keys
}
+func qualityReports(own bool) string {
+ if own {
+ return "on"
+ }
+ return "off"
+}
+
+// OperatorKey is a key Paul sets by hand after a run, never Alta: the
+// audit admits it, under its profile, only beside every other key of the
+// app's OperatorKeys, with its kind and (for an env key) its value.
+type OperatorKey struct {
+ Name string
+ Secret bool
+ Value string
+}
+
+// OperatorKeys is app's post-run group under profile p: Memoria's AI on
+// an own team (MEMORIA_AI=on and the TensorX key, both or neither;
+// memoria refuses to boot with one alone). Outside teams have none.
+func OperatorKeys(app App, p Profile) []OperatorKey {
+ if p != ProfileOwn || app.Slug != "memoria" {
+ return nil
+ }
+ return []OperatorKey{
+ {Name: "MEMORIA_AI", Value: "on"},
+ {Name: "MEMORIA_TENSORX_KEY", Secret: true},
+ }
+}
+
+// profileWrites is every env key some run's choice writes into app's
+// environment for label beyond the outside recipe, with the exact value
+// it writes: a later run may take back out a key that is still exactly
+// Alta's own, and nothing else (a foreign value is an extra key).
+func profileWrites(app App, label string) map[string]string {
+ base := map[string]bool{}
+ for _, k := range Recipe(app, Inputs{Label: label}) {
+ base[k.Name] = true
+ }
+ out := map[string]string{}
+ for _, p := range Profiles {
+ for _, k := range Recipe(app, Inputs{Label: label, RunOptions: RunOptions{Profile: p, Samples: true}}) {
+ if !base[k.Name] && k.Class == Set {
+ out[k.Name] = k.Value
+ }
+ }
+ }
+ return out
+}
+
+// OperatorState is how much of app's post-run group an environment holds.
+type OperatorState int
+
+const (
+ OperatorNone OperatorState = iota // no key of the group (or no group)
+ OperatorPartial // some, not all
+ OperatorWhole // all, each with its kind and value
+ OperatorInvalid // all, but one has the wrong kind or value
+)
+
+// operatorState reads an environment's keys (name → kind, value) against
+// group.
+func operatorState(group []OperatorKey, kind func(name string) (k, value string, ok bool)) OperatorState {
+ held, bad := 0, false
+ for _, g := range group {
+ k, v, ok := kind(g.Name)
+ if !ok {
+ continue
+ }
+ held++
+ switch {
+ case g.Secret && k != "secret", !g.Secret && k != "env", !g.Secret && v != g.Value:
+ bad = true
+ }
+ }
+ switch {
+ case held == 0:
+ return OperatorNone
+ case held < len(group):
+ return OperatorPartial
+ case bad:
+ return OperatorInvalid
+ }
+ return OperatorWhole
+}
+
// ownerKey is a stopgap allowlist holding the owner's address, for an app
// without roster mode (Track 1's shape). Every app has roster mode now, so
// no recipe uses it; it stays so the address rules (§4: deleted once every
diff --git a/provision/engine.go b/provision/engine.go
index 226fd33..8e8f876 100644
--- a/provision/engine.go
+++ b/provision/engine.go
@@ -114,7 +114,7 @@ func (e *Engine) StartInitialize(ctx context.Context, typed string) (int64, erro
if ins.Generation != nil {
return 0, fail("already-initialized")
}
- id, err := e.cfg.Store.NewRun(ctx, homeop.KindInitialize, "", nil)
+ id, err := e.cfg.Store.NewRun(ctx, homeop.KindInitialize, "", nil, RunOptions{})
if err != nil {
return 0, err
}
@@ -129,6 +129,8 @@ type NewTeam struct {
// Forked: the team moves an existing stopgap whose environments Paul
// forked to <label>-team (§6, "Moving the lagged stopgap").
Forked bool
+ // Options is the run's profile (zero: outside) and samples choice.
+ Options RunOptions
}
// EnvironmentName is a team's owned environment's name.
@@ -157,11 +159,12 @@ func validEnvironment(s string) bool {
func (e *Engine) CreateTeam(ctx context.Context, in NewTeam) (int64, error) {
in.Apps = SortApps(in.Apps)
env := EnvironmentName(in.Label, in.Forked)
+ opt, okOpt := in.Options.Normal()
switch {
- case !LabelPattern.MatchString(in.Label):
- return 0, fail("label-shape")
- case ReservedLabels[in.Label]:
- return 0, fail("label-reserved")
+ case LabelRefusal(in.Label) != "":
+ return 0, fail(LabelRefusal(in.Label))
+ case !okOpt:
+ return 0, fail("profile-unknown")
case !homeop.TeamName(in.Name):
return 0, fail("name-shape")
case !homeop.OwnerAddress(in.Owner):
@@ -187,18 +190,20 @@ func (e *Engine) CreateTeam(ctx context.Context, in NewTeam) (int64, error) {
if err := e.cfg.Store.CreateTeam(ctx, in.Label, in.Name, env, in.Forked, in.Owner, in.Apps); err != nil {
return 0, err
}
- id, err := e.cfg.Store.NewRun(ctx, homeop.KindCreateTeam, in.Label, in.Apps)
+ id, err := e.cfg.Store.NewRun(ctx, homeop.KindCreateTeam, in.Label, in.Apps, opt)
if err != nil {
return 0, err
}
e.cfg.Store.Audit(ctx, id, in.Label, "", "run-start", homeop.KindCreateTeam)
+ e.auditOptions(ctx, id, in.Label, opt)
return id, e.submitPlans(ctx, id, in.Label, in.Name, in.Owner, homeop.KindCreateTeam, in.Apps)
}
// AddApps starts an add-apps run: new apps for a team, or a parked run's
// apps resumed under a fresh plan (§6: "A run that parks resumes under a
-// new plan of kind add-apps").
-func (e *Engine) AddApps(ctx context.Context, label string, apps []string) (int64, error) {
+// new plan of kind add-apps"). opt with no profile continues each app
+// with its own choice (ContinuedOptions); a profile names a fresh one.
+func (e *Engine) AddApps(ctx context.Context, label string, apps []string, opt RunOptions) (int64, error) {
apps = SortApps(apps)
// Home's adoption of the canonical apps is its own signed scope
// (existing_team on the plan, Home discussion 103); an ordinary
@@ -211,10 +216,31 @@ func (e *Engine) AddApps(ctx context.Context, label string, apps []string) (int6
if err != nil {
return 0, fail("no-team")
}
+ if opt.Profile == "" {
+ if opt, err = e.ContinuedOptions(ctx, label, apps); err != nil {
+ return 0, err
+ }
+ }
+ opt, ok := opt.Normal()
+ if !ok {
+ return 0, fail("profile-unknown")
+ }
+ // An environment already written keeps its choice: step 7 is done and
+ // never rewrites it, so a run under another choice would finish while
+ // changing nothing. Refused, naming the app.
+ for _, a := range apps {
+ written, ok, err := e.cfg.Store.WrittenOptions(ctx, label, a)
+ if err != nil {
+ return 0, err
+ }
+ if ok && written != opt {
+ return 0, fail("profile-differs-" + a)
+ }
+ }
if t.TeamSQID == "" {
// The team was never seeded: only a create-team plan admits
// owner-seed and seed-team. Resume that instead.
- return e.resumeCreate(ctx, t, apps)
+ return e.resumeCreate(ctx, t, apps, opt)
}
if len(apps) == 0 {
return 0, fail("no-apps")
@@ -234,17 +260,77 @@ func (e *Engine) AddApps(ctx context.Context, label string, apps []string) (int6
if err := e.cfg.Store.AddApps(ctx, label, fresh); err != nil {
return 0, err
}
- id, err := e.cfg.Store.NewRun(ctx, homeop.KindAddApps, label, apps)
+ id, err := e.cfg.Store.NewRun(ctx, homeop.KindAddApps, label, apps, opt)
if err != nil {
return 0, err
}
e.cfg.Store.Audit(ctx, id, label, "", "run-start", homeop.KindAddApps)
+ e.auditOptions(ctx, id, label, opt)
return id, e.submitPlans(ctx, id, label, "", "", homeop.KindAddApps, apps)
}
+// ContinueApps is what "Continue under a new plan" takes: the team's
+// active apps with steps still to do (step 13 not done). With none,
+// finished is true and apps is every active app, as before.
+func (e *Engine) ContinueApps(ctx context.Context, label string) (apps []string, finished bool, err error) {
+ t, err := e.cfg.Store.Team(ctx, label)
+ if err != nil {
+ return nil, false, fail("no-team")
+ }
+ var active, open []string
+ for _, a := range Slugs() {
+ if t.Apps[a] != "active" {
+ continue
+ }
+ active = append(active, a)
+ if _, done, err := e.cfg.Store.Done(ctx, label, a, StepAudit); err != nil {
+ return nil, false, err
+ } else if !done {
+ open = append(open, a)
+ }
+ }
+ if len(open) == 0 {
+ return active, true, nil
+ }
+ return open, false, nil
+}
+
+// ContinuedOptions is a run's choice when Paul made none (Continue): each
+// app's own (Store.AppOptions: written, else the newest run naming it),
+// which must agree; an app that disagrees with the first is refused by
+// name. No apps: the team's last run's.
+func (e *Engine) ContinuedOptions(ctx context.Context, label string, apps []string) (RunOptions, error) {
+ if len(apps) == 0 {
+ return e.cfg.Store.LastOptions(ctx, label)
+ }
+ var first RunOptions
+ for i, a := range SortApps(apps) {
+ opt, err := e.cfg.Store.AppOptions(ctx, label, a)
+ if err != nil {
+ return RunOptions{}, err
+ }
+ if i == 0 {
+ first = opt
+ } else if opt != first {
+ return RunOptions{}, fail("profile-differs-" + a)
+ }
+ }
+ return first, nil
+}
+
+// auditOptions records a provisioning run's choice in the audit: fixed
+// words only.
+func (e *Engine) auditOptions(ctx context.Context, run int64, label string, opt RunOptions) {
+ detail := string(opt.Profile)
+ if opt.Samples {
+ detail += "+samples"
+ }
+ e.cfg.Store.Audit(ctx, run, label, "", "run-profile", detail)
+}
+
// resumeCreate is a fresh create-team plan for a team whose seed has not
// committed: its owner must still be held (it is, until step 13).
-func (e *Engine) resumeCreate(ctx context.Context, t Team, apps []string) (int64, error) {
+func (e *Engine) resumeCreate(ctx context.Context, t Team, apps []string, opt RunOptions) (int64, error) {
owner, ok, err := e.cfg.Store.Owner(ctx, t.Label)
if err != nil {
return 0, err
@@ -260,11 +346,12 @@ func (e *Engine) resumeCreate(ctx context.Context, t Team, apps []string) (int64
}
apps = SortApps(apps)
}
- id, err := e.cfg.Store.NewRun(ctx, homeop.KindCreateTeam, t.Label, apps)
+ id, err := e.cfg.Store.NewRun(ctx, homeop.KindCreateTeam, t.Label, apps, opt)
if err != nil {
return 0, err
}
e.cfg.Store.Audit(ctx, id, t.Label, "", "run-start", homeop.KindCreateTeam)
+ e.auditOptions(ctx, id, t.Label, opt)
return id, e.submitPlans(ctx, id, t.Label, t.Name, owner, homeop.KindCreateTeam, apps)
}
@@ -292,7 +379,7 @@ func (e *Engine) RetireApps(ctx context.Context, label string, apps []string, ty
return 0, fail("app-not-active")
}
}
- id, err := e.cfg.Store.NewRun(ctx, homeop.KindRetireApps, label, apps)
+ id, err := e.cfg.Store.NewRun(ctx, homeop.KindRetireApps, label, apps, RunOptions{})
if err != nil {
return 0, err
}
diff --git a/provision/engine_test.go b/provision/engine_test.go
index 78785f2..37e6a74 100644
--- a/provision/engine_test.go
+++ b/provision/engine_test.go
@@ -163,7 +163,7 @@ func TestCrashAfterEveryAct(t *testing.T) {
// The window may have closed during the restart: Paul
// confirms a fresh plan for the same apps.
if r2 := h.drive(h.engine(nil), run, 40); r2.State != "done" {
- next, err := h.engine(nil).AddApps(h.ctx(), "lagged", allApps)
+ next, err := h.engine(nil).AddApps(h.ctx(), "lagged", allApps, RunOptions{})
if err != nil {
t.Fatalf("resume plan: %v (run %s %s)", err, r2.State, r2.Code)
}
@@ -291,7 +291,7 @@ func TestWindowExpiryParksAndAddAppsResumes(t *testing.T) {
if r = h.drive(e, run, 10); r.State != "parked" || r.Code != "window-expired" {
t.Fatalf("after window: %s %s", r.State, r.Code)
}
- next, err := e.AddApps(h.ctx(), "lagged", allApps)
+ next, err := e.AddApps(h.ctx(), "lagged", allApps, RunOptions{})
if err != nil {
t.Fatal(err)
}
@@ -323,7 +323,7 @@ func TestLabelsAreNeverReused(t *testing.T) {
}
// Ordinary add-apps and retire refuse it too: adopting the canonical
// apps is Home's own signed scope, never an ordinary plan under the label.
- if _, err := e.AddApps(h.ctx(), "oficina", []string{"docs"}); !errors.As(err, &fl) || fl.Code != "label-reserved" {
+ if _, err := e.AddApps(h.ctx(), "oficina", []string{"docs"}, RunOptions{}); !errors.As(err, &fl) || fl.Code != "label-reserved" {
t.Fatalf("add-apps under the reserved label: %v", err)
}
if _, err := e.RetireApps(h.ctx(), "oficina", []string{"docs"}, "oficina"); !errors.As(err, &fl) || fl.Code != "label-reserved" {
@@ -487,7 +487,7 @@ func TestDeprovision(t *testing.T) {
}
// Retired hostnames are never reused.
h.tick(homeop.WindowLifetime * time.Second)
- if _, err := e.AddApps(h.ctx(), "lagged", []string{"calls"}); !errors.As(err, &fl) || fl.Code != "app-retired" {
+ if _, err := e.AddApps(h.ctx(), "lagged", []string{"calls"}, RunOptions{}); !errors.As(err, &fl) || fl.Code != "app-retired" {
t.Fatalf("re-adding a retired app: %v", err)
}
// Untouched apps keep running.
diff --git a/provision/guard_test.go b/provision/guard_test.go
index cb73817..153c95e 100644
--- a/provision/guard_test.go
+++ b/provision/guard_test.go
@@ -116,15 +116,29 @@ func TestGuardRefusesPlatformManagedKeys(t *testing.T) {
_, err = e.cfg.Console.PutConfig(h.ctx(), "sheets", "alpha", nil, []string{k}, "")
refusedLocally(t, h, "unset "+k, err)
}
+ // Memoria's AI pair is Paul's alone: never set, in any kind; a
+ // fork's blanked MEMORIA_AI may still be unset.
+ for _, k := range []string{"MEMORIA_AI", "MEMORIA_TENSORX_KEY"} {
+ for _, v := range []console.SetVar{{Kind: "env", Value: "on"}, {Kind: "secret", Envelope: "x"}} {
+ _, err := e.cfg.Console.PutConfig(h.ctx(), "sheets", "alpha", map[string]console.SetVar{k: v}, nil, "")
+ refusedLocally(t, h, "set "+k, err)
+ }
+ }
if len(h.con.Requests) != before {
t.Fatal("a refused request reached the console")
}
+ if _, err := e.cfg.Console.PutConfig(h.ctx(), "sheets", "alpha", nil, []string{"MEMORIA_AI"}, ""); err != nil {
+ t.Fatalf("unset of MEMORIA_AI refused: %v", err)
+ }
// And the recipe never names one.
for _, a := range Apps {
for _, k := range Recipe(a, Inputs{Label: "alpha"}) {
if console.PlatformManaged(k.Name) {
t.Fatalf("%s recipe names platform-managed %s", a.Slug, k.Name)
}
+ if console.OperatorOnly(k.Name) {
+ t.Fatalf("%s recipe names operator-only %s", a.Slug, k.Name)
+ }
}
}
}
diff --git a/provision/migrations/0002_run_options.sql b/provision/migrations/0002_run_options.sql
new file mode 100644
index 0000000..47e1bfe
--- /dev/null
+++ b/provision/migrations/0002_run_options.sql
@@ -0,0 +1,5 @@
+-- A run's profile and samples choice (Paul, 2026-11-12): recorded on the
+-- run, shown with its plan. 'outside' is the design's recipes unchanged;
+-- 'own' is for Paul's own teams. Samples sets DOCS_SAMPLE_DOCUMENTS.
+ALTER TABLE runs ADD COLUMN profile TEXT NOT NULL DEFAULT 'outside' CHECK (profile IN ('outside', 'own'));
+ALTER TABLE runs ADD COLUMN samples INTEGER NOT NULL DEFAULT 0 CHECK (samples IN (0, 1));
diff --git a/provision/profile_test.go b/provision/profile_test.go
new file mode 100644
index 0000000..844cc59
--- /dev/null
+++ b/provision/profile_test.go
@@ -0,0 +1,601 @@
+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", "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 Apps {
+ 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 Apps {
+ 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)
+ }
+ }
+ }
+ if len(OperatorKeys(app, ProfileOutside)) != 0 {
+ t.Fatal("an outside team admits Memoria AI")
+ }
+ got := OperatorKeys(app, ProfileOwn)
+ 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 Apps {
+ if a.Slug != "memoria" && len(OperatorKeys(a, ProfileOwn)) != 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)
+ }
+}
diff --git a/provision/review_test.go b/provision/review_test.go
index c2db4de..6d4728e 100644
--- a/provision/review_test.go
+++ b/provision/review_test.go
@@ -170,7 +170,7 @@ func TestUnansweredRequestAfterTheWindowParks(t *testing.T) {
if r.State != "parked" || st.Code != "window-expired" {
t.Fatalf("run %s %s, register %s %s", r.State, r.Code, st.State, st.Code)
}
- next, err := e.AddApps(h.ctx(), "lagged", []string{"sheets"})
+ next, err := e.AddApps(h.ctx(), "lagged", []string{"sheets"}, RunOptions{})
if err != nil {
t.Fatal(err)
}
@@ -326,7 +326,7 @@ func TestTornSeedStillForgetsTheAddress(t *testing.T) {
// The crashed holder's lock goes stale, and the create-team window
// closes: the rest runs under a new add-apps plan.
h.tick(homeop.WindowLifetime * time.Second)
- next, err := h.engine(nil).AddApps(h.ctx(), "lagged", allApps)
+ next, err := h.engine(nil).AddApps(h.ctx(), "lagged", allApps, RunOptions{})
if err != nil {
t.Fatal(err)
}
diff --git a/provision/steps.go b/provision/steps.go
index 1a5d9cb..9a0eec5 100644
--- a/provision/steps.go
+++ b/provision/steps.go
@@ -393,7 +393,7 @@ func (e *Engine) stepRegister(ctx context.Context, p *pass, app App) error {
// ---- step 7: environment ----
func (e *Engine) inputs(ctx context.Context, p *pass, app App) (Inputs, error) {
- in := Inputs{Label: p.run.Label, TeamSQID: p.team.TeamSQID, Home: e.cfg.HomeCfg, CallsZone: e.cfg.CallsZone}
+ in := Inputs{Label: p.run.Label, TeamSQID: p.team.TeamSQID, Home: e.cfg.HomeCfg, CallsZone: e.cfg.CallsZone, RunOptions: p.run.Options}
if owner, ok, err := e.cfg.Store.Owner(ctx, p.run.Label); err != nil {
return in, err
} else if ok {
@@ -424,6 +424,21 @@ func (e *Engine) stepEnv(ctx context.Context, p *pass, app App) error {
set := map[string]console.SetVar{}
var unset []string
recipe := map[string]bool{}
+ // Paul's own post-run keys (an own team's Memoria AI), once he has
+ // set the whole group: Alta neither writes nor removes them. Part of
+ // one (a fork's blanked MEMORIA_AI) is any other key.
+ operator := OperatorKeys(app, in.Profile)
+ switch operatorState(operator, lookup(present)) {
+ case OperatorWhole:
+ for _, k := range operator {
+ recipe[k.Name] = true
+ }
+ case OperatorInvalid:
+ // The whole pair, but not as memoria reads it: Paul's to fix,
+ // here rather than at the audit.
+ return fail("operator-keys-invalid")
+ }
+ ownWrites := profileWrites(app, in.Label)
running := false // a write landed on an instance already running
for _, k := range keys {
recipe[k.Name] = true
@@ -445,7 +460,11 @@ func (e *Engine) stepEnv(ctx context.Context, p *pass, app App) error {
if recipe[name] || console.PlatformManaged(name) {
continue
}
- if !p.team.Forked {
+ if v, ok := ownWrites[name]; !p.team.Forked && !(ok && present[name].Kind == "env" && present[name].Value == v) {
+ // A key exactly as Alta writes it under another run's profile
+ // or samples choice (OFICINA_DASHBOARD_TEAM=<label>,
+ // DOCS_SAMPLE_DOCUMENTS=1, written before that run parked) is
+ // Alta's own to take back out; anything else refuses.
return fail("extra-key")
}
// A forked environment carries Track 1's own keys: anything the
@@ -534,7 +553,8 @@ func (e *Engine) stepEnv(ctx context.Context, p *pass, app App) error {
if len(ps.Missing) > 0 {
return park("awaiting-platform-keys")
}
- return e.record(ctx, p, app.Slug, StepEnv, map[string]any{"platform": ps.Keys, "binding": EnvironmentBinding(env, keys, ps.Keys)})
+ return e.record(ctx, p, app.Slug, StepEnv, map[string]any{"platform": ps.Keys, "binding": EnvironmentBinding(env, keys, ps.Keys),
+ "profile": string(in.Profile), "samples": in.Samples})
}
// ---- step 8: instance ----
@@ -817,7 +837,11 @@ func (e *Engine) AuditEnvironment(ctx context.Context, label string, app App) er
if err != nil {
return err
}
- p := &pass{run: Run{Label: label}, team: t}
+ opt, err := e.writtenOptions(ctx, label, app)
+ if err != nil {
+ return err
+ }
+ p := &pass{run: Run{Label: label, Options: opt}, team: t}
in, err := e.inputs(ctx, p, app)
if err != nil {
return err
@@ -846,8 +870,22 @@ func (e *Engine) AuditEnvironment(ctx context.Context, label string, app App) er
for _, k := range ps.Keys {
want[k] = Key{Name: k, Class: Platform}
}
+ // Paul's post-run group (an own team's Memoria AI) is admitted
+ // whole or not at all, never one key of it.
+ operator := OperatorKeys(app, in.Profile)
+ admitted := map[string]bool{}
+ switch operatorState(operator, lookup(present)) {
+ case OperatorPartial:
+ return fail("audit-operator-partial")
+ case OperatorInvalid:
+ return fail("operator-keys-invalid")
+ case OperatorWhole:
+ for _, k := range operator {
+ admitted[k.Name] = true
+ }
+ }
for name := range present {
- if _, ok := want[name]; !ok {
+ if _, ok := want[name]; !ok && !admitted[name] {
return fail("audit-extra-key")
}
}
@@ -885,6 +923,27 @@ func (e *Engine) AuditEnvironment(ctx context.Context, label string, app App) er
return nil
}
+// lookup reads a console config's keys for operatorState.
+func lookup(present map[string]console.Var) func(string) (string, string, bool) {
+ return func(name string) (string, string, bool) {
+ v, ok := present[name]
+ return v.Kind, v.Value, ok
+ }
+}
+
+// writtenOptions is the run options app's environment was written with
+// (Store.WrittenOptions); an environment not yet written has the default.
+func (e *Engine) writtenOptions(ctx context.Context, label string, app App) (RunOptions, error) {
+ opt, ok, err := e.cfg.Store.WrittenOptions(ctx, label, app.Slug)
+ if err != nil {
+ return RunOptions{}, err
+ }
+ if !ok {
+ return RunOptions{Profile: ProfileOutside}, nil
+ }
+ return opt, nil
+}
+
func (e *Engine) stepAudit(ctx context.Context, p *pass, app App) error {
if err := e.AuditEnvironment(ctx, p.run.Label, app); err != nil {
return err
diff --git a/provision/store.go b/provision/store.go
index 684567c..cd096b0 100644
--- a/provision/store.go
+++ b/provision/store.go
@@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "slices"
"strings"
"time"
@@ -319,11 +320,18 @@ type Run struct {
PlanExpires int64
State, Code string
Created, Upd time.Time
+ // Options is the profile and samples choice the run writes recipes
+ // with (create-team and add-apps; the others record outside).
+ Options RunOptions
}
// NewRun starts a run. Any unfinished run for the same label is
// superseded: one live plan per team.
-func (s *Store) NewRun(ctx context.Context, kind, label string, apps []string) (int64, error) {
+func (s *Store) NewRun(ctx context.Context, kind, label string, apps []string, opt RunOptions) (int64, error) {
+ opt, ok := opt.Normal()
+ if !ok {
+ return 0, errors.New("provision: unknown profile")
+ }
now := s.now().Unix()
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -338,7 +346,7 @@ func (s *Store) NewRun(ctx context.Context, kind, label string, apps []string) (
return 0, err
}
}
- res, err := tx.ExecContext(ctx, "INSERT INTO runs(label,kind,apps,state,created_at,updated_at) VALUES(?,?,?,'planned',?,?)", label, kind, strings.Join(apps, ","), now, now)
+ res, err := tx.ExecContext(ctx, "INSERT INTO runs(label,kind,apps,state,created_at,updated_at,profile,samples) VALUES(?,?,?,'planned',?,?,?,?)", label, kind, strings.Join(apps, ","), now, now, string(opt.Profile), opt.Samples)
if err != nil {
return 0, err
}
@@ -355,9 +363,11 @@ func scanRun(sc interface{ Scan(...any) error }) (Run, error) {
var plan sql.NullString
var exp sql.NullInt64
var c, u int64
- if err := sc.Scan(&r.ID, &r.Label, &r.Kind, &apps, &plan, &exp, &r.State, &r.Code, &c, &u); err != nil {
+ var profile string
+ if err := sc.Scan(&r.ID, &r.Label, &r.Kind, &apps, &plan, &exp, &r.State, &r.Code, &c, &u, &profile, &r.Options.Samples); err != nil {
return Run{}, err
}
+ r.Options.Profile = Profile(profile)
if apps != "" {
r.Apps = strings.Split(apps, ",")
}
@@ -365,7 +375,7 @@ func scanRun(sc interface{ Scan(...any) error }) (Run, error) {
return r, nil
}
-const runCols = "id,label,kind,apps,plan_id,plan_expires_at,state,code,created_at,updated_at"
+const runCols = "id,label,kind,apps,plan_id,plan_expires_at,state,code,created_at,updated_at,profile,samples"
func (s *Store) Run(ctx context.Context, id int64) (Run, error) {
return scanRun(s.db.QueryRowContext(ctx, "SELECT "+runCols+" FROM runs WHERE id=?", id))
@@ -389,6 +399,66 @@ func (s *Store) Runs(ctx context.Context, label string) ([]Run, error) {
return out, rows.Err()
}
+// LastOptions is the options of label's newest create-team or add-apps
+// run: what a run continued without a fresh choice writes with. A label
+// with none has the default (outside, no samples).
+func (s *Store) LastOptions(ctx context.Context, label string) (RunOptions, error) {
+ r, err := scanRun(s.db.QueryRowContext(ctx, "SELECT "+runCols+" FROM runs WHERE label=? AND kind IN ('create-team','add-apps') ORDER BY id DESC LIMIT 1", label))
+ if errors.Is(err, sql.ErrNoRows) {
+ return RunOptions{Profile: ProfileOutside}, nil
+ }
+ if err != nil {
+ return RunOptions{}, err
+ }
+ return r.Options, nil
+}
+
+// WrittenOptions is the run options app's environment was written with,
+// as step 7 recorded them when it finished. ok is false while step 7 is
+// not done. A step recorded before options existed reads as outside.
+func (s *Store) WrittenOptions(ctx context.Context, label, app string) (RunOptions, bool, error) {
+ d, ok, err := s.Done(ctx, label, app, StepEnv)
+ if err != nil || !ok {
+ return RunOptions{}, false, err
+ }
+ opt := RunOptions{Profile: ProfileOutside}
+ if p, _ := d["profile"].(string); p != "" {
+ opt.Profile = Profile(p)
+ }
+ opt.Samples, _ = d["samples"].(bool)
+ if opt, ok = opt.Normal(); !ok {
+ return RunOptions{}, false, errors.New("provision: unknown profile recorded")
+ }
+ return opt, true, nil
+}
+
+// AppOptions is the choice app runs under when Paul makes none: the one
+// its environment was written with (step 7 done), else that of the newest
+// create-team or add-apps run naming it, else the default.
+func (s *Store) AppOptions(ctx context.Context, label, app string) (RunOptions, error) {
+ if opt, ok, err := s.WrittenOptions(ctx, label, app); err != nil || ok {
+ return opt, err
+ }
+ rows, err := s.db.QueryContext(ctx, "SELECT "+runCols+" FROM runs WHERE label=? AND kind IN ('create-team','add-apps') ORDER BY id DESC", label)
+ if err != nil {
+ return RunOptions{}, err
+ }
+ defer rows.Close()
+ for rows.Next() {
+ r, err := scanRun(rows)
+ if err != nil {
+ return RunOptions{}, err
+ }
+ if slices.Contains(r.Apps, app) {
+ return r.Options, nil
+ }
+ }
+ if err := rows.Err(); err != nil {
+ return RunOptions{}, err
+ }
+ return RunOptions{Profile: ProfileOutside}, nil
+}
+
// LiveRuns lists every run not finished.
func (s *Store) LiveRuns(ctx context.Context) ([]Run, error) {
rows, err := s.db.QueryContext(ctx, "SELECT "+runCols+" FROM runs WHERE state IN ('planned','running','parked') ORDER BY id")