mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-16 14:41:37 +00:00
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:
@@ -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", ""),
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user