Files
reverse-engineering-anything/src/domain/safeJson.test.ts
T
morluto da526fc014 fix(providers): preserve reply bytes and structured JSON ownership
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.
2026-10-26 17:52:32 +08:00

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),
});
},
);