// Package stagingtest holds the staging suite's assertions so the local // rig can exercise both safe choices and deliberate coordinator failures. package stagingtest import ( "fmt" "net/url" "regexp" "slices" "strings" "time" "amadan.net/oficina/equipo/internal/equipo/personapi" "amadan.net/oficina/equipo/internal/wire" ) // suitePerson is a fresh suite person's address, as the staging harness // makes them: suite-@equipo-staging.invalid. var suitePerson = regexp.MustCompile(`^suite-[a-z0-9-]+@equipo-staging\.invalid$`) // SuitePerson reports whether address is a fresh suite person the staging // harness added (never the owner or the long-lived suite person). func SuitePerson(address string) bool { return suitePerson.MatchString(address) } // Roster reads the whole roster through get, a page at a time (the API // pages it, 50 a page by default). func Roster(get func(path string, out *personapi.Page[personapi.RosterMember])) []personapi.RosterMember { var all []personapi.RosterMember q := url.Values{"limit": {"100"}} for { var page personapi.Page[personapi.RosterMember] get("/api/v1/roster?"+q.Encode(), &page) all = append(all, page.Items...) if page.NextCursor == "" { return all } q.Set("cursor", page.NextCursor) } } func Latency(first, limit time.Duration, retry func() time.Duration) ([]time.Duration, error) { samples := []time.Duration{first} if first <= limit { return samples, nil } samples = append(samples, retry()) if samples[1] > limit { return samples, fmt.Errorf("first-token samples %v both exceed %v", samples, limit) } return samples, nil } // Placement accepts a question or placement in a named, existing project. // A question cannot excuse creating a repository or choosing another project. // requiredCard is used when the person has already named an exact repository. func Placement(cards []wire.Card, tasks []wire.Task, named []string, requiredCard bool) error { question, placed, projectCard := false, false, false for _, c := range cards { switch c.Kind { case wire.CardQuestion, wire.CardAccess: question = question || c.Question != "" case wire.CardProject: if c.State == wire.CardCreated { return fmt.Errorf("repository %s created without consent", c.Name) } if !slices.Contains(named, c.Name) { return fmt.Errorf("placed in unnamed project %s", c.Name) } if c.State == wire.CardAdded || c.State == wire.CardWorking { placed, projectCard = true, true } } } for _, task := range tasks { // Project is the project's title; Repo names the repository. if !slices.Contains(named, strings.TrimPrefix(task.Repo, "amadan.net/")) { return fmt.Errorf("task placed in unnamed project %s (%s)", task.Repo, task.Project) } placed = true } if requiredCard && !projectCard { return fmt.Errorf("missing project card for %v", named) } if !question && !placed { return fmt.Errorf("no placement question or work in %v", named) } return nil }