package hub import ( "context" "testing" "time" ) // AdmittedCount is the drive surface's one window into a live room // (spec §8.2): how many peers are actually in the call, and never who // they are. A room nobody has opened is zero rather than an error — // the caller holds a meeting row, and a meeting with no room is simply // a meeting nobody has entered. func TestAdmittedCountCountsAdmittedOnlyAndNeverAWaitingGuest(t *testing.T) { now := time.Date(2026, 9, 11, 9, 0, 0, 0, time.UTC) h := testHub(&now) ctx := context.Background() if n := h.AdmittedCount("r1"); n != 0 { t.Fatalf("a room nobody has opened: %d, want 0", n) } m, err := h.Open("r1", "sm", 1, "Mia", KindMember) if err != nil { t.Fatal(err) } if n := h.AdmittedCount("r1"); n != 0 { t.Fatalf("an unjoined participation counts: %d, want 0", n) } if err := h.Join(ctx, "r1", "sm", m.Peer); err != nil { t.Fatal(err) } if n := h.AdmittedCount("r1"); n != 1 { t.Fatalf("a joined member: %d, want 1", n) } g, err := h.Open("r1", "sg", 100, "Gus", KindGuest) if err != nil { t.Fatal(err) } if err := h.Join(ctx, "r1", "sg", g.Peer); err != nil { t.Fatal(err) } if n := h.AdmittedCount("r1"); n != 1 { t.Fatalf("a waiting guest is counted: %d, want 1", n) } if err := h.Admit(ctx, "r1", "sm", m.Peer, g.Peer); err != nil { t.Fatal(err) } if n := h.AdmittedCount("r1"); n != 2 { t.Fatalf("after admitting the guest: %d, want 2", n) } if n := h.AdmittedCount("r2"); n != 0 { t.Fatalf("another room's count leaked: %d, want 0", n) } if err := h.Leave("r1", "sg", g.Peer); err != nil { t.Fatal(err) } if n := h.AdmittedCount("r1"); n != 1 { t.Fatalf("after the guest left: %d, want 1", n) } }