Docs: Fable's follow-ups on #103 — invariants in AGENTS.md, the orphan clause tested, truer share copy
1. AGENTS.md: the suite producer's invariants with spec §8.2.2 cited — bumpRevision in the same transaction for every write that changes S3's bytes, deletes through deleteDocument, no fallback from randomSource, S2 never caches, exactly three routes on the outer mux. 2. Feed's owner_id > 0 clause kept and tested: TestSuiteAnOrphanIsNeverAnnounced hand-writes a feed row for an orphan and checks S1 skips it, S3 refuses it and S2 answers NOT_VISIBLE; red with the clause removed. Kept rather than dropped because a feed row already says an item exists. 3. 0011_suite.sql cites suite main c38e3ad, not 12848f8. 4. Copy: a team document says "people you give edit access" change it; a private document with a published link says the link opens it too (docs.share.team.body.private_published); TestSuiteShareWordsMentionThePublishedLink, red without the published branch. 5. Operator note for $DOCS_SUITE_CONSUMERS beside the allowlist's in AGENTS.md: format, one or two tokens, server.TokenHash, unset is off, malformed refuses boot.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+149
−7
AGENTS.md+44 −0internal/docs/migrations/0011_suite.sql+2 −2internal/docs/render.go+6 −5internal/docs/share.go+4 −0internal/docs/suite_test.go+93 −0
CI passed — run details
diff --git a/AGENTS.md b/AGENTS.md| index 00d254e..165533b 100644 |
| --- a/AGENTS.md |
| +++ b/AGENTS.md |
| @@ -103,6 +103,50 @@ the same fail-closed shape `Origin`/`InstanceKey`/`Mailer` already use, |
| chosen over silently admitting nobody because a silently-empty allowlist |
| would boot looking identical to a working instance. |
| +### Suite consumers (`$DOCS_SUITE_CONSUMERS`, spec §8.2.2) |
| + |
| +The siblings allowed to call Docs' suite routes (memoria, today). Strict |
| +JSON, one entry per consumer, one or two tokens each (two only while a |
| +token is being rotated): |
| + |
| + [{"consumer_id":"memoria","tokens":[{"epoch":1,"sha256":"<64 hex>"}]}] |
| + |
| +`sha256` is the hex SHA-256 of the bearer token the operator minted for |
| +that consumer — `server.TokenHash(token)` in `amadan.net/oficina/suite/server` |
| +— never the token itself. Unset or empty: no consumers, and `/suite/*` |
| +answers 404 like any unknown path. Anything malformed (not a list, an |
| +empty list, `null`, an unknown field, a non-hex or wrong-length hash, a |
| +repeated or empty `consumer_id`, three tokens) refuses boot. |
| + |
| +## The suite producer: invariants (spec §8.2.2) |
| + |
| +Docs serves suite S1/S2/S3 to memoria and holds every live document to the |
| +suite revision 10 rules. Break one of these and memoria can show somebody a |
| +document they may no longer read; the reasoning and the review history are |
| +in spec §8.2.2. |
| + |
| +- **Every write that changes what S3 serves moves the revision in the same |
| + transaction**: call `bumpRevision` (`internal/docs/suite_feed.go`) inside |
| + the transaction that makes the change — content, title, visibility, |
| + deletion, and anything new that changes the title or the text. It draws a |
| + new random revision and writes the `suite_feed` row; if either fails the |
| + change must not commit. Creation goes through `createDocument`. |
| +- **Any delete verb goes through `Store.deleteDocument`**, which announces |
| + the document gone. A delete that only sets `deleted_at` leaves memoria |
| + holding it. |
| +- **Revisions and feed nonces come only from `randomSource`** |
| + (`crypto/rand`). A failed read is an error that stops the change; never |
| + fall back to a clock, a counter or `math/rand`, which a restore or |
| + anybody else can reproduce. Revisions have no order: S2's `STALE` is read |
| + from `suite_feed`, never from comparing numbers. |
| +- **S2 never caches** — not an answer, not a person's standing, not across |
| + pairs of one call. Team standing is asked again after the last database |
| + read (`suiteProducer.Rule`). |
| +- **Exactly three suite routes sit on the outer mux** (`mountSuite`): |
| + `GET /suite/s1`, `POST /suite/s2`, `GET /suite/s3/{item}`, outside the |
| + session, admission and `homeCSRF` layers. Never a prefix, and nothing |
| + else outside the router. |
| + |
| ## Running it locally |
| `./scripts/run-dev.sh` builds and runs the app in one command: `-env |
diff --git a/internal/docs/migrations/0011_suite.sql b/internal/docs/migrations/0011_suite.sql| index 60500ef..f220cc2 100644 |
| --- a/internal/docs/migrations/0011_suite.sql |
| +++ b/internal/docs/migrations/0011_suite.sql |
| @@ -1,6 +1,6 @@ |
| -- The team rung, and the revision counter and feed log the suite contract's |
| --- producer half reads (spec §8.2.1 and §8.2.2; suite revision 10, commit |
| --- 12848f8). |
| +-- producer half reads (spec §8.2.1 and §8.2.2; suite revision 10, suite |
| +-- main c38e3ad). |
| -- |
| -- visibility: Paul's ruling, 2026-11-01, "New docs Team, old private". The |
| -- column DEFAULT is 'private', and that default is the half of the ruling |
diff --git a/internal/docs/render.go b/internal/docs/render.go| index 087d3e8..6613a0d 100644 |
| --- a/internal/docs/render.go |
| +++ b/internal/docs/render.go |
| @@ -87,11 +87,12 @@ var Catalog = rastrillo.Catalog{ |
| // "New docs Team, old private"). The body says which side the switch is |
| // on in words, so the state never rests on a button's label alone, and |
| // says that the team reads and does not edit. |
| - "docs.share.team.heading": "Your team", |
| - "docs.share.team.body.team": "Everyone on your team can read this document. Only you and the people you add above can change it.", |
| - "docs.share.team.body.private": "Only you and the people you add above can open this document.", |
| - "docs.share.team.make_private": "Make private", |
| - "docs.share.team.make_team": "Share with your team", |
| + "docs.share.team.heading": "Your team", |
| + "docs.share.team.body.team": "Everyone on your team can read this document. Only you and people you give edit access can change it.", |
| + "docs.share.team.body.private": "Only you and the people you add above can open this document.", |
| + "docs.share.team.body.private_published": "Only you, the people you add above and anyone with the published link can open this document.", |
| + "docs.share.team.make_private": "Make private", |
| + "docs.share.team.make_team": "Share with your team", |
| // docs.share.public.* is the third rung — a read-only link anyone |
| // can follow, signed in or not (suite doctrine ruling 15). |
diff --git a/internal/docs/share.go b/internal/docs/share.go| index 46ef893..5880766 100644 |
| --- a/internal/docs/share.go |
| +++ b/internal/docs/share.go |
| @@ -202,6 +202,10 @@ func (h *handlers) renderShare(w http.ResponseWriter, r *http.Request, doc *Docu |
| page.TeamBody = rastrillo.T(r, "docs.share.team.body.team") |
| page.TeamButton = rastrillo.T(r, "docs.share.team.make_private") |
| page.TeamDestination = VisibilityPrivate |
| + } else if published { |
| + page.TeamBody = rastrillo.T(r, "docs.share.team.body.private_published") |
| + page.TeamButton = rastrillo.T(r, "docs.share.team.make_team") |
| + page.TeamDestination = VisibilityTeam |
| } else { |
| page.TeamBody = rastrillo.T(r, "docs.share.team.body.private") |
| page.TeamButton = rastrillo.T(r, "docs.share.team.make_team") |
diff --git a/internal/docs/suite_test.go b/internal/docs/suite_test.go| index 3e5ca4a..ee09879 100644 |
| --- a/internal/docs/suite_test.go |
| +++ b/internal/docs/suite_test.go |
| @@ -459,6 +459,7 @@ func TestSuiteTeamRungLoneShape(t *testing.T) { |
| if rec := form(t, app, "alice@example.com", "/d/"+team.Sqid+"/share/team", "visibility=everyone"); rec.Code != http.StatusBadRequest { |
| t.Errorf("an unknown visibility: %d, want 400", rec.Code) |
| } |
| + |
| } |
| // The team rung in team mode follows roster standing: a Member who does not |
| @@ -1388,3 +1389,95 @@ func TestSuiteRevisionsRedrawAndNeverFallBack(t *testing.T) { |
| t.Errorf("a broken source changed something: documents %d→%d, revision %d→%d", before, after, doc.Revision, revisionOf(t, app.store, doc.ID)) |
| } |
| } |
| + |
| +// An orphan — a document 0002_owners.sql left at owner_id 0, readable by |
| +// nobody — is not live, even if a feed row names it. Nothing in Docs writes |
| +// one (announce runs only for documents with an owner), so the row is made |
| +// by hand: S1 skips it, S3 refuses it and S2 answers NOT_VISIBLE. Kept as a |
| +// clause in Feed rather than left to S2 and S3 because a feed row is itself |
| +// a disclosure that an item exists, and an orphan is not Docs' to announce. |
| +// |
| +// MUTATION-TESTED 2026-11-02, reverted: Feed without "documents.owner_id > |
| +// 0" → the orphan's sqid in the feed (Fable's review found this clause |
| +// survived every other test). |
| +func TestSuiteAnOrphanIsNeverAnnounced(t *testing.T) { |
| + app, err := NewForTest(t) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + ctx := context.Background() |
| + now := time.Now().UTC() |
| + orphan := &Document{Sqid: "orphan0011", Title: "Nobody's", GUID: "orphan-guid", ClientID: 1, OwnerID: 0, Visibility: VisibilityTeam, Revision: 42, CreatedAt: now, UpdatedAt: now} |
| + if err := app.store.db.Create(orphan).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := app.store.db.Transaction(func(tx *gorm.DB) error { return announce(tx, orphan.ID, 42, false) }); err != nil { |
| + t.Fatal(err) |
| + } |
| + f, err := app.suite.Feed(ctx, "", 100) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, row := range f.Rows { |
| + if row.ItemID == orphan.Sqid { |
| + t.Errorf("the feed announced an orphan: %+v", row) |
| + } |
| + } |
| + if _, err := app.suite.Content(ctx, orphan.Sqid, 42); !errors.Is(err, suite.ErrNotAvailable) { |
| + t.Errorf("S3 served an orphan: %v", err) |
| + } |
| + app.TestPerson(t, "alice@example.com") |
| + got, err := app.suite.Rule(ctx, suite.Subject{Kind: suite.SubjectAddress, Value: "alice@example.com"}, []suite.ItemRevision{{ItemID: orphan.Sqid, Revision: 42}}) |
| + if err != nil || got[0] != suite.NOT_VISIBLE { |
| + t.Errorf("S2 for an orphan on the team rung: %v %v, want NOT_VISIBLE", got, err) |
| + } |
| +} |
| + |
| +// The rung's words on the share page are true (Fable on #103): a private |
| +// document with a published link says the link opens it too, and a team |
| +// document says edit access, not "the people above", decides who changes it. |
| +// |
| +// MUTATION-TESTED 2026-11-02, reverted: renderShare without the published |
| +// branch → the plain private words on a published document. |
| +func TestSuiteShareWordsMentionThePublishedLink(t *testing.T) { |
| + app, err := NewForTest(t) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + req := app.TestRequest(t, "alice@example.com", http.MethodGet, "/", nil) |
| + cookies := req.Cookies() |
| + do := func(method, path, body string) *httptest.ResponseRecorder { |
| + t.Helper() |
| + r := httptest.NewRequest(method, path, strings.NewReader(body)) |
| + for _, c := range cookies { |
| + r.AddCookie(c) |
| + } |
| + if method == http.MethodPost { |
| + r.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| + r.Header.Set("Sec-Fetch-Site", "same-origin") |
| + } |
| + return serve(app, r) |
| + } |
| + rec := do(http.MethodPost, "/documents", "title=Notes") |
| + sqid := strings.TrimPrefix(rec.Header().Get("Location"), "/d/") |
| + if !strings.Contains(do(http.MethodGet, "/d/"+sqid+"/share", "").Body.String(), "docs.share.team.body.team") { |
| + t.Error("a team document's share page") |
| + } |
| + if rec := do(http.MethodPost, "/d/"+sqid+"/share/team", "visibility=private"); rec.Code != http.StatusSeeOther { |
| + t.Fatalf("make private: %d", rec.Code) |
| + } |
| + if rec := do(http.MethodPost, "/d/"+sqid+"/share/link", "on=1"); rec.Code != http.StatusSeeOther { |
| + t.Fatalf("publish: %d", rec.Code) |
| + } |
| + share := do(http.MethodGet, "/d/"+sqid+"/share", "").Body.String() |
| + if !strings.Contains(share, "docs.share.team.body.private_published") { |
| + t.Error("a published private document's share page does not mention the link") |
| + } |
| + if rec := do(http.MethodPost, "/d/"+sqid+"/share/link", "on=0"); rec.Code != http.StatusSeeOther { |
| + t.Fatalf("unpublish: %d", rec.Code) |
| + } |
| + share = do(http.MethodGet, "/d/"+sqid+"/share", "").Body.String() |
| + if strings.Contains(share, "docs.share.team.body.private_published") || !strings.Contains(share, "docs.share.team.body.private") { |
| + t.Error("an unpublished private document's share page still mentions a link") |
| + } |
| +} |