Memoria team mode: Fable's #32 notes (N1–N4)
N1: TestTeamGuardedWritesRunInsideGuard pins, without the lapsing seam, that guarded and guard run the write inside teammode.Guard: the write's own body lapses standing and the row must be absent (Fable's M27, which survived the route table, now dies). N2: authorizeFor answers an owner write whose lease lapses at the role read as ErrUnavailable (503), as standing() does at the route, not ErrNotMember (404). N3: the unused teamOwner is gone. N4: go mod tidy (roster and teammode are direct requirements; stale connect ff16bf56 sums dropped).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+82
−11
go.mod+2 −2go.sum+0 −2internal/memoria/team_access.go+0 −7internal/memoria/team_guard.go+6 −0internal/memoria/team_guard_test.go+74 −0
CI passed — run details
Intent
diff --git a/go.mod b/go.mod| index 66d7826..47f334e 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -8,6 +8,8 @@ require ( |
| amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d |
| amadan.net/oficina/home/connect v0.0.0-20261028171508-67c12e39a9d2 |
| amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d |
| + amadan.net/oficina/home/roster v0.0.0-20261028171508-67c12e39a9d2 |
| + amadan.net/oficina/home/teammode v0.0.0-20261028171508-67c12e39a9d2 |
| amadan.net/oficina/suite v0.0.0-20260905215529-60b01a8a0d6d |
| amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3 |
| github.com/carlosframework/rastrillo v0.23.0 |
| @@ -27,8 +29,6 @@ require ( |
| ) |
| require ( |
| - amadan.net/oficina/home/roster v0.0.0-20261028171508-67c12e39a9d2 // indirect |
| - amadan.net/oficina/home/teammode v0.0.0-20261028171508-67c12e39a9d2 // indirect |
| amadan.net/rastrillo/rastrillo/money v0.1.0 // indirect |
| github.com/BurntSushi/toml v1.6.0 // indirect |
| github.com/chromedp/sysutil v1.1.0 // indirect |
diff --git a/go.sum b/go.sum| index 7648529..dfdf288 100644 |
| --- a/go.sum |
| +++ b/go.sum |
| @@ -1,7 +1,5 @@ |
| amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d h1:p9+01xRdBD7s1viTINgQ6XoDD5ghOxYubD7FNcjhBTw= |
| amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw= |
| -amadan.net/oficina/home/connect v0.0.0-20261024233715-ff16bf56bc4d h1:9sVZBph2xUuejZt73DYaoCfoyvrvZCnuPHcyMsg562E= |
| -amadan.net/oficina/home/connect v0.0.0-20261024233715-ff16bf56bc4d/go.mod h1:ix81eFV87yE9f2SXiRuxYCVM4lAgTRC5YoQMiH3+TDk= |
| amadan.net/oficina/home/connect v0.0.0-20261028171508-67c12e39a9d2 h1:MPO8MRkk+tT2k+95fZPJ0JStnmAKUCKiVoPbfBVTk6E= |
| amadan.net/oficina/home/connect v0.0.0-20261028171508-67c12e39a9d2/go.mod h1:ix81eFV87yE9f2SXiRuxYCVM4lAgTRC5YoQMiH3+TDk= |
| amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d h1:8RTZkLQnyxvH2g0RMovhN/m2LN9D8qb+kBfqdBeqq+s= |
diff --git a/internal/memoria/team_access.go b/internal/memoria/team_access.go| index dca86f6..fb572cd 100644 |
| --- a/internal/memoria/team_access.go |
| +++ b/internal/memoria/team_access.go |
| @@ -269,13 +269,6 @@ func (a *app) teamPartial(r *http.Request) bool { |
| return !ok || p.access.Partial() |
| } |
| -// teamOwner reports whether the roster says this request's person is one |
| -// of the team's owners, now. |
| -func (a *app) teamOwner(r *http.Request) bool { |
| - p, ok := teamPersonFrom(r.Context()) |
| - return ok && p.access.Role() == rosterOwner |
| -} |
| - |
| // teamAdmission is admissionOf in team mode: the request's own person if |
| // requireSession already resolved one, else the session resolved and |
| // asked about now. It never ends a session itself. |
diff --git a/internal/memoria/team_guard.go b/internal/memoria/team_guard.go| index 8866927..d7547ee 100644 |
| --- a/internal/memoria/team_guard.go |
| +++ b/internal/memoria/team_guard.go |
| @@ -72,6 +72,12 @@ func authorizeFor(rule writeRule, acc *teammode.Access) func(roster.State) error |
| return err |
| } |
| if rule == ownerWrite && acc.Role() != rosterOwner { |
| + // Role re-reads the lease: a lapse between Guard's standing and |
| + // this read is Unknown, the retryable 503, as standing() answers |
| + // at the route — never a 404 to an owner because Home was slow. |
| + if acc.State() == roster.Unknown { |
| + return teammode.ErrUnavailable |
| + } |
| return teammode.ErrNotMember |
| } |
| return nil |
diff --git a/internal/memoria/team_guard_test.go b/internal/memoria/team_guard_test.go| index 8901f3b..dd795f3 100644 |
| --- a/internal/memoria/team_guard_test.go |
| +++ b/internal/memoria/team_guard_test.go |
| @@ -304,3 +304,77 @@ func TestTeamConnectorWritesNeedTheOwnerRole(t *testing.T) { |
| t.Fatalf("an owner's connector save = %v", err) |
| } |
| } |
| + |
| +// Fable's N1 (#32): every write `guarded` runs is INSIDE Guard — checked |
| +// without the lapsing seam, whose wrapper sits around whatever is handed to |
| +// Guard and so cannot tell "authorize, write, authorize" from "authorize, |
| +// authorize, write" (M27 survived the route table that way). Here the |
| +// write's own body lapses the standing, so only an after-check that runs |
| +// after the write can refuse it, and the row must be absent. The same for |
| +// guard, which Ingest and Delete call around their bodies. |
| +// |
| +// MUTATION-TESTED 2026-10-30: M27 (guarded runs Guard with a no-op write, |
| +// then writes in the same transaction) → "guarded"; guard calling write |
| +// after teamGuard → "guard". |
| +func TestTeamGuardedWritesRunInsideGuard(t *testing.T) { |
| + f := newTeamFixture(t) |
| + f.member(teamSubject('a'), "member") |
| + insert := func(db *gormTx, n string) error { |
| + return db.Create(&FactReport{ReporterPrint: n, SealedReport: []byte{1}}).Error |
| + } |
| + rows := func(n string) int { |
| + var c int |
| + f.d.Writer().QueryRow("SELECT COUNT(*) FROM fact_reports WHERE reporter_print=?", n).Scan(&c) |
| + return c |
| + } |
| + |
| + // The presence half: a write whose standing holds commits. |
| + if err := f.app.store.guarded(f.asMember(teamSubject('a')), memberWrite, func(db *gormTx) error { return insert(db, "kept") }); err != nil || rows("kept") != 1 { |
| + t.Fatalf("a write under standing = %v, %d rows", err, rows("kept")) |
| + } |
| + |
| + f.renewed() |
| + err := f.app.store.guarded(f.asMember(teamSubject('a')), memberWrite, func(db *gormTx) error { |
| + f.expired() |
| + return insert(db, "guarded") |
| + }) |
| + if !errors.Is(err, teammode.ErrUnavailable) || rows("guarded") != 0 { |
| + t.Fatalf("guarded: a write that lapsed its own standing = %v, %d rows; want refused and absent", err, rows("guarded")) |
| + } |
| + |
| + f.recovered() |
| + err = f.app.store.db.G.Transaction(func(tx *gormTx) error { |
| + return f.app.store.guard(f.asMember(teamSubject('a')), memberWrite, func() error { |
| + f.expired() |
| + return insert(tx, "guard") |
| + }) |
| + }) |
| + if !errors.Is(err, teammode.ErrUnavailable) || rows("guard") != 0 { |
| + t.Fatalf("guard: a write that lapsed its own standing = %v, %d rows; want refused and absent", err, rows("guard")) |
| + } |
| +} |
| + |
| +// Fable's N2 (#32): an owner write whose lease lapses between Guard's |
| +// standing and the role read is Unknown — the retryable 503 — not a 404; |
| +// a member's owner write is still a definite no. |
| +// |
| +// MUTATION-TESTED 2026-10-30: the State re-check in authorizeFor removed → |
| +// "lapsed owner". |
| +func TestTeamOwnerWriteLapsingAtTheRoleIsUnavailable(t *testing.T) { |
| + f := newTeamFixture(t) |
| + f.member(teamSubject('o'), "owner") |
| + f.member(teamSubject('m'), "member") |
| + member := f.app.team.Access(context.Background(), teamSubject('m')) |
| + if err := authorizeFor(ownerWrite, member)(roster.Member); !errors.Is(err, teammode.ErrNotMember) { |
| + t.Fatalf("member's owner write = %v, want ErrNotMember", err) |
| + } |
| + owner := f.app.team.Access(context.Background(), teamSubject('o')) |
| + if err := authorizeFor(ownerWrite, owner)(roster.Member); err != nil { |
| + t.Fatalf("owner's owner write = %v", err) |
| + } |
| + f.expired() |
| + // Guard read Member a moment ago; the role read finds the lease gone. |
| + if err := authorizeFor(ownerWrite, owner)(roster.Member); !errors.Is(err, teammode.ErrUnavailable) { |
| + t.Fatalf("lapsed owner: owner write = %v, want ErrUnavailable", err) |
| + } |
| +} |