Sheets: Fable #53's required tests and notes
The ConfigureTeam issuer clause (another Home issuer is refused); format and size leave nothing behind after a refused write; the empty partial list (a Home-only member with no shares, under Unknown: 200, the notice, no team sheet, no "No sheets yet"). Notes: an identity storage failure in the middleware is a 503 that keeps the session; a roster owner's share resting on standing through a lower share, lease lapsing, is a 503 and commits nothing. Each kills its mutant (M1, M3, M7, M8, M9). Tests only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+113
−0
internal/sheets/team_access_test.go+19 −0internal/sheets/team_config_test.go+16 −0internal/sheets/team_guard_test.go+78 −0
CI failed — run details
diff --git a/internal/sheets/team_access_test.go b/internal/sheets/team_access_test.go| index eaf49ad..aab97d9 100644 |
| --- a/internal/sheets/team_access_test.go |
| +++ b/internal/sheets/team_access_test.go |
| @@ -248,6 +248,25 @@ func TestTeamSignInAllocatesOnlyForACurrentMember(t *testing.T) { |
| } |
| } |
| +// Paul's ruling with nothing to show: a Home-only member with no shares, |
| +// under Unknown, gets the partial notice and an empty list — not a 503, |
| +// not the team's sheets, and not "No sheets yet", which would read as an |
| +// answer (Fable, #53 Required 3). |
| +func TestTeamEmptyPartialListSaysPartialNotEmpty(t *testing.T) { |
| + f := newTeamFixture(t) |
| + teamSheet(t, f, "Team plan") |
| + a := teamSubject('a') |
| + f.dir.Set(a, "member") |
| + f.signInHome(t, a) |
| + f.expired(t) |
| + rec := f.get(t, "/sheets") |
| + body := rec.Body.String() |
| + if rec.Code != http.StatusOK || !strings.Contains(body, "data-partial") || strings.Contains(body, "Team plan") || strings.Contains(body, "No sheets yet") { |
| + t.Errorf("empty list under Unknown = %d (partial %v, team %v, empty state %v)", rec.Code, |
| + strings.Contains(body, "data-partial"), strings.Contains(body, "Team plan"), strings.Contains(body, "No sheets yet")) |
| + } |
| +} |
| + |
| // viewer is the request's actor as a handler sees it. |
| func (f *teamFixture) viewer(t *testing.T) Member { |
| t.Helper() |
diff --git a/internal/sheets/team_config_test.go b/internal/sheets/team_config_test.go| index 1d38dd1..9bb592c 100644 |
| --- a/internal/sheets/team_config_test.go |
| +++ b/internal/sheets/team_config_test.go |
| @@ -80,6 +80,22 @@ func TestTeamConfigPinsTheProvisioningRecord(t *testing.T) { |
| if err := wrongConsumer.ConfigureTeam(); !errors.Is(err, errTeamConfig) { |
| t.Errorf("settings for another consumer = %v, want refusal", err) |
| } |
| + // And for another Home issuer (Fable, #53 Required 1): without the |
| + // check the census asks under the settings' issuer, finds nothing |
| + // foreign, and activates. |
| + issuer := teamTestBindings() |
| + issuer.Issuer = "https://id.other.example" |
| + issuerCfg, issuerDir := teamConfigFor(t, issuer) |
| + issuerSettings, err := teammode.Verify(issuerCfg, teammodetest.Home(issuer), "sheets", testOrigin) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + wrongIssuer, _ := appWithSchema(t, testOrigin, TeamBootSchema, signedInAddress) |
| + wrongIssuer.teamSettings, wrongIssuer.teamTransport = issuerSettings, issuerDir |
| + homeOn(t, wrongIssuer, "") |
| + if err := wrongIssuer.ConfigureTeam(); !errors.Is(err, errTeamConfig) || wrongIssuer.team != nil { |
| + t.Errorf("settings for another issuer = %v, want refusal", err) |
| + } |
| none, _ := appWithSchema(t, testOrigin, TeamBootSchema, signedInAddress) |
| if err := none.ConfigureTeam(); err != nil || none.team != nil { |
| t.Error("no team settings changed something") |
diff --git a/internal/sheets/team_guard_test.go b/internal/sheets/team_guard_test.go| index dce7b96..c681524 100644 |
| --- a/internal/sheets/team_guard_test.go |
| +++ b/internal/sheets/team_guard_test.go |
| @@ -258,6 +258,84 @@ func TestTeamEveryWriteRouteRefusesALapseBeforeCommit(t *testing.T) { |
| if live, _ := f.app.linksOn(s.ID); len(live) != 1 { |
| t.Errorf("links after refused create and revoke = %d, want 1", len(live)) |
| } |
| + // Format and size had no transaction before guards; they get one only |
| + // through the guard, and a refused one must leave nothing (#53). |
| + if fm, _ := h.Formats(); len(fm) != 0 { |
| + t.Errorf("formats after a refused format = %d, want none", len(fm)) |
| + } |
| + if cols, rows, _ := h.Sizes(); len(cols) != 0 || len(rows) != 0 { |
| + t.Errorf("sizes after a refused resize = %v %v, want none", cols, rows) |
| + } |
| +} |
| + |
| +// Fable's note 2 on #53: a lower share from somebody else does not carry |
| +// a write the team rung admitted through a lapse. A share outranks the team |
| +// rung in roleFor, so the one place a lower share sits under a higher role |
| +// is the roster-owner rule: a roster owner holding a viewer share on an |
| +// orphaned sheet may share it as owner, and that rests on standing. |
| +func TestTeamLowerShareDoesNotCarryALapsingWrite(t *testing.T) { |
| + f := newTeamFixture(t) |
| + o, a := teamSubject('o'), teamSubject('a') |
| + f.dir.Set(o, "owner") |
| + f.dir.Set(a, "member") |
| + f.signInHome(t, a) |
| + created := f.request(t, "POST", "/sheets", url.Values{"title": {"Orphan"}}, false) |
| + if created.Code != http.StatusSeeOther { |
| + t.Fatalf("create = %d", created.Code) |
| + } |
| + orphan := created.Header().Get("Location") |
| + var sheetID uint64 |
| + fmt.Sscanf(orphan, "/sheets/%d", &sheetID) |
| + f.dir.Set(a, "") |
| + f.refreshed(t) |
| + |
| + f.signInHome(t, o) |
| + _, owner := f.teamWriter(t) |
| + colleague, _ := f.app.memberFor("colleague@example.com") |
| + if err := f.app.db.Create(&Grant{SheetID: sheetID, MemberID: owner.ID, Role: string(SheetViewer), GrantedBy: colleague.ID}).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + if rec := f.get(t, orphan+"/share"); rec.Code != http.StatusOK { |
| + t.Fatalf("roster owner with a viewer share on an orphaned sheet's sharing = %d, want 200", rec.Code) |
| + } |
| + teamGuard = func(ctx context.Context, authorize func(roster.State) error, write func() error) error { |
| + return teammode.Guard(ctx, authorize, func() error { |
| + if err := write(); err != nil { |
| + return err |
| + } |
| + f.clock.Step(roster.MaximumAge + time.Second) |
| + return nil |
| + }) |
| + } |
| + t.Cleanup(func() { teamGuard = teammode.Guard }) |
| + if rec := f.request(t, "POST", orphan+"/share", url.Values{"address": {"new@example.com"}, "role": {"viewer"}}, false); rec.Code != http.StatusServiceUnavailable { |
| + t.Errorf("an owner's share resting on standing, lease lapsing = %d, want 503", rec.Code) |
| + } |
| + teamGuard = teammode.Guard |
| + var n int64 |
| + if f.app.db.Model(&Grant{}).Joins("JOIN members ON members.id = grants.member_id").Where("members.address = ?", "new@example.com").Count(&n); n != 0 { |
| + t.Errorf("a refused share committed %d grant(s)", n) |
| + } |
| +} |
| + |
| +// Fable's note 1 on #53: storage that cannot say who a session is answers |
| +// a retryable 503, and keeps the session; it never signs the person out. |
| +func TestTeamIdentityStorageFailureIsUnavailableNotSignOut(t *testing.T) { |
| + f := newTeamFixture(t, "x@example.com") |
| + f.local(t, "x@example.com") |
| + session := f.jar[f.app.homeSessions.CookieName()] |
| + closed, err := rdb.Open(filepath.Join(t.TempDir(), "closed.db"), quietLogger()) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + closed.Close() |
| + f.app.team.db = closed.Writer() |
| + if rec := f.get(t, "/sheets"); rec.Code != http.StatusServiceUnavailable { |
| + t.Errorf("identity over unreadable storage = %d, want 503", rec.Code) |
| + } |
| + if f.jar[f.app.homeSessions.CookieName()] != session { |
| + t.Error("a storage failure signed the person out") |
| + } |
| } |
| func mustList(t *testing.T, f *teamFixture) []SheetSummary { |