Align discard-post-changes guard with bDS2 (require the published file on disk) #78
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Source: Audit section 2.9.
Spec:
specs/post.alliumrule DiscardPostChanges requirespost.file_path != ""("a never-published draft has no file version to restore"); errors if the file is missing.bDS2:
../bDS2/lib/bds/posts.exdiscard_post_changes(~line 223): not_found when file_path empty OR file missing; otherwise upserts the record from the file viaRebuildFromFiles.upsert_post_from_fileand resyncs links.Current behaviour (RuDS):
crates/bds-core/src/engine/post.rsdiscard_post_draft(~line 356) gates onpublished_at.is_some()instead, and when the file is missing silently falls back to thepublished_*snapshot columns. Differences: (a) a rebuilt draft that has a file but no published_at is discardable in bDS2 but rejected by RuDS; (b) missing file errors in bDS2 but "succeeds" from snapshot in RuDS; (c) RuDS does not resync post links on discard.Task: Match bDS2: guard on file_path non-empty + file exists (error otherwise), restore full record from the file (status from frontmatter), resync post links, keep the savepoint + FTS handling. Remove the snapshot fallback (see companion issue on published_* snapshot semantics). Update tests
discard_post_draft_restores_published_stateetc.Acceptance: Behaviour matches bDS2 for: normal discard, file-missing error, draft-with-file-no-published_at discard.
Implemented in
535303e. Discard now follows bDS2's canonical-file guard: an empty or missing file path returns not-found, and database published_at no longer controls eligibility. The post is restored from parsed frontmatter (including status and timestamps), content/checksum are cleared, links are rebuilt from the file body, and FTS/database updates remain savepoint-protected; snapshot policy is deliberately left to companion issue #79. Added regressions for normal restoration/link resync, missing-file immutability, a draft with no database published_at, frontmatter status, and FTS rollback. Updated README. Verified with Allium check/analyse, cargo fmt --check, cargo check --workspace, cargo machete --with-metadata, cargo build --workspace, focused discard tests, and cargo test --workspace (all passed; one intentional model-download test ignored).