Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(mcp-host): pin what keepZipTextWhole changes for every JSZip user
marcoteb0dd5992411ce
diff --git a/mcp-host/src/workflow/__tests__/zipText.test.ts b/mcp-host/src/workflow/__tests__/zipText.test.tsnew file mode 100644index 000000000..69c96f82f--- /dev/null+++ b/mcp-host/src/workflow/__tests__/zipText.test.ts@@ -0,0 +1,42 @@+/**+ * keepZipTextWhole changes JSZip for the whole process, so these tests pin what+ * it changes: a text part is written as the UTF-8 of its string, which is what+ * JSZip writes anyway unless a character straddles one of its 16K chunks.+ */+import { describe, expect, it } from 'vitest'+import JSZip from 'jszip'+import { keepZipTextWhole } from '../zipText'++// An emoji whose surrogate pair straddles JSZip's 16K-character chunk edge.+const EDGE = `${'a'.repeat(16383)}\u{1F600}tail`++async function roundTrip(parts: Record<string, [string | Buffer, JSZip.JSZipFileOptions?]>) {+ const zip = new JSZip()+ for (const [name, [data, options]] of Object.entries(parts)) zip.file(name, data, options)+ return JSZip.loadAsync(await zip.generateAsync({ type: 'nodebuffer' }))+}++describe('keepZipTextWhole', () => {+ it('is needed: without it a character at a chunk edge is written as U+FFFD', async () => {+ const out = await roundTrip({ 'e.xml': [EDGE] })+ expect(await out.file('e.xml')!.async('string')).toContain('�')+ })++ it('writes every part as before, and the character at the edge whole', async () => {+ keepZipTextWhole()+ keepZipTextWhole()+ const plain = 'héllo <x a="1"/>'.repeat(5000)+ const out = await roundTrip({+ 'e.xml': [EDGE],+ 'p.xml': [plain],+ 'b.bin': [Buffer.from([1, 2, 3])],+ 's.b64': ['AQID', { base64: true }],+ 'r.bin': ['\u0001\u0002\u0003', { binary: true }],+ })+ expect(await out.file('e.xml')!.async('string')).toBe(EDGE)+ expect(await out.file('p.xml')!.async('string')).toBe(plain)+ expect([...(await out.file('b.bin')!.async('nodebuffer'))]).toEqual([1, 2, 3])+ expect([...(await out.file('s.b64')!.async('nodebuffer'))]).toEqual([1, 2, 3])+ expect([...(await out.file('r.bin')!.async('nodebuffer'))]).toEqual([1, 2, 3])+ })+})diff --git a/mcp-host/src/workflow/zipText.ts b/mcp-host/src/workflow/zipText.tsindex 0d2dba673..294e0adb4 100644--- a/mcp-host/src/workflow/zipText.ts+++ b/mcp-host/src/workflow/zipText.ts@@ -11,7 +11,9 @@ let whole = false* written as two U+FFFD. ExcelJS and pptxgenjs hand it their XML as strings.* From the first call on, a text string is handed over as its UTF-8 bytes,* which are what JSZip writes for it when nothing is split. Set when a package- * is written, so importing this module changes nothing.+ * is written, so importing this module changes nothing. The change reaches+ * every JSZip user in the process, the DOCX writer included, on purpose: it+ * writes the same bytes they would, less the split (see zipText.test.ts).*/export function keepZipTextWhole(): void {if (whole) return