Skip to content

Commit c067802

Browse files
Pandah97steipete
andauthored
fix(microsoft-foundry): keep connection test error truncation UTF-16 safe (#102605)
* fix(microsoft-foundry): keep connection test error truncation UTF-16 safe Replace `.slice(0, 200)` with `truncateUtf16Safe(body, 200)` in testFoundryConnection error messages to prevent surrogate pair corruption. Ref. lsr911 pattern — mechanical substitution, no behavior change. * test(microsoft-foundry): cover UTF-16-safe connection errors --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent bebf0b9 commit c067802

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

extensions/microsoft-foundry/onboard.connection.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,40 @@ describe("testFoundryConnection", () => {
7070
"Connection Test",
7171
);
7272
});
73+
74+
it.each([
75+
{
76+
status: 400,
77+
expectedPrefix:
78+
"Endpoint is reachable but returned 400 Bad Request - check your deployment name and API version.\n",
79+
expectedSuffix: "",
80+
},
81+
{
82+
status: 503,
83+
expectedPrefix: "Warning: test request returned 503. ",
84+
expectedSuffix: "\nProceeding anyway - you can fix the endpoint later.",
85+
},
86+
])(
87+
"keeps $status error-body previews UTF-16 safe",
88+
async ({ status, expectedPrefix, expectedSuffix }) => {
89+
const note = vi.fn();
90+
const prefix = "x".repeat(199);
91+
hoisted.fetchWithSsrFGuard.mockResolvedValue({
92+
response: new Response(`${prefix}😀tail`, { status }),
93+
release: async () => {},
94+
});
95+
96+
await testFoundryConnection({
97+
ctx: { prompter: { note } } as never,
98+
endpoint: "https://example.openai.azure.com",
99+
modelId: "gpt-4o",
100+
api: DEFAULT_API,
101+
});
102+
103+
expect(note).toHaveBeenCalledExactlyOnceWith(
104+
`${expectedPrefix}${prefix}${expectedSuffix}`,
105+
"Connection Test",
106+
);
107+
},
108+
);
73109
});

extensions/microsoft-foundry/onboard.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
normalizeOptionalString,
88
normalizeStringifiedOptionalString,
99
} from "openclaw/plugin-sdk/string-coerce-runtime";
10+
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
1011
import {
1112
azLoginDeviceCode,
1213
azLoginDeviceCodeWithOptions,
@@ -613,7 +614,7 @@ export async function testFoundryConnection(params: {
613614
FOUNDRY_CONNECTION_TEST_ERROR_BODY_LIMIT_BYTES,
614615
).catch(() => "");
615616
await params.ctx.prompter.note(
616-
`Endpoint is reachable but returned 400 Bad Request - check your deployment name and API version.\n${body.slice(0, 200)}`,
617+
`Endpoint is reachable but returned 400 Bad Request - check your deployment name and API version.\n${truncateUtf16Safe(body, 200)}`,
617618
"Connection Test",
618619
);
619620
} else if (!res.ok) {
@@ -622,7 +623,7 @@ export async function testFoundryConnection(params: {
622623
FOUNDRY_CONNECTION_TEST_ERROR_BODY_LIMIT_BYTES,
623624
).catch(() => "");
624625
await params.ctx.prompter.note(
625-
`Warning: test request returned ${res.status}. ${body.slice(0, 200)}\nProceeding anyway - you can fix the endpoint later.`,
626+
`Warning: test request returned ${res.status}. ${truncateUtf16Safe(body, 200)}\nProceeding anyway - you can fix the endpoint later.`,
626627
"Connection Test",
627628
);
628629
} else {

0 commit comments

Comments
 (0)