oficina / docs Public

Docs team mode: tests for the allocation gate under Unknown and the activation census

Hand mutations found both uncovered: Unknown read as a definite refusal at
first Home entry, and either identity table dropped from the census.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 4a0f8087d5999ab528a6104f656b8407c8e1b65e parent 2162770
2 files changed, +63 −0
  • internal/docs/team_identity_test.go +46 −0
  • internal/docs/team_router_test.go +17 −0

CI cancelled — superseded by a newer push — run details

diff --git a/internal/docs/team_identity_test.go b/internal/docs/team_identity_test.go
index 71cdceb..3408563 100644
--- a/internal/docs/team_identity_test.go
+++ b/internal/docs/team_identity_test.go
@@ -132,3 +132,49 @@ func TestTeamIdentityAddressAbsenceNeverRedeemsEmptyGrant(t *testing.T) {
t.Fatal("unsupported local method accepted")
}
}
+
+// Activation refuses a database holding a Home identity from another issuer,
+// in either of Docs' tables, and writes no marker: the marker pins one issuer,
+// and a row from another would be read under it.
+func TestTeamActivationCensusCoversBothIdentityTables(t *testing.T) {
+ for _, table := range []string{"docs_identity_links", "docs_home_identities"} {
+ t.Run(table, func(t *testing.T) {
+ cfg, home := teamConfigFixture(t)
+ settings, e := validatedTeamConfig(cfg, home, "https://docs.example")
+ if e != nil {
+ t.Fatal(e)
+ }
+ app := newSampleDocumentsInternalTestApp(t, "0")
+ ctx := t.Context()
+ if _, e = migrate.Apply(ctx, app.db, TeamBootSchema); e != nil {
+ t.Fatal(e)
+ }
+ const other = "https://other.example"
+ subject := "pr_" + strings.Repeat("a", 26)
+ switch table {
+ case "docs_identity_links":
+ person, e := app.Store().EnsurePerson(ctx, "linked@example.com")
+ if e != nil {
+ t.Fatal(e)
+ }
+ if _, e = app.db.Writer().Exec("INSERT INTO docs_identity_links(issuer,subject,person_id) VALUES(?,?,?)", other, subject, person); e != nil {
+ t.Fatal(e)
+ }
+ default:
+ ps, e := principalstore.New(app.db.Writer(), principalstore.Config{Issuer: other, Team: "TeamA", RequireMembership: func(context.Context, principalstore.MembershipRequest) error { return nil }})
+ if e != nil {
+ t.Fatal(e)
+ }
+ if _, e = ps.EnsureHome(ctx, principalstore.HomeIdentity{Issuer: other, Subject: subject}); e != nil {
+ t.Fatal(e)
+ }
+ }
+ if _, e = newTeamRuntime(ctx, settings, app.db.Writer(), home); e != errTeamConfig {
+ t.Fatal("activated over another issuer's identity", e)
+ }
+ if _, activated, e := teamState.Required(ctx, app.db.Writer()); e != nil || activated {
+ t.Fatal("a refused census wrote the marker", e)
+ }
+ })
+ }
+}
diff --git a/internal/docs/team_router_test.go b/internal/docs/team_router_test.go
index 992ec46..1ecfc49 100644
--- a/internal/docs/team_router_test.go
+++ b/internal/docs/team_router_test.go
@@ -384,3 +384,20 @@ func TestTeamListAsksPartialAfterListing(t *testing.T) {
t.Fatal("a shares-only list built under a lapsed lease was not marked partial")
}
}
+
+// A first Home entry the roster cannot decide is a retryable 503 that
+// allocates nothing: the allocation gate is Runtime.AdmitUnlinked, and only
+// its definite "not a member" is the 403 "unknown".
+func TestTeamRouterHomeOnlyFirstEntryUnderUnknownIsRetryable(t *testing.T) {
+ f := newTeamRouterFixture(t)
+ f.directory.change(nil, true)
+ f.clock.step(61 * time.Second)
+ b := f.browser()
+ nonce := b.start(t, "/auth/start?return_to=%2F", "")
+ if r := b.exchange(t, nonce, teamSubject('c'), time.Now()); r.Code != 503 {
+ t.Fatal("undecided first entry was not retryable", r.Code)
+ }
+ if _, e := f.app.store.team.principals.Resolve(t.Context(), bridgeIssuer, teamSubject('c')); !errors.Is(e, principalstore.ErrRefused) {
+ t.Fatal("undecided first entry allocated a principal", e)
+ }
+}