package thintest import ( "net/http" "net/url" "strconv" "strings" "testing" "amadan.net/oficina/equipo/internal/wire" ) // TestContractShipsButtons (Paul, 2026-11-11): "Does merging to main // ship to users?" is two buttons that apply at once, outside the Change // form. A tap posts only the answer at the page's revision and leaves // the rest of the policy as it was; Undo is the same post with the // value before, "unknown" included; each is an audited policy write. A // stale revision changes nothing; a member sees no buttons and is // refused. func TestContractShipsButtons(t *testing.T) { r := newToolRigAt(t, wire.ProtocolInjectionDefences) project := r.project() owner := r.inst.Cookie() path := "/projects/" + project + "/merge-policy" // A policy with something in every field, so a tap that dropped one // would show. p0, _ := r.client.MergePolicy(r.ctx, project) if _, err := r.client.SetMergePolicy(r.ctx, project, wire.SetMergePolicy{Mode: "ask", MaxLines: 40, MaxFiles: 3, MainShips: "unknown", ExtraSensitive: []string{"billing/**"}, Words: "ask me before Woodstar merges", Revision: p0.Revision}); err != nil { t.Fatal(err) } base, _ := r.client.MergePolicy(r.ctx, project) audits := func() int { var n int if err := r.inst.DB.Writer().QueryRow("SELECT COUNT(*) FROM chat_merge_audit WHERE project_id = ? AND kind = 'policy'", project).Scan(&n); err != nil { t.Fatal(err) } return n } tap := func(c *http.Cookie, value string, rev int64) int { t.Helper() status, loc := r.post(c, path, url.Values{"revision": {strconv.FormatInt(rev, 10)}, "only": {"main_ships"}, "main_ships": {value}}) if status == http.StatusSeeOther && loc != "/projects/"+project { t.Fatalf("tap %s came back to %q", value, loc) } return status } pressed := func(page, value string) bool { return strings.Contains(page, `aria-pressed="true" data-merge-ships-choice="`+value+`"`) } // Before the first tap: two buttons, neither pressed, no select. page := r.get(owner, "/projects/"+project, 200) for _, v := range []string{"yes", "no"} { if !strings.Contains(page, `aria-pressed="false" data-merge-ships-choice="`+v+`"`) { t.Fatalf("no unpressed %s button: %s", v, page) } } if strings.Contains(page, `