MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / StartContractServer

Function StartContractServer

internal/testutil/contract_server.go:39–165  ·  view source on GitHub ↗
(ctx context.Context, dbURL string)

Source from the content-addressed store, hash-verified

37}
38
39func StartContractServer(ctx context.Context, dbURL string) (*ContractServer, error) {
40 pool, err := OpenPreparedTestDB(ctx, dbURL)
41 if err != nil {
42 return nil, err
43 }
44
45 store := identity.NewStore(pool)
46 signer := headers.NewSigner(TestHMACSecret)
47 smtpRelay := outbound.NewSMTPRelay(&config.OutboundSMTPConfig{})
48 sender := outbound.NewSender(smtpRelay, "test.e2a.dev")
49 noopUsage := usage.NewNoopUsageTracker()
50
51 // Limits/usage/webhook components the /v1 Deps bind to. Caps are set
52 // generously so contract scenarios exercise contract shape, not quota
53 // enforcement (the 402 limit paths have dedicated httpapi unit tests).
54 usageStore := usage.NewStore(pool)
55 enforcer := limits.NewEnforcer(limits.NewStore(pool), usageStore, limits.Defaults{
56 PlanCode: "contract_test", MaxAgents: 100000, MaxDomains: 100000,
57 MaxMessagesMonth: 100000, MaxStorageBytes: 1 << 40,
58 }, time.Minute)
59 subscriberStore := webhook.NewSubscriberStore(pool)
60 idempotencyStore := idempotency.NewStore(pool)
61
62 router := mux.NewRouter()
63 api := agent.NewAPI(store, sender, smtpRelay, nil, noopUsage, "e2a.dev", "test.e2a.dev", "agents.e2a.dev", "", false)
64 api.SetIdempotencyStore(idempotencyStore)
65 api.SetEnforcer(enforcer)
66 api.SetUsageStore(usageStore)
67 api.SetSubscriberStore(subscriberStore)
68 api.RegisterRoutes(router)
69
70 wsHub := ws.NewHub()
71 wsHandler := ws.NewHandler(wsHub, store)
72
73 // Wrap the legacy mux with the typed /v1 surface using the SAME builder
74 // the production binary uses, so contract scenarios hit the real /v1
75 // handler (and a dep prod wires but the harness forgets fails loudly here).
76 v1 := apiserver.New(apiserver.Params{
77 API: api, Store: store, Enforcer: enforcer, UsageStore: usageStore,
78 SubscriberStore: subscriberStore, Idempotency: idempotencyStore, Pool: pool,
79 SMTPDomain: "test.e2a.dev", SharedDomain: "agents.e2a.dev",
80 PublicURL: "http://127.0.0.1", Production: false,
81 EventsEnabled: true,
82 Legacy: router, WSHandle: wsHandler.ServeWithEmail,
83 })
84
85 httpLn, err := net.Listen("tcp", "127.0.0.1:0")
86 if err != nil {
87 pool.Close()
88 wsHub.Close()
89 return nil, err
90 }
91
92 httpServer := &http.Server{
93 Handler: v1,
94 ReadHeaderTimeout: 5 * time.Second,
95 }
96

Callers 2

mainFunction · 0.92
setupEnvFunction · 0.92

Calls 15

SetIdempotencyStoreMethod · 0.95
SetEnforcerMethod · 0.95
SetUsageStoreMethod · 0.95
SetSubscriberStoreMethod · 0.95
RegisterRoutesMethod · 0.95
CloseMethod · 0.95
ListenAndServeMethod · 0.95
CreateOrGetUserMethod · 0.95
CloseMethod · 0.95
CreateAPIKeyMethod · 0.95
NewStoreFunction · 0.92
NewSignerFunction · 0.92

Tested by 1

setupEnvFunction · 0.74