From e23f7da2d5028d537724dd8b227b818661ea70cc Mon Sep 17 00:00:00 2001 From: Heimdall Date: Sun, 8 Nov 2026 09:19:32 +0000 Subject: [PATCH] Test: a failed image write leaves no temp file Co-Authored-By: Claude Sonnet 5.5 --- tests/persona-chat-images.test.mjs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/persona-chat-images.test.mjs b/tests/persona-chat-images.test.mjs index 3c7901c..adae637 100644 --- a/tests/persona-chat-images.test.mjs +++ b/tests/persona-chat-images.test.mjs @@ -3,7 +3,7 @@ import test from "node:test"; import assert from "node:assert/strict"; import { createHash } from "node:crypto"; -import { existsSync, mkdtempSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs"; +import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { MAX_BYTES, MAX_PIXELS, RETAIN_MS, ROOM_CAP_BYTES, classify, createImageStore, fetchImage, sniff } from "../tools/persona-chat-images.mjs"; @@ -148,6 +148,14 @@ test("files are 0640 and directories 0750 with the setgid bit kept, whatever the } finally { process.umask(old); } }); +test("a write that cannot finish leaves no temp file and no partial image under the final name", () => { + const { root, store } = storeIn(); + const bytes = png(6, 6); + mkdirSync(join(root, sha("!r:x"), `${sha(bytes)}.png`), { recursive: true }); // the final name is taken by a directory: the rename fails + assert.throws(() => store.put("!r:x", bytes, "image/png")); + assert.deepEqual(readdirSync(join(root, sha("!r:x"))).filter(n => n.startsWith(".tmp-")), []); +}); + test("a stored image stays until it is at least 24 h old and acked, whichever is later", () => { const { root, clock, store } = storeIn(); const ref = store.put("!r:x", png(), "image/png");