fix: Enforce the tag dedupe and 25-cap on every post write path #73
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
rosa/vernier!73
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/tag-cap-on-writes"
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?
Fixes #51.
Problem
Post::newdedupes tags and rejects sets larger than 25, but the rule only ran when a post was read back from a row. Every write path skipped it, so an over-cap tag set committed, then failedPost::try_fromon the RETURNING row — the post persisted in a state every subsequent read rejects withTooManyTags, permanently unreadable.Fix
The dedupe + cap rule now lives in exactly one place,
Tag::dedupe_and_cap(with the cap asTag::MAX_PER_POST), applied at every construction of aPost/PostEdit/PostCreatetag list:Post::newdelegates to it (read-side behavior unchanged).MicropubUpdate::apply_todedupes and caps the resolved category set: anaddof a category the post already has is a no-op, and an over-cap merge orreplaceis the newApplyUpdateError::TooManyTags, mapped to a Micropubinvalid_requestin the service layer.micropub_createvalidates categories before building itsPostCreate.DomainError::TooManyTags, surfacing as a 400 like their per-tag errors — not a 500.The repository's
Post::try_fromon the returned row stays as a last-resort integrity check, but is no longer the only guard. No limits changed, no migration, no persistence restructuring.Tests
add/replacerejected, duplicateaddis a no-op at the cap,replacededupes before counting,dedupe_and_capunit tests.addbeyond the cap on a 25-tag post → 400 with the post untouched and still readable; duplicateadd→ 204; web edit form with 26 tags → 400, post still readable.The
cimise task passes.