Define the 'published feed' predicate once and add a repository conformance test #29
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
rosa/vernier#29
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
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?
Problem
The ADR-0004 rule for "a live, public, published Post" exists three times, in three languages:
crates/infra/src/repositories/postgres.rsWHERE clauses (find_posts_published_by_user~804-808,find_drafts_by_user~783-786,find_posts_published_with_tag~827-831). The drafts query even hand-encodesstatus = 'draft' OR published_at IS NULL OR published_at > NOW().crates/domain/src/mocks.rs(find_posts_published_by_user~407,find_drafts_by_user~380,find_posts_published_with_tag~435-437), usingpost.is_live(now) && post.visibility().is_public().crates/domain/src/models/post.rs:is_live(:442) andis_viewable_by(:449) already define liveness/visibility.The two
AppRepositoryadapters are supposed to be behaviourally identical, but nothing enforces it: the mock filters with the domain's ownis_live, while Postgres re-expresses the same rule as free-form SQL. They can silently drift. A change to what "published" means is a three-file edit with no test that would catch a mismatch.Deletion test: you can't delete the SQL — but you can delete the duplicated policy. If the predicate were one named concept the SQL and mock both had to satisfy, deleting the ad-hoc copies would concentrate the rule, not lose it.
Solution
Two moves, either or both:
CONTEXT.md: Published, Scheduled, Draft). Make the predicate a single domain function and have the mock filter through it, so the model and the test adapter share one definition rather than two.PostgresAppRepositoryandMemoryAppRepopins the two adapters to identical behaviour — the "interface is the test surface" principle applied to a seam that currently has two untethered adapters.Benefits
MemoryAppRepois that service tests don't need a database — that payoff is only sound if the two adapters agree.Constraints preserved
Architecture review candidate 2 of 4 (Worth exploring). Cheap, high-confidence — a conformance test is almost pure upside.