server (revision 11): cursor reset, no-store on every response, Routes deprecated
- Feed may return server.ErrCursorReset (= suite.ErrCursorReset) for a
cursor its log does not recognise; the package answers S1's fixed 409.
A reset of "" is a 500: it would loop a consumer for ever. Fable H1(b).
- Producer's doc makes revision identity normative: a revision names one
byte sequence for ever; reissue after a restore is non-conformant; STALE
from the log, never by comparing numbers. Fable H1(a).
- Cache-Control: no-store and Vary: Authorization on every response,
401s, the mux's 404/405 and the deprecated Routes included. Fable M3.
- Routes is Deprecated (kept: the module is additive, and Docs' and Fichas'
tests call it); Handler is the only thing an app mounts. Fable M4.
- S2 refuses a pair at revision < 1 (400), as S3 does; a feed row at
revision < 1 is a 500. Tests for the scheme check ("Digest ", seven
bytes), the SHA-256 length and a zero touched_at. Fable L5.
Every new guard mutation-tested; the mutations are recorded in the tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+269
−40
server/consumers.go+5 −2server/server.go+102 −23server/server_test.go+162 −15
diff --git a/server/consumers.go b/server/consumers.go| index b4d0899..1dc77ca 100644 |
| --- a/server/consumers.go |
| +++ b/server/consumers.go |
| @@ -91,8 +91,11 @@ func TokenHash(token string) string { |
| // answers every other one with the same empty 401: no token, a malformed |
| // header, an unknown token and a retired one are indistinguishable. Every |
| // configured hash is compared, in constant time, whatever matched first. |
| +// |
| +// Its 401 carries the same Cache-Control and Vary as every other response |
| +// of this package (noStore). |
| func Authenticate(consumers []Consumer, next http.Handler) http.Handler { |
| - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + return noStore(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| tok, ok := bearer(r) |
| if !ok || tok == "" { |
| w.WriteHeader(http.StatusUnauthorized) |
| @@ -115,5 +118,5 @@ func Authenticate(consumers []Consumer, next http.Handler) http.Handler { |
| return |
| } |
| next.ServeHTTP(w, r.WithContext(contextWithConsumer(r.Context(), match))) |
| - }) |
| + })) |
| } |
diff --git a/server/server.go b/server/server.go| index 037e8b4..4caf8f8 100644 |
| --- a/server/server.go |
| +++ b/server/server.go |
| @@ -4,10 +4,13 @@ |
| // is held. |
| // |
| // An app implements Producer — its feed, its own per-person read check, and |
| -// an item's text — and mounts Handler beside its router. Everything the |
| +// an item's text — and mounts Handler beside its router. Handler is the only |
| +// thing an app mounts; its conformance test is conformance.RunProducer, which |
| +// drives Handler through a bearer token it mints for itself. Everything the |
| // contract fixes and an app could get subtly wrong lives here instead: the |
| -// bearer check, the strict S2 decode and cap, the wire shapes, and the one |
| -// byte-identical refusal S3 gives for anything it will not serve. |
| +// bearer check, the strict S2 decode and cap, the wire shapes, the cache |
| +// headers on every response, the cursor reset, and the one byte-identical |
| +// refusal S3 gives for anything it will not serve. |
| // |
| // Like the rest of the module it has no dependencies beyond the standard |
| // library, so an app's pin chain stays one deep (AGENTS.md). |
| @@ -27,13 +30,32 @@ import ( |
| ) |
| // Producer is an app's half of the contract. |
| +// |
| +// Revisions name bytes for ever (doctrine §6.6, revision 11). An (item, |
| +// revision) a producer has once issued names one byte sequence, and no |
| +// revision is ever issued twice — not after a restore from a backup either. |
| +// A counter or a clock is reissued by a restore: an old revision a consumer |
| +// holds then matches different bytes, and Rule says VISIBLE over text the |
| +// item no longer has. A producer whose revisions can be reissued is not |
| +// conformant. Draw them at random (Docs and Fichas use a random positive |
| +// int63, redrawn on a collision with the current one) and decide STALE from |
| +// the producer's own log, never by comparing numbers. |
| type Producer interface { |
| // Feed returns the rows after cursor — "" is the beginning — at most |
| // limit of them, in the app's own log order, and the cursor to ask from |
| // next. At the tip it returns rows: [] and the SAME cursor it was given |
| // (a consumer stops polling only when the cursor comes back unchanged |
| // with no rows; a fresh cursor at the tip makes it page forever). The |
| - // cursor is opaque and never empty. |
| + // cursor is opaque and never empty, and every row's revision is 1 or |
| + // more. |
| + // |
| + // A cursor the producer's log does not recognise — the log was restored |
| + // from a backup, or another log issued it — is ErrCursorReset, never the |
| + // tip and never a failure: this package answers it with S1's one fixed |
| + // 409, and the consumer drops everything it holds from this producer and |
| + // reads from "" (§6.6). So a cursor must carry enough to be recognised: |
| + // a position alone is reissued by a restore; a position and a random |
| + // stamp written with it is not. "" is never reset. |
| // |
| // Since revision 10 the feed carries every live item, private and |
| // granted ones included; gone means deleted, and nothing else. |
| @@ -41,18 +63,22 @@ type Producer interface { |
| // Rule answers, for each pair in order, whether asker may open that item |
| // now: the app's own read check (team rung, ownership, a live grant; |
| - // never a link). VISIBLE at the current revision; STALE when the asker |
| - // may open it and the asked revision is older than current; NOT_VISIBLE |
| - // when the asker may not, or the item is deleted or unknown; UNKNOWN when |
| - // the app cannot say (an asker of a kind it does not key on, a revision |
| - // its log does not recognise, a roster it cannot reach). Never cached. |
| - // It returns exactly len(pairs) answers. |
| + // never a link; and nothing at all for a person with no team standing, |
| + // their own items included). VISIBLE at the current revision; STALE when |
| + // the asker may open it and the asked revision is one the log holds that |
| + // is not current; NOT_VISIBLE when the asker may not, or the item is |
| + // deleted or an id the app does not know; UNKNOWN when the app cannot |
| + // say (an asker of a kind it does not key on, a revision its log does not |
| + // hold, a roster it cannot reach). The person is checked before the |
| + // revision: a person who may not open the item learns nothing about its |
| + // revisions. Never cached. It returns exactly len(pairs) answers. |
| Rule(ctx context.Context, asker suite.Subject, pairs []suite.ItemRevision) ([]suite.Authorization, error) |
| // Content returns the item's text at revision, as the plain text a |
| // consumer indexes. suite.ErrNotAvailable for a deleted item, an unknown |
| - // id, or a revision that is not the current one; this package turns it |
| - // into the one refusal every such case shares. |
| + // id, or a revision that is not the current one (one the log holds, or |
| + // one it never issued); this package turns it into the one refusal every |
| + // such case shares. |
| Content(ctx context.Context, itemID string, revision int64) ([]byte, error) |
| } |
| @@ -72,20 +98,35 @@ const MaxContentBytes = 2 << 20 |
| // and an asker, are far under it. |
| const maxS2Body = 256 << 10 |
| +// ErrCursorReset is what Feed returns for a cursor its log does not |
| +// recognise. It is suite.ErrCursorReset itself, so either name matches with |
| +// errors.Is; this package answers it with suite.CursorResetStatus and |
| +// suite.CursorResetBody (doctrine §6.6). |
| +var ErrCursorReset = suite.ErrCursorReset |
| + |
| // Handler returns the authenticated routes, or nil when no consumer is |
| // configured: an app with no consumers serves no suite routes at all |
| -// (doctrine §3, A.2 — the routes exist wherever consumer tokens do). |
| +// (doctrine §3, A.2 — the routes exist wherever consumer tokens do). It is |
| +// the only thing an app mounts. |
| func Handler(p Producer, consumers []Consumer, logger *slog.Logger) http.Handler { |
| if len(consumers) == 0 { |
| return nil |
| } |
| - return Authenticate(consumers, Routes(p, logger)) |
| + return Authenticate(consumers, routes(p, logger)) |
| } |
| -// Routes is the three routes with no authentication. An app never mounts it |
| -// directly; it exists for Handler and for the conformance harness, which |
| -// drives a handler without a bearer token. |
| +// Routes is the three routes with NO bearer check: mounted, it serves every |
| +// live item — private ones included — to anybody who can reach the app. |
| +// |
| +// Deprecated: never mount it. Mount Handler, and test with |
| +// conformance.RunProducer or conformance.CheckProducer, which drive Handler |
| +// through a token they mint (revision 11). Routes stays only because the |
| +// module is additive (AGENTS.md) and Docs' and Fichas' tests call it. |
| func Routes(p Producer, logger *slog.Logger) http.Handler { |
| + return routes(p, logger) |
| +} |
| + |
| +func routes(p Producer, logger *slog.Logger) http.Handler { |
| if logger == nil { |
| logger = slog.New(slog.NewTextHandler(io.Discard, nil)) |
| } |
| @@ -93,12 +134,42 @@ func Routes(p Producer, logger *slog.Logger) http.Handler { |
| mux.HandleFunc("GET "+suite.RouteS1, func(w http.ResponseWriter, r *http.Request) { serveS1(p, logger, w, r) }) |
| mux.HandleFunc("POST "+suite.RouteS2, func(w http.ResponseWriter, r *http.Request) { serveS2(p, logger, w, r) }) |
| mux.HandleFunc("GET "+suite.RouteS3+"/{item}", func(w http.ResponseWriter, r *http.Request) { serveS3(p, logger, w, r) }) |
| - return mux |
| + return noStore(mux) |
| +} |
| + |
| +// noStore marks every response this package writes, the mux's own 404 and |
| +// 405 included, as one nobody may keep: an S2 answer is one person's, and |
| +// an S3 body may be a private item's. no-store keeps a cache at the platform |
| +// edge from serving it to the next request (leak list item 11's shape); |
| +// Vary: Authorization says, to any cache that ignores no-store, that a |
| +// response belongs to the credential that fetched it. Set before anything |
| +// else is written, so a refusal carries exactly the headers every other |
| +// refusal does (Fable, review of c38e3ad, M3). |
| +func noStore(next http.Handler) http.Handler { |
| + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + w.Header().Set("Cache-Control", "no-store") |
| + w.Header().Set("Vary", "Authorization") |
| + next.ServeHTTP(w, r) |
| + }) |
| } |
| func serveS1(p Producer, logger *slog.Logger, w http.ResponseWriter, r *http.Request) { |
| cursor := r.URL.Query().Get("cursor") |
| feed, err := p.Feed(r.Context(), cursor, FeedPageLimit) |
| + if errors.Is(err, ErrCursorReset) { |
| + if cursor == "" { |
| + // The beginning names no position, so it cannot be one the log |
| + // lost; a reset here would send a consumer back to "" for ever. |
| + logger.Error("suite S1: the producer reset the beginning") |
| + w.WriteHeader(http.StatusInternalServerError) |
| + return |
| + } |
| + // The fixed body and nothing else: no position, no count, no reason. |
| + w.Header().Set("Content-Type", "application/json") |
| + w.WriteHeader(suite.CursorResetStatus) |
| + io.WriteString(w, suite.CursorResetBody) |
| + return |
| + } |
| if err != nil { |
| // Never an empty feed: an empty page for a failed read would move a |
| // consumer's cursor past changes it never saw. |
| @@ -119,10 +190,10 @@ func serveS1(p Producer, logger *slog.Logger, w http.ResponseWriter, r *http.Req |
| writeJSON(w, feed) |
| } |
| -// checkFeed holds the producer to what DecodeS1 will demand. Its errors are |
| -// fixed strings of this package's own, never the producer's, so they may be |
| -// logged., so a mistake |
| -// is a 500 here rather than a consumer stalling on a page it refuses. |
| +// checkFeed holds the producer to what DecodeS1 will demand, so a mistake is |
| +// a 500 here rather than a consumer stalling on a page it refuses. Its errors |
| +// are fixed strings of this package's own, never the producer's, so they may |
| +// be logged. |
| func checkFeed(f suite.Feed) error { |
| if f.Cursor == "" { |
| return errors.New("empty cursor") |
| @@ -134,6 +205,11 @@ func checkFeed(f suite.Feed) error { |
| if row.ItemID == "" || row.TouchedAt.IsZero() { |
| return errors.New("row without an item id or a time") |
| } |
| + if row.Revision < 1 { |
| + // S2 and S3 refuse a revision under 1, so a row carrying one |
| + // could never be asked about or fetched. |
| + return errors.New("row with a revision under 1") |
| + } |
| } |
| return nil |
| } |
| @@ -158,7 +234,10 @@ func serveS2(p Producer, logger *slog.Logger, w http.ResponseWriter, r *http.Req |
| return |
| } |
| for _, pr := range req.Pairs { |
| - if pr.ItemID == "" { |
| + // No revision under 1, as S3 refuses one: no producer issues it, so |
| + // a pair carrying one is a consumer bug, refused rather than ruled |
| + // (Fable, review of c38e3ad, L5). |
| + if pr.ItemID == "" || pr.Revision < 1 { |
| w.WriteHeader(http.StatusBadRequest) |
| return |
| } |
diff --git a/server/server_test.go b/server/server_test.go| index 81595d4..9ab8c37 100644 |
| --- a/server/server_test.go |
| +++ b/server/server_test.go |
| @@ -4,6 +4,7 @@ import ( |
| "bytes" |
| "context" |
| "errors" |
| + "fmt" |
| "log/slog" |
| "net/http" |
| "net/http/httptest" |
| @@ -30,6 +31,9 @@ type fixtureProducer struct { |
| cursor string // overrides the feed's cursor when set |
| content []byte // overrides S3 bytes when set |
| lastAsker suite.Subject |
| + zeroTime bool // the first row carries no touched_at |
| + zeroRev bool // the first row carries revision 0 |
| + resetStart bool // Feed resets even the beginning |
| } |
| func (p *fixtureProducer) find(id string) (suite.CustodyCase, bool) { |
| @@ -48,10 +52,23 @@ func (p *fixtureProducer) Feed(_ context.Context, cursor string, limit int) (sui |
| if cursor == "end" { |
| return suite.Feed{Cursor: "end"}, nil |
| } |
| + if cursor != "" || p.resetStart { |
| + // The only cursors this log issues are "end" and the override, and |
| + // a test's own; anything else names no position in it (§6.6). |
| + if p.cursor == "" || cursor != p.cursor { |
| + return suite.Feed{}, fmt.Errorf("fichas-like: cursor %q: %w", cursor, server.ErrCursorReset) |
| + } |
| + } |
| var rows []suite.FeedRow |
| for _, c := range p.f.Cases { |
| rows = append(rows, suite.FeedRow{ItemID: c.ItemID, Revision: c.Revision, Gone: c.Rung == suite.RungDeleted, TouchedAt: time.Date(2026, 11, 1, 9, 0, 0, 0, time.UTC)}) |
| } |
| + if p.zeroTime { |
| + rows[0].TouchedAt = time.Time{} |
| + } |
| + if p.zeroRev { |
| + rows[0].Revision = 0 |
| + } |
| for i := 0; i < p.extraRows; i++ { |
| rows = append(rows, suite.FeedRow{ItemID: "extra-" + strconv.Itoa(i), Revision: 1, TouchedAt: time.Date(2026, 11, 1, 9, 0, 0, 0, time.UTC)}) |
| } |
| @@ -80,15 +97,17 @@ func (p *fixtureProducer) Rule(_ context.Context, asker suite.Subject, pairs []s |
| for _, pr := range pairs { |
| c, ok := p.find(pr.ItemID) |
| may := ok && asker == p.f.Asker && c.Rung != suite.RungDeleted && (c.Rung == suite.RungTeam || c.Owner == "asker" || c.AskerGrant) |
| + // STALE from the log, never by comparing numbers (§6.6): this log |
| + // holds the current revision and the one before it. |
| switch { |
| case !may: |
| out = append(out, suite.NOT_VISIBLE) |
| - case pr.Revision < c.Revision: |
| + case pr.Revision == c.Revision: |
| + out = append(out, suite.VISIBLE) |
| + case pr.Revision == c.Revision-1: |
| out = append(out, suite.STALE) |
| - case pr.Revision > c.Revision: |
| - out = append(out, suite.UNKNOWN) |
| default: |
| - out = append(out, suite.VISIBLE) |
| + out = append(out, suite.UNKNOWN) |
| } |
| } |
| if p.short { |
| @@ -162,7 +181,8 @@ func TestNoConsumersServesNothing(t *testing.T) { |
| // MUTATION-TESTED 2026-11-01, each reverted: the hash comparison skipped |
| // (any bearer admitted) → "an unknown token"; only the first token of a |
| // consumer compared → "the second token"; a reason written in the 401 body |
| -// → "alike". |
| +// → "alike". Revision 11: the scheme check removed (any seven bytes taken |
| +// as "Bearer ") → "not a bearer", which "Basic " never caught. |
| func TestAuthentication(t *testing.T) { |
| h := server.Handler(producer(t), consumers(t, token, "the-next-token"), nil) |
| ok := do(h, "GET", suite.RouteS1, token, nil) |
| @@ -180,9 +200,12 @@ func TestAuthentication(t *testing.T) { |
| r.Header.Set("Authorization", "Bearer not-the-token") |
| return r |
| }, |
| + // Seven bytes, as "Bearer " is: with "Basic " (six) the token was |
| + // cut one byte short and refused whether or not the scheme was |
| + // checked (Fable, review of c38e3ad, L5). |
| "not a bearer": func() *http.Request { |
| r := httptest.NewRequest("GET", suite.RouteS1, nil) |
| - r.Header.Set("Authorization", "Basic "+token) |
| + r.Header.Set("Authorization", "Digest "+token) |
| return r |
| }, |
| "an empty bearer": func() *http.Request { |
| @@ -196,7 +219,7 @@ func TestAuthentication(t *testing.T) { |
| if rec.Code != 401 { |
| t.Errorf("%s: %d, want 401", name, rec.Code) |
| } |
| - got := strconv.Itoa(rec.Code) + "|" + rec.Body.String() |
| + got := signature(rec) |
| if first == "" { |
| first = got |
| } else if got != first { |
| @@ -205,6 +228,9 @@ func TestAuthentication(t *testing.T) { |
| } |
| } |
| +// MUTATION-TESTED 2026-11-01, reverted: the SHA-256 length check reduced to |
| +// "not empty" → "31 bytes of hex" and "33 bytes of hex" (Fable, review of |
| +// c38e3ad, L5: nothing tested it). |
| func TestParseConsumers(t *testing.T) { |
| good := `[{"consumer_id":"memoria","tokens":[{"epoch":1,"sha256":"` + server.TokenHash("x") + `"}]}]` |
| if cs, err := server.ParseConsumers(good); err != nil || len(cs) != 1 || cs[0].ID != "memoria" { |
| @@ -219,6 +245,10 @@ func TestParseConsumers(t *testing.T) { |
| "three tokens": `[{"consumer_id":"m","tokens":[{"epoch":1,"sha256":"` + h + `"},{"epoch":2,"sha256":"` + h + `"},{"epoch":3,"sha256":"` + h + `"}]}]`, |
| "no tokens": `[{"consumer_id":"m","tokens":[]}]`, |
| "not hex": `[{"consumer_id":"m","tokens":[{"epoch":1,"sha256":"plaintext-token"}]}]`, |
| + // Hex, and a byte short of a SHA-256: no token can ever match it, so |
| + // it is a typo that would serve nobody (Fable, review of c38e3ad, L5). |
| + "31 bytes of hex": `[{"consumer_id":"m","tokens":[{"epoch":1,"sha256":"` + h[:62] + `"}]}]`, |
| + "33 bytes of hex": `[{"consumer_id":"m","tokens":[{"epoch":1,"sha256":"` + h + `00"}]}]`, |
| "a repeated id": `[{"consumer_id":"m","tokens":[{"epoch":1,"sha256":"` + h + `"}]},{"consumer_id":"m","tokens":[{"epoch":1,"sha256":"` + h + `"}]}]`, |
| "trailing content": good + `[]`, |
| "not a list": `{"consumer_id":"m"}`, |
| @@ -325,14 +355,7 @@ func TestS3RefusesAlike(t *testing.T) { |
| if base.Code != 404 { |
| t.Fatalf("baseline: %d", base.Code) |
| } |
| - sig := func(r *httptest.ResponseRecorder) string { |
| - var hs []string |
| - for k, v := range r.Header() { |
| - hs = append(hs, k+"="+strings.Join(v, ",")) |
| - } |
| - sort.Strings(hs) |
| - return strconv.Itoa(r.Code) + "|" + strings.Join(hs, "|") + "|" + r.Body.String() |
| - } |
| + sig := signature |
| for name, url := range map[string]string{ |
| "deleted": suite.RouteS3 + "/doc-deleted?revision=6", |
| "superseded": suite.RouteS3 + "/doc-team?revision=6", |
| @@ -448,3 +471,127 @@ func (p *emptyIDProducer) Feed(ctx context.Context, cursor string, limit int) (s |
| } |
| return f, err |
| } |
| + |
| +// signature is a response as a client could compare it: status, every |
| +// header, body. |
| +func signature(r *httptest.ResponseRecorder) string { |
| + var hs []string |
| + for k, v := range r.Header() { |
| + hs = append(hs, k+"="+strings.Join(v, ",")) |
| + } |
| + sort.Strings(hs) |
| + return strconv.Itoa(r.Code) + "|" + strings.Join(hs, "|") + "|" + r.Body.String() |
| +} |
| + |
| +// A cursor the producer's log does not recognise is S1's one fixed 409, and |
| +// the consumer's decoder reads it as a reset (doctrine §6.6, revision 11). |
| +// The beginning is never reset: a producer that resets "" would send a |
| +// consumer back to "" for ever, so that is a 500. |
| +// |
| +// MUTATION-TESTED 2026-11-01, each reverted: the ErrCursorReset branch |
| +// removed (a reset answered as a failed feed) → "a foreign cursor"; the "" |
| +// guard removed → "the beginning reset"; the body written through |
| +// json.Encoder as an object with a second field → "a foreign cursor". |
| +func TestS1CursorReset(t *testing.T) { |
| + p := producer(t) |
| + h := server.Handler(p, consumers(t, token), nil) |
| + rec := do(h, "GET", suite.RouteS1+"?cursor=17.4421", token, nil) |
| + if _, err := suite.DecodeS1(rec.Code, rec.Body.Bytes()); !errors.Is(err, suite.ErrCursorReset) { |
| + t.Errorf("a foreign cursor: %d %q, %v; want the reset", rec.Code, rec.Body.String(), err) |
| + } |
| + if rec.Code != 409 || rec.Body.String() != suite.CursorResetBody || rec.Header().Get("Content-Type") != "application/json" { |
| + t.Errorf("a foreign cursor: %d %q %q, want exactly 409 %s as JSON", rec.Code, rec.Body.String(), rec.Header().Get("Content-Type"), suite.CursorResetBody) |
| + } |
| + // The cursors the log did issue still read. |
| + if rec := do(h, "GET", suite.RouteS1+"?cursor=end", token, nil); rec.Code != 200 { |
| + t.Errorf("the log's own cursor: %d", rec.Code) |
| + } |
| + p.resetStart = true |
| + if rec := do(h, "GET", suite.RouteS1+"?cursor=", token, nil); rec.Code != 500 { |
| + t.Errorf("the beginning reset: %d, want 500", rec.Code) |
| + } |
| +} |
| + |
| +// Every response the package writes is one nobody may keep, and refusals of |
| +// a kind stay byte-identical with the headers on (Fable, review of c38e3ad, |
| +// M3). Through Handler, so the 401 is covered, and including the mux's own |
| +// 404 and 405, which no route of ours writes. |
| +// |
| +// MUTATION-TESTED 2026-11-01, each reverted: noStore dropped from routes → |
| +// "Routes" (through Handler, Authenticate's own noStore still covers it); |
| +// noStore dropped from Authenticate → "no token"; Vary not set → every |
| +// response. |
| +func TestEveryResponseIsNoStore(t *testing.T) { |
| + p := producer(t) |
| + h := server.Handler(p, consumers(t, token), nil) |
| + ask := `{"asker":{"kind":"person_ref","value":"pers_ana"},"pairs":[{"item_id":"doc-team","revision":7}]}` |
| + cases := map[string]func() *httptest.ResponseRecorder{ |
| + "S1 200": func() *httptest.ResponseRecorder { return do(h, "GET", suite.RouteS1, token, nil) }, |
| + "S1 409": func() *httptest.ResponseRecorder { return do(h, "GET", suite.RouteS1+"?cursor=x", token, nil) }, |
| + "S2 200": func() *httptest.ResponseRecorder { return do(h, "POST", suite.RouteS2, token, []byte(ask)) }, |
| + "S2 400": func() *httptest.ResponseRecorder { return do(h, "POST", suite.RouteS2, token, []byte("nope")) }, |
| + "S3 200": func() *httptest.ResponseRecorder { |
| + return do(h, "GET", suite.RouteS3+"/doc-team?revision=7", token, nil) |
| + }, |
| + "S3 404": func() *httptest.ResponseRecorder { |
| + return do(h, "GET", suite.RouteS3+"/doc-deleted?revision=6", token, nil) |
| + }, |
| + "S3 POST": func() *httptest.ResponseRecorder { |
| + return do(h, "POST", suite.RouteS3+"/doc-team?revision=7", token, nil) |
| + }, |
| + "no such route": func() *httptest.ResponseRecorder { return do(h, "GET", "/suite/s9", token, nil) }, |
| + "no token": func() *httptest.ResponseRecorder { return do(h, "GET", suite.RouteS1, "", nil) }, |
| + "a wrong token": func() *httptest.ResponseRecorder { |
| + return do(h, "GET", suite.RouteS3+"/doc-team?revision=7", "nope", nil) |
| + }, |
| + } |
| + for name, run := range cases { |
| + rec := run() |
| + if rec.Header().Get("Cache-Control") != "no-store" || rec.Header().Get("Vary") != "Authorization" { |
| + t.Errorf("%s (%d): Cache-Control %q, Vary %q; want no-store and Authorization", name, rec.Code, rec.Header().Get("Cache-Control"), rec.Header().Get("Vary")) |
| + } |
| + } |
| + // The deprecated Routes too, which apps' own tests still call. |
| + if rec := do(server.Routes(p, nil), "GET", suite.RouteS3+"/doc-team?revision=7", "", nil); rec.Header().Get("Cache-Control") != "no-store" || rec.Header().Get("Vary") != "Authorization" { |
| + t.Errorf("Routes: Cache-Control %q, Vary %q", rec.Header().Get("Cache-Control"), rec.Header().Get("Vary")) |
| + } |
| + if cases["S3 POST"]().Code == 200 { |
| + t.Error("S3 served a POST") |
| + } |
| + p.feedErr, p.ruleErr, p.contentErr = errors.New("down"), errors.New("down"), errors.New("down") |
| + for name, rec := range map[string]*httptest.ResponseRecorder{ |
| + "S1 503": do(h, "GET", suite.RouteS1, token, nil), |
| + "S2 503": do(h, "POST", suite.RouteS2, token, []byte(ask)), |
| + "S3 503": do(h, "GET", suite.RouteS3+"/doc-team?revision=7", token, nil), |
| + } { |
| + if rec.Code != 503 || rec.Header().Get("Cache-Control") != "no-store" || rec.Header().Get("Vary") != "Authorization" { |
| + t.Errorf("%s: %d, Cache-Control %q, Vary %q", name, rec.Code, rec.Header().Get("Cache-Control"), rec.Header().Get("Vary")) |
| + } |
| + } |
| +} |
| + |
| +// Revision 11's edges (Fable, review of c38e3ad, L5): S2 refuses a revision |
| +// under 1 in a pair, as S3 does; a feed row with no touched_at or a revision |
| +// under 1 is the producer's mistake, a 500, never a page. |
| +// |
| +// MUTATION-TESTED 2026-11-01, each reverted: S2's revision check removed → |
| +// "revision 0" and "revision -1"; checkFeed's TouchedAt check removed → "no |
| +// touched_at"; checkFeed's revision check removed → "revision 0 in the feed". |
| +func TestRevision11Edges(t *testing.T) { |
| + p := producer(t) |
| + h := server.Handler(p, consumers(t, token), nil) |
| + for name, rev := range map[string]string{"revision 0": "0", "revision -1": "-1"} { |
| + body := `{"asker":{"kind":"person_ref","value":"pers_ana"},"pairs":[{"item_id":"doc-team","revision":` + rev + `}]}` |
| + if rec := do(h, "POST", suite.RouteS2, token, []byte(body)); rec.Code != 400 { |
| + t.Errorf("%s in an S2 pair: %d, want 400", name, rec.Code) |
| + } |
| + } |
| + p.zeroTime = true |
| + if rec := do(h, "GET", suite.RouteS1, token, nil); rec.Code != 500 { |
| + t.Errorf("no touched_at: %d, want 500", rec.Code) |
| + } |
| + p.zeroTime, p.zeroRev = false, true |
| + if rec := do(h, "GET", suite.RouteS1, token, nil); rec.Code != 500 { |
| + t.Errorf("revision 0 in the feed: %d, want 500", rec.Code) |
| + } |
| +} |