Skip to content

Commit 109f037

Browse files
committed
fix(qa-matrix): use truncateUtf16Safe for message body/caption previews
Replace .slice(0, 200) with truncateUtf16Safe() on MATRIX message body and caption fields in attachment detail lines and scenario artifacts to prevent UTF-16 surrogate pair corruption.
1 parent e595a8c commit 109f037

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
12
// Qa Matrix plugin module implements scenario runtime media behavior.
23
import type { MatrixQaObservedEvent } from "../../substrate/events.js";
34
import { MATRIX_QA_MEDIA_ROOM_KEY, resolveMatrixQaScenarioRoomId } from "./scenario-catalog.js";
@@ -43,7 +44,7 @@ function buildMatrixQaAttachmentDetailLines(params: {
4344
`${params.label} msgtype: ${params.attachmentEvent.msgtype ?? "<none>"}`,
4445
`${params.label} attachment kind: ${params.attachmentEvent.attachment?.kind ?? "<none>"}`,
4546
`${params.label} attachment filename: ${params.attachmentEvent.attachment?.filename ?? "<none>"}`,
46-
`${params.label} body preview: ${params.attachmentEvent.body?.slice(0, 200) ?? "<none>"}`,
47+
`${params.label} body preview: ${params.attachmentEvent.body ? truncateUtf16Safe(params.attachmentEvent.body, 200) : "<none>"}`,
4748
];
4849
}
4950

@@ -124,7 +125,9 @@ export async function runImageUnderstandingAttachmentScenario(context: MatrixQaS
124125
const reply = buildMatrixReplyArtifact(matched.event);
125126
return {
126127
artifacts: {
127-
attachmentCaptionPreview: attachmentEvent.event.attachment?.caption?.slice(0, 200),
128+
attachmentCaptionPreview: attachmentEvent.event.attachment?.caption
129+
? truncateUtf16Safe(attachmentEvent.event.attachment.caption, 200)
130+
: undefined,
128131
attachmentFilename: MATRIX_QA_IMAGE_ATTACHMENT_FILENAME,
129132
driverEventId,
130133
reply,
@@ -441,7 +444,9 @@ export async function runGeneratedImageDeliveryScenario(context: MatrixQaScenari
441444
);
442445
return {
443446
artifacts: {
444-
attachmentBodyPreview: matchedEvent.body?.slice(0, 200),
447+
attachmentBodyPreview: matchedEvent.body
448+
? truncateUtf16Safe(matchedEvent.body, 200)
449+
: undefined,
445450
attachmentEventId: matchedEvent.eventId,
446451
attachmentFilename: attachment.filename,
447452
attachmentKind: attachment.kind,

0 commit comments

Comments
 (0)