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): bound sniff buffer to SNIFF_BYTES + test temp-cleanup on stream failure
[._.]/ Adam Eivye165ff810fd2
diff --git a/server/services/chatgptZipImport.js b/server/services/chatgptZipImport.jsindex 53df4d0685..d5f00c141d 100644--- a/server/services/chatgptZipImport.js+++ b/server/services/chatgptZipImport.js@@ -140,7 +140,13 @@ const streamAssetToFile = (entry, filePath, max) => new Promise((resolve, rejectwrite(chunk, _enc, cb) {size += chunk.length;if (size > max) { cb(new Error(`ZIP member exceeds ${max} byte limit`)); return; }- if (headLen < SNIFF_BYTES) { head.push(chunk); headLen += chunk.length; }+ if (headLen < SNIFF_BYTES) {+ // Keep only the bytes still needed to reach SNIFF_BYTES, so `head` holds+ // at most SNIFF_BYTES regardless of how the producer chunks the asset.+ const slice = chunk.subarray(0, SNIFF_BYTES - headLen);+ head.push(slice);+ headLen += slice.length;+ }if (out.write(chunk)) cb();else out.once('drain', cb);},diff --git a/server/services/chatgptZipImport.test.js b/server/services/chatgptZipImport.test.jsindex 37efc8a2c9..1e8e6ffb89 100644--- a/server/services/chatgptZipImport.test.js+++ b/server/services/chatgptZipImport.test.js@@ -157,6 +157,21 @@ describe('chatgptZipImport service', () => {expect(assets.get('file-DOC').file).toBe('file-DOC.csv');});+ it('cleans up the streamed temp file when the stream fails (corrupt asset-name map)', async () => {+ // The asset streams to a <id>.part temp before the name map is parsed; a+ // corrupt name map throws mid-stream, so the temp must be unlinked rather+ // than orphaned on disk (the new stream-to-disk cleanup path).+ const zipPath = await writeZip([+ ['conversations-000.json', JSON.stringify([{ id: 'c1', title: 'A', mapping: {} }])],+ ['file-IMG.dat', PNG],+ ['conversation_asset_file_names.json', 'this is { not valid json'],+ ]);+ const assetDir = join(TMP, 'assets');+ await expect(extractChatgptZip(zipPath, { assetDir })).rejects.toThrow();+ const written = await readdir(assetDir).catch(() => []);+ expect(written).toEqual([]); // no <id>.part temp left behind+ });+it('cleans up already-written assets and throws a 400 when a conversation shard is corrupt JSON', async () => {const zipPath = await writeZip([['conversations-000.json', '[{ "id": "c1", "title": "A", "mapping": {} '], // truncated → JSON.parse throws