mirror of
https://github.com/morluto/rea.git
synced 2026-11-08 15:56:35 +00:00
Share strict UTF-8 JSON admission across bounded worker reports. Preserve IDA/JEB structured dictionaries through negotiated SDK validation and adapter decoding, retaining inherited tool validation and protocol handling. Validated 240 tests, including real SDK/HTTP exchanges and firmware file reads; 83 host-specific cases skipped. Typecheck, lint, and discovery passed. Real-provider execution and modern MCP protocol behavior remain unverified.
29 lines
818 B
TypeScript
29 lines
818 B
TypeScript
import { expect, it } from "vitest";
|
|
import { safeParseUtf8Json } from "./safeJson.js";
|
|
|
|
it("distinguishes malformed UTF-8 from a literal Unicode replacement character", () => {
|
|
const invalid = Buffer.concat([
|
|
Buffer.from('{"message":"'),
|
|
Buffer.from([0xff]),
|
|
Buffer.from('"}'),
|
|
]);
|
|
expect(safeParseUtf8Json(invalid)).toMatchObject({
|
|
ok: false,
|
|
cause: { code: "ERR_ENCODING_INVALID_ENCODED_DATA" },
|
|
});
|
|
expect(safeParseUtf8Json(Buffer.from('{"message":"valid � 雪"}'))).toEqual({
|
|
ok: true,
|
|
value: { message: "valid � 雪" },
|
|
});
|
|
});
|
|
|
|
it.each(["\uFEFF{}", '{"message":', ""])(
|
|
"retains strict JSON failure causes for %j",
|
|
(text) => {
|
|
expect(safeParseUtf8Json(Buffer.from(text))).toMatchObject({
|
|
ok: false,
|
|
cause: expect.any(SyntaxError),
|
|
});
|
|
},
|
|
);
|