Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): clean up temp files on a rejected Apple Health import
[._.]/ Adam Eivyad3638dce88f
diff --git a/server/lib/zipStream.test.js b/server/lib/zipStream.test.jsindex 0115623b97..095dcb8bd9 100644--- a/server/lib/zipStream.test.js+++ b/server/lib/zipStream.test.js@@ -222,6 +222,22 @@ describe('collectZipEntry', () => {await expect(collected).rejects.toThrow(/exceeds 16 byte limit/);});+ it('rejects (does not hang) when a deflated member is corrupt', async () => {+ // method:8 declares deflate, but the payload is not a valid raw-deflate+ // stream — the inflate pipeline must error and reject the collect, not hang.+ const garbage = Buffer.from('not a valid deflate stream at all');+ const zip = Buffer.concat([buildEntry('clinical_records/bad.json', garbage, { method: 8 }), buildEocd()]);+ const collected = new Promise((resolve, reject) => {+ const parser = parseZip();+ let read;+ parser.on('entry', (entry) => { read = collectZipEntry(entry); });+ parser.on('close', () => read.then(resolve, reject));+ parser.on('error', reject);+ Readable.from([zip]).pipe(parser);+ });+ await expect(collected).rejects.toThrow();+ });+it('collects multiple JSON members alongside a drained member (appleHealth pattern)', async () => {// Mirrors server/routes/appleHealth.js: drain export.xml, collect every// clinical_records/*.json into buffers, await them all on 'close'.diff --git a/server/routes/appleHealth.js b/server/routes/appleHealth.jsindex ce0e26bf4a..08dbefb421 100644--- a/server/routes/appleHealth.js+++ b/server/routes/appleHealth.js@@ -156,10 +156,18 @@ router.post('/import/xml', uploadXml, asyncHandler(async (req, res) => {// polled flag; the clinical collects are awaited as promises.const finalize = () => Promise.all(clinicalReads).then(settle(resolve));if (xmlWriteFinished) return finalize();- const check = setInterval(() => { if (xmlWriteFinished) { clearInterval(check); finalize(); } }, XML_WRITE_POLL_INTERVAL_MS);- setTimeout(() => { clearInterval(check); finalize(); }, XML_WRITE_TIMEOUT_MS);+ const check = setInterval(() => { if (xmlWriteFinished) { clearInterval(check); clearTimeout(timer); finalize(); } }, XML_WRITE_POLL_INTERVAL_MS);+ const timer = setTimeout(() => { clearInterval(check); finalize(); }, XML_WRITE_TIMEOUT_MS);}).on('error', settle(reject));+ }).catch(async (err) => {+ // A rejected parse (missing export.xml, or an oversized/corrupt clinical+ // record member) would otherwise orphan the uploaded ZIP and any partial+ // extracted XML on disk. Clean both up before the error bubbles to the+ // centralized middleware (mirrors chatgptZipImport's reject cleanup).+ await fs.unlink(filePath).catch(() => {});+ await fs.unlink(xmlPath).catch(() => {});+ throw err;});await fs.unlink(filePath);