Align discard-post-changes guard with bDS2 (require the published file on disk) #78

Closed
opened 2026-07-20 19:43:59 +00:00 by hugo · 1 comment
Owner

Source: Audit section 2.9.

Spec: specs/post.allium rule DiscardPostChanges requires post.file_path != "" ("a never-published draft has no file version to restore"); errors if the file is missing.

bDS2: ../bDS2/lib/bds/posts.ex discard_post_changes (~line 223): not_found when file_path empty OR file missing; otherwise upserts the record from the file via RebuildFromFiles.upsert_post_from_file and resyncs links.

Current behaviour (RuDS): crates/bds-core/src/engine/post.rs discard_post_draft (~line 356) gates on published_at.is_some() instead, and when the file is missing silently falls back to the published_* 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_state etc.

Acceptance: Behaviour matches bDS2 for: normal discard, file-missing error, draft-with-file-no-published_at discard.

**Source:** Audit section 2.9. **Spec:** `specs/post.allium` rule DiscardPostChanges requires `post.file_path != ""` ("a never-published draft has no file version to restore"); errors if the file is missing. **bDS2:** `../bDS2/lib/bds/posts.ex` `discard_post_changes` (~line 223): not_found when file_path empty OR file missing; otherwise upserts the record from the file via `RebuildFromFiles.upsert_post_from_file` and resyncs links. **Current behaviour (RuDS):** `crates/bds-core/src/engine/post.rs` `discard_post_draft` (~line 356) gates on `published_at.is_some()` instead, and when the file is missing silently falls back to the `published_*` 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_state` etc. **Acceptance:** Behaviour matches bDS2 for: normal discard, file-missing error, draft-with-file-no-published_at discard.
hugo added the bug label 2026-07-20 19:43:59 +00:00
Author
Owner

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).

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).
hugo closed this issue 2026-07-21 20:46:22 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: hugo/RuDS#78