feat: add the rail and grouped projects overview
31 files changed,
+1,315
−42
.amadan/ci.d/50-perf+2 −0.rastrillo/budgets.txt+1 −0Makefile+1 −2docs/mockups/README.md+3 −0docs/mockups/conversation.html+1 −1internal/equipo/app.go+16 −2internal/equipo/auth.go+1 −1internal/equipo/budgets.go+8 −0internal/equipo/copy.go+92 −2internal/equipo/copy_test.go+37 −0internal/equipo/handlers.go+534 −0internal/equipo/icons/icons.go+11 −0internal/equipo/navigation.go+20 −0internal/equipo/render.go+15 −6internal/equipo/static/equipo.css+15 −0internal/equipo/templates/chrome.html+13 −0internal/equipo/templates/empty.html+1 −0internal/equipo/templates/form_error.html+1 −0internal/equipo/templates/forms.html+34 −0internal/equipo/templates/index.html+1 −11internal/equipo/templates/layout.html+1 −1internal/equipo/templates/overview.html+0 −9internal/equipo/templates/people.html+16 −0internal/equipo/templates/project.html+6 −0internal/equipo/templates/project_form.html+1 −0internal/equipo/templates/projects.html+17 −0internal/equipo/templates/settings.html+16 −0internal/equipo/templates/specialist.html+18 −0internal/equipotest/foundation_test.go+1 −1internal/equipotest/pages_test.go+393 −0internal/equipotest/perf_test.go+39 −6
diff --git a/.amadan/ci.d/50-perf b/.amadan/ci.d/50-perf| new file mode 100755 |
| index 00000000..0c6a01a7 |
| --- /dev/null |
| +++ b/.amadan/ci.d/50-perf |
| @@ -0,0 +1,2 @@ |
| +#!/bin/sh |
| +exec make perf |
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 3775c4c6..6f58fc5d 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -10,3 +10,4 @@ |
| # perf <METHOD> <path> <duration>|skip <reason> |
| # boot <duration> <reason> |
| size internal/equipo/team 6500 - Preserve the copied transactional core; this budget extension covers its existing 5,243 source lines without splitting the store. |
| +perf GET /* skip Unknown private paths render 404; this fallback contains no screens. |
diff --git a/Makefile b/Makefile| index e7021866..bfa616b2 100644 |
| --- a/Makefile |
| +++ b/Makefile |
| @@ -188,7 +188,6 @@ gitleaks: |
| migration-check: |
| go run amadan.net/rastrillo/rastrillo/cmd/rastrillo migration check |
| -# Performance joins CI in Task 8, after authenticated screens exist. |
| # ci is the one gate: what a runner executes and what you run before |
| # pushing are the same definition. amadan's runner falls back to this |
| # target when .amadan/ci is absent; ci.d/ carries the same targets, |
| @@ -196,4 +195,4 @@ migration-check: |
| # fails the build the moment models.go and migrations/ disagree, |
| # instead of at boot on whatever machine notices next. If the app |
| # declares manifest resources, also add: rastrillo generate --check |
| -ci: build vet fmt-check staticcheck govulncheck gitleaks budget test migration-check |
| +ci: build vet fmt-check staticcheck govulncheck gitleaks budget test migration-check perf |
diff --git a/docs/mockups/README.md b/docs/mockups/README.md| index a59d9d5f..a4ca3805 100644 |
| --- a/docs/mockups/README.md |
| +++ b/docs/mockups/README.md |
| @@ -17,3 +17,6 @@ point; the copy is not approved and goes through copy review when built. |
| Letters in coloured squares anywhere except `nav.html` are placeholders. Paul |
| rejected initials: the real UI uses an icon plus the specialist's name. |
| + |
| +No coloured left-border accents on cards, notes or list items. Use a full |
| +hairline border and a background tint instead. Use only theme tokens in app CSS. |
diff --git a/docs/mockups/conversation.html b/docs/mockups/conversation.html| index 8b036fe1..f18e3743 100644 |
| --- a/docs/mockups/conversation.html |
| +++ b/docs/mockups/conversation.html |
| @@ -77,7 +77,7 @@ h1.t{font-size:1.25rem;margin:0 0 14px;font-weight:600} |
| .btns{display:flex;gap:6px;margin-top:10px;flex-wrap:wrap} |
| .b1{background:#2257df;color:#fff;border-radius:7px;padding:4px 12px;font-size:12.5px} |
| .b2{border:1px solid #cfd5df;border-radius:7px;padding:4px 12px;font-size:12.5px;background:#fff} |
| -.settle{align-self:stretch;border-left:3px solid #7a4cc2;background:#faf8fe;border-radius:6px;padding:8px 12px;font-size:13px} |
| +.settle{align-self:stretch;border:1px solid #e6e0f5;background:#faf8fe;border-radius:10px;padding:8px 12px;font-size:13px} |
| .settle small{color:#6b7280;display:block;margin-top:2px} |
| .rank{margin:6px 0 0;padding:0;list-style:none} |
| .rank li{display:flex;gap:10px;align-items:baseline;padding:6px 0;border-top:1px solid #f0f2f5} |
diff --git a/internal/equipo/app.go b/internal/equipo/app.go| index 06ee9f4d..1e22335f 100644 |
| --- a/internal/equipo/app.go |
| +++ b/internal/equipo/app.go |
| @@ -99,9 +99,23 @@ func Router(d *db.DB, cfg Config, mailer mail.Sender, logger *slog.Logger) (chi. |
| r.Get("/", func(w http.ResponseWriter, r *http.Request) { |
| http.Redirect(w, r, "/conversation", http.StatusSeeOther) |
| }) |
| - for _, path := range []string{"/conversation", "/work", "/projects", "/people", "/settings"} { |
| - r.Get(path, func(w http.ResponseWriter, r *http.Request) { render(w, http.StatusOK, "index", nil) }) |
| + r.Get("/work", a.index) |
| + for _, path := range []string{"/conversation", "/needs-you", "/journey", "/connections"} { |
| + r.Get(path, a.empty) |
| } |
| + r.Get("/projects", a.projects) |
| + r.Get("/projects/new", a.projectForm) |
| + r.Get("/projects/{id}", a.project) |
| + r.Get("/projects/{id}/edit", a.projectForm) |
| + r.Get("/people", a.people) |
| + r.Get("/settings", a.settings) |
| + r.Get("/specialists/{key}", a.specialist) |
| + r.Post("/accounts", a.saveAccount) |
| + r.Post("/projects", a.saveProject) |
| + r.Post("/projects/{id}", a.saveProject) |
| + r.Post("/team/members", a.saveMember) |
| + r.Post("/team/budgets", a.saveBudgets) |
| + r.Post("/specialists/{key}", a.saveSpecialist) |
| r.Handle("/*", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ErrorPage(w, r, http.StatusNotFound, "") })) |
| }) |
| return a, nil |
diff --git a/internal/equipo/auth.go b/internal/equipo/auth.go| index 6c1a9de4..a25c2b5f 100644 |
| --- a/internal/equipo/auth.go |
| +++ b/internal/equipo/auth.go |
| @@ -54,7 +54,7 @@ func renderSignin(a *auth.Auth, w http.ResponseWriter, r *http.Request) { |
| } |
| state := a.SigninState(r) |
| a.PrepareSigninResponse(w, state) |
| - render(w, http.StatusOK, "signin_page", map[string]any{"State": state, "Brand": map[string]string{"Name": copyBrand}}) |
| + render(w, "signin_page", map[string]any{"State": state, "Brand": map[string]string{"Name": copyBrand}}) |
| } |
| // RequireMember lets composed routes use the same admission as the app. |
diff --git a/internal/equipo/budgets.go b/internal/equipo/budgets.go| index c70643aa..fae57617 100644 |
| --- a/internal/equipo/budgets.go |
| +++ b/internal/equipo/budgets.go |
| @@ -76,6 +76,11 @@ func (s *Store) SaveBudgets(ctx context.Context, actor Actor, config BudgetConfi |
| }) |
| } |
| func (s *Store) Budgets(ctx context.Context) (BudgetConfig, error) { |
| + return s.readBudgets(ctx, false) |
| +} |
| + |
| +// allowUnset is only for metadata forms. Execution still requires saved limits. |
| +func (s *Store) readBudgets(ctx context.Context, allowUnset bool) (BudgetConfig, error) { |
| var config BudgetConfig |
| if s == nil || s.db == nil { |
| return config, ErrUnavailable |
| @@ -88,6 +93,9 @@ func (s *Store) Budgets(ctx context.Context) (BudgetConfig, error) { |
| var row budgetRecord |
| if err := tx.Where("team_id = ?", instance.ID).First(&row).Error; err != nil { |
| if errors.Is(err, gorm.ErrRecordNotFound) { |
| + if allowUnset { |
| + return nil |
| + } |
| return ErrUnavailable |
| } |
| return storeError(err) |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index 2731f374..ecdb76e9 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -4,8 +4,6 @@ package equipo |
| // App-owned runtime strings belong here, including boot diagnostics. |
| const ( |
| copyBrand = "Equipo" |
| - copyOverview = "Overview" |
| - copyPlaceholder = "Not available yet." |
| copyRenderFailure = "Something went wrong." |
| copyMissingKey = "EQUIPO_INSTANCE_KEY is required." |
| copyInvalidOrigin = "EQUIPO_ORIGIN must be an HTTPS origin, or HTTP on loopback." |
| @@ -25,3 +23,95 @@ const ( |
| // BootLog is the shared diagnostic used by the command entry point. |
| const BootLog = "Equipo could not start." |
| + |
| +// COPY REVIEW REQUIRED. Keys identify the screen and control for the copy pass. |
| +var pageCopy = map[string]string{ |
| + "nav.account": "Account", |
| + "brand": copyBrand, |
| + "nav.conversation": "Conversation", |
| + "nav.needs-you": "Needs you", |
| + "nav.journey": "Journey", |
| + "nav.projects": "Projects", |
| + "nav.product": "Product", |
| + "nav.design": "Design", |
| + "nav.copy": "Copy", |
| + "nav.engineering": "Engineering", |
| + "nav.review": "Review", |
| + "nav.connections": "Connections", |
| + "nav.people": "People", |
| + "nav.settings": "Settings", |
| + "nav.specialists": "Specialists", |
| + "nav.team": "Team", |
| + "nav.work": "Work", |
| + "nav.back": "Back to Work", |
| + "nav.signout": "Sign out", |
| + "conversation.empty": "Your conversation will be here. Work is not enabled yet.", |
| + "needs-you.empty": "Nothing needs your decision yet.", |
| + "journey.empty": "No work has started.", |
| + "connections.empty": "Connections are not available yet.", |
| + "projects.empty": "No projects yet.", |
| + "projects.add": "Add a project", |
| + "projects.edit": "Edit project", |
| + "projects.count": "Projects", |
| + "projects.metadata": "Project settings", |
| + "signals.unconnected": "CARLOS signals are unavailable.", |
| + "activity.empty": "No work has started.", |
| + "activity.working": "Working now", |
| + "activity.queued": "Queued", |
| + "activity.finished": "Finished", |
| + "specialist.empty": "Specialist settings are saved here. Work is not enabled yet.", |
| + "form.save": "Save", |
| + "form.invalid": copyInvalid, |
| + "form.conflict": copyConflict, |
| + "service.unavailable": copyUnavailable, |
| + "form.forbidden": copyForbidden, |
| + "form.not-found": copyNotFound, |
| + "form.back": "Back to the form", |
| + "project.name": "Name", |
| + "project.account": "Account label", |
| + "project.kind": "Kind", |
| + "project.repository": "Repository", |
| + "project.app": "App name", |
| + "project.branch": "Default branch", |
| + "kind.app": "App", |
| + "kind.website": "Website", |
| + "kind.repository": "Repository", |
| + "owner.work": "Work decisions", |
| + "owner.merge": "Merge decisions", |
| + "owner.copy": "Copy decisions", |
| + "owner.design": "Design decisions", |
| + "owner.product": "Product decisions", |
| + "owners.title": "Decision owners", |
| + "value.none": "None", |
| + "value.unset": "Unset", |
| + "account.add": "Add an account label", |
| + "account.label": "Account label", |
| + "account.note": "Account labels grant no access to CARLOS.", |
| + "people.add": "Add a person", |
| + "people.address": "Email address", |
| + "people.role": "Role", |
| + "people.active": "Active", |
| + "people.inactive": "Removed", |
| + "role.owner": "Owner", |
| + "role.member": "Member", |
| + "budget.title": "Monthly limits", |
| + "budget.team": "Team limits", |
| + "budget.project": "Project limits", |
| + "budget.calls": "Calls", |
| + "budget.input": "Input tokens", |
| + "budget.output": "Output tokens", |
| + "budget.seconds": "Seconds", |
| + "budget.note": "Leave every project limit blank to keep it unset. Set all four limits together.", |
| + "budget.usage": "Usage", |
| + "budget.zero": "0 calls, 0 input tokens, 0 output tokens, 0 seconds. Work is not enabled.", |
| + "specialist.mode": "Model selection", |
| + "mode.best_fit": "Best fit", |
| + "mode.fixed": "Fixed model", |
| + "specialist.provider": "Provider label", |
| + "specialist.family": "Model family", |
| + "specialist.model": "Model", |
| + "specialist.concurrent": "Runs at once", |
| + "specialist.instructions": "Standing instructions", |
| +} |
| + |
| +func copyText(key string) string { return pageCopy[key] } |
diff --git a/internal/equipo/copy_test.go b/internal/equipo/copy_test.go| new file mode 100644 |
| index 00000000..2c92695e |
| --- /dev/null |
| +++ b/internal/equipo/copy_test.go |
| @@ -0,0 +1,37 @@ |
| +package equipo |
| + |
| +import ( |
| + "io/fs" |
| + "regexp" |
| + "testing" |
| +) |
| + |
| +func TestTemplateCopyKeys(t *testing.T) { |
| + keys := regexp.MustCompile(`\bcopy "([^"]+)"`) |
| + err := fs.WalkDir(appFS, "templates", func(path string, entry fs.DirEntry, err error) error { |
| + if err != nil { |
| + return err |
| + } |
| + if entry.IsDir() { |
| + return nil |
| + } |
| + raw, err := appFS.ReadFile(path) |
| + if err != nil { |
| + return err |
| + } |
| + for _, match := range keys.FindAllStringSubmatch(string(raw), -1) { |
| + if copyText(match[1]) == "" { |
| + t.Errorf("%s: missing copy key %s", path, match[1]) |
| + } |
| + } |
| + return nil |
| + }) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, item := range Navigation() { |
| + if copyText(item.CopyKey) == "" { |
| + t.Errorf("missing navigation copy %s", item.CopyKey) |
| + } |
| + } |
| +} |
diff --git a/internal/equipo/handlers.go b/internal/equipo/handlers.go| new file mode 100644 |
| index 00000000..edf7eb8d |
| --- /dev/null |
| +++ b/internal/equipo/handlers.go |
| @@ -0,0 +1,534 @@ |
| +package equipo |
| + |
| +import ( |
| + "crypto/rand" |
| + "errors" |
| + "net/http" |
| + "strconv" |
| + "strings" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/team" |
| + "amadan.net/rastrillo/rastrillo/auth" |
| + "github.com/go-chi/chi/v5" |
| +) |
| + |
| +type ownerField struct { |
| + Key, Address string |
| + Required bool |
| +} |
| +type budgetField struct{ Name, CopyKey, Value string } |
| +type budgetForm struct { |
| + Name string |
| + Fields []budgetField |
| +} |
| +type pageData struct { |
| + Nav []NavItem |
| + Key, Title, EmptyKey, Address, TeamName string |
| + Owner bool |
| + Groups []ProjectGroup |
| + Count int |
| + Detail ProjectDetail |
| + Members []Member |
| + Owners []ownerField |
| + RequestID, Action string |
| + Budget BudgetConfig |
| + BudgetForms []budgetForm |
| + Specialist Specialist |
| + ErrorKey, Back string |
| +} |
| + |
| +func (a *application) page(r *http.Request, key string) (pageData, error) { |
| + id, ok := auth.From(r) |
| + if !ok { |
| + return pageData{}, ErrForbidden |
| + } |
| + member, err := a.store.Member(r.Context(), id.Address) |
| + if err != nil { |
| + return pageData{}, err |
| + } |
| + var instance Team |
| + if err := a.store.db.G.WithContext(r.Context()).First(&instance).Error; err != nil { |
| + return pageData{}, storeError(err) |
| + } |
| + return pageData{Nav: Navigation(), Key: key, Title: "nav." + key, Address: id.Address, TeamName: instance.Name, Owner: member.Active && member.Role == RoleOwner}, nil |
| +} |
| +func (a *application) failure(w http.ResponseWriter, r *http.Request, err error) { |
| + status, key := http.StatusServiceUnavailable, "service.unavailable" |
| + switch { |
| + case errors.Is(err, ErrInvalid): |
| + status, key = 422, "form.invalid" |
| + case errors.Is(err, ErrConflict): |
| + status, key = 409, "form.conflict" |
| + case errors.Is(err, ErrForbidden): |
| + status, key = 403, "form.forbidden" |
| + case errors.Is(err, ErrNotFound): |
| + status, key = 404, "form.not-found" |
| + } |
| + // Error pages do not repeat database reads that may have just failed. |
| + back := "/work" |
| + switch { |
| + case r.URL.Path == "/projects": |
| + back = "/projects/new" |
| + case strings.HasPrefix(r.URL.Path, "/projects/"): |
| + back = r.URL.Path + "/edit" |
| + case r.URL.Path == "/accounts" || r.URL.Path == "/team/budgets": |
| + back = "/settings" |
| + case r.URL.Path == "/team/members": |
| + back = "/people" |
| + case strings.HasPrefix(r.URL.Path, "/specialists/"): |
| + back = r.URL.Path |
| + } |
| + navKey := "" |
| + for _, item := range Navigation() { |
| + if r.URL.Path == item.Href || strings.HasPrefix(r.URL.Path, item.Href+"/") { |
| + navKey = item.Key |
| + break |
| + } |
| + } |
| + if r.URL.Path == "/accounts" || r.URL.Path == "/team/budgets" { |
| + navKey = "settings" |
| + } |
| + if r.URL.Path == "/team/members" { |
| + navKey = "people" |
| + } |
| + if status == 404 { |
| + back = "/work" |
| + if navKey == "projects" { |
| + back = "/projects" |
| + } |
| + } |
| + if r.Method == http.MethodGet && status != 404 { |
| + back = r.URL.Path |
| + } |
| + id, _ := auth.From(r) |
| + renderStatus(w, status, "form_error", pageData{Nav: Navigation(), Key: navKey, Address: id.Address, Title: key, ErrorKey: key, Back: back, TeamName: copyBrand}) |
| +} |
| +func (a *application) index(w http.ResponseWriter, r *http.Request) { |
| + data, err := a.page(r, "work") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + render(w, "index", data) |
| +} |
| +func (a *application) empty(w http.ResponseWriter, r *http.Request) { |
| + key := strings.TrimPrefix(r.URL.Path, "/") |
| + data, err := a.page(r, key) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + data.EmptyKey = key + ".empty" |
| + render(w, "empty", data) |
| +} |
| +func (a *application) projectData(r *http.Request) (pageData, error) { |
| + data, err := a.page(r, "projects") |
| + if err != nil { |
| + return data, err |
| + } |
| + data.Groups, err = a.store.Projects(r.Context()) |
| + if err != nil { |
| + return data, err |
| + } |
| + for _, g := range data.Groups { |
| + data.Count += len(g.Projects) |
| + } |
| + data.Budget, err = a.store.readBudgets(r.Context(), true) |
| + if err != nil { |
| + return data, err |
| + } |
| + err = a.store.db.G.WithContext(r.Context()).Where("active = ?", true).Order("address").Find(&data.Members).Error |
| + if err != nil { |
| + return data, storeError(err) |
| + } |
| + data.RequestID = rand.Text() |
| + data.Action = "/projects" |
| + data.Detail.Project = Project{Kind: ProjectApp, DefaultBranch: "main"} |
| + data.Owners = decisionFields(nil) |
| + return data, nil |
| +} |
| +func decisionFields(owners []DecisionOwner) []ownerField { |
| + out := []ownerField{} |
| + for _, key := range []string{"work", "merge", "copy", "design", "product"} { |
| + field := ownerField{Key: key, Required: key == "work" || key == "merge"} |
| + for _, o := range owners { |
| + if o.Decision == key { |
| + field.Address = o.Address |
| + } |
| + } |
| + out = append(out, field) |
| + } |
| + return out |
| +} |
| +func (a *application) projects(w http.ResponseWriter, r *http.Request) { |
| + data, err := a.projectData(r) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + data.BudgetForms = budgetForms(data.Budget, data.Groups) |
| + render(w, "projects", data) |
| +} |
| +func projectID(r *http.Request) (int64, error) { |
| + id, err := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64) |
| + if err != nil || id <= 0 { |
| + return 0, ErrNotFound |
| + } |
| + return id, nil |
| +} |
| +func (a *application) project(w http.ResponseWriter, r *http.Request) { |
| + data, err := a.page(r, "projects") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + id, err := projectID(r) |
| + if err == nil { |
| + data.Detail, err = a.store.Project(r.Context(), id) |
| + } |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + data.Title = "projects.metadata" |
| + render(w, "project", data) |
| +} |
| +func (a *application) projectForm(w http.ResponseWriter, r *http.Request) { |
| + data, err := a.projectData(r) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + if !data.Owner { |
| + a.failure(w, r, ErrForbidden) |
| + return |
| + } |
| + data.Title = "projects.add" |
| + if chi.URLParam(r, "id") != "" { |
| + id, e := projectID(r) |
| + err = e |
| + if err == nil { |
| + data.Detail, err = a.store.Project(r.Context(), id) |
| + } |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + data.Title = "projects.edit" |
| + data.Action = "/projects/" + strconv.FormatInt(id, 10) |
| + data.Owners = decisionFields(data.Detail.Owners) |
| + } |
| + render(w, "project_form", data) |
| +} |
| +func (a *application) people(w http.ResponseWriter, r *http.Request) { |
| + data, err := a.page(r, "people") |
| + if err == nil { |
| + err = storeError(a.store.db.G.WithContext(r.Context()).Order("address").Find(&data.Members).Error) |
| + } |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + render(w, "people", data) |
| +} |
| +func (a *application) settings(w http.ResponseWriter, r *http.Request) { |
| + data, err := a.projectData(r) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + data.Key = "settings" |
| + data.Title = "nav.settings" |
| + data.BudgetForms = budgetForms(data.Budget, data.Groups) |
| + render(w, "settings", data) |
| +} |
| +func (a *application) specialist(w http.ResponseWriter, r *http.Request) { |
| + key := chi.URLParam(r, "key") |
| + if !validSpecialistKey(key) { |
| + a.failure(w, r, ErrNotFound) |
| + return |
| + } |
| + data, err := a.page(r, key) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + specialists, err := a.store.Specialists(r.Context()) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + for _, s := range specialists { |
| + if s.Key == key { |
| + data.Specialist = s |
| + render(w, "specialist", data) |
| + return |
| + } |
| + } |
| + a.failure(w, r, ErrNotFound) |
| +} |
| +func validSpecialistKey(key string) bool { |
| + for _, k := range []string{"product", "design", "copy", "engineering", "review"} { |
| + if key == k { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// Reject unknown and duplicate fields, including submitted identity. Role on the |
| +// roster form describes the target member; the actor always comes from auth.From. |
| +func (a *application) writeForm(w http.ResponseWriter, r *http.Request, allowed ...string) (Actor, error) { |
| + id, ok := auth.From(r) |
| + if !ok { |
| + return Actor{}, ErrForbidden |
| + } |
| + member, err := a.store.Member(r.Context(), id.Address) |
| + if err != nil { |
| + return Actor{}, err |
| + } |
| + if !member.Active || member.Role != RoleOwner { |
| + return Actor{}, ErrForbidden |
| + } |
| + r.Body = http.MaxBytesReader(w, r.Body, 1<<20) |
| + if err := r.ParseForm(); err != nil { |
| + return Actor{}, ErrInvalid |
| + } |
| + for key, values := range r.PostForm { |
| + found := false |
| + for _, k := range allowed { |
| + if key == k { |
| + found = true |
| + break |
| + } |
| + } |
| + if !found || len(values) != 1 { |
| + return Actor{}, ErrInvalid |
| + } |
| + } |
| + return Actor{Address: id.Address}, nil |
| +} |
| +func number(r *http.Request, key string) (int64, error) { |
| + v, err := strconv.ParseInt(r.PostForm.Get(key), 10, 64) |
| + if err != nil || v < 0 { |
| + return 0, ErrInvalid |
| + } |
| + return v, nil |
| +} |
| +func (a *application) saveAccount(w http.ResponseWriter, r *http.Request) { |
| + actor, err := a.writeForm(w, r, "id", "revision", "label") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + id, err := number(r, "id") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + revision, err := number(r, "revision") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + _, err = a.store.SaveAccount(r.Context(), actor, Account{ID: id, Revision: revision, Label: r.PostForm.Get("label")}) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + http.Redirect(w, r, "/settings", http.StatusSeeOther) |
| +} |
| +func (a *application) saveProject(w http.ResponseWriter, r *http.Request) { |
| + actor, err := a.writeForm(w, r, "revision", "account_id", "name", "kind", "repository", "app_name", "default_branch", "request_id", "owner_work", "owner_merge", "owner_copy", "owner_design", "owner_product") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + var id int64 |
| + if chi.URLParam(r, "id") != "" { |
| + id, err = projectID(r) |
| + if err == nil { |
| + _, err = a.store.Project(r.Context(), id) |
| + } |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + } |
| + revision, err := number(r, "revision") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + accountID, err := number(r, "account_id") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + owners := []DecisionOwner{} |
| + for _, key := range []string{"work", "merge", "copy", "design", "product"} { |
| + if address := r.PostForm.Get("owner_" + key); address != "" { |
| + owners = append(owners, DecisionOwner{Decision: key, Address: address}) |
| + } |
| + } |
| + p, err := a.store.SaveProject(r.Context(), actor, Project{ID: id, Revision: revision, AccountID: accountID, Name: r.PostForm.Get("name"), Kind: ProjectKind(r.PostForm.Get("kind")), Repository: r.PostForm.Get("repository"), AppName: r.PostForm.Get("app_name"), DefaultBranch: r.PostForm.Get("default_branch")}, owners, r.PostForm.Get("request_id")) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + http.Redirect(w, r, "/projects/"+strconv.FormatInt(p.ID, 10), http.StatusSeeOther) |
| +} |
| +func (a *application) saveMember(w http.ResponseWriter, r *http.Request) { |
| + actor, err := a.writeForm(w, r, "address", "role", "active", "revision") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + revision, err := number(r, "revision") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + active, err := strconv.ParseBool(r.PostForm.Get("active")) |
| + if err != nil { |
| + a.failure(w, r, ErrInvalid) |
| + return |
| + } |
| + err = a.store.SetMember(r.Context(), actor, r.PostForm.Get("address"), Role(r.PostForm.Get("role")), active, revision) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + http.Redirect(w, r, "/people", http.StatusSeeOther) |
| +} |
| +func (a *application) saveSpecialist(w http.ResponseWriter, r *http.Request) { |
| + key := chi.URLParam(r, "key") |
| + if !validSpecialistKey(key) { |
| + a.failure(w, r, ErrNotFound) |
| + return |
| + } |
| + actor, err := a.writeForm(w, r, "revision", "model_selection", "provider", "model_family", "model", "standing_instructions", "max_concurrent") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + revision, err := number(r, "revision") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + concurrent, err := number(r, "max_concurrent") |
| + if err != nil || int64(int(concurrent)) != concurrent { |
| + a.failure(w, r, ErrInvalid) |
| + return |
| + } |
| + err = a.store.SaveSpecialist(r.Context(), actor, Specialist{Key: key, Revision: revision, ModelSelection: r.PostForm.Get("model_selection"), Provider: r.PostForm.Get("provider"), ModelFamily: r.PostForm.Get("model_family"), Model: r.PostForm.Get("model"), StandingInstructions: r.PostForm.Get("standing_instructions"), MaxConcurrent: int(concurrent)}) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + http.Redirect(w, r, "/specialists/"+key, http.StatusSeeOther) |
| +} |
| + |
| +func limitFields(prefix string, p team.PeriodLimits, set bool) []budgetField { |
| + fields := []budgetField{{Name: prefix + "calls", CopyKey: "budget.calls"}, {Name: prefix + "input", CopyKey: "budget.input"}, {Name: prefix + "output", CopyKey: "budget.output"}, {Name: prefix + "seconds", CopyKey: "budget.seconds"}} |
| + for i, n := range []int64{p.Calls, p.InputTokens, p.OutputTokens, p.Seconds} { |
| + if set { |
| + fields[i].Value = strconv.FormatInt(n, 10) |
| + } |
| + } |
| + return fields |
| +} |
| +func budgetForms(config BudgetConfig, groups []ProjectGroup) []budgetForm { |
| + forms := []budgetForm{{Name: copyText("budget.team"), Fields: limitFields("team_", config.Team, config.Revision > 0)}} |
| + for _, g := range groups { |
| + for _, d := range g.Projects { |
| + p, ok := config.Projects[team.ProjectID(d.Project.ID)] |
| + forms = append(forms, budgetForm{Name: d.Project.Name, Fields: limitFields("project_"+strconv.FormatInt(d.Project.ID, 10)+"_", p, ok)}) |
| + } |
| + } |
| + return forms |
| +} |
| +func parseLimits(r *http.Request, prefix string) (team.PeriodLimits, bool, error) { |
| + keys := []string{"calls", "input", "output", "seconds"} |
| + n := []int64{} |
| + blank := 0 |
| + for _, key := range keys { |
| + value := r.PostForm.Get(prefix + key) |
| + if value == "" { |
| + blank++ |
| + n = append(n, 0) |
| + continue |
| + } |
| + v, err := number(r, prefix+key) |
| + if err != nil || v <= 0 { |
| + return team.PeriodLimits{}, false, ErrInvalid |
| + } |
| + n = append(n, v) |
| + } |
| + if blank == 4 { |
| + return team.PeriodLimits{}, false, nil |
| + } |
| + if blank != 0 { |
| + return team.PeriodLimits{}, false, ErrInvalid |
| + } |
| + return team.PeriodLimits{Calls: n[0], InputTokens: n[1], OutputTokens: n[2], Seconds: n[3]}, true, nil |
| +} |
| +func (a *application) saveBudgets(w http.ResponseWriter, r *http.Request) { |
| + groups, err := a.store.Projects(r.Context()) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + allowed := []string{"revision"} |
| + for _, form := range budgetForms(BudgetConfig{}, groups) { |
| + for _, field := range form.Fields { |
| + allowed = append(allowed, field.Name) |
| + } |
| + } |
| + actor, err := a.writeForm(w, r, allowed...) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + revision, err := number(r, "revision") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + limits, set, err := parseLimits(r, "team_") |
| + if err != nil || !set { |
| + a.failure(w, r, ErrInvalid) |
| + return |
| + } |
| + config := BudgetConfig{Revision: revision, Team: limits, Projects: map[team.ProjectID]team.PeriodLimits{}} |
| + for _, g := range groups { |
| + for _, d := range g.Projects { |
| + p, set, err := parseLimits(r, "project_"+strconv.FormatInt(d.Project.ID, 10)+"_") |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + if set { |
| + config.Projects[team.ProjectID(d.Project.ID)] = p |
| + } |
| + } |
| + } |
| + // A project added since the form was read must not lose limits on submission. |
| + old, err := a.store.readBudgets(r.Context(), true) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + for id, p := range old.Projects { |
| + if _, present := r.PostForm["project_"+strconv.FormatInt(int64(id), 10)+"_calls"]; !present { |
| + config.Projects[id] = p |
| + } |
| + } |
| + err = a.store.SaveBudgets(r.Context(), actor, config) |
| + if err != nil { |
| + a.failure(w, r, err) |
| + return |
| + } |
| + http.Redirect(w, r, "/settings", http.StatusSeeOther) |
| +} |
diff --git a/internal/equipo/icons/icons.go b/internal/equipo/icons/icons.go| index b92bd36d..3acd20e5 100644 |
| --- a/internal/equipo/icons/icons.go |
| +++ b/internal/equipo/icons/icons.go |
| @@ -20,6 +20,17 @@ package icons |
| import "html/template" |
| var icons = map[string]template.HTML{ |
| + "users": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" /> <path d="M16 3.128a4 4 0 0 1 0 7.744" /> <path d="M22 21v-2a4 4 0 0 0-3-3.87" /> <circle cx="9" cy="7" r="4" /></svg>`, |
| + "message-circle": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>`, |
| + "inbox": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M22 12h-6l-2 3h-4l-2-3H2"/><path d="M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"/></svg>`, |
| + "route": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="6" cy="19" r="3"/><path d="M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15"/><circle cx="18" cy="5" r="3"/></svg>`, |
| + "folder": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/></svg>`, |
| + "lightbulb": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5"/><path d="M9 18h6"/><path d="M10 22h4"/></svg>`, |
| + "pencil": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M12 20h9"/><path d="M16.4 3.6a2.1 2.1 0 0 1 3 3L7.4 18.6a2 2 0 0 1-.9.5l-2.9.8.8-2.9a2 2 0 0 1 .5-.8z"/></svg>`, |
| + "type": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M4 7V4h16v3"/><path d="M9 20h6"/><path d="M12 4v16"/></svg>`, |
| + "code": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="m16 18 6-6-6-6"/><path d="m8 6-6 6 6 6"/></svg>`, |
| + "plug": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M12 22v-5"/><path d="M9 8V2"/><path d="M15 8V2"/><path d="M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z"/></svg>`, |
| + "sliders": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M10 5H3" /> <path d="M12 19H3" /> <path d="M14 3v4" /> <path d="M16 17v4" /> <path d="M21 12h-9" /> <path d="M21 19h-5" /> <path d="M21 5h-7" /> <path d="M8 10v4" /> <path d="M8 12H3" /></svg>`, |
| "alert-triangle": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>`, |
| "check": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M20 6 9 17l-5-5"/></svg>`, |
| "check-circle": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>`, |
diff --git a/internal/equipo/navigation.go b/internal/equipo/navigation.go| new file mode 100644 |
| index 00000000..c4667e85 |
| --- /dev/null |
| +++ b/internal/equipo/navigation.go |
| @@ -0,0 +1,20 @@ |
| +package equipo |
| + |
| +type NavItem struct{ Key, Group, Href, CopyKey, Icon string } |
| + |
| +func Navigation() []NavItem { |
| + return []NavItem{ |
| + {"conversation", "", "/conversation", "nav.conversation", "message-circle"}, |
| + {"needs-you", "", "/needs-you", "nav.needs-you", "inbox"}, |
| + {"journey", "", "/journey", "nav.journey", "route"}, |
| + {"projects", "", "/projects", "nav.projects", "folder"}, |
| + {"product", "specialists", "/specialists/product", "nav.product", "lightbulb"}, |
| + {"design", "specialists", "/specialists/design", "nav.design", "pencil"}, |
| + {"copy", "specialists", "/specialists/copy", "nav.copy", "type"}, |
| + {"engineering", "specialists", "/specialists/engineering", "nav.engineering", "code"}, |
| + {"review", "specialists", "/specialists/review", "nav.review", "check-circle"}, |
| + {"connections", "team", "/connections", "nav.connections", "plug"}, |
| + {"people", "team", "/people", "nav.people", "users"}, |
| + {"settings", "team", "/settings", "nav.settings", "sliders"}, |
| + } |
| +} |
diff --git a/internal/equipo/render.go b/internal/equipo/render.go| index 9b220769..355e82f2 100644 |
| --- a/internal/equipo/render.go |
| +++ b/internal/equipo/render.go |
| @@ -26,18 +26,23 @@ var assets = rastrillo.NewAssets(appFS) |
| var pages = map[string]*template.Template{} |
| func init() { |
| - for _, name := range []string{"index", "overview", "errors", "signin_page"} { |
| + for _, name := range []string{"index", "empty", "projects", "project", "project_form", "people", "settings", "specialist", "errors", "signin_page", "form_error"} { |
| page := template.Must(template.New("layout"). |
| Funcs(ui.Funcs(ui.WithIcons(icons.Icon, icons.Assets))). |
| - Funcs(template.FuncMap{"asset": assets.Path, "copy": func(key string) string { |
| - return map[string]string{"brand": copyBrand, "overview": copyOverview, "placeholder": copyPlaceholder}[key] |
| - }}).ParseFS(ui.Templates(), "*.html")) |
| + Funcs(template.FuncMap{"asset": assets.Path, "copy": copyText, |
| + "kindKey": func(k ProjectKind) string { return "kind." + string(k) }, |
| + "ownerKey": func(k string) string { return "owner." + k }, |
| + "roleKey": func(k Role) string { return "role." + string(k) }, |
| + }).ParseFS(ui.Templates(), "*.html")) |
| if name == "signin_page" { |
| stage, _ := ui.Layout("stage") |
| page = template.Must(page.Parse(string(stage))) |
| } else { |
| page = template.Must(page.ParseFS(appFS, "templates/layout.html")) |
| } |
| + if name != "signin_page" && name != "errors" { |
| + page = template.Must(page.ParseFS(appFS, "templates/chrome.html", "templates/forms.html")) |
| + } |
| pages[name] = template.Must(page.ParseFS(appFS, "templates/"+name+".html")) |
| } |
| } |
| @@ -46,7 +51,11 @@ func init() { |
| // the wire: a template error becomes a clean 500 instead of garbage |
| // appended to a half-written page, and headers (flash cookies, say) |
| // stay settable until the status line is written. |
| -func render(w http.ResponseWriter, status int, name string, data any) { |
| +func render(w http.ResponseWriter, name string, data any) { |
| + renderStatus(w, http.StatusOK, name, data) |
| +} |
| + |
| +func renderStatus(w http.ResponseWriter, status int, name string, data any) { |
| var buf bytes.Buffer |
| if err := pages[name].ExecuteTemplate(&buf, "layout", data); err != nil { |
| http.Error(w, copyRenderFailure, http.StatusInternalServerError) |
| @@ -64,5 +73,5 @@ func render(w http.ResponseWriter, status int, name string, data any) { |
| // so a panic gets the same page a handled failure would; wire it to |
| // Ctx.ErrorPage too as the app grows handlers of its own. |
| func ErrorPage(w http.ResponseWriter, r *http.Request, status int, ref string) { |
| - render(w, status, "errors", map[string]any{"Status": status, "Ref": ref}) |
| + renderStatus(w, status, "errors", map[string]any{"Status": status, "Ref": ref}) |
| } |
diff --git a/internal/equipo/static/equipo.css b/internal/equipo/static/equipo.css| new file mode 100644 |
| index 00000000..4226d850 |
| --- /dev/null |
| +++ b/internal/equipo/static/equipo.css |
| @@ -0,0 +1,15 @@ |
| +[equipo-projects] { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); gap: var(--rst-sp-4); } |
| +[equipo-card], [equipo-note] { border: 1px solid var(--rst-line); border-radius: var(--rst-radius); padding: var(--rst-sp-4); margin-block: var(--rst-sp-4); background: var(--rst-surface-2); } |
| +[equipo-card] { background: var(--rst-surface); min-width: 0; } |
| +[equipo-account] { margin-block: var(--rst-sp-6); } |
| +[equipo-nav-group] { color: var(--rst-text-muted); padding: var(--rst-sp-2); font-size: var(--rst-fs-sm); } |
| +[equipo-muted], [equipo-metadata] dt { color: var(--rst-text-muted); } |
| +[equipo-metadata] { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: var(--rst-sp-2); } |
| +[equipo-metadata] dd { margin: 0; } |
| +[equipo-form] { display: grid; gap: var(--rst-sp-4); max-width: 42rem; } |
| +[equipo-form] label { display: grid; gap: var(--rst-sp-2); } |
| +[equipo-form] fieldset { display: grid; gap: var(--rst-sp-4); border: 1px solid var(--rst-line); padding: var(--rst-sp-4); min-width: 0; } |
| +[equipo-form] input, [equipo-form] select, [equipo-form] textarea { width: 100%; min-width: 0; box-sizing: border-box; } |
| +[equipo-form] button { justify-self: start; } |
| +[rst-page] { overflow-wrap: anywhere; } |
| +[rst-page] .icon, [rst-shell-brand] .icon { width: 1em; height: 1em; flex-shrink: 0; margin-inline-end: var(--rst-sp-2); } |
diff --git a/internal/equipo/templates/chrome.html b/internal/equipo/templates/chrome.html| new file mode 100644 |
| index 00000000..4c27b1d3 |
| --- /dev/null |
| +++ b/internal/equipo/templates/chrome.html |
| @@ -0,0 +1,13 @@ |
| +{{define "title"}}{{copy .Title}} · {{copy "brand"}}{{end}} |
| +{{define "head"}}<link rel="stylesheet" href="{{asset "static/equipo.css"}}">{{end}} |
| +{{define "up"}}/work{{if .Key}}#nav-{{.Key}}{{end}}{{end}} |
| +{{define "brand"}}<a rst-shell-brand href="/people">{{icon "users"}}{{.TeamName}}</a>{{end}} |
| +{{define "nav"}} |
| +{{$key := .Key}}{{$group := ""}} |
| +{{range .Nav}} |
| +{{if ne .Group $group}}{{if .Group}}<p equipo-nav-group>{{copy (printf "nav.%s" .Group)}}</p>{{end}}{{$group = .Group}}{{end}} |
| +<a id="nav-{{.Key}}" href="{{.Href}}"{{if eq .Key $key}} aria-current="page"{{end}}>{{icon .Icon}}<span>{{copy .CopyKey}}</span></a> |
| +{{end}} |
| +{{end}} |
| +{{define "profile"}}{{if .Address}}<span rst-person-av aria-hidden="true">{{icon "users"}}</span><span rst-person-name>{{.Address}}</span>{{else}}<span rst-person-av="empty placeholder" aria-hidden="true"></span><span rst-person-name>{{copy "nav.account"}}</span>{{end}}{{end}} |
| +{{define "account"}}{{if .Address}}<form method="post" action="/signout"><button rst-btn type="submit">{{copy "nav.signout"}}</button></form>{{end}}{{end}} |
diff --git a/internal/equipo/templates/empty.html b/internal/equipo/templates/empty.html| new file mode 100644 |
| index 00000000..921908ff |
| --- /dev/null |
| +++ b/internal/equipo/templates/empty.html |
| @@ -0,0 +1 @@ |
| +{{define "content"}}<h1>{{copy .Title}}</h1><section equipo-note data-empty-state="{{.EmptyKey}}"><p>{{copy .EmptyKey}}</p></section>{{end}} |
diff --git a/internal/equipo/templates/form_error.html b/internal/equipo/templates/form_error.html| new file mode 100644 |
| index 00000000..6afe1f97 |
| --- /dev/null |
| +++ b/internal/equipo/templates/form_error.html |
| @@ -0,0 +1 @@ |
| +{{define "content"}}<h1>{{copy .ErrorKey}}</h1><a href="{{.Back}}">{{copy "form.back"}}</a>{{end}} |
diff --git a/internal/equipo/templates/forms.html b/internal/equipo/templates/forms.html| new file mode 100644 |
| index 00000000..6b3708f2 |
| --- /dev/null |
| +++ b/internal/equipo/templates/forms.html |
| @@ -0,0 +1,34 @@ |
| +{{define "project-metadata"}} |
| +<dl equipo-metadata> |
| +<dt>{{copy "project.kind"}}</dt><dd>{{copy (kindKey .Project.Kind)}}</dd> |
| +<dt>{{copy "project.repository"}}</dt><dd>{{.Project.Repository}}</dd> |
| +<dt>{{copy "project.app"}}</dt><dd>{{if .Project.AppName}}{{.Project.AppName}}{{else}}{{copy "value.none"}}{{end}}</dd> |
| +<dt>{{copy "project.branch"}}</dt><dd>{{.Project.DefaultBranch}}</dd> |
| +{{range .Owners}}<dt>{{copy (ownerKey .Decision)}}</dt><dd>{{.Address}}</dd>{{end}} |
| +</dl> |
| +{{end}} |
| +{{define "project-fields"}} |
| +{{if .Groups}} |
| +<form method="post" action="{{.Action}}" equipo-form> |
| +<input type="hidden" name="revision" value="{{.Detail.Project.Revision}}"> |
| +<input type="hidden" name="request_id" value="{{.RequestID}}"> |
| +<label>{{copy "project.account"}}<select rst-input name="account_id" required>{{range .Groups}}<option value="{{.Account.ID}}"{{if eq .Account.ID $.Detail.Project.AccountID}} selected{{end}}>{{.Account.Label}}</option>{{end}}</select></label> |
| +<label>{{copy "project.name"}}<input rst-input name="name" value="{{.Detail.Project.Name}}" required></label> |
| +<label>{{copy "project.kind"}}<select rst-input name="kind" required> |
| +<option value="app"{{if eq .Detail.Project.Kind "app"}} selected{{end}}>{{copy "kind.app"}}</option> |
| +<option value="website"{{if eq .Detail.Project.Kind "website"}} selected{{end}}>{{copy "kind.website"}}</option> |
| +<option value="repository"{{if eq .Detail.Project.Kind "repository"}} selected{{end}}>{{copy "kind.repository"}}</option> |
| +</select></label> |
| +<label>{{copy "project.repository"}}<input rst-input name="repository" value="{{.Detail.Project.Repository}}" required></label> |
| +<label>{{copy "project.app"}}<input rst-input name="app_name" value="{{.Detail.Project.AppName}}"></label> |
| +<label>{{copy "project.branch"}}<input rst-input name="default_branch" value="{{.Detail.Project.DefaultBranch}}" required></label> |
| +<fieldset><legend>{{copy "owners.title"}}</legend> |
| +{{range .Owners}}{{$field := .}}<label>{{copy (ownerKey .Key)}}<select rst-input name="owner_{{.Key}}"{{if .Required}} required{{end}}><option value="">{{copy "value.none"}}</option>{{range $.Members}}<option value="{{.Address}}"{{if eq .Address $field.Address}} selected{{end}}>{{.Address}}</option>{{end}}</select></label>{{end}} |
| +</fieldset> |
| +<button rst-btn="primary" type="submit">{{copy "form.save"}}</button> |
| +</form> |
| +{{else}}<a href="/settings">{{copy "account.add"}}</a>{{end}} |
| +{{end}} |
| +{{define "budget-summary"}} |
| +{{range .BudgetForms}}<h3>{{.Name}}</h3><dl equipo-metadata>{{range .Fields}}<dt>{{copy .CopyKey}}</dt><dd data-limit-set="{{if .Value}}true{{else}}false{{end}}">{{if .Value}}{{.Value}}{{else}}{{copy "value.unset"}}{{end}}</dd>{{end}}</dl>{{end}} |
| +{{end}} |
diff --git a/internal/equipo/templates/index.html b/internal/equipo/templates/index.html| index 2f38908e..c278b50d 100644 |
| --- a/internal/equipo/templates/index.html |
| +++ b/internal/equipo/templates/index.html |
| @@ -1,12 +1,2 @@ |
| -{{/* index.html: the home page, and on a phone the list of |
| - sections: the view block says this page is the index, so below |
| - 800px the rail is the whole page and this content is hidden; on a |
| - desktop the rail sits beside it. Give each section a nav link with |
| - an id here, and give its page an up block naming /#<that id>, so a |
| - phone comes back to the row it left. */}} |
| {{define "view"}}index{{end}} |
| -{{define "brand"}}<a rst-shell-brand href="/">{{copy "brand"}}</a>{{end}} |
| -{{define "nav"}}<a id="nav-overview" href="/overview">{{copy "overview"}}</a>{{end}} |
| -{{define "content"}} |
| -<h1>{{copy "placeholder"}}</h1> |
| -{{end}} |
| +{{define "content"}}<h1>{{copy "nav.work"}}</h1><p>{{copy "activity.empty"}}</p>{{end}} |
diff --git a/internal/equipo/templates/layout.html b/internal/equipo/templates/layout.html| index 37136723..e0493e46 100644 |
| --- a/internal/equipo/templates/layout.html |
| +++ b/internal/equipo/templates/layout.html |
| @@ -51,7 +51,7 @@ |
| accessible name (WCAG 2.5.3); rel="up" for tools that read it. An |
| app that wants its name on it ("‹ Ledger") edits this line, which is |
| the app's own from the moment it is scaffolded. */}} |
| -<div rst-shell-back><a href="{{block "up" .}}/{{end}}" rel="up" aria-label="{{Tf "rastrillo.ui.shell_up" "name" (T "rastrillo.ui.shell_up_label")}}">{{T "rastrillo.ui.shell_up_label"}}</a></div> |
| +<div rst-shell-back><a href="{{block "up" .}}/{{end}}" rel="up" aria-label="{{copy "nav.back"}}">{{copy "nav.work"}}</a></div> |
| <aside rst-shell-rail> |
| {{/* The index's heading is the app's name: the brand, in a span of its |
| own, then the page's title for an app whose brand renders nothing |
diff --git a/internal/equipo/templates/overview.html b/internal/equipo/templates/overview.html| deleted file mode 100644 |
| index 453f27c5..00000000 |
| --- a/internal/equipo/templates/overview.html |
| +++ /dev/null |
| @@ -1,9 +0,0 @@ |
| -{{/* overview.html: a section. up is its way back: the index, with |
| - this section's nav link as the fragment, which is where focus |
| - returns on a phone even with scripts off. */}} |
| -{{define "up"}}/#nav-overview{{end}} |
| -{{define "brand"}}<a rst-shell-brand href="/">{{copy "brand"}}</a>{{end}} |
| -{{define "nav"}}<a id="nav-overview" href="/overview" aria-current="page">{{copy "overview"}}</a>{{end}} |
| -{{define "content"}} |
| -<h1>{{copy "placeholder"}}</h1> |
| -{{end}} |
diff --git a/internal/equipo/templates/people.html b/internal/equipo/templates/people.html| new file mode 100644 |
| index 00000000..d91256c3 |
| --- /dev/null |
| +++ b/internal/equipo/templates/people.html |
| @@ -0,0 +1,16 @@ |
| +{{define "content"}} |
| +<h1>{{copy "nav.people"}}</h1> |
| +{{range .Members}}<section equipo-card><h2>{{.Address}}</h2> |
| +{{if $.Owner}}<form method="post" action="/team/members" equipo-form> |
| +<input type="hidden" name="address" value="{{.Address}}"><input type="hidden" name="revision" value="{{.Revision}}"> |
| +<label>{{copy "people.role"}}<select rst-input name="role"><option value="owner"{{if eq .Role "owner"}} selected{{end}}>{{copy "role.owner"}}</option><option value="member"{{if eq .Role "member"}} selected{{end}}>{{copy "role.member"}}</option></select></label> |
| +<label>{{copy "people.active"}}<select rst-input name="active"><option value="true"{{if .Active}} selected{{end}}>{{copy "people.active"}}</option><option value="false"{{if not .Active}} selected{{end}}>{{copy "people.inactive"}}</option></select></label> |
| +<button rst-btn type="submit">{{copy "form.save"}}</button></form> |
| +{{else}}<p>{{copy (roleKey .Role)}} · {{if .Active}}{{copy "people.active"}}{{else}}{{copy "people.inactive"}}{{end}}</p>{{end}} |
| +</section>{{end}} |
| +{{if .Owner}}<section equipo-card><h2>{{copy "people.add"}}</h2><form method="post" action="/team/members" equipo-form> |
| +<input type="hidden" name="revision" value="0"><input type="hidden" name="active" value="true"> |
| +<label>{{copy "people.address"}}<input rst-input type="email" name="address" required></label> |
| +<label>{{copy "people.role"}}<select rst-input name="role"><option value="member">{{copy "role.member"}}</option><option value="owner">{{copy "role.owner"}}</option></select></label> |
| +<button rst-btn="primary" type="submit">{{copy "form.save"}}</button></form></section>{{end}} |
| +{{end}} |
diff --git a/internal/equipo/templates/project.html b/internal/equipo/templates/project.html| new file mode 100644 |
| index 00000000..a1669e13 |
| --- /dev/null |
| +++ b/internal/equipo/templates/project.html |
| @@ -0,0 +1,6 @@ |
| +{{define "content"}} |
| +<h1>{{.Detail.Project.Name}}</h1> |
| +<section equipo-card data-project-kind="{{.Detail.Project.Kind}}"><h2>{{copy "projects.metadata"}}</h2>{{template "project-metadata" .Detail}}</section> |
| +<p data-activity="empty">{{copy "activity.empty"}}</p><p data-signals="unavailable">{{copy "signals.unconnected"}}</p> |
| +{{if .Owner}}<a rst-btn href="/projects/{{.Detail.Project.ID}}/edit">{{copy "projects.edit"}}</a>{{end}} |
| +{{end}} |
diff --git a/internal/equipo/templates/project_form.html b/internal/equipo/templates/project_form.html| new file mode 100644 |
| index 00000000..4335280c |
| --- /dev/null |
| +++ b/internal/equipo/templates/project_form.html |
| @@ -0,0 +1 @@ |
| +{{define "content"}}<h1>{{copy .Title}}</h1>{{template "project-fields" .}}{{end}} |
diff --git a/internal/equipo/templates/projects.html b/internal/equipo/templates/projects.html| new file mode 100644 |
| index 00000000..78b17f1a |
| --- /dev/null |
| +++ b/internal/equipo/templates/projects.html |
| @@ -0,0 +1,17 @@ |
| +{{define "content"}} |
| +<h1>{{copy "nav.projects"}}</h1> |
| +<p data-project-count="{{.Count}}">{{copy "projects.count"}}: {{.Count}}</p> |
| +{{range .Groups}} |
| +<section equipo-account> |
| +<h2>{{.Account.Label}} <small>{{copy "projects.count"}}: {{len .Projects}}</small></h2> |
| +<div equipo-projects> |
| +{{range .Projects}}<article equipo-card data-project-kind="{{.Project.Kind}}"> |
| +<h3><a href="/projects/{{.Project.ID}}">{{icon "folder"}}{{.Project.Name}}</a></h3> |
| +{{template "project-metadata" .}} |
| +<p data-activity="empty">{{copy "activity.empty"}}</p><p equipo-muted data-signals="unavailable">{{copy "signals.unconnected"}}</p> |
| +</article>{{else}}<p>{{copy "projects.empty"}}</p>{{end}} |
| +</div></section> |
| +{{else}}<p>{{copy "projects.empty"}}</p>{{end}} |
| +<section equipo-note><h2>{{copy "budget.title"}}</h2>{{template "budget-summary" .}}<h3>{{copy "budget.usage"}}</h3><p data-usage="0">{{copy "budget.zero"}}</p></section> |
| +{{if .Owner}}<section equipo-card><h2>{{copy "projects.add"}}</h2>{{template "project-fields" .}}</section>{{end}} |
| +{{end}} |
diff --git a/internal/equipo/templates/settings.html b/internal/equipo/templates/settings.html| new file mode 100644 |
| index 00000000..76f324bd |
| --- /dev/null |
| +++ b/internal/equipo/templates/settings.html |
| @@ -0,0 +1,16 @@ |
| +{{define "content"}} |
| +<h1>{{copy "nav.settings"}}</h1> |
| +<p>{{copy "account.note"}}</p> |
| +{{range .Groups}}<section equipo-card><h2>{{.Account.Label}}</h2>{{if $.Owner}}<form method="post" action="/accounts" equipo-form> |
| +<input type="hidden" name="id" value="{{.Account.ID}}"><input type="hidden" name="revision" value="{{.Account.Revision}}"> |
| +<label>{{copy "account.label"}}<input rst-input name="label" value="{{.Account.Label}}" required></label><button rst-btn type="submit">{{copy "form.save"}}</button></form>{{end}}</section>{{end}} |
| +{{if .Owner}}<section equipo-card><h2>{{copy "account.add"}}</h2><form method="post" action="/accounts" equipo-form> |
| +<input type="hidden" name="id" value="0"><input type="hidden" name="revision" value="0"><label>{{copy "account.label"}}<input rst-input name="label" required></label><button rst-btn="primary" type="submit">{{copy "form.save"}}</button></form></section>{{end}} |
| +<section equipo-card><h2>{{copy "budget.title"}}</h2> |
| +{{if .Owner}}<p>{{copy "budget.note"}}</p><form method="post" action="/team/budgets" equipo-form><input type="hidden" name="revision" value="{{.Budget.Revision}}"> |
| +{{range .BudgetForms}}<fieldset><legend>{{.Name}}</legend>{{range .Fields}}<label>{{copy .CopyKey}}<input rst-input name="{{.Name}}" type="number" min="1" step="1" value="{{.Value}}"></label>{{end}}</fieldset>{{end}} |
| +<button rst-btn="primary" type="submit">{{copy "form.save"}}</button></form> |
| +{{else}}{{template "budget-summary" .}}{{end}} |
| +<h3>{{copy "budget.usage"}}</h3><p data-usage="0">{{copy "budget.zero"}}</p> |
| +</section> |
| +{{end}} |
diff --git a/internal/equipo/templates/specialist.html b/internal/equipo/templates/specialist.html| new file mode 100644 |
| index 00000000..dcdde9e1 |
| --- /dev/null |
| +++ b/internal/equipo/templates/specialist.html |
| @@ -0,0 +1,18 @@ |
| +{{define "content"}} |
| +<h1>{{copy .Title}}</h1><p equipo-note>{{copy "specialist.empty"}}</p> |
| +<section equipo-card><h2>{{copy "activity.working"}}</h2><p data-activity="empty">{{copy "activity.empty"}}</p></section> |
| +<section equipo-card><h2>{{copy "activity.queued"}}</h2><p data-activity="empty">{{copy "activity.empty"}}</p></section> |
| +<section equipo-card><h2>{{copy "activity.finished"}}</h2><p data-activity="empty">{{copy "activity.empty"}}</p></section> |
| +<section equipo-card><h2>{{copy "nav.settings"}}</h2> |
| +<form method="post" action="/specialists/{{.Specialist.Key}}" equipo-form> |
| +<fieldset{{if not .Owner}} disabled{{end}}> |
| +<input type="hidden" name="revision" value="{{.Specialist.Revision}}"> |
| +<label>{{copy "specialist.mode"}}<select rst-input name="model_selection"><option value="best_fit"{{if eq .Specialist.ModelSelection "best_fit"}} selected{{end}}>{{copy "mode.best_fit"}}</option><option value="fixed"{{if eq .Specialist.ModelSelection "fixed"}} selected{{end}}>{{copy "mode.fixed"}}</option></select></label> |
| +<label>{{copy "specialist.provider"}}<input rst-input name="provider" value="{{.Specialist.Provider}}"></label> |
| +<label>{{copy "specialist.family"}}<input rst-input name="model_family" value="{{.Specialist.ModelFamily}}"></label> |
| +<label>{{copy "specialist.model"}}<input rst-input name="model" value="{{.Specialist.Model}}"></label> |
| +<label>{{copy "specialist.concurrent"}}<input rst-input name="max_concurrent" type="number" min="1" step="1" value="{{.Specialist.MaxConcurrent}}" required></label> |
| +<label>{{copy "specialist.instructions"}}<textarea rst-input name="standing_instructions" rows="5">{{.Specialist.StandingInstructions}}</textarea></label> |
| +{{if .Owner}}<button rst-btn="primary" type="submit">{{copy "form.save"}}</button>{{end}} |
| +</fieldset></form></section> |
| +{{end}} |
diff --git a/internal/equipotest/foundation_test.go b/internal/equipotest/foundation_test.go| index 7347411c..4b9d9112 100644 |
| --- a/internal/equipotest/foundation_test.go |
| +++ b/internal/equipotest/foundation_test.go |
| @@ -167,7 +167,7 @@ func TestFoundationMigratesTwice(t *testing.T) { |
| // each must fail. Executing with a fake make also checks shell behavior. |
| func TestCIGateSteps(t *testing.T) { |
| root := filepath.Join("..", "..") |
| - want := []string{"build", "vet", "fmt-check", "staticcheck", "govulncheck", "gitleaks", "budget", "test", "migration-check"} |
| + want := []string{"build", "vet", "fmt-check", "staticcheck", "govulncheck", "gitleaks", "budget", "test", "migration-check", "perf"} |
| sort.Strings(want) |
| contents, err := os.ReadFile(filepath.Join(root, "Makefile")) |
| if err != nil { |
diff --git a/internal/equipotest/pages_test.go b/internal/equipotest/pages_test.go| new file mode 100644 |
| index 00000000..6caa839b |
| --- /dev/null |
| +++ b/internal/equipotest/pages_test.go |
| @@ -0,0 +1,393 @@ |
| +package equipotest |
| + |
| +import ( |
| + "amadan.net/rastrillo/rastrillo/db" |
| + "context" |
| + "fmt" |
| + "io" |
| + "log/slog" |
| + "net/http" |
| + "net/http/httptest" |
| + "net/url" |
| + "regexp" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo" |
| +) |
| + |
| +const memberAddress = "reader@example.com" |
| + |
| +var railPaths = []string{"/conversation", "/needs-you", "/journey", "/projects", "/specialists/product", "/specialists/design", "/specialists/copy", "/specialists/engineering", "/specialists/review", "/connections", "/people", "/settings"} |
| +var railNames = []string{"Conversation", "Needs you", "Journey", "Projects", "Product", "Design", "Copy", "Engineering", "Review", "Connections", "People", "Settings"} |
| + |
| +func newPageFixture(t *testing.T) authFixture { |
| + t.Helper() |
| + logger := slog.New(slog.NewTextHandler(io.Discard, nil)) |
| + d, err := db.Open(schema.Path(t), logger) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { d.Close() }) |
| + mailer := &capturingMailer{} |
| + mux, err := equipo.App(d, testConfig(testOrigin), mailer, logger) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + server := httptest.NewServer(mux) |
| + t.Cleanup(server.Close) |
| + return authFixture{db: d, store: equipo.NewStore(d), mail: mailer, server: server} |
| +} |
| + |
| +func pageOwner(t *testing.T) (authFixture, *http.Client) { |
| + t.Helper() |
| + f := newPageFixture(t) |
| + c := signinClient(t, f.server.URL) |
| + challenge := prepareEmail(t, c, f.server.URL, ownerAddress) |
| + // Issue the real challenge before yielding, so its age overlaps other setup. |
| + t.Parallel() |
| + submitEmail(t, c, f.server.URL, testOrigin, challenge) |
| + res := confirmEmail(t, c, f.server.URL, testOrigin, f.mail) |
| + defer res.Body.Close() |
| + if res.StatusCode != 303 { |
| + t.Fatalf("verify: %d", res.StatusCode) |
| + } |
| + return f, c |
| +} |
| +func pageBody(t *testing.T, c *http.Client, base, path string) string { |
| + t.Helper() |
| + res := clientGet(t, c, base+path) |
| + body := readBody(t, res) |
| + if res.StatusCode != 200 { |
| + t.Fatalf("%s: %d: %s", path, res.StatusCode, body) |
| + } |
| + return body |
| +} |
| +func pagePost(t *testing.T, c *http.Client, base, path, origin string, v url.Values, want int) string { |
| + t.Helper() |
| + res := clientPost(t, c, base+path, origin, v) |
| + body := readBody(t, res) |
| + if res.StatusCode != want { |
| + t.Fatalf("POST %s: %d want %d: %s", path, res.StatusCode, want, body) |
| + } |
| + return res.Header.Get("Location") |
| +} |
| +func seedPageProject(t *testing.T, s *equipo.Store, account equipo.Account, kind equipo.ProjectKind, name string) equipo.Project { |
| + t.Helper() |
| + app := name |
| + if kind == equipo.ProjectRepository { |
| + app = "" |
| + } |
| + p, err := s.SaveProject(context.Background(), equipo.Actor{Address: ownerAddress}, equipo.Project{AccountID: account.ID, Name: name, Kind: kind, Repository: "amadan.net/oficina/" + name, AppName: app, DefaultBranch: "release/stable"}, []equipo.DecisionOwner{{Decision: "work", Address: ownerAddress}, {Decision: "merge", Address: ownerAddress}}, "seed-"+name) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return p |
| +} |
| +func TestRailRoutes(t *testing.T) { |
| + f, c := pageOwner(t) |
| + for _, path := range append(append([]string{}, railPaths...), "/work") { |
| + body := pageBody(t, c, f.server.URL, path) |
| + nav := regexp.MustCompile(`(?s)<nav rst-shell-nav>.*?</nav>`).FindString(body) |
| + links := regexp.MustCompile(`(?s)<a\b[^>]*>.*?</a>`).FindAllString(nav, -1) |
| + if len(links) != 12 { |
| + t.Fatalf("%s: %d rail destinations", path, len(links)) |
| + } |
| + for i, link := range links { |
| + if !strings.Contains(link, `href="`+railPaths[i]+`"`) || !strings.Contains(link, railNames[i]) || !strings.Contains(link, "<svg") { |
| + t.Fatalf("rail entry %d: %s", i, link) |
| + } |
| + } |
| + currentCount := strings.Count(body, `aria-current="page"`) |
| + want := 1 |
| + if path == "/work" { |
| + want = 0 |
| + if !strings.Contains(body, `rst-shell-sidebar="index"`) { |
| + t.Fatal("not phone index") |
| + } |
| + } |
| + if currentCount != want { |
| + t.Fatalf("ambiguous navigation position: %s: %d", path, currentCount) |
| + } |
| + if !strings.Contains(body, `rst-shell-brand href="/people"`) { |
| + t.Fatal("missing team link") |
| + } |
| + if strings.Contains(nav, ">Apps<") || strings.Contains(nav, ">Billing<") { |
| + t.Fatal("console navigation leaked") |
| + } |
| + if path != "/work" && !strings.Contains(body, `href="/work#nav-`) { |
| + t.Fatal("missing phone parent") |
| + } |
| + for _, asset := range []string{"theme.", "shell.", "tokens.", "equipo."} { |
| + if !strings.Contains(body, "/static/"+asset) { |
| + t.Fatalf("missing %s", asset) |
| + } |
| + } |
| + } |
| + res := clientGet(t, c, f.server.URL+"/") |
| + defer res.Body.Close() |
| + if res.StatusCode != 303 || res.Header.Get("Location") != "/conversation" { |
| + t.Fatal("root landing") |
| + } |
| + for _, p := range []string{"/projects/99999", "/projects/nope", "/projects/99999/edit", "/specialists/nope"} { |
| + assertStatus(t, c, f.server.URL+p, 404) |
| + } |
| +} |
| +func TestProjectsOverview(t *testing.T) { |
| + f, c := pageOwner(t) |
| + ctx := context.Background() |
| + actor := equipo.Actor{Address: ownerAddress} |
| + a, err := f.store.SaveAccount(ctx, actor, equipo.Account{Label: "First account"}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + b, err := f.store.SaveAccount(ctx, actor, equipo.Account{Label: "Second account"}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + seedPageProject(t, f.store, a, equipo.ProjectApp, "shop") |
| + seedPageProject(t, f.store, a, equipo.ProjectWebsite, "site") |
| + seedPageProject(t, f.store, b, equipo.ProjectRepository, "library") |
| + body := pageBody(t, c, f.server.URL, "/projects") |
| + for _, s := range []string{"First account", "Second account", `data-project-count="3"`, `data-project-kind="app"`, `data-project-kind="website"`, `data-project-kind="repository"`, "amadan.net/oficina/shop", "release/stable", ownerAddress, `data-signals="unavailable"`, `data-activity="empty"`, `data-limit-set="false"`} { |
| + if !strings.Contains(body, s) { |
| + t.Fatalf("overview missing %s", s) |
| + } |
| + } |
| + if strings.Count(body, `data-project-kind=`) != 3 { |
| + t.Fatal("duplicated project lists") |
| + } |
| + formFields(t, body, "/projects") |
| +} |
| +func TestOverviewFailureIsNotZero(t *testing.T) { |
| + f, c := pageOwner(t) |
| + if _, err := f.db.Writer().Exec("DROP TABLE projects"); err != nil { |
| + t.Fatal(err) |
| + } |
| + res := clientGet(t, c, f.server.URL+"/projects") |
| + body := readBody(t, res) |
| + if res.StatusCode != http.StatusServiceUnavailable { |
| + t.Fatal("failed count rendered as empty") |
| + } |
| + if strings.Contains(body, `data-activity="empty"`) || strings.Contains(body, `data-project-count="0"`) { |
| + t.Fatal("failure rendered activity") |
| + } |
| +} |
| +func TestProjectForms(t *testing.T) { |
| + f := newPageFixture(t) |
| + c := signinClient(t, f.server.URL) |
| + member := signinClient(t, f.server.URL) |
| + if err := f.store.SetMember(context.Background(), equipo.Actor{Address: ownerAddress}, memberAddress, equipo.RoleMember, true, 0); err != nil { |
| + t.Fatal(err) |
| + } |
| + ownerChallenge := prepareEmail(t, c, f.server.URL, ownerAddress) |
| + memberChallenge := prepareEmail(t, member, f.server.URL, memberAddress) |
| + t.Parallel() |
| + submitEmail(t, c, f.server.URL, testOrigin, ownerChallenge) |
| + res := confirmEmail(t, c, f.server.URL, testOrigin, f.mail) |
| + res.Body.Close() |
| + submitEmail(t, member, f.server.URL, testOrigin, memberChallenge) |
| + res = confirmEmail(t, member, f.server.URL, testOrigin, f.mail) |
| + res.Body.Close() |
| + a, err := f.store.SaveAccount(context.Background(), equipo.Actor{Address: ownerAddress}, equipo.Account{Label: "A"}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + v := formFields(t, pageBody(t, c, f.server.URL, "/projects/new"), "/projects") |
| + v.Set("account_id", fmt.Sprint(a.ID)) |
| + v.Set("name", "<script>alert(1)</script>") |
| + v.Set("kind", "app") |
| + v.Set("repository", "amadan.net/oficina/test") |
| + v.Set("app_name", "test") |
| + v.Set("default_branch", "release/one") |
| + v.Set("owner_work", ownerAddress) |
| + v.Set("owner_merge", memberAddress) |
| + pagePost(t, c, f.server.URL, "/projects", "https://foreign.example", v, 403) |
| + v.Set("actor", memberAddress) |
| + pagePost(t, c, f.server.URL, "/projects", testOrigin, v, 422) |
| + v.Del("actor") |
| + path := pagePost(t, c, f.server.URL, "/projects", testOrigin, v, 303) |
| + pagePost(t, c, f.server.URL, "/projects/999999", testOrigin, v, 404) |
| + if retry := pagePost(t, c, f.server.URL, "/projects", testOrigin, v, 303); retry != path { |
| + t.Fatal("retry changed project") |
| + } |
| + body := pageBody(t, member, f.server.URL, path) |
| + if strings.Contains(body, "<script>alert(1)</script>") || !strings.Contains(body, "<script>") { |
| + t.Fatal("stored HTML executed") |
| + } |
| + edit := formFields(t, pageBody(t, c, f.server.URL, path+"/edit"), path) |
| + if edit.Get("default_branch") != "release/one" { |
| + t.Fatal("branch lost") |
| + } |
| + edit.Set("account_id", fmt.Sprint(a.ID)) |
| + edit.Set("kind", "website") |
| + edit.Set("default_branch", "release/two") |
| + edit.Set("owner_work", ownerAddress) |
| + edit.Set("owner_merge", memberAddress) |
| + pagePost(t, member, f.server.URL, path, testOrigin, edit, 403) |
| + pagePost(t, c, f.server.URL, path, testOrigin, edit, 303) |
| + edit.Set("request_id", "stale") |
| + pagePost(t, c, f.server.URL, path, testOrigin, edit, 409) |
| + body = pageBody(t, c, f.server.URL, path) |
| + if !strings.Contains(body, `data-project-kind="website"`) || !strings.Contains(body, "release/two") { |
| + t.Fatal("edit lost kind or branch") |
| + } |
| + invalid := formFields(t, pageBody(t, c, f.server.URL, path+"/edit"), path) |
| + invalid.Set("kind", "bad") |
| + pagePost(t, c, f.server.URL, path, testOrigin, invalid, 422) |
| +} |
| +func TestRosterRouteCSRF(t *testing.T) { |
| + f, c := pageOwner(t) |
| + v := url.Values{"address": {"new@example.com"}, "role": {"member"}, "active": {"true"}, "revision": {"0"}} |
| + pagePost(t, c, f.server.URL, "/team/members", testOrigin, v, 303) |
| + m, err := f.store.Member(context.Background(), "new@example.com") |
| + if err != nil || !m.Active { |
| + t.Fatal("mounted route did not save") |
| + } |
| + v.Set("role", "owner") |
| + v.Set("revision", fmt.Sprint(m.Revision)) |
| + pagePost(t, c, f.server.URL, "/team/members", "https://foreign.example", v, 403) |
| + after, err := f.store.Member(context.Background(), m.Address) |
| + if err != nil || after != m { |
| + t.Fatal("foreign origin changed roster") |
| + } |
| +} |
| +func TestEmptyScreensDoNotStartWork(t *testing.T) { |
| + f, c := pageOwner(t) |
| + for _, path := range []string{"/conversation", "/needs-you", "/journey", "/connections", "/specialists/engineering"} { |
| + body := pageBody(t, c, f.server.URL, path) |
| + for _, action := range []string{`action="/run`, `action="/connect`, `name="message"`, `contenteditable="true"`} { |
| + if strings.Contains(body, action) { |
| + t.Fatalf("%s enables work", path) |
| + } |
| + } |
| + } |
| + for _, path := range []string{"/run", "/connect", "/conversation"} { |
| + pagePost(t, c, f.server.URL, path, testOrigin, url.Values{}, 404) |
| + } |
| + var n int |
| + if err := f.db.Writer().QueryRow("SELECT count(*) FROM sqlite_master WHERE type='table' AND name IN ('jobs','attempts','actions')").Scan(&n); err != nil || n != 0 { |
| + t.Fatal("execution store opened") |
| + } |
| +} |
| + |
| +func TestSettingsForms(t *testing.T) { |
| + f, c := pageOwner(t) |
| + ctx := context.Background() |
| + body := pageBody(t, c, f.server.URL, "/settings") |
| + v := formFields(t, body, "/accounts") |
| + v.Set("label", "<script>alert(1)</script>") |
| + pagePost(t, c, f.server.URL, "/accounts", testOrigin, v, 303) |
| + body = pageBody(t, c, f.server.URL, "/settings") |
| + if strings.Contains(body, "<script>alert(1)</script>") { |
| + t.Fatal("account HTML executed") |
| + } |
| + groups, err := f.store.Projects(ctx) |
| + if err != nil || len(groups) != 1 { |
| + t.Fatal("account was not created") |
| + } |
| + account := groups[0].Account |
| + v = url.Values{"id": {fmt.Sprint(account.ID)}, "revision": {fmt.Sprint(account.Revision)}, "label": {"Renamed"}} |
| + pagePost(t, c, f.server.URL, "/accounts", testOrigin, v, 303) |
| + pagePost(t, c, f.server.URL, "/accounts", testOrigin, v, 409) |
| + p := seedPageProject(t, f.store, account, equipo.ProjectRepository, "budget-project") |
| + body = pageBody(t, c, f.server.URL, "/settings") |
| + v = formFields(t, body, "/team/budgets") |
| + if v.Get("team_calls") != "" { |
| + t.Fatal("unset limit became zero") |
| + } |
| + for _, key := range []string{"calls", "input", "output", "seconds"} { |
| + v.Set("team_"+key, "1000") |
| + v.Set(fmt.Sprintf("project_%d_%s", p.ID, key), "100") |
| + } |
| + pagePost(t, c, f.server.URL, "/team/budgets", testOrigin, v, 303) |
| + b, err := f.store.Budgets(ctx) |
| + if err != nil || b.Revision != 1 || len(b.Projects) != 1 || b.Team.Calls != 1000 { |
| + t.Fatalf("saved limits: %+v %v", b, err) |
| + } |
| + pagePost(t, c, f.server.URL, "/team/budgets", testOrigin, v, 409) |
| + body = pageBody(t, c, f.server.URL, "/settings") |
| + v = formFields(t, body, "/team/budgets") |
| + if v.Get("team_calls") != "1000" { |
| + t.Fatal("saved budget not shown") |
| + } |
| + v.Set("team_calls", "bogus") |
| + pagePost(t, c, f.server.URL, "/team/budgets", testOrigin, v, 422) |
| + v.Set("team_calls", "1000") |
| + v.Set("actor", ownerAddress) |
| + pagePost(t, c, f.server.URL, "/team/budgets", testOrigin, v, 422) |
| + v.Del("actor") |
| + pagePost(t, c, f.server.URL, "/team/budgets", "https://foreign.example", v, 403) |
| + // Clearing a project requires all four blanks; team limits stay explicit. |
| + for _, key := range []string{"calls", "input", "output", "seconds"} { |
| + v.Set(fmt.Sprintf("project_%d_%s", p.ID, key), "") |
| + } |
| + pagePost(t, c, f.server.URL, "/team/budgets", testOrigin, v, 303) |
| + b, err = f.store.Budgets(ctx) |
| + if err != nil || len(b.Projects) != 0 { |
| + t.Fatal("project limits were not cleared") |
| + } |
| + body = pageBody(t, c, f.server.URL, "/projects") |
| + if !strings.Contains(body, `data-limit-set="false"`) || !strings.Contains(body, "1000") || !strings.Contains(body, `data-usage="0"`) { |
| + t.Fatal("limits and usage not distinct") |
| + } |
| +} |
| +func TestSpecialistForms(t *testing.T) { |
| + f, c := pageOwner(t) |
| + path := "/specialists/engineering" |
| + v := formFields(t, pageBody(t, c, f.server.URL, path), path) |
| + v.Set("model_selection", "fixed") |
| + v.Set("provider", "Provider") |
| + v.Set("model_family", "Family") |
| + v.Set("model", "Model") |
| + v.Set("max_concurrent", "2") |
| + v.Set("standing_instructions", "<script>alert(1)</script>") |
| + pagePost(t, c, f.server.URL, path, testOrigin, v, 303) |
| + pagePost(t, c, f.server.URL, path, testOrigin, v, 409) |
| + body := pageBody(t, c, f.server.URL, path) |
| + if strings.Contains(body, "<script>alert(1)</script>") || !strings.Contains(body, "<script>") { |
| + t.Fatal("specialist HTML executed") |
| + } |
| + v = formFields(t, body, path) |
| + v.Set("model_selection", "fixed") |
| + v.Set("provider", "") |
| + pagePost(t, c, f.server.URL, path, testOrigin, v, 422) |
| + v.Set("provider", "Provider") |
| + v.Set("actor", ownerAddress) |
| + pagePost(t, c, f.server.URL, path, testOrigin, v, 422) |
| + v.Del("actor") |
| + pagePost(t, c, f.server.URL, path, "https://foreign.example", v, 403) |
| + // The same cookie must lose write access immediately after demotion. |
| + actor := equipo.Actor{Address: ownerAddress} |
| + if err := f.store.SetMember(context.Background(), actor, "other@example.com", equipo.RoleOwner, true, 0); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := f.store.SetMember(context.Background(), actor, ownerAddress, equipo.RoleMember, true, 1); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, p := range []string{path, "/accounts", "/team/budgets", "/team/members", "/projects"} { |
| + pagePost(t, c, f.server.URL, p, testOrigin, v, 403) |
| + } |
| + body = pageBody(t, c, f.server.URL, path) |
| + if !strings.Contains(body, "fieldset disabled") { |
| + t.Fatal("member has enabled settings") |
| + } |
| + pageBody(t, c, f.server.URL, "/people") |
| + pageBody(t, c, f.server.URL, "/settings") |
| +} |
| +func TestSettingsReadFailure(t *testing.T) { |
| + t.Parallel() |
| + for _, table := range []string{"budget_records", "specialists", "accounts", "decision_owners"} { |
| + t.Run(table, func(t *testing.T) { |
| + f, c := pageOwner(t) |
| + if _, err := f.db.Writer().Exec("DROP TABLE " + table); err != nil { |
| + t.Fatal(err) |
| + } |
| + path := "/projects" |
| + if table == "specialists" { |
| + path = "/specialists/product" |
| + } |
| + assertStatus(t, c, f.server.URL+path, 503) |
| + }) |
| + } |
| +} |
diff --git a/internal/equipotest/perf_test.go b/internal/equipotest/perf_test.go| index beeb69aa..b8bec0da 100644 |
| --- a/internal/equipotest/perf_test.go |
| +++ b/internal/equipotest/perf_test.go |
| @@ -3,9 +3,12 @@ |
| package equipotest |
| import ( |
| + "context" |
| + "fmt" |
| "io" |
| "log/slog" |
| "net/http" |
| + "strings" |
| "testing" |
| "time" |
| @@ -42,12 +45,42 @@ func TestPerfScreens(t *testing.T) { |
| t.Fatal(err) |
| } |
| defer closeAll() |
| - // Task 8 enables this lane in CI. |
| - // A {param} route also needs a Paths entry backed by a seeded row. |
| + store := equipo.NewStore(d) |
| + account, err := store.SaveAccount(context.Background(), equipo.Actor{Address: ownerAddress}, equipo.Account{Label: "Performance account"}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + project := seedPageProject(t, store, account, equipo.ProjectApp, "performance-project") |
| + projectPath := fmt.Sprintf("/projects/%d", project.ID) |
| + paths := map[string]string{"/projects/{id}": projectPath, "/projects/{id}/edit": projectPath + "/edit", "/specialists/{key}": "/specialists/engineering"} |
| perftest.Screens(t, perftest.ScreenConfig{ |
| - Routes: r, Handler: h, |
| - Signin: func(c *http.Client, base string) { signinEmail(t, c, base, testOrigin, mailer, ownerAddress) }, |
| - Expect: map[string]int{"/": 303, "/auth/callback": 303, "/auth/verify": 303, "/*": 404}, |
| + Routes: r, Handler: h, Paths: paths, |
| + Signin: func(c *http.Client, base string) { |
| + signinEmail(t, c, base, testOrigin, mailer, ownerAddress) |
| + checks := map[string]string{ |
| + "/work": `rst-shell-sidebar="index"`, |
| + "/conversation": `data-empty-state="conversation.empty"`, |
| + "/needs-you": `data-empty-state="needs-you.empty"`, |
| + "/journey": `data-empty-state="journey.empty"`, |
| + "/projects": `data-project-count="1"`, |
| + "/projects/new": `action="/projects"`, |
| + projectPath: "performance-project", |
| + projectPath + "/edit": `action="` + projectPath + `"`, |
| + "/connections": `data-empty-state="connections.empty"`, |
| + "/people": `action="/team/members"`, |
| + "/settings": `action="/team/budgets"`, |
| + } |
| + for _, key := range []string{"product", "design", "copy", "engineering", "review"} { |
| + checks["/specialists/"+key] = `action="/specialists/` + key + `"` |
| + } |
| + for path, want := range checks { |
| + body := pageBody(t, c, base, path) |
| + if !strings.Contains(body, want) { |
| + t.Errorf("%s missing page content %q", path, want) |
| + } |
| + } |
| + }, |
| + Expect: map[string]int{"/": 303, "/signin": 200, "/auth/callback": 303, "/auth/verify": 303}, |
| }) |
| } |
| @@ -77,6 +110,6 @@ func TestPerfBoot(t *testing.T) { |
| } |
| return h, func() { closeAll(); d.Close() }, nil |
| }, |
| - Path: "/", |
| + Path: "/", Expect: http.StatusSeeOther, |
| }) |
| } |