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 "embed"
5 "encoding/json"
6 "fmt"
7)
8
9//go:embed fixtures/*.json
10var fixtureFS embed.FS
11
12// Route shapes the server half mounts beside an app's own router. They are
13// part of the contract: the conformance harness fires exactly these, so an app
14// that mounts them elsewhere fails gate 1 rather than failing in production.
15const (
16 RouteS1 = "/suite/s1" // GET, ?cursor=
17 RouteS2 = "/suite/s2" // POST, body is S2Request
18 RouteS3 = "/suite/s3" // GET, /suite/s3/{item_id}?revision=
19)
20
21// S2Request is the wire shape of an authorization question: a typed asker
22// (§3) and up to MaxS2Pairs items. The consumer token rides the transport,
23// not the body.
24type S2Request struct {
25 Asker Subject `json:"asker"`
26 Pairs []ItemRevision `json:"pairs"`
27}
28
29// Rung is where an item sits on the sharing ladder (§4.2, ruling 15). A link
30// is not a rung; it is a read-only capability that any rung may carry, and
31// who may open an item keys on the rung (with ownership and grants), never
32// on the link. Since revision 10 the rung no longer bounds what a consumer
33// holds; it decides S2.
34type Rung string
35
36const (
37 RungPrivate Rung = "private"
38 RungGranted Rung = "granted"
39 RungTeam Rung = "team"
40 RungDeleted Rung = "deleted"
41)
42
43// CustodyCase is one row of the custody fixture: an item, where it sits, and
44// what both calls must answer for the fixture's asker. Since revision 10
45// (Paul, 2026-11-01) a consumer holds every live item and S2 answers from
46// the app's own read check, so the rung matters only through that check.
47type CustodyCase struct {
48 Name string `json:"name"`
49 ItemID string `json:"item_id"`
50 Revision int64 `json:"revision"`
51 Rung Rung `json:"rung"`
52 Link string `json:"link"`
53 // Owner is "asker" when the fixture's asker owns the item and "other"
54 // when another member does. AskerGrant is whether the asker holds a live
55 // individual grant on it. Together with Rung they are what an app seeds
56 // so its own read check produces the S2 answers below (revision 10). The
57 // harness cannot see how an app mapped them while seeding, so a case
58 // seeded wrongly can pass; what an owner keeps is held to the app's own
59 // tests as much as to this fixture.
60 //
61 // Revision 11 added a third value, "stranger" (an owner who has since
62 // lost team standing, case doc-owner-left). That case was withdrawn on
63 // 2026-11-02, answering Fable's review of 0a59e7d (H1): Paul has not
64 // ruled whether such a person keeps their own items, and gate 5 reads
65 // that they do (doctrine §14). No binding case uses "stranger".
66 Owner string `json:"owner"`
67 AskerGrant bool `json:"asker_grant"`
68 S3Status int `json:"s3_status"`
69 // S3Body is the exact body a content fetch must return: the item's bytes
70 // for a 200, and empty for every refusal. Checking the status alone let a
71 // server return the required 404 while including the item's secrets in the
72 // body, or return a 200 carrying a different item entirely.
73 S3Body string `json:"s3_body"`
74 S2Result Authorization `json:"s2_result"`
75 // PriorRevision is a revision the item's log holds that is not its
76 // current one: an app seeds its log with it before Revision. It is
77 // Revision - 1 in every case, so an app that seeded "one behind" before
78 // revision 11 seeds the same log, but the harness reads it from here and
79 // never computes it — a revision is a name, and a producer whose
80 // revisions are random has no "one behind" (doctrine §6.6, revision 11).
81 PriorRevision int64 `json:"prior_revision"`
82 // UnknownRevision is a revision the item's log never issued. Some cases
83 // put it BELOW Revision and away from PriorRevision, so a producer that
84 // decides STALE by comparing numbers — the counter's habit, which is
85 // what a restore turns into a leak — answers STALE where it owes
86 // UNKNOWN; the rest put it above, so one that says STALE for anything
87 // not current fails too. (Revision 11 said "most" are below; it was
88 // four of ten, and is three of nine since doc-owner-left was withdrawn.
89 // TestCustodyFixtureUnknownRevisionsBothSides holds the fixture to
90 // having both among the cases the asker may open.) An app must never
91 // issue it while seeding.
92 UnknownRevision int64 `json:"unknown_revision"`
93 // S2ResultSuperseded is the answer at PriorRevision: STALE for a person
94 // who may open the item — readable, but the app of record has moved on —
95 // and NOT_VISIBLE for one who may not. (The name is revision 9's; the
96 // module is additive.)
97 S2ResultSuperseded Authorization `json:"s2_result_superseded"`
98 // S2ResultAhead is the answer at UnknownRevision, a revision the log
99 // does not hold: UNKNOWN for a person who may open the item (§4.3),
100 // NOT_VISIBLE for one who may not. (Named when the harness asked one
101 // revision ahead; since revision 11 it asks at UnknownRevision.)
102 S2ResultAhead Authorization `json:"s2_result_ahead"`
103 // S2ResultStranger is the answer for a person with no team standing.
104 S2ResultStranger Authorization `json:"s2_result_stranger"`
105}
106
107// NonexistentItemID is never in the fixture. A refusal for an item that does
108// not exist has to be byte-for-byte the refusal for one that was deleted, so
109// a consumer cannot tell a deletion from an id it made up, and S2 answers it
110// NOT_VISIBLE for everybody — never VISIBLE, which is a producer failing
111// open (revision 11). (Before revision 10 the S3 rule held for every item
112// that was not team-visible.)
113const NonexistentItemID = "doc-no-such-item-ever"
114
115// NeverIssuedCursor is a cursor no producer issued. S1 answers it with the
116// cursor reset (CursorResetStatus, CursorResetBody), never as the tip and
117// never as a failure (doctrine §6.6, revision 11). A producer must not issue
118// it.
119const NeverIssuedCursor = "suite-conformance-cursor-never-issued"
120
121// CustodyFixture is gate 3's world: one case per rung, plus team-plus-link
122// and the after-ingest transitions the reviews asked for.
123type CustodyFixture struct {
124 Team string `json:"team"`
125 Asker Subject `json:"asker"`
126 // Stranger has no team standing, owns nothing in the fixture and holds
127 // no grant on any of it, so every case refuses them, the team rung
128 // included. Whether a person removed from the team keeps items they own
129 // or were individually granted is NOT ruled (doctrine §14, NEEDS PAUL);
130 // the fixture asks nothing about it.
131 Stranger Subject `json:"stranger"`
132 Cases []CustodyCase `json:"cases"`
133}
134
135// LoadCustodyFixture returns the golden custody cases every app runs.
136func LoadCustodyFixture() (CustodyFixture, error) {
137 raw, err := fixtureFS.ReadFile("fixtures/custody.json")
138 if err != nil {
139 return CustodyFixture{}, fmt.Errorf("suite: reading custody fixture: %w", err)
140 }
141 return parseCustodyFixture(raw)
142}
143
144func parseCustodyFixture(raw []byte) (CustodyFixture, error) {
145 var f CustodyFixture
146 if err := json.Unmarshal(raw, &f); err != nil {
147 return CustodyFixture{}, fmt.Errorf("suite: parsing custody fixture: %w", err)
148 }
149 if len(f.Cases) == 0 {
150 return CustodyFixture{}, fmt.Errorf("suite: custody fixture has no cases")
151 }
152 for _, c := range f.Cases {
153 // Three distinct names, each one S2 and S3 would accept: a fixture
154 // whose prior or unknown revision is the current one, or under 1,
155 // asks nothing it claims to ask.
156 if c.Revision < 1 || c.PriorRevision < 1 || c.UnknownRevision < 1 ||
157 c.PriorRevision == c.Revision || c.UnknownRevision == c.Revision || c.UnknownRevision == c.PriorRevision {
158 return CustodyFixture{}, fmt.Errorf("suite: custody case %s: revisions %d, %d, %d are not three distinct revisions of 1 or more", c.ItemID, c.Revision, c.PriorRevision, c.UnknownRevision)
159 }
160 }
161 return f, nil
162}
163