From c335ecdb73e64c5379028280202cc2ee2141248a Mon Sep 17 00:00:00 2001 From: huangjianxiong Date: Thu, 9 Jul 2026 18:49:35 +0800 Subject: [PATCH] fix(microsoft-foundry): keep Azure CLI error truncation UTF-16 safe (#102604) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(microsoft-foundry): keep Azure CLI error truncation UTF-16 safe Replace `.slice(0, 300)` with `truncateUtf16Safe(normalized, 300)` in summarizeAzErrorMessage to prevent surrogate pair corruption. Ref. lsr911 pattern — mechanical substitution, no behavior change. * test(microsoft-foundry): cover UTF-16-safe CLI errors * test(microsoft-foundry): assert complete CLI error --------- Co-authored-by: Peter Steinberger --- extensions/microsoft-foundry/cli.ts | 3 ++- extensions/microsoft-foundry/index.test.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/extensions/microsoft-foundry/cli.ts b/extensions/microsoft-foundry/cli.ts index 05c22df78871..9b65841ded97 100644 --- a/extensions/microsoft-foundry/cli.ts +++ b/extensions/microsoft-foundry/cli.ts @@ -4,6 +4,7 @@ import { normalizeOptionalString, normalizeStringifiedOptionalString, } from "openclaw/plugin-sdk/string-coerce-runtime"; +import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime"; import type { AzAccessToken, AzAccount } from "./shared.js"; import { COGNITIVE_SERVICES_RESOURCE } from "./shared.js"; @@ -34,7 +35,7 @@ function summarizeAzErrorMessage(raw: string): string { if (/aadsts\d+/i.test(normalized)) { return "Azure login failed for the selected tenant. Re-run `az login --use-device-code` and confirm the tenant is correct."; } - return normalized.slice(0, 300); + return truncateUtf16Safe(normalized, 300); } function buildAzCommandError(error: Error, stderr: string, stdout: string): Error { diff --git a/extensions/microsoft-foundry/index.test.ts b/extensions/microsoft-foundry/index.test.ts index 8ab1d902e676..f02a5502a98f 100644 --- a/extensions/microsoft-foundry/index.test.ts +++ b/extensions/microsoft-foundry/index.test.ts @@ -1830,6 +1830,22 @@ describe("microsoft-foundry plugin", () => { await expect(getAccessTokenResultAsync()).rejects.toThrow("Azure CLI is not logged in"); }); + it("keeps bounded Azure CLI error details UTF-16 safe", async () => { + const prefix = "x".repeat(299); + execFileMock.mockImplementationOnce( + ( + _file: unknown, + _args: unknown, + _options: unknown, + callback: (error: Error | null, stdout: string, stderr: string) => void, + ) => callback(new Error("az failed"), "", `${prefix}😀tail`), + ); + + await expect(getAccessTokenResultAsync()).rejects.toMatchObject({ + message: `az failed: ${prefix}`, + }); + }); + it("deletes legacy provider-level secret refs", () => { const secretRef = { source: "env" as const,