fix(memory-host): use truncateUtf16Safe for QMD stderr context truncation (#102547)

* fix(memory-host): use truncateUtf16Safe for QMD stderr context truncation

* test(memory): cover UTF-16-safe qmd stderr summary

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
lsr911
2026-07-09 17:38:43 +08:00
committed by GitHub
parent 4cc92009ed
commit bb1fa4012e
2 changed files with 11 additions and 1 deletions

View File

@@ -60,6 +60,15 @@ complete`,
expect(parseQmdQueryJson("", "[qmd] warning: no results found\n")).toStrictEqual([]);
});
it("keeps bounded stderr context UTF-16 safe", () => {
const prefix = "a".repeat(116);
const stderr = `${prefix}😀${"b".repeat(120)}`;
expect(() => parseQmdQueryJson("", stderr)).toThrow(
`qmd query returned invalid JSON: stdout empty (stderr: ${prefix}...)`,
);
});
it("does not treat arbitrary non-marker text as no-results output", () => {
expect(() =>
parseQmdQueryJson("warning: search completed; no results found for this query", ""),

View File

@@ -1,4 +1,5 @@
// Memory Host SDK module implements qmd query parser behavior.
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
import { formatErrorMessage } from "./error-utils.js";
import { normalizeLowercaseStringOrEmpty } from "./string-utils.js";
@@ -81,7 +82,7 @@ function isQmdNoResultsLine(line: string): boolean {
/** Bound stderr context included in parse errors. */
function summarizeQmdStderr(raw: string): string {
return raw.length <= 120 ? raw : `${raw.slice(0, 117)}...`;
return raw.length <= 120 ? raw : `${truncateUtf16Safe(raw, 117)}...`;
}
/** Parse and normalize a strict qmd JSON array payload. */