Skip to content

Commit 2ee93b1

Browse files
Test proxy update
1 parent c5ac702 commit 2ee93b1

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

test/harness/replayingCapiProxy.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
*--------------------------------------------------------------------------------------------*/
44

5-
import type { retrieveAvailableModels } from "@github/copilot/sdk";
65
import { existsSync } from "fs";
76
import { mkdir, readFile, writeFile } from "fs/promises";
87
import type {
@@ -663,9 +662,23 @@ function transformOpenAIRequestMessage(
663662
} else if (m.role === "user" && typeof m.content === "string") {
664663
content = normalizeUserMessage(m.content);
665664
} else if (m.role === "tool" && typeof m.content === "string") {
666-
// If it's a JSON tool call result, normalize the whitespace and property ordering
665+
// If it's a JSON tool call result, normalize the whitespace and property ordering.
666+
// For successful tool results wrapped in {resultType, textResultForLlm}, unwrap to
667+
// just the inner value so snapshots stay stable across envelope format changes.
667668
try {
668-
content = JSON.stringify(sortJsonKeys(JSON.parse(m.content)));
669+
const parsed = JSON.parse(m.content);
670+
if (
671+
parsed &&
672+
typeof parsed === "object" &&
673+
parsed.resultType === "success" &&
674+
"textResultForLlm" in parsed
675+
) {
676+
content = typeof parsed.textResultForLlm === "string"
677+
? parsed.textResultForLlm
678+
: JSON.stringify(sortJsonKeys(parsed.textResultForLlm));
679+
} else {
680+
content = JSON.stringify(sortJsonKeys(parsed));
681+
}
669682
} catch {
670683
content = m.content.trim();
671684
}
@@ -950,9 +963,7 @@ function convertToStreamingResponseChunks(
950963
return chunks;
951964
}
952965

953-
function createGetModelsResponse(modelIds: string[]): {
954-
data: Awaited<ReturnType<typeof retrieveAvailableModels>>;
955-
} {
966+
function createGetModelsResponse(modelIds: string[]) {
956967
// Obviously the following might not match any given model. We could track the original responses from /models,
957968
// but that risks invalidating the caches too frequently and making this unmaintainable. If this approximation
958969
// turns out to be insufficient, we can tweak the logic here based on known model IDs.

0 commit comments

Comments
 (0)