diff --git a/extensions/qa-matrix/src/runners/contract/scenario-runtime-shared.test.ts b/extensions/qa-matrix/src/runners/contract/scenario-runtime-shared.test.ts index 20d6b3594d9f..37c55b3c7f44 100644 --- a/extensions/qa-matrix/src/runners/contract/scenario-runtime-shared.test.ts +++ b/extensions/qa-matrix/src/runners/contract/scenario-runtime-shared.test.ts @@ -1,6 +1,9 @@ // Qa Matrix tests cover scenario runtime shared plugin behavior. import { afterEach, describe, expect, it, vi } from "vitest"; -import { resolveMatrixQaNoReplyWindowMs } from "./scenario-runtime-shared.js"; +import { + buildMatrixReplyArtifact, + resolveMatrixQaNoReplyWindowMs, +} from "./scenario-runtime-shared.js"; describe("matrix scenario runtime shared", () => { afterEach(() => { @@ -19,4 +22,18 @@ describe("matrix scenario runtime shared", () => { expect(resolveMatrixQaNoReplyWindowMs(30_000)).toBe(8_000); } }); + + it("keeps reply previews UTF-16 safe without changing empty-body artifacts", () => { + const event = { + kind: "message" as const, + roomId: "!room:matrix-qa.test", + eventId: "$event", + sender: "@sut:matrix-qa.test", + type: "m.room.message", + }; + const prefix = "a".repeat(199); + + expect(buildMatrixReplyArtifact({ ...event, body: `${prefix}😀tail` }).bodyPreview).toBe(prefix); + expect(buildMatrixReplyArtifact({ ...event, body: " " }).bodyPreview).toBe(""); + }); }); diff --git a/extensions/qa-matrix/src/runners/contract/scenario-runtime-shared.ts b/extensions/qa-matrix/src/runners/contract/scenario-runtime-shared.ts index 4f0acad5b30f..f924d6afe1bc 100644 --- a/extensions/qa-matrix/src/runners/contract/scenario-runtime-shared.ts +++ b/extensions/qa-matrix/src/runners/contract/scenario-runtime-shared.ts @@ -1,5 +1,6 @@ // Qa Matrix plugin module implements scenario runtime shared behavior. import { randomUUID } from "node:crypto"; +import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime"; import { createMatrixQaClient, type MatrixQaRoomObserver } from "../../substrate/client.js"; import type { MatrixQaObservedEvent } from "../../substrate/events.js"; import type { MatrixQaFaultProxyObserver } from "../../substrate/fault-proxy.js"; @@ -189,7 +190,7 @@ export function buildMatrixReplyArtifact( ): MatrixQaReplyArtifact { const replyBody = event.body?.trim(); return { - bodyPreview: replyBody?.slice(0, 200), + bodyPreview: replyBody === undefined ? undefined : truncateUtf16Safe(replyBody, 200), eventId: event.eventId, mentions: event.mentions, relatesTo: event.relatesTo,