seed default channel(s) on boot
ci / build (pull_request) Successful in 23s
ci / image (pull_request) Skipped

fresh relay seeds configured open channels (RELAY_DEFAULT_CHANNELS,
default general) so a client always has a room. relay-signed 9007
through the normal pipeline; idempotent; never reopens a closed group.

also adds mission/roadmap and separation rationale to the readme.
This commit is contained in:
Robert Goodall
2026-07-25 08:11:39 -04:00
parent 294616642f
commit 8e9235a820
7 changed files with 220 additions and 15 deletions
+48
View File
@@ -192,3 +192,51 @@ func TestMultiUserAdminOverWebsocket(t *testing.T) {
t.Fatal("admin did not receive the admitted member's message")
}
}
// SeedDefaultChannels creates configured channels that don't exist yet, signed
// by the relay, and is idempotent: seeding an already-present channel is a
// no-op. A seeded open channel accepts chat without an explicit create.
func TestSeedDefaultChannels(t *testing.T) {
store := &slicestore.SliceStore{}
if err := store.Init(); err != nil {
t.Fatalf("store init: %v", err)
}
app := buildRelay(relayConfig{
secretKey: nostr.Generate(),
store: store,
name: "test-relay",
defaultChannels: []string{"general", "general", ""}, // dupes/blanks ignored
})
ctx := context.Background()
app.SeedDefaultChannels(ctx)
if !app.groups.Has("general") {
t.Fatal("expected default channel 'general' to be seeded")
}
// The seed event is signed by the relay identity.
if !app.groups.IsAdmin("general", app.pubKey) {
t.Fatal("expected the relay to be admin of the seeded channel")
}
// Idempotent: a second seed doesn't error or duplicate.
app.SeedDefaultChannels(ctx)
// Seeding never clobbers an existing channel: pre-create one closed, then a
// seed of the same id must leave it closed.
closed := nostr.Event{Kind: nostr.KindSimpleGroupCreateGroup, CreatedAt: nostr.Now(), Tags: nostr.Tags{{"h", "ops"}, {"closed"}}}
mustSign(t, app.secretKey, &closed)
if _, err := app.relay.AddEvent(ctx, closed); err != nil {
t.Fatalf("pre-create closed group: %v", err)
}
app.defaultChannels = []string{"ops"}
app.SeedDefaultChannels(ctx)
// A non-member posting to the still-closed 'ops' must be rejected.
stranger := nostr.Generate()
if reject, _ := app.groups.Evaluate(func() nostr.Event {
e := nostr.Event{Kind: nostr.KindSimpleGroupChatMessage, CreatedAt: nostr.Now(), Tags: nostr.Tags{{"h", "ops"}}}
mustSign(t, stranger, &e)
return e
}()); !reject {
t.Fatal("seed must not reopen a pre-existing closed channel")
}
}