(t *testing.T, pool *pgxpool.Pool, opts ...TestServerOption)
| 74 | } |
| 75 | |
| 76 | func TestServer(t *testing.T, pool *pgxpool.Pool, opts ...TestServerOption) *E2ATestServer { |
| 77 | t.Helper() |
| 78 | o := testServerOpts{} |
| 79 | for _, opt := range opts { |
| 80 | opt(&o) |
| 81 | } |
| 82 | |
| 83 | store := identity.NewStore(pool) |
| 84 | signer := headers.NewSigner(TestHMACSecret) |
| 85 | outboundCfg := &config.OutboundSMTPConfig{ |
| 86 | Host: o.outboundSMTPHost, |
| 87 | Port: o.outboundSMTPPort, |
| 88 | } |
| 89 | fromDomain := "test.e2a.dev" |
| 90 | if o.outboundSMTPFromDomain != "" { |
| 91 | fromDomain = o.outboundSMTPFromDomain |
| 92 | } |
| 93 | smtpRelay := outbound.NewSMTPRelay(outboundCfg) |
| 94 | sender := outbound.NewSender(smtpRelay, fromDomain) |
| 95 | |
| 96 | // Webhooks-resource (PR-180) wiring. The publisher fans events |
| 97 | // to enabled subscribers; the subscriber store is what the /test |
| 98 | // + /deliveries handlers read. We wire them into both the API |
| 99 | // and the relay so trigger sites fire events. The retry worker |
| 100 | // is constructed but NOT started — tests call Tick(ctx) directly |
| 101 | // for deterministic delivery without the 30s tick. |
| 102 | subscriberStore := webhook.NewSubscriberStore(pool) |
| 103 | subscriberDeliverer := webhook.NewSubscriberDeliverer(false) |
| 104 | subscriberWorker := webhook.NewSubscriberRetryWorker(subscriberStore, subscriberDeliverer, store) |
| 105 | publisher := webhookpub.New(store, webhookpub.NewDBInserter(pool), webhookpub.StaticFlag(true)) |
| 106 | |
| 107 | // HTTP server |
| 108 | router := mux.NewRouter() |
| 109 | noopUsage := usage.NewNoopUsageTracker() |
| 110 | usageStore := usage.NewStore(pool) |
| 111 | // Generous caps — e2e exercises behavior, not quota enforcement. |
| 112 | enforcer := limits.NewEnforcer(limits.NewStore(pool), usageStore, limits.Defaults{ |
| 113 | PlanCode: "test", MaxAgents: 100000, MaxDomains: 100000, |
| 114 | MaxMessagesMonth: 100000, MaxStorageBytes: 1 << 40, |
| 115 | }, time.Minute) |
| 116 | idempotencyStore := idempotency.NewStore(pool) |
| 117 | api := agent.NewAPI(store, sender, smtpRelay, nil, noopUsage, "e2a.dev", "test.e2a.dev", "agents.e2a.dev", "", false) |
| 118 | api.SetIdempotencyStore(idempotencyStore) |
| 119 | api.SetSubscriberStore(subscriberStore) |
| 120 | api.SetPublisher(publisher) |
| 121 | api.SetEnforcer(enforcer) |
| 122 | api.SetUsageStore(usageStore) |
| 123 | api.RegisterRoutes(router) |
| 124 | |
| 125 | // WebSocket live-tail transport — wired as a /v1 route via WSHandle below. |
| 126 | wsHub := ws.NewHub() |
| 127 | wsHandler := ws.NewHandler(wsHub, store) |
| 128 | |
| 129 | // Wrap the legacy mux with the typed /v1 surface (the same apiserver |
| 130 | // builder prod + StartContractServer use) so e2e exercises the real /v1 |
| 131 | // handler; the remaining non-v1 routes (oauth/auth/health) fall through to the mux. |
| 132 | v1 := apiserver.New(apiserver.Params{ |
| 133 | API: api, Store: store, Enforcer: enforcer, UsageStore: usageStore, |
no test coverage detected