Fixture and harness (revision 11): named revisions, unknown ids, cursor reset, RunProducer
- custody.json: every case carries prior_revision (in the log, not current; Revision - 1, so Docs' and Fichas' seeding stays correct) and unknown_revision (never issued; mostly BELOW current, so a producer comparing numbers fails). The harness computes no +-1. S3 refuses both. Fable H1(d). New case doc-owner-left: owner "stranger", NOT_VISIBLE for everybody (this session's proposal, L4). Revision-9 comments fixed. - Harness: S2 about NonexistentItemID for asker and stranger is NOT_VISIBLE (H2); S3 with no, a malformed or a zero revision is the baseline refusal, and a POST is not served (M5); S1 at a cursor never issued must be the CURSOR_RESET 409 (H1b); every response must carry Cache-Control: no-store and Vary: Authorization (M3). - conformance.RunProducer / CheckProducer drive a server.Producer through server.Handler with a token the harness mints, and require the 401 without it (M4). conformance imports server; server's tests are an external package, so there is no cycle. - Reference server: log-based STALE; eleven new broken variants, each refused. Loader rejects a case without three distinct revisions >= 1. Every new check mutation-tested; recorded in the tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+473
−108
conformance/conformance.go+191 −48conformance/conformance_test.go+122 −33fixtures.go+60 −17fixtures/custody.json+55 −6fixtures_test.go+32 −0server/server_test.go+13 −4
diff --git a/conformance/conformance.go b/conformance/conformance.go| index 87dadf6..7bfa0cf 100644 |
| --- a/conformance/conformance.go |
| +++ b/conformance/conformance.go |
| @@ -1,16 +1,22 @@ |
| // Package conformance drives an app's server half against the doctrine's |
| // golden fixtures. |
| // |
| -// An app mounts its suite routes on a handler and hands that handler here. |
| -// The harness fires the fixture's requests at it and reports what the contract |
| -// says should have happened and did not. Doctrine §10: two specs are guesses, |
| -// two implementations are facts — this is where the second implementation |
| -// corrects the first. |
| +// An app built on suite/server hands its Producer to RunProducer, which |
| +// mounts it exactly as the app does — server.Handler, behind a bearer token |
| +// the harness mints for itself — so what is tested is what is served, and |
| +// no unauthenticated handler ever needs to exist. An app with its own server |
| +// half hands that handler to Run or RunAs. The harness fires the fixture's |
| +// requests and reports what the contract says should have happened and did |
| +// not. Doctrine §10: two specs are guesses, two implementations are facts — |
| +// this is where the second implementation corrects the first. |
| package conformance |
| import ( |
| "bytes" |
| + "crypto/rand" |
| + "encoding/hex" |
| "encoding/json" |
| + "errors" |
| "fmt" |
| "net/http" |
| "net/http/httptest" |
| @@ -21,6 +27,7 @@ import ( |
| "testing" |
| "amadan.net/oficina/suite" |
| + "amadan.net/oficina/suite/server" |
| ) |
| // Report is what a run found. An empty Failures is a pass. |
| @@ -62,6 +69,53 @@ func RunAs(t *testing.T, h http.Handler, kind suite.SubjectKind) { |
| } |
| } |
| +// RunProducer is how an app built on suite/server runs gate 3: the |
| +// producer mounted through server.Handler, exactly as the app mounts it, and |
| +// driven with a token the harness mints (revision 11). kind is the asker |
| +// kind the app keys on. |
| +func RunProducer(t *testing.T, p server.Producer, kind suite.SubjectKind) { |
| + t.Helper() |
| + report := CheckProducer(p, kind) |
| + for _, f := range report.Failures { |
| + t.Error(f) |
| + } |
| + if report.Checked == 0 { |
| + t.Error("conformance ran no checks; a gate that asserts nothing passes everything") |
| + } |
| +} |
| + |
| +// CheckProducer is RunProducer without a *testing.T. Beyond CheckAs it |
| +// asks once with no token, which must be the 401 — Handler, not routes |
| +// served to anybody. |
| +func CheckProducer(p server.Producer, kind suite.SubjectKind) Report { |
| + var r Report |
| + raw := make([]byte, 32) |
| + if _, err := rand.Read(raw); err != nil { |
| + r.fail("minting the harness's token: %v", err) |
| + return r |
| + } |
| + token := hex.EncodeToString(raw) |
| + h := server.Handler(p, []server.Consumer{{ |
| + ID: "suite-conformance", |
| + Tokens: []server.Token{{Epoch: 1, SHA256: server.TokenHash(token)}}, |
| + }}, nil) |
| + |
| + anon := do(h, "GET", suite.RouteS3+"/"+suite.NonexistentItemID+"?revision=1", nil) |
| + r.Checked++ |
| + if anon.Code != http.StatusUnauthorized { |
| + r.fail("a request with no token: got %d, want 401", anon.Code) |
| + } |
| + |
| + report := CheckAs(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { |
| + req = req.Clone(req.Context()) |
| + req.Header.Set("Authorization", "Bearer "+token) |
| + h.ServeHTTP(w, req) |
| + }), kind) |
| + r.Checked += report.Checked |
| + r.Failures = append(r.Failures, report.Failures...) |
| + return r |
| +} |
| + |
| // Check drives the handler and returns what it found, without touching a |
| // *testing.T. It exists so the harness itself can be tested: a harness that |
| // passes every server is worse than no harness, and the only way to know is to |
| @@ -86,13 +140,49 @@ func CheckAs(h http.Handler, kind suite.SubjectKind) Report { |
| } |
| fixture.Asker.Kind, fixture.Stranger.Kind = kind, kind |
| - checkS3(h, fixture, &r) |
| - checkS2(h, fixture, &r) |
| - checkWrongKind(h, fixture, kind, &r) |
| - checkS1(h, fixture, &r) |
| + audit := &storeAudit{next: h, r: &r, seen: map[string]bool{}} |
| + checkS3(audit, fixture, &r) |
| + checkS2(audit, fixture, &r) |
| + checkWrongKind(audit, fixture, kind, &r) |
| + checkS1(audit, fixture, &r) |
| return r |
| } |
| +// storeAudit holds every response the harness receives to the headers the |
| +// doctrine requires on all of them (§6.5, revision 11): Cache-Control: |
| +// no-store, so no cache between two apps keeps one person's S2 answer or a |
| +// private item's S3 body for the next request, and Vary: Authorization. One |
| +// failure per route, method and status, not one per request. |
| +type storeAudit struct { |
| + next http.Handler |
| + r *Report |
| + seen map[string]bool |
| +} |
| + |
| +func (a *storeAudit) ServeHTTP(w http.ResponseWriter, req *http.Request) { |
| + rec := httptest.NewRecorder() |
| + a.next.ServeHTTP(rec, req) |
| + res := rec.Result() |
| + route := req.URL.Path |
| + if strings.HasPrefix(route, suite.RouteS3+"/") { |
| + route = suite.RouteS3 |
| + } |
| + key := fmt.Sprintf("%s %s %d", req.Method, route, res.StatusCode) |
| + if !a.seen[key] { |
| + a.seen[key] = true |
| + a.r.Checked++ |
| + if res.Header.Get("Cache-Control") != "no-store" || res.Header.Get("Vary") != "Authorization" { |
| + a.r.fail("%s: Cache-Control %q and Vary %q, want no-store and Authorization on every response", |
| + key, res.Header.Get("Cache-Control"), res.Header.Get("Vary")) |
| + } |
| + } |
| + for k, v := range res.Header { |
| + w.Header()[k] = v |
| + } |
| + w.WriteHeader(res.StatusCode) |
| + w.Write(rec.Body.Bytes()) |
| +} |
| + |
| // Gate 2's kind rule: an asker of a kind the app does not key on is UNKNOWN |
| // for the whole call, never NOT_VISIBLE and never an answer read off the |
| // value alone (Astra, 2026-11-01: the reference server compared values only |
| @@ -104,11 +194,12 @@ func checkWrongKind(h http.Handler, f suite.CustodyFixture, kind suite.SubjectKi |
| } |
| wrong := suite.Subject{Kind: other, Value: f.Asker.Value} |
| pairs := make([]suite.ItemRevision, 0, len(f.Cases)) |
| + want := make([]suite.Authorization, 0, len(f.Cases)) |
| for _, c := range f.Cases { |
| pairs = append(pairs, suite.ItemRevision{ItemID: c.ItemID, Revision: c.Revision}) |
| + want = append(want, suite.UNKNOWN) |
| } |
| - askS2(h, f, r, "the asker's value under the kind this app does not key on", wrong, pairs, |
| - func(suite.CustodyCase) suite.Authorization { return suite.UNKNOWN }) |
| + ask(h, r, "the asker's value under the kind this app does not key on", wrong, pairs, want) |
| } |
| // Gate 3, the content half. Since revision 10 (Paul, 2026-11-01) every live |
| @@ -125,12 +216,14 @@ func checkS3(h http.Handler, f suite.CustodyFixture, r *Report) { |
| r.fail("S3 for an item that does not exist: got %d, want 404", baseline.Code) |
| } |
| - // Only the current revision is ever served: a consumer asking for |
| - // revision 6 or 8 of an item now at 7 gets the refusal, not today's |
| - // bytes under another number (Astra, 2026-11-01: the reference server |
| - // served the older one; a mutant serving the newer one passed). |
| + // Only the current revision is ever served: a consumer asking for a |
| + // revision the log holds but has moved past, or one it never issued, |
| + // gets the refusal, not today's bytes under another name (Astra, |
| + // 2026-11-01: the reference server served the older one; a mutant |
| + // serving the newer one passed). Since revision 11 the fixture names |
| + // both revisions; the harness computes neither. |
| for _, c := range f.Cases { |
| - for _, rev := range []int64{c.Revision - 1, c.Revision + 1} { |
| + for _, rev := range []int64{c.PriorRevision, c.UnknownRevision} { |
| rec := do(h, "GET", suite.RouteS3+"/"+c.ItemID+"?revision="+strconv.FormatInt(rev, 10), nil) |
| r.Checked++ |
| if refusal(rec) != refusal(baseline) { |
| @@ -138,6 +231,26 @@ func checkS3(h http.Handler, f suite.CustodyFixture, r *Report) { |
| c.ItemID, rev, c.Revision, refusal(rec), refusal(baseline)) |
| } |
| } |
| + // No revision, a malformed one and one under 1 are the same refusal |
| + // (Fable, review of c38e3ad, M5): a server that read a missing |
| + // revision as "the current one" serves bytes nobody named, and one |
| + // that answered 400 tells the caller the item exists. |
| + for what, query := range map[string]string{"no revision": "", "a malformed revision": "?revision=seven", "revision 0": "?revision=0"} { |
| + rec := do(h, "GET", suite.RouteS3+"/"+c.ItemID+query, nil) |
| + r.Checked++ |
| + if refusal(rec) != refusal(baseline) { |
| + r.fail("S3 %s with %s: %s, want the refusal for an item that does not exist (%s)", |
| + c.ItemID, what, refusal(rec), refusal(baseline)) |
| + } |
| + } |
| + // S3 is a GET. A POST is not served, whatever it is answered with. |
| + if c.S3Status == 200 { |
| + rec := do(h, "POST", suite.RouteS3+"/"+c.ItemID+"?revision="+strconv.FormatInt(c.Revision, 10), nil) |
| + r.Checked++ |
| + if rec.Code >= 200 && rec.Code <= 299 || strings.Contains(rec.Body.String(), c.S3Body) { |
| + r.fail("S3 %s on POST: %d, and S3 serves a GET only", c.ItemID, rec.Code) |
| + } |
| + } |
| } |
| for _, c := range f.Cases { |
| @@ -180,43 +293,58 @@ func checkS3(h http.Handler, f suite.CustodyFixture, r *Report) { |
| // grant, and never a link. The fixture's asker owns one private item, holds a |
| // grant on another and a former grant on a deleted one, and does not own the |
| // link-shared and moved-to-private items, so each part of the check shows. |
| +// |
| +// Since revision 11 the revisions asked about are the fixture's own: its |
| +// prior_revision (one the log holds, not current) and its unknown_revision |
| +// (one the log never issued). The harness computes no "one behind": a |
| +// revision is a name, and a producer comparing numbers is the one a restore |
| +// turns into a leak (doctrine §6.6). |
| func checkS2(h http.Handler, f suite.CustodyFixture, r *Report) { |
| - // Three questions, not one. A single question at the current revision for |
| - // a single person lets a server answer from the rung alone and read |
| + // Several questions, not one. A single question at the current revision |
| + // for a single person lets a server answer from the rung alone and read |
| // neither the asker nor the revision it was sent. |
| - current := make([]suite.ItemRevision, 0, len(f.Cases)) |
| - behind := make([]suite.ItemRevision, 0, len(f.Cases)) |
| - for _, c := range f.Cases { |
| - current = append(current, suite.ItemRevision{ItemID: c.ItemID, Revision: c.Revision}) |
| - behind = append(behind, suite.ItemRevision{ItemID: c.ItemID, Revision: c.Revision - 1}) |
| + at := func(rev func(suite.CustodyCase) int64, want func(suite.CustodyCase) suite.Authorization) ([]suite.ItemRevision, []suite.Authorization) { |
| + pairs := make([]suite.ItemRevision, 0, len(f.Cases)) |
| + wants := make([]suite.Authorization, 0, len(f.Cases)) |
| + for _, c := range f.Cases { |
| + pairs = append(pairs, suite.ItemRevision{ItemID: c.ItemID, Revision: rev(c)}) |
| + wants = append(wants, want(c)) |
| + } |
| + return pairs, wants |
| } |
| + current := func(c suite.CustodyCase) int64 { return c.Revision } |
| + prior := func(c suite.CustodyCase) int64 { return c.PriorRevision } |
| + unknown := func(c suite.CustodyCase) int64 { return c.UnknownRevision } |
| + stranger := func(c suite.CustodyCase) suite.Authorization { return c.S2ResultStranger } |
| - askS2(h, f, r, "the fixture's asker, at the current revision", f.Asker, current, |
| - func(c suite.CustodyCase) suite.Authorization { return c.S2Result }) |
| + pairs, want := at(current, func(c suite.CustodyCase) suite.Authorization { return c.S2Result }) |
| + ask(h, r, "the fixture's asker, at the current revision", f.Asker, pairs, want) |
| + pairs, want = at(prior, func(c suite.CustodyCase) suite.Authorization { return c.S2ResultSuperseded }) |
| + ask(h, r, "the fixture's asker, at a prior revision the log holds", f.Asker, pairs, want) |
| + pairs, want = at(unknown, func(c suite.CustodyCase) suite.Authorization { return c.S2ResultAhead }) |
| + ask(h, r, "the fixture's asker, at a revision the log never issued", f.Asker, pairs, want) |
| - askS2(h, f, r, "the fixture's asker, one revision behind", f.Asker, behind, |
| - func(c suite.CustodyCase) suite.Authorization { return c.S2ResultSuperseded }) |
| + // The stranger at every revision: a server that checks the revision |
| + // before the person tells a stranger STALE or UNKNOWN where it owes |
| + // them NOT_VISIBLE (Astra, 2026-11-01). |
| + pairs, want = at(current, stranger) |
| + ask(h, r, "a person with no team standing", f.Stranger, pairs, want) |
| + pairs, want = at(prior, stranger) |
| + ask(h, r, "a person with no team standing, at a prior revision", f.Stranger, pairs, want) |
| + pairs, want = at(unknown, stranger) |
| + ask(h, r, "a person with no team standing, at a revision never issued", f.Stranger, pairs, want) |
| - ahead := make([]suite.ItemRevision, 0, len(f.Cases)) |
| - for _, c := range f.Cases { |
| - ahead = append(ahead, suite.ItemRevision{ItemID: c.ItemID, Revision: c.Revision + 1}) |
| - } |
| - askS2(h, f, r, "the fixture's asker, one revision ahead", f.Asker, ahead, |
| - func(c suite.CustodyCase) suite.Authorization { return c.S2ResultAhead }) |
| - |
| - askS2(h, f, r, "a person with no team standing", f.Stranger, current, |
| - func(c suite.CustodyCase) suite.Authorization { return c.S2ResultStranger }) |
| - |
| - // The stranger at the other revisions too: a server that checks the |
| - // revision before the person tells a stranger STALE where it owes them |
| - // NOT_VISIBLE (Astra, 2026-11-01). |
| - askS2(h, f, r, "a person with no team standing, one revision behind", f.Stranger, behind, |
| - func(c suite.CustodyCase) suite.Authorization { return c.S2ResultStranger }) |
| - askS2(h, f, r, "a person with no team standing, one revision ahead", f.Stranger, ahead, |
| - func(c suite.CustodyCase) suite.Authorization { return c.S2ResultStranger }) |
| + // An id the producer does not know is NOT_VISIBLE for everybody. A |
| + // server that fails open — VISIBLE for whatever it cannot find — passes |
| + // every fixture case, because every fixture case exists (Fable, review |
| + // of c38e3ad, H2). |
| + none := []suite.ItemRevision{{ItemID: suite.NonexistentItemID, Revision: 1}} |
| + ask(h, r, "the fixture's asker, about an id the app does not know", f.Asker, none, []suite.Authorization{suite.NOT_VISIBLE}) |
| + ask(h, r, "a person with no team standing, about an id the app does not know", f.Stranger, none, []suite.Authorization{suite.NOT_VISIBLE}) |
| } |
| -func askS2(h http.Handler, f suite.CustodyFixture, r *Report, what string, asker suite.Subject, pairs []suite.ItemRevision, want func(suite.CustodyCase) suite.Authorization) { |
| +// ask puts one S2 question and holds each answer to want, pair by pair. |
| +func ask(h http.Handler, r *Report, what string, asker suite.Subject, pairs []suite.ItemRevision, want []suite.Authorization) { |
| if err := suite.CheckS2Batch(pairs); err != nil { |
| r.fail("custody fixture is over the S2 cap: %v", err) |
| return |
| @@ -229,12 +357,14 @@ func askS2(h http.Handler, f suite.CustodyFixture, r *Report, what string, asker |
| } |
| rec := do(h, "POST", suite.RouteS2, body) |
| + // DecodeS2 is strict: a row carrying anything beyond item_id, revision |
| + // and result makes the whole call UNKNOWN, and fails here. |
| got := suite.DecodeS2(pairs, rec.Code, rec.Body.Bytes()) |
| - for i, c := range f.Cases { |
| + for i, p := range pairs { |
| r.Checked++ |
| - if got[i] != want(c) { |
| - r.fail("S2 %s asked for %s: got %s, want %s", c.ItemID, what, got[i], want(c)) |
| + if got[i] != want[i] { |
| + r.fail("S2 %s asked for %s: got %s, want %s", p.ItemID, what, got[i], want[i]) |
| } |
| } |
| } |
| @@ -280,6 +410,19 @@ func checkS1(h http.Handler, f suite.CustodyFixture, r *Report) { |
| } |
| cursor = feed.Cursor |
| } |
| + |
| + // A cursor the log does not recognise — restored from a backup, or |
| + // issued by another log — is the fixed 409, which tells the consumer to |
| + // drop what it holds and read from the beginning. Answered as the tip, |
| + // it leaves a consumer holding a dead log's items for ever; answered as |
| + // a failure, it stalls the consumer for ever (Fable, review of c38e3ad, |
| + // H1; doctrine §6.6). |
| + rec := do(h, "GET", suite.RouteS1+"?cursor="+url.QueryEscape(suite.NeverIssuedCursor), nil) |
| + r.Checked++ |
| + if _, err := suite.DecodeS1(rec.Code, rec.Body.Bytes()); !errors.Is(err, suite.ErrCursorReset) { |
| + r.fail("S1 with a cursor the log never issued: %d %q, want %d %s", rec.Code, rec.Body.String(), suite.CursorResetStatus, suite.CursorResetBody) |
| + } |
| + |
| for _, c := range f.Cases { |
| r.Checked++ |
| row, ok := last[c.ItemID] |
diff --git a/conformance/conformance_test.go b/conformance/conformance_test.go| index d3882ea..eb8dfc8 100644 |
| --- a/conformance/conformance_test.go |
| +++ b/conformance/conformance_test.go |
| @@ -39,6 +39,19 @@ type referenceServer struct { |
| stuckWithRows bool // the same cursor back, with rows |
| reservedCursor bool // cursors that need query escaping (correct) |
| repeatEarlierRow bool // an item's last row older than its current revision |
| + |
| + // Revision 11 (Fable's review of c38e3ad). |
| + numericRevisions bool // STALE for any revision below current, held in the log or not |
| + failOpen bool // VISIBLE for an id it does not know |
| + ownerBeforeStanding bool // an owner who lost team standing still opens their item |
| + titleInS2Row bool // an S2 row carrying the item's title |
| + missingRevisionIsNow bool // S3 with no ?revision serves the current bytes |
| + malformedRevision400 bool // S3 answers 400 for a malformed revision |
| + s3ServesPost bool // S3 serves a POST |
| + foreignCursorIsTip bool // a cursor the log never issued answered as the tip |
| + foreignCursorFails bool // a cursor the log never issued answered 503 |
| + cacheable bool // no Cache-Control: no-store |
| + noVary bool // no-store, and no Vary: Authorization |
| } |
| func (s *referenceServer) find(itemID string) (suite.CustodyCase, bool) { |
| @@ -51,15 +64,21 @@ func (s *referenceServer) find(itemID string) (suite.CustodyCase, bool) { |
| } |
| func (s *referenceServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| + if !s.cacheable { |
| + w.Header().Set("Cache-Control", "no-store") |
| + if !s.noVary { |
| + w.Header().Set("Vary", "Authorization") |
| + } |
| + } |
| switch { |
| - case strings.HasPrefix(r.URL.Path, suite.RouteS3+"/"): |
| + case strings.HasPrefix(r.URL.Path, suite.RouteS3+"/") && (r.Method == "GET" || s.s3ServesPost): |
| s.serveS3(w, r) |
| - case r.URL.Path == suite.RouteS2: |
| + case r.URL.Path == suite.RouteS2 && r.Method == "POST": |
| s.serveS2(w, r) |
| - case r.URL.Path == suite.RouteS1: |
| + case r.URL.Path == suite.RouteS1 && r.Method == "GET": |
| s.serveS1(w, r) |
| default: |
| - http.NotFound(w, r) |
| + w.WriteHeader(http.StatusMethodNotAllowed) |
| } |
| } |
| @@ -78,7 +97,15 @@ func (s *referenceServer) serveS3(w http.ResponseWriter, r *http.Request) { |
| } |
| // Revision 10: every live item is held, so every live item is served — |
| // at its current revision only. |
| - rev, _ := strconv.ParseInt(r.URL.Query().Get("revision"), 10, 64) |
| + raw := r.URL.Query().Get("revision") |
| + rev, err := strconv.ParseInt(raw, 10, 64) |
| + if raw == "" && s.missingRevisionIsNow { |
| + rev = c.Revision |
| + } |
| + if raw != "" && err != nil && s.malformedRevision400 { |
| + w.WriteHeader(400) |
| + return |
| + } |
| if c.Rung != suite.RungDeleted && (rev == c.Revision || (s.serveSuperseded && rev < c.Revision) || (s.serveFuture && rev > c.Revision)) { |
| w.WriteHeader(200) |
| if s.wrongBodyForTeamItem { |
| @@ -113,6 +140,7 @@ func (s *referenceServer) serveS2(w http.ResponseWriter, r *http.Request) { |
| ItemID string `json:"item_id"` |
| Revision int64 `json:"revision"` |
| Result suite.Authorization `json:"result"` |
| + Title string `json:"title,omitempty"` |
| } |
| out := struct { |
| Results []result `json:"results"` |
| @@ -137,6 +165,11 @@ func (s *referenceServer) serveS2(w http.ResponseWriter, r *http.Request) { |
| if c.Rung == suite.RungDeleted { |
| return false |
| } |
| + if stranger { |
| + // No team standing reaches nothing, ownership included |
| + // (revision 11). |
| + return s.ownerBeforeStanding && c.Owner == "stranger" |
| + } |
| if s.linkCountsAsGrant && c.Link != "" { |
| return true |
| } |
| @@ -152,6 +185,9 @@ func (s *referenceServer) serveS2(w http.ResponseWriter, r *http.Request) { |
| switch { |
| case !ok: |
| answer = suite.NOT_VISIBLE |
| + if s.failOpen { |
| + answer = suite.VISIBLE |
| + } |
| case s.ignoreAskerAndRevision: |
| // Answers from the rung alone: any asker, any revision. This is |
| @@ -163,24 +199,32 @@ func (s *referenceServer) serveS2(w http.ResponseWriter, r *http.Request) { |
| case stranger && s.revisionBeforePerson && p.Revision < c.Revision: |
| answer = suite.STALE |
| - case stranger: |
| - // No team standing reaches nothing, the team rung included. |
| + case !mayOpen(c): |
| answer = suite.NOT_VISIBLE |
| - case mayOpen(c) && p.Revision < c.Revision: |
| + case p.Revision == c.Revision: |
| + answer = suite.VISIBLE |
| + |
| + case p.Revision == c.PriorRevision: |
| + // In the log, and not current (§6.6): decided from the log. |
| answer = suite.STALE |
| - case mayOpen(c) && p.Revision > c.Revision: |
| - // A revision the log does not recognise (§4.3). |
| - answer = suite.UNKNOWN |
| - if s.staleWhenAhead { |
| - answer = suite.STALE |
| - } |
| + case s.numericRevisions && p.Revision < c.Revision: |
| + // The counter's habit: below current reads as "older". |
| + answer = suite.STALE |
| - case mayOpen(c): |
| - answer = suite.VISIBLE |
| + case s.staleWhenAhead && p.Revision > c.Revision: |
| + answer = suite.STALE |
| + |
| + default: |
| + // A revision the log does not hold (§4.3, §6.6). |
| + answer = suite.UNKNOWN |
| + } |
| + row := result{ItemID: p.ItemID, Revision: p.Revision, Result: answer} |
| + if s.titleInS2Row && ok { |
| + row.Title = c.Name |
| } |
| - out.Results = append(out.Results, result{ItemID: p.ItemID, Revision: p.Revision, Result: answer}) |
| + out.Results = append(out.Results, row) |
| } |
| w.Header().Set("Content-Type", "application/json") |
| @@ -211,27 +255,35 @@ func (s *referenceServer) serveS1(w http.ResponseWriter, r *http.Request) { |
| half := len(rows) / 2 |
| var page []map[string]any |
| next := cursor |
| - switch cursor { |
| - case "": |
| - page, next = rows[:half], "c-1" |
| - case "c-1": |
| - page, next = rows[half:], "c-2" |
| - default: |
| - page = []map[string]any{} |
| - } |
| + issued := []string{"", "c-1", "c-2"} |
| if s.reservedCursor { |
| // A cursor with characters a query string must escape. A harness |
| // that sent it unescaped would read "c 1&x=y" as "c 1". |
| - switch cursor { |
| - case "": |
| - page, next = rows[:half], "c 1&x=y" |
| - case "c 1&x=y": |
| - page, next = rows[half:], "c+2#end" |
| - default: |
| + issued = []string{"", "c 1&x=y", "c+2#end"} |
| + } |
| + switch cursor { |
| + case issued[0]: |
| + page, next = rows[:half], issued[1] |
| + case issued[1]: |
| + page, next = rows[half:], issued[2] |
| + case issued[2]: |
| + page = []map[string]any{} |
| + default: |
| + // A cursor this log never issued (§6.6, revision 11). |
| + switch { |
| + case s.foreignCursorIsTip: |
| page = []map[string]any{} |
| + case s.foreignCursorFails: |
| + w.WriteHeader(503) |
| + return |
| + default: |
| + w.Header().Set("Content-Type", "application/json") |
| + w.WriteHeader(suite.CursorResetStatus) |
| + w.Write([]byte(suite.CursorResetBody)) |
| + return |
| } |
| } |
| - if s.repeatEarlierRow && cursor == "c-1" { |
| + if s.repeatEarlierRow && cursor == issued[1] { |
| // The second page repeats an item from the first at an older |
| // revision: the item's state is its LAST row, and it is stale. |
| stale := map[string]any{} |
| @@ -244,7 +296,7 @@ func (s *referenceServer) serveS1(w http.ResponseWriter, r *http.Request) { |
| if s.neverEnds { |
| next = cursor + "x" |
| } |
| - if s.stuckWithRows && cursor == "c-1" { |
| + if s.stuckWithRows && cursor == issued[1] { |
| next = cursor |
| } |
| w.Header().Set("Content-Type", "application/json") |
| @@ -438,3 +490,40 @@ func TestHarnessRound3(t *testing.T) { |
| t.Error("an address-keyed server ignoring the kind passed") |
| } |
| } |
| + |
| +// Fable's review of c38e3ad (revision 11): each a broken server the harness |
| +// must refuse. The reference server above passes; each bend breaks one rule. |
| +// |
| +// MUTATION-TESTED 2026-11-01 on the harness, each reverted, by the bend that |
| +// then passed: the S2 questions at the fixture's unknown_revision replaced |
| +// by Revision+1 → "revisions compared as numbers"; the NonexistentItemID |
| +// questions removed → "an unknown id answered VISIBLE"; DecodeS2's |
| +// DisallowUnknownFields removed → "a title in an S2 row"; the |
| +// missing/malformed S3 loop removed → "no revision serves today's bytes" |
| +// and "a malformed revision answered 400"; the POST probe removed → "S3 |
| +// served on POST"; the foreign-cursor probe removed → both foreign-cursor |
| +// bends; storeAudit's header check removed → "a cacheable response", and |
| +// its Vary half alone → "no Vary: Authorization". (The stranger questions at |
| +// prior and unknown revisions removed → "STALE for a stranger", in the test |
| +// above.) |
| +func TestHarnessCatchesWhatRevision10Missed(t *testing.T) { |
| + for name, bend := range map[string]func(*referenceServer){ |
| + "revisions compared as numbers": func(s *referenceServer) { s.numericRevisions = true }, |
| + "an unknown id answered VISIBLE": func(s *referenceServer) { s.failOpen = true }, |
| + "an owner without standing": func(s *referenceServer) { s.ownerBeforeStanding = true }, |
| + "a title in an S2 row": func(s *referenceServer) { s.titleInS2Row = true }, |
| + "no revision serves today's bytes": func(s *referenceServer) { s.missingRevisionIsNow = true }, |
| + "a malformed revision answered 400": func(s *referenceServer) { s.malformedRevision400 = true }, |
| + "S3 served on POST": func(s *referenceServer) { s.s3ServesPost = true }, |
| + "a foreign cursor answered as the tip": func(s *referenceServer) { s.foreignCursorIsTip = true }, |
| + "a foreign cursor answered 503": func(s *referenceServer) { s.foreignCursorFails = true }, |
| + "a cacheable response": func(s *referenceServer) { s.cacheable = true }, |
| + "no Vary: Authorization": func(s *referenceServer) { s.noVary = true }, |
| + } { |
| + s := newReference(t) |
| + bend(s) |
| + if report := conformance.Check(s); len(report.Failures) == 0 { |
| + t.Errorf("%s: the harness passed it", name) |
| + } |
| + } |
| +} |
diff --git a/fixtures.go b/fixtures.go| index 82b4bca..beac5cd 100644 |
| --- a/fixtures.go |
| +++ b/fixtures.go |
| @@ -28,7 +28,9 @@ type S2Request struct { |
| // Rung is where an item sits on the sharing ladder (§4.2, ruling 15). A link |
| // is not a rung; it is a read-only capability that any rung may carry, and |
| -// custody keys on the rung alone. |
| +// who may open an item keys on the rung (with ownership and grants), never |
| +// on the link. Since revision 10 the rung no longer bounds what a consumer |
| +// holds; it decides S2. |
| type Rung string |
| const ( |
| @@ -48,10 +50,12 @@ type CustodyCase struct { |
| Revision int64 `json:"revision"` |
| Rung Rung `json:"rung"` |
| Link string `json:"link"` |
| - // Owner is "asker" when the fixture's asker owns the item and "other" |
| - // when somebody else does; AskerGrant is whether the asker holds a live |
| - // individual grant on it. Together with Rung they are what an app seeds |
| - // so its own read check produces the S2 answers below (revision 10). |
| + // Owner is "asker" when the fixture's asker owns the item, "other" when |
| + // another member does, and "stranger" when the fixture's stranger does — |
| + // a person who owned it as a member and has since lost team standing |
| + // (revision 11). AskerGrant is whether the asker holds a live individual |
| + // grant on it. Together with Rung they are what an app seeds so its own |
| + // read check produces the S2 answers below (revision 10). |
| Owner string `json:"owner"` |
| AskerGrant bool `json:"asker_grant"` |
| S3Status int `json:"s3_status"` |
| @@ -61,13 +65,29 @@ type CustodyCase struct { |
| // body, or return a 200 carrying a different item entirely. |
| S3Body string `json:"s3_body"` |
| S2Result Authorization `json:"s2_result"` |
| - // S2ResultSuperseded is the answer when the same item is asked about one |
| - // revision behind. A team item is STALE — readable, but the app of record |
| - // has moved on — and anything custody already refuses stays refused. |
| + // PriorRevision is a revision the item's log holds that is not its |
| + // current one: an app seeds its log with it before Revision. It is |
| + // Revision - 1 in every case, so an app that seeded "one behind" before |
| + // revision 11 seeds the same log, but the harness reads it from here and |
| + // never computes it — a revision is a name, and a producer whose |
| + // revisions are random has no "one behind" (doctrine §6.6, revision 11). |
| + PriorRevision int64 `json:"prior_revision"` |
| + // UnknownRevision is a revision the item's log never issued. Most cases |
| + // put it BELOW Revision and away from PriorRevision, so a producer that |
| + // decides STALE by comparing numbers — the counter's habit, which is |
| + // what a restore turns into a leak — answers STALE where it owes |
| + // UNKNOWN; the rest put it above, so one that says STALE for anything |
| + // not current fails too. An app must never issue it while seeding. |
| + UnknownRevision int64 `json:"unknown_revision"` |
| + // S2ResultSuperseded is the answer at PriorRevision: STALE for a person |
| + // who may open the item — readable, but the app of record has moved on — |
| + // and NOT_VISIBLE for one who may not. (The name is revision 9's; the |
| + // module is additive.) |
| S2ResultSuperseded Authorization `json:"s2_result_superseded"` |
| - // S2ResultAhead is the answer one revision ahead of the app's own: a |
| - // revision its log does not recognise. UNKNOWN for a person who may open |
| - // the item (§4.3), NOT_VISIBLE for one who may not. |
| + // S2ResultAhead is the answer at UnknownRevision, a revision the log |
| + // does not hold: UNKNOWN for a person who may open the item (§4.3), |
| + // NOT_VISIBLE for one who may not. (Named when the harness asked one |
| + // revision ahead; since revision 11 it asks at UnknownRevision.) |
| S2ResultAhead Authorization `json:"s2_result_ahead"` |
| // S2ResultStranger is the answer for a person with no team standing. |
| S2ResultStranger Authorization `json:"s2_result_stranger"` |
| @@ -75,17 +95,27 @@ type CustodyCase struct { |
| // NonexistentItemID is never in the fixture. A refusal for an item that does |
| // not exist has to be byte-for-byte the refusal for one that was deleted, so |
| -// a consumer cannot tell a deletion from an id it made up. (Before revision |
| -// 10 the same held for every item that was not team-visible.) |
| +// a consumer cannot tell a deletion from an id it made up, and S2 answers it |
| +// NOT_VISIBLE for everybody — never VISIBLE, which is a producer failing |
| +// open (revision 11). (Before revision 10 the S3 rule held for every item |
| +// that was not team-visible.) |
| const NonexistentItemID = "doc-no-such-item-ever" |
| -// CustodyFixture is gate 3's world: one case per rung, plus team-plus-link and |
| -// the after-ingest transitions the reviews asked for. |
| +// NeverIssuedCursor is a cursor no producer issued. S1 answers it with the |
| +// cursor reset (CursorResetStatus, CursorResetBody), never as the tip and |
| +// never as a failure (doctrine §6.6, revision 11). A producer must not issue |
| +// it. |
| +const NeverIssuedCursor = "suite-conformance-cursor-never-issued" |
| + |
| +// CustodyFixture is gate 3's world: one case per rung, plus team-plus-link, |
| +// the after-ingest transitions the reviews asked for, and (revision 11) a |
| +// private item whose owner has since lost team standing. |
| type CustodyFixture struct { |
| Team string `json:"team"` |
| Asker Subject `json:"asker"` |
| - // Stranger has no team standing. Every case refuses them, the team-visible |
| - // ones included: team standing is what makes a team item readable. |
| + // Stranger has no team standing. Every case refuses them, the team rung |
| + // and the one they own included: without team standing a person reaches |
| + // nothing, ownership included (revision 11, this session's proposal). |
| Stranger Subject `json:"stranger"` |
| Cases []CustodyCase `json:"cases"` |
| } |
| @@ -96,6 +126,10 @@ func LoadCustodyFixture() (CustodyFixture, error) { |
| if err != nil { |
| return CustodyFixture{}, fmt.Errorf("suite: reading custody fixture: %w", err) |
| } |
| + return parseCustodyFixture(raw) |
| +} |
| + |
| +func parseCustodyFixture(raw []byte) (CustodyFixture, error) { |
| var f CustodyFixture |
| if err := json.Unmarshal(raw, &f); err != nil { |
| return CustodyFixture{}, fmt.Errorf("suite: parsing custody fixture: %w", err) |
| @@ -103,5 +137,14 @@ func LoadCustodyFixture() (CustodyFixture, error) { |
| if len(f.Cases) == 0 { |
| return CustodyFixture{}, fmt.Errorf("suite: custody fixture has no cases") |
| } |
| + for _, c := range f.Cases { |
| + // Three distinct names, each one S2 and S3 would accept: a fixture |
| + // whose prior or unknown revision is the current one, or under 1, |
| + // asks nothing it claims to ask. |
| + if c.Revision < 1 || c.PriorRevision < 1 || c.UnknownRevision < 1 || |
| + c.PriorRevision == c.Revision || c.UnknownRevision == c.Revision || c.UnknownRevision == c.PriorRevision { |
| + 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) |
| + } |
| + } |
| return f, nil |
| } |
diff --git a/fixtures/custody.json b/fixtures/custody.json| index 1ec285e..6cfe521 100644 |
| --- a/fixtures/custody.json |
| +++ b/fixtures/custody.json |
| @@ -9,8 +9,8 @@ |
| "team-visible ones. A consumer holds private and granted items too, and", |
| "S2 decides per person, from the app's own read check, with no", |
| "intersection with custody. So every live item answers S3 200 with its", |
| - "own bytes; only a deleted item, and one that never existed, answer the", |
| - "identical 404.", |
| + "own bytes at its current revision; a deleted item, one that never", |
| + "existed, and any revision that is not current answer the identical 404.", |
| "", |
| "The asker is the same person for every case, and the item id is quoted", |
| "in every case, so a server cannot pass by answering differently for", |
| @@ -20,10 +20,24 @@ |
| "asker may open the item today; the rung decides that only through the", |
| "app's own read check.", |
| "", |
| - "s2_result_ahead is the answer one revision AHEAD of the app's own: a", |
| - "revision its log does not recognise is UNKNOWN for a person who may", |
| - "open the item (§4.3), and NOT_VISIBLE for one who may not — a person", |
| - "with no right to the item learns nothing about its revisions." |
| + "REVISION 11 (this session, 2026-11-01, answering Fable's review of", |
| + "c38e3ad): revisions are names, not counts (doctrine §6.6). Each case", |
| + "carries prior_revision — a revision its log holds that is not current —", |
| + "and unknown_revision — one its log never issued. An app seeds its log", |
| + "with prior_revision then revision, and never issues unknown_revision.", |
| + "s2_result_superseded is the answer at prior_revision: STALE for a person", |
| + "who may open the item, NOT_VISIBLE for one who may not.", |
| + "s2_result_ahead is the answer at unknown_revision: UNKNOWN for a person", |
| + "who may open the item (§4.3), NOT_VISIBLE for one who may not — a person", |
| + "with no right to the item learns nothing about its revisions. Most", |
| + "unknown revisions sit BELOW the current one, so a producer comparing", |
| + "numbers (the counter's habit) says STALE where it owes UNKNOWN. Both S3", |
| + "revisions are refused with the identical 404.", |
| + "", |
| + "owner \"stranger\" (doc-owner-left, revision 11, this session's proposal):", |
| + "the item's owner has lost team standing. They get NOT_VISIBLE like every", |
| + "stranger: without team standing a person reaches nothing, ownership", |
| + "included." |
| ], |
| "team": "acme", |
| "asker": { |
| @@ -40,6 +54,8 @@ |
| "item_id": "doc-team", |
| "s3_body": "the Q3 plan, shared with the whole team", |
| "revision": 7, |
| + "prior_revision": 6, |
| + "unknown_revision": 5, |
| "rung": "team", |
| "link": null, |
| "owner": "other", |
| @@ -55,6 +71,8 @@ |
| "item_id": "doc-private", |
| "s3_body": "my own notes, private to me", |
| "revision": 4, |
| + "prior_revision": 3, |
| + "unknown_revision": 2, |
| "rung": "private", |
| "link": null, |
| "owner": "asker", |
| @@ -70,6 +88,8 @@ |
| "item_id": "doc-granted", |
| "s3_body": "the board pack, shared with me by name", |
| "revision": 9, |
| + "prior_revision": 8, |
| + "unknown_revision": 10, |
| "rung": "granted", |
| "link": null, |
| "owner": "other", |
| @@ -85,6 +105,8 @@ |
| "item_id": "doc-guest", |
| "s3_body": "the contractor brief, shared with a guest only", |
| "revision": 2, |
| + "prior_revision": 1, |
| + "unknown_revision": 3, |
| "rung": "granted", |
| "link": null, |
| "owner": "other", |
| @@ -100,6 +122,8 @@ |
| "item_id": "doc-link", |
| "s3_body": "the press draft, private with a read link", |
| "revision": 5, |
| + "prior_revision": 4, |
| + "unknown_revision": 6, |
| "rung": "private", |
| "link": "read", |
| "owner": "other", |
| @@ -115,6 +139,8 @@ |
| "item_id": "doc-team-link", |
| "s3_body": "the launch checklist, team-shared and link-shared", |
| "revision": 3, |
| + "prior_revision": 2, |
| + "unknown_revision": 1, |
| "rung": "team", |
| "link": "read", |
| "owner": "other", |
| @@ -130,6 +156,8 @@ |
| "item_id": "doc-deleted", |
| "s3_body": "", |
| "revision": 6, |
| + "prior_revision": 5, |
| + "unknown_revision": 7, |
| "rung": "deleted", |
| "link": null, |
| "owner": "other", |
| @@ -145,6 +173,8 @@ |
| "item_id": "doc-was-team", |
| "s3_body": "the old roadmap, moved back to private", |
| "revision": 8, |
| + "prior_revision": 7, |
| + "unknown_revision": 9, |
| "rung": "private", |
| "link": null, |
| "owner": "other", |
| @@ -160,6 +190,8 @@ |
| "item_id": "doc-link-added-late", |
| "s3_body": "the hiring plan, private, link added later", |
| "revision": 11, |
| + "prior_revision": 10, |
| + "unknown_revision": 12, |
| "rung": "private", |
| "link": "read", |
| "owner": "other", |
| @@ -169,6 +201,23 @@ |
| "s2_result_superseded": "NOT_VISIBLE", |
| "s2_result_ahead": "NOT_VISIBLE", |
| "s2_result_stranger": "NOT_VISIBLE" |
| + }, |
| + { |
| + "name": "private, owned by a member who has since lost team standing", |
| + "item_id": "doc-owner-left", |
| + "s3_body": "the old offsite notes, private to a former member", |
| + "revision": 12, |
| + "prior_revision": 11, |
| + "unknown_revision": 10, |
| + "rung": "private", |
| + "link": null, |
| + "owner": "stranger", |
| + "asker_grant": false, |
| + "s3_status": 200, |
| + "s2_result": "NOT_VISIBLE", |
| + "s2_result_superseded": "NOT_VISIBLE", |
| + "s2_result_ahead": "NOT_VISIBLE", |
| + "s2_result_stranger": "NOT_VISIBLE" |
| } |
| ] |
| } |
diff --git a/fixtures_test.go b/fixtures_test.go| index 1af7858..77f39e2 100644 |
| --- a/fixtures_test.go |
| +++ b/fixtures_test.go |
| @@ -61,3 +61,35 @@ func TestHostileHostFixture(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// The custody fixture names three distinct revisions per case, each one S2 |
| +// and S3 would accept (revision 11). A case whose prior or unknown revision |
| +// is its current one would ask the harness's questions of nothing. |
| +// |
| +// MUTATION-TESTED 2026-11-01, reverted: the loader's revision check removed |
| +// → every bad case below accepted. |
| +func TestCustodyFixtureRevisionsAreDistinct(t *testing.T) { |
| + f, err := LoadCustodyFixture() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, c := range f.Cases { |
| + if c.PriorRevision != c.Revision-1 { |
| + // Docs and Fichas seed "one behind" before revision 11; keeping |
| + // prior at Revision - 1 keeps their seeding correct. |
| + t.Errorf("%s: prior_revision %d, want %d", c.ItemID, c.PriorRevision, c.Revision-1) |
| + } |
| + } |
| + for name, rv := range map[string]string{ |
| + "prior is current": `"revision":7,"prior_revision":7,"unknown_revision":5`, |
| + "unknown is current": `"revision":7,"prior_revision":6,"unknown_revision":7`, |
| + "unknown is prior": `"revision":7,"prior_revision":6,"unknown_revision":6`, |
| + "prior missing": `"revision":7,"unknown_revision":5`, |
| + "unknown under 1": `"revision":7,"prior_revision":6,"unknown_revision":0`, |
| + } { |
| + raw := `{"cases":[{"item_id":"doc-x",` + rv + `}]}` |
| + if _, err := parseCustodyFixture([]byte(raw)); err == nil { |
| + t.Errorf("%s: accepted", name) |
| + } |
| + } |
| +} |
diff --git a/server/server_test.go b/server/server_test.go| index 9ab8c37..5ccc190 100644 |
| --- a/server/server_test.go |
| +++ b/server/server_test.go |
| @@ -104,7 +104,7 @@ func (p *fixtureProducer) Rule(_ context.Context, asker suite.Subject, pairs []s |
| out = append(out, suite.NOT_VISIBLE) |
| case pr.Revision == c.Revision: |
| out = append(out, suite.VISIBLE) |
| - case pr.Revision == c.Revision-1: |
| + case pr.Revision == c.PriorRevision: |
| out = append(out, suite.STALE) |
| default: |
| out = append(out, suite.UNKNOWN) |
| @@ -161,10 +161,19 @@ func do(h http.Handler, method, url, tok string, body []byte) *httptest.Response |
| } |
| // The routes this package serves pass the doctrine's own harness, driven |
| -// through a producer that only knows the fixture. The harness never sends a |
| -// malformed revision or an unauthenticated request, which is why the tests |
| -// below exist beside it. |
| +// through a producer that only knows the fixture, mounted as an app mounts |
| +// it: Handler, behind a token (conformance.RunProducer, revision 11). The |
| +// tests below cover what the harness does not send. |
| +// |
| +// MUTATION-TESTED 2026-11-01, reverted: CheckProducer driving the deprecated |
| +// Routes in place of Handler → "a request with no token: got 404". |
| func TestRoutesPassConformance(t *testing.T) { |
| + conformance.RunProducer(t, producer(t), suite.SubjectPersonRef) |
| +} |
| + |
| +// The deprecated Routes still serves what it served, for the apps whose |
| +// tests call it (the module is additive). |
| +func TestDeprecatedRoutesStillConform(t *testing.T) { |
| conformance.Run(t, server.Routes(producer(t), nil)) |
| } |