oficina / suite Public

Clone
git clone https://amadan.net/oficina/suite

Plain git — no account needed to clone.

Download

Download this file

1package suite
2
3import (
4 "encoding/json"
5 "os"
6 "testing"
7)
8
9type hostCase struct {
10 Host string `json:"host"`
11 Why string `json:"why"`
12}
13
14type redirectCase struct {
15 From string `json:"from"`
16 To string `json:"to"`
17 Why string `json:"why"`
18}
19
20type hostileHosts struct {
21 Team string `json:"team"`
22 Refuse []hostCase `json:"refuse"`
23 Reach []hostCase `json:"reach"`
24 Redirect redirectCase `json:"redirect"`
25 Comment []string `json:"comment"`
26}
27
28func loadHostileHosts(t *testing.T) hostileHosts {
29 t.Helper()
30 raw, err := os.ReadFile("fixtures/hostile_hosts.json")
31 if err != nil {
32 t.Fatalf("reading fixture: %v", err)
33 }
34 var f hostileHosts
35 if err := json.Unmarshal(raw, &f); err != nil {
36 t.Fatalf("parsing fixture: %v", err)
37 }
38 return f
39}
40
41// The hostile-hostname fixture is the shared list, so every app runs gate 4
42// against the same hosts rather than each inventing its own. This test is the
43// module holding itself to the fixture it publishes.
44func TestHostileHostFixture(t *testing.T) {
45 f := loadHostileHosts(t)
46 if f.Redirect.From == "" || f.Redirect.To == "" {
47 t.Error("fixture has no redirect case; TestSiblingClientRefusesAFixtureRedirect needs one")
48 }
49 if len(f.Refuse) == 0 || len(f.Reach) == 0 {
50 t.Fatal("fixture has no cases; a gate that asserts nothing passes everything")
51 }
52
53 for _, c := range f.Refuse {
54 if err := CheckSiblingHost(f.Team, c.Host); err == nil {
55 t.Errorf("reached %q, want it refused — %s", c.Host, c.Why)
56 }
57 }
58 for _, c := range f.Reach {
59 if err := CheckSiblingHost(f.Team, c.Host); err != nil {
60 t.Errorf("refused %q (%v), want it reached — %s", c.Host, err, c.Why)
61 }
62 }
63}
64
65// The custody fixture names three distinct revisions per case, each one S2
66// and S3 would accept (revision 11). A case whose prior or unknown revision
67// is its current one would ask the harness's questions of nothing.
68//
69// MUTATION-TESTED 2026-11-01, reverted: the loader's revision check removed
70// → every bad case below accepted.
71func TestCustodyFixtureRevisionsAreDistinct(t *testing.T) {
72 f, err := LoadCustodyFixture()
73 if err != nil {
74 t.Fatal(err)
75 }
76 for _, c := range f.Cases {
77 if c.PriorRevision != c.Revision-1 {
78 // Docs and Fichas seed "one behind" before revision 11; keeping
79 // prior at Revision - 1 keeps their seeding correct.
80 t.Errorf("%s: prior_revision %d, want %d", c.ItemID, c.PriorRevision, c.Revision-1)
81 }
82 }
83 for name, rv := range map[string]string{
84 "prior is current": `"revision":7,"prior_revision":7,"unknown_revision":5`,
85 "unknown is current": `"revision":7,"prior_revision":6,"unknown_revision":7`,
86 "unknown is prior": `"revision":7,"prior_revision":6,"unknown_revision":6`,
87 "prior missing": `"revision":7,"unknown_revision":5`,
88 "unknown under 1": `"revision":7,"prior_revision":6,"unknown_revision":0`,
89 } {
90 raw := `{"cases":[{"item_id":"doc-x",` + rv + `}]}`
91 if _, err := parseCustodyFixture([]byte(raw)); err == nil {
92 t.Errorf("%s: accepted", name)
93 }
94 }
95}
96
97// The fixture puts some unknown revisions below the current one and some
98// above, among the cases the asker may open (where the answer is UNKNOWN
99// and a wrong STALE shows). Without a case below, a producer comparing
100// numbers passes; without one above, a producer answering STALE for
101// anything not current passes. Revision 11 claimed "most" sat below, which
102// was never checked and was false (four of ten); this holds the claim the
103// harness actually depends on (Fable's review of 0a59e7d, L3).
104//
105// MUTATION-TESTED 2026-11-02, reverted: doc-granted's unknown_revision moved
106// from 10 to 7 (below its current 9, leaving no openable case above) → "no
107// case the asker may open puts unknown_revision above". doc-team's,
108// doc-private's and doc-team-link's moved above their current revisions
109// (8, 5, 4) → "no case the asker may open puts unknown_revision below".
110func TestCustodyFixtureUnknownRevisionsBothSides(t *testing.T) {
111 f, err := LoadCustodyFixture()
112 if err != nil {
113 t.Fatal(err)
114 }
115 below, above := 0, 0
116 for _, c := range f.Cases {
117 if c.S2ResultAhead != UNKNOWN {
118 continue
119 }
120 if c.UnknownRevision < c.Revision {
121 below++
122 } else {
123 above++
124 }
125 }
126 if below == 0 {
127 t.Error("no case the asker may open puts unknown_revision below the current revision; a producer comparing numbers passes")
128 }
129 if above == 0 {
130 t.Error("no case the asker may open puts unknown_revision above the current revision; a producer answering STALE for anything not current passes")
131 }
132}
133