Artifact 808ad06947959d8db95ef4025aa0261b1464f451afd9c4664f8518ad31912e4c:
- File
internal/web/protect_test.go
— part of check-in
[0d3bcdd784]
at
2026-08-26 23:16:39
on branch protect-4
— RFC 0007 phase 4: the settings surface, under a
Protected branches beside capabilities on the repository settings page: a branch or glob per row, owners as logins, every matching rule applies, blank the owners to remove one. The form rebuilds the stored set, so a renamed row is a delete and a write.
The cost is stated where the rule is set, because both things it changes surprise someone who knows fossil: on this forge i means less than it means in fossil, and a stock client can be refused a push its capability string says it may make. Policy of this forge, outside the repository; a clone is byte-identical to an unprotected one.
The section is not drawn on a forge with no policy store. (user: dmestas, size: 2062) [annotate] [blame] [check-ins using] [more...]
package web import ( "strings" "testing" "craftdesign.group/quarry/internal/oltp" ) type fakeProtect struct{ rules map[string][]oltp.Protection } func (f fakeProtect) Protections(repo string) ([]oltp.Protection, error) { return f.rules[repo], nil } func (f fakeProtect) SetProtection(string, string, []string) error { return nil } // The settings page states the cost where the rule is set: on this // forge `i` means less than it means in fossil, and a stock client can // be refused a push its capability string says it may make. Both are // surprising to someone who knows fossil, and a page that set the rule // without saying so would be the RFC's own "never disguised as // fossil's" broken in the UI. func TestSettingsPageStatesWhatProtectionCosts(t *testing.T) { src := settingsSource for _, want := range []string{ `action="/r/{{.Repo}}/settings/protect"`, "means less than it means in", "stored outside the repository", "byte-identical", } { if !strings.Contains(src, want) { t.Errorf("settings page lacks %q", want) } } } // No policy store: the section is not drawn, rather than drawn empty // and unsaveable. With one: an empty list is the ordinary state and the // page must still offer the first row. func TestProtectPanelOffersAFirstRowAndHidesWithoutAStore(t *testing.T) { if p := protectPanelFor(nil, "alpha"); p != nil { t.Error("a forge with no policy store drew the section") } p := protectPanelFor(fakeProtect{rules: map[string][]oltp.Protection{}}, "alpha") if p == nil || len(p.Rules) != 0 || p.Blank != 0 { t.Fatalf("empty policy gave %+v, want no rules and a blank row at 0", p) } p = protectPanelFor(fakeProtect{rules: map[string][]oltp.Protection{ "alpha": {{Branch: "trunk", Owners: []string{"alice", "bob"}}, {Branch: "release-*", Owners: []string{"bob"}}}, }}, "alpha") if len(p.Rules) != 2 || p.Blank != 2 { t.Fatalf("two rules gave %+v", p) } if p.Rules[0].Owners != "alice bob" { t.Errorf("owners rendered as %q, want space-separated for the input", p.Rules[0].Owners) } }