mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-03 20:24:03 +00:00
Repair invalid \u escapes during streaming JSON parsing without changing valid Unicode escapes. Split oversized node CI doctor/infra shards and fix the restart test mock deadlock so PR CI stays under the no-output threshold.\n\nCo-authored-by: Coder <83845889+coder999999999@users.noreply.github.com>
22 lines
983 B
TypeScript
22 lines
983 B
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { parseJsonWithRepair, parseStreamingJson, repairJson } from "./json-parse.js";
|
|
|
|
describe("json-parse repairJson invalid \\u escapes", () => {
|
|
it("repairs a \\u not followed by four hex digits so the result parses", () => {
|
|
// JS string is: {"path":"C:\users"} — a model emitting an unescaped Windows path.
|
|
const broken = '{"path":"C:\\users"}';
|
|
expect(() => JSON.parse(repairJson(broken))).not.toThrow();
|
|
expect(parseJsonWithRepair(broken)).toEqual({ path: "C:\\users" });
|
|
});
|
|
|
|
it("preserves valid \\uXXXX escapes", () => {
|
|
expect(parseJsonWithRepair('{"e":"\\u0041"}')).toEqual({ e: "A" });
|
|
});
|
|
|
|
it("recovers streaming tool-call arguments instead of dropping them to {}", () => {
|
|
// LaTeX-style \u (\underline) is a valid string value the model may emit in args.
|
|
const args = '{"cmd":"\\underline{x}"}';
|
|
expect(parseStreamingJson(args)).toEqual({ cmd: "\\underline{x}" });
|
|
});
|
|
});
|