From dee27d8f2805c9e409853462d35f9103e1a8c53e Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 27 Apr 2026 08:49:13 +0300 Subject: processor: refactor to two-phase commit for inbox processing Introduce postPlan to capture everything validated in Phase 1 before any filesystem mutation occurs. Phase 1 scans the inbox, validates all source files (parses text, markdown, image, audio), checks markdown image claims for conflicts, and collects a plan per item. Phase 2 commits mutations only after every plan is validated: creates post directories, writes assets, persists post.json, and removes sources. If Phase 1 fails (e.g. unsupported file, missing markdown image, claim conflict), no mutations occur and the inbox is left untouched. Roll back the partial post directory if a mutation fails during commit. Also refactor image and audio sub-processors into validation-only and write-only parts (validateImage/writeImageAsset, validateAudio/copyFile) so that Phase 1 is strictly read-only. All existing tests pass. --- internal/processor/audio.go | 24 +-- internal/processor/image.go | 33 ++-- internal/processor/processor.go | 338 ++++++++++++++++++++-------------------- 3 files changed, 189 insertions(+), 206 deletions(-) (limited to 'internal') diff --git a/internal/processor/audio.go b/internal/processor/audio.go index 98aedcf..68938cf 100644 --- a/internal/processor/audio.go +++ b/internal/processor/audio.go @@ -4,27 +4,15 @@ import ( "fmt" "io" "os" - "path/filepath" ) -// processAudio copies an .mp3 file into destDir and returns an HTML