package main
import (
"os"
"strings"
"testing"
)
// The composition root is the one file two sessions edit at once, and
// a stale copy of it swept into somebody else's landing once dropped
// the reply receiver, the endpoint registration and the email-default
// hook without a compile error: nothing else references them, so the
// build stayed green while the forge silently stopped taking replies.
// This reads the source and names each wire, so losing one fails a
// test rather than a user.
func TestCompositionRootKeepsItsWires(t *testing.T) {
src, err := os.ReadFile("main.go")
if err != nil {
t.Fatal(err)
}
wires := map[string]string{
"reply receiver mounted": `mux.Handle("POST /api/v1/notify/events", api.NewReplyReceiver(`,
"reply endpoint registered": `nclient.EnsureReplyEndpoint(`,
"reply secret kept": `odb.SetNotifyHook(`,
"reply store handed to deps": `deps.Replies = odb`,
"email off for a new account": `emailOffByDefault(ctx, a.client, account)`,
"email defaults in start log": `sync.Quieted`,
"admins alerted on first error": `alertAdmins(`,
"subscribers reconciled": `reconcileNotify(context.Background(), nclient, odb)`,
}
for name, wire := range wires {
if !strings.Contains(string(src), wire) {
t.Errorf("FAIL: main.go no longer has the wire for %s: %s", name, wire)
}
}
t.Logf("ok: %d wires present in the composition root", len(wires))
}