GET /api/team: the seeded readiness probe Alta reads before activating a team Base
Base has no Home roster mode; its owner is seeded from BASE_OWNER. The probe names the configured Home consumer and whether an owner exists (oficina/alta design/team-bundle spec §1.2). No address, name or count; no session; 404 without Oficina ID.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+89
−0
internal/web/app.go+1 −0internal/web/team_probe.go+38 −0internal/webtest/team_probe_test.go+50 −0
CI failed — run details
CI log
=== build === CGO_ENABLED=0 go build ./... === vet === go vet ./... === fmt-check === === staticcheck === go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 ./... === govulncheck === go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 ./... No vulnerabilities found. === gitleaks === [90m12:27PM[0m [32mINF[0m [1mUnknown SCM platform. Use --platform to include links in findings.[0m [36mhost=[0mamadan.net [90m12:27PM[0m [32mINF[0m [1m1 commits scanned.[0m [90m12:27PM[0m [32mINF[0m [1mscanned ~2938348 bytes (2.94 MB) in 1.08s[0m [90m12:27PM[0m [32mINF[0m [1mno leaks found[0m === budget === go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget size internal/webtest: 8543 test lines, over the 8500 its exemption (line 2) allows rastrillo: budget size: 1 problem(s) exit status 1 make: *** [Makefile:44: budget] Error 1 amadan: step budget failed: exit status 2 amadan: job failed at step budget — its output is above, not at the tail of this log
diff --git a/internal/web/app.go b/internal/web/app.go| index 6f429c9..00a455c 100644 |
| --- a/internal/web/app.go |
| +++ b/internal/web/app.go |
| @@ -162,6 +162,7 @@ func App(d *db.DB, cfg config.Config, mailer mail.Sender, inst Installer, logger |
| } |
| r.Get("/static/fonts/*", look.FontHandler().ServeHTTP) |
| r.Get("/static/*", look.Assets.Handler().ServeHTTP) |
| + r.Get("/api/team", a.teamProbe) |
| if o := a.oficina; o != nil { |
| r.Get("/signin", a.oficinaSignin) |
| r.Get("/signin/local", a.signin) |
diff --git a/internal/web/team_probe.go b/internal/web/team_probe.go| new file mode 100644 |
| index 0000000..fe426a3 |
| --- /dev/null |
| +++ b/internal/web/team_probe.go |
| @@ -0,0 +1,38 @@ |
| +package web |
| + |
| +import ( |
| + "encoding/json" |
| + "net/http" |
| +) |
| + |
| +// teamProbe answers GET /api/team, the readiness probe Alta reads before |
| +// it activates a team Base in Home's directory (oficina/alta |
| +// design/team-bundle, spec §1.2). Base has no Home roster mode: its owner |
| +// is seeded from BASE_OWNER, so it answers in the seeded mode. It names |
| +// the Home consumer it was configured as, and whether an owner exists yet. |
| +// It carries no address, name or count, and needs no session. |
| +// |
| +// A Base without Oficina ID has no consumer and is never ready: 404. |
| +func (a *app) teamProbe(w http.ResponseWriter, r *http.Request) { |
| + if a.cfg.Home == nil || a.cfg.Home.ConsumerID == "" { |
| + http.NotFound(w, r) |
| + return |
| + } |
| + var owners int |
| + if err := a.db.QueryRowContext(r.Context(), `SELECT count(*) FROM members WHERE role = 'owner'`).Scan(&owners); err != nil { |
| + http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable) |
| + return |
| + } |
| + roster := "owner-pending" |
| + if owners > 0 { |
| + roster = "ok" |
| + } |
| + w.Header().Set("Content-Type", "application/json") |
| + w.Header().Set("Cache-Control", "no-store") |
| + _ = json.NewEncoder(w).Encode(struct { |
| + TeamMode bool `json:"team_mode"` |
| + Seeded bool `json:"seeded"` |
| + Consumer string `json:"consumer"` |
| + Roster string `json:"roster"` |
| + }{false, true, a.cfg.Home.ConsumerID, roster}) |
| +} |
diff --git a/internal/webtest/team_probe_test.go b/internal/webtest/team_probe_test.go| new file mode 100644 |
| index 0000000..dff939e |
| --- /dev/null |
| +++ b/internal/webtest/team_probe_test.go |
| @@ -0,0 +1,50 @@ |
| +package webtest |
| + |
| +import ( |
| + "encoding/json" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// GET /api/team is Alta's readiness probe for a team Base (seeded mode). |
| +func TestTeamProbeSeeded(t *testing.T) { |
| + a := newHomeApp(t) |
| + r := a.get("/api/team") |
| + if r.Code != 200 || r.Header.Get("Content-Type") != "application/json" || r.Header.Get("Cache-Control") != "no-store" { |
| + t.Fatalf("%d %v %s", r.Code, r.Header, r.Body) |
| + } |
| + if strings.Contains(r.Body, "@") { |
| + t.Fatalf("probe carries an address: %s", r.Body) |
| + } |
| + var got map[string]any |
| + if err := json.Unmarshal([]byte(r.Body), &got); err != nil { |
| + t.Fatal(err) |
| + } |
| + want := map[string]any{"team_mode": false, "seeded": true, "consumer": homeConsumer, "roster": "ok"} |
| + if len(got) != len(want) { |
| + t.Fatalf("fields %v", got) |
| + } |
| + for k, v := range want { |
| + if got[k] != v { |
| + t.Fatalf("%s = %v, want %v (%s)", k, got[k], v, r.Body) |
| + } |
| + } |
| +} |
| + |
| +func TestTeamProbeOwnerPending(t *testing.T) { |
| + a := newHomeApp(t) |
| + if _, err := a.DB.Exec(`UPDATE members SET role = 'member' WHERE role = 'owner'`); err != nil { |
| + t.Fatal(err) |
| + } |
| + r := a.get("/api/team") |
| + if r.Code != 200 || !strings.Contains(r.Body, `"roster":"owner-pending"`) { |
| + t.Fatalf("%d %s", r.Code, r.Body) |
| + } |
| +} |
| + |
| +func TestTeamProbeWithoutOficinaID(t *testing.T) { |
| + a := newApp(t) |
| + if r := a.get("/api/team"); r.Code != 404 { |
| + t.Fatalf("%d %s", r.Code, r.Body) |
| + } |
| +} |