Skip to content

Commit 0846618

Browse files
committed
Unify replay protocol paths
Select a protocol descriptor once per backend so CAPI and BYOK share routing, canonical matching, errors, JSON/SSE responses, and exchange inspection. Replay compaction directly from canonical snapshots instead of synthesizing provider-specific responses. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 85a40918-bd95-440b-b6e9-97c757a71f8c
1 parent 818f289 commit 0846618

2 files changed

Lines changed: 164 additions & 334 deletions

File tree

test/harness/modelProtocolAdapters.test.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,22 @@ import {
2626

2727
type ByokBackend = Exclude<ReplayBackend, "capi">;
2828

29-
const backends: ByokBackend[] = [
29+
const backends: ReplayBackend[] = [
30+
"capi",
3031
"anthropic-messages",
3132
"openai-responses",
3233
"openai-completions",
3334
];
3435

35-
const endpoints: Record<ByokBackend, string> = {
36+
const endpoints: Record<ReplayBackend, string> = {
37+
capi: "/chat/completions",
3638
"anthropic-messages": "/v1/messages",
3739
"openai-responses": "/responses",
3840
"openai-completions": "/chat/completions",
3941
};
4042

41-
const models: Record<ByokBackend, string> = {
43+
const models: Record<ReplayBackend, string> = {
44+
capi: "gpt-4.1",
4245
"anthropic-messages": "claude-sonnet-4.5",
4346
"openai-responses": "gpt-4.1",
4447
"openai-completions": "gpt-4.1",
@@ -76,7 +79,7 @@ const completionWithTool: ChatCompletion = {
7679
};
7780

7881
function requestFor(
79-
backend: ByokBackend,
82+
backend: ReplayBackend,
8083
prompt: string,
8184
): Record<string, unknown> {
8285
const model = models[backend];
@@ -100,6 +103,7 @@ function requestFor(
100103
},
101104
],
102105
};
106+
case "capi":
103107
case "openai-completions":
104108
return {
105109
model,
@@ -372,7 +376,7 @@ describe("protocol-aware replay", () => {
372376
}
373377

374378
async function withProxy(
375-
backend: ByokBackend,
379+
backend: ReplayBackend,
376380
action: (proxyUrl: string) => Promise<void>,
377381
): Promise<void> {
378382
const proxy = new ReplayingCapiProxy(
@@ -432,7 +436,10 @@ describe("protocol-aware replay", () => {
432436
role: "user",
433437
content: "Hello",
434438
});
435-
if (backend !== "openai-completions") {
439+
if (
440+
backend === "anthropic-messages" ||
441+
backend === "openai-responses"
442+
) {
436443
expect(exchanges[0].response).toBeUndefined();
437444
}
438445
});
@@ -526,8 +533,17 @@ describe("protocol-aware replay", () => {
526533
});
527534

528535
test.each(backends)(
529-
"synthesizes compaction responses through %s",
536+
"replays compaction responses through %s",
530537
async (backend) => {
538+
await writeSnapshot([
539+
{ role: "system", content: "${system}" },
540+
{ role: "user", content: "${compaction_prompt}" },
541+
{
542+
role: "assistant",
543+
content:
544+
"<overview>Compacted</overview><history>History</history><checkpoint_title>Checkpoint</checkpoint_title>",
545+
},
546+
]);
531547
await withProxy(backend, async (proxyUrl) => {
532548
const response = await postJson(
533549
proxyUrl,
@@ -554,4 +570,15 @@ describe("protocol-aware replay", () => {
554570
await expect(response.text()).resolves.toContain("protocol_mismatch");
555571
});
556572
});
573+
574+
test("keeps foreign model endpoints unavailable in CAPI mode", async () => {
575+
await withProxy("capi", async (proxyUrl) => {
576+
const response = await postJson(
577+
proxyUrl,
578+
endpoints["openai-responses"],
579+
requestFor("openai-responses", "Hello"),
580+
);
581+
expect(response.status).toBe(404);
582+
});
583+
});
557584
});

0 commit comments

Comments
 (0)