MCPcopy Create free account
hub / github.com/github/copilot-sdk / assertRouting

Function assertRouting

nodejs/test/e2e/multi_provider_registry.e2e.test.ts:137–200  ·  view source on GitHub ↗
(
        selectionId: string,
        expectedWireModel: string,
        expectedProviderHeader: string
    )

Source from the content-addressed store, hash-verified

135 });
136
137 async function assertRouting(
138 selectionId: string,
139 expectedWireModel: string,
140 expectedProviderHeader: string
141 ): Promise<void> {
142 // Two OpenAI-compatible providers, both pointed at the replay proxy so
143 // their /chat/completions traffic is captured. They are distinguished on
144 // the wire by their per-provider X-Provider header. "alpha" carries two
145 // models (multiple models per provider); "delta" carries one.
146 const providers: NamedProviderConfig[] = [
147 {
148 name: "alpha",
149 type: "openai",
150 wireApi: "completions",
151 baseUrl: openAiEndpoint.url,
152 apiKey: "alpha-secret",
153 headers: { "X-Provider": "alpha" },
154 },
155 {
156 name: "delta",
157 type: "openai",
158 wireApi: "completions",
159 baseUrl: openAiEndpoint.url,
160 apiKey: "delta-secret",
161 headers: { "X-Provider": "delta" },
162 },
163 ];
164 const models: ProviderModelConfig[] = [
165 { id: "sonnet", provider: "alpha", wireModel: "byok-gpt-4o" },
166 { id: "haiku", provider: "alpha", wireModel: "byok-gpt-4o-mini" },
167 { id: "turbo", provider: "delta", wireModel: "byok-gpt-4-turbo" },
168 ];
169
170 const session = await client.createSession({
171 onPermissionRequest: approveAll,
172 model: selectionId,
173 providers,
174 models,
175 });
176
177 try {
178 await session.sendAndWait({ prompt: "What is 5+5?" });
179 const exchanges = await waitForExchanges();
180 expect(exchanges.length).toBe(1);
181 const exchange = exchanges[0];
182
183 // The wire model sent to the provider is the selected model's
184 // wireModel, not its provider-qualified selection id.
185 expect(exchange.request.model).toBe(expectedWireModel);
186
187 // The request carried the owning provider's custom header, proving
188 // the turn was dispatched against the correct provider connection.
189 expect(getHeader(exchange, "X-Provider")).toBe(expectedProviderHeader);
190
191 // The provider's API key was applied as an Authorization header.
192 expect(getHeader(exchange, "Authorization")).toBeTruthy();
193 } finally {
194 try {

Calls 5

getHeaderFunction · 0.85
waitForExchangesFunction · 0.70
createSessionMethod · 0.45
sendAndWaitMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…