Skip to content

Commit 0e62669

Browse files
Pandah97steipete
andauthored
fix(qa-matrix): keep shared reply previews UTF-16 safe (#102656)
* fix(qa-matrix): keep reply body preview truncation UTF-16 safe Replace `.slice(0, 200)` with `truncateUtf16Safe(replyBody, 200)` in buildMatrixReplyArtifact to prevent surrogate pair corruption. Ref. lsr911 pattern — mechanical substitution, no behavior change. * test(qa-matrix): preserve reply preview semantics --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent f6b9901 commit 0e62669

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

extensions/qa-matrix/src/runners/contract/scenario-runtime-shared.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Qa Matrix tests cover scenario runtime shared plugin behavior.
22
import { afterEach, describe, expect, it, vi } from "vitest";
3-
import { resolveMatrixQaNoReplyWindowMs } from "./scenario-runtime-shared.js";
3+
import {
4+
buildMatrixReplyArtifact,
5+
resolveMatrixQaNoReplyWindowMs,
6+
} from "./scenario-runtime-shared.js";
47

58
describe("matrix scenario runtime shared", () => {
69
afterEach(() => {
@@ -19,4 +22,18 @@ describe("matrix scenario runtime shared", () => {
1922
expect(resolveMatrixQaNoReplyWindowMs(30_000)).toBe(8_000);
2023
}
2124
});
25+
26+
it("keeps reply previews UTF-16 safe without changing empty-body artifacts", () => {
27+
const event = {
28+
kind: "message" as const,
29+
roomId: "!room:matrix-qa.test",
30+
eventId: "$event",
31+
sender: "@sut:matrix-qa.test",
32+
type: "m.room.message",
33+
};
34+
const prefix = "a".repeat(199);
35+
36+
expect(buildMatrixReplyArtifact({ ...event, body: `${prefix}😀tail` }).bodyPreview).toBe(prefix);
37+
expect(buildMatrixReplyArtifact({ ...event, body: " " }).bodyPreview).toBe("");
38+
});
2239
});

extensions/qa-matrix/src/runners/contract/scenario-runtime-shared.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Qa Matrix plugin module implements scenario runtime shared behavior.
22
import { randomUUID } from "node:crypto";
3+
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
34
import { createMatrixQaClient, type MatrixQaRoomObserver } from "../../substrate/client.js";
45
import type { MatrixQaObservedEvent } from "../../substrate/events.js";
56
import type { MatrixQaFaultProxyObserver } from "../../substrate/fault-proxy.js";
@@ -189,7 +190,7 @@ export function buildMatrixReplyArtifact(
189190
): MatrixQaReplyArtifact {
190191
const replyBody = event.body?.trim();
191192
return {
192-
bodyPreview: replyBody?.slice(0, 200),
193+
bodyPreview: replyBody === undefined ? undefined : truncateUtf16Safe(replyBody, 200),
193194
eventId: event.eventId,
194195
mentions: event.mentions,
195196
relatesTo: event.relatesTo,

0 commit comments

Comments
 (0)