| 1 | import assert from "node:assert/strict"; |
| 2 | import { boundedPayloadSections, TOOL_PREVIEW_MAX_BLOCKS, TOOL_PREVIEW_MAX_BYTES, utf8Prefix } from "../lib/toolPayloadPreview"; |
| 3 | |
| 4 | const fields = Object.fromEntries(Array.from({ length: 100 }, (_, index) => [`field-${index}`, "界".repeat(1000)])); |
| 5 | const sections = boundedPayloadSections(fields); |
| 6 | assert.ok(sections.length <= TOOL_PREVIEW_MAX_BLOCKS, "preview bounds structured blocks"); |
| 7 | assert.ok(new TextEncoder().encode(sections.map(section => section.body).join("")).byteLength <= TOOL_PREVIEW_MAX_BYTES, "preview bounds UTF-8 bytes"); |
| 8 | assert.equal(utf8Prefix("😀😀", 4), "😀", "UTF-8 truncation preserves surrogate pairs"); |
| 9 | console.log("tool payload preview: 16KiB and 64-block budgets passed"); |
| 10 |