feat: atomic social local writes, remote review enrichment

SocialCommand methods take events. Local follow ops = one FollowCommand::apply
tx (rows + events). k_ap path (remote, block/unblock): best-effort publish in
CompositeSocialAdapter after k_ap write; not atomic, k_ap owns tx.
save_remote_review takes events, enqueued in same tx via
sqlite::persistence::enqueue_events. Deps drop event_publisher: social
command, ReviewObjectHandler.

Remaining .publish( sites:
announce-only: users/delete_account UserDeleted, person/get + get_credits
PersonEnrichmentRequested, jobs/enrichment_staleness, http-axum search,
ImageStored (sync_poster, poster_sync_handler, image-converter backfill,
update_profile; object storage), federation_event_bridge (handler reaction),
nats relay (transport).
non-atomic by necessity: CompositeSocialAdapter::announce (k_ap-owned write).
Everything else rides its write.
This commit is contained in:
2026-10-26 01:12:58 +01:00
parent 6c295866a0
commit 9a4d0c1714
29 changed files with 1115 additions and 408 deletions

View File

@@ -241,7 +241,6 @@ pub fn build_deps(
social: SocialGroup {
command: SocialCommandDeps {
social_command: repos.social_command.clone(),
event_publisher: services.event_publisher.clone(),
},
query: SocialQueryDeps {
follow_graph: repos.follow_graph.clone(),

View File

@@ -104,6 +104,7 @@ pub async fn wire_server_social(
ap.service,
Arc::clone(&db.user),
instance.clone(),
Arc::clone(event_publisher),
));
Ok(ServerSocial {

View File

@@ -145,3 +145,73 @@ async fn handler_names_are_unique() {
// Image conversion ("image_conversion") is disabled in the test config.
assert_eq!(sorted, expected);
}
async fn queued(pool: &sqlx::SqlitePool, event_type: &str) -> i64 {
sqlx::query_scalar(
"SELECT COUNT(*) FROM event_queue WHERE event_type = ? AND event_id IS NOT NULL",
)
.bind(event_type)
.fetch_one(pool)
.await
.unwrap()
}
/// A local follow writes both follow rows and its event in one commit, in
/// both federation builds.
#[tokio::test]
async fn a_local_follow_lands_with_its_event_in_the_outbox() {
let (router, pool) = support::server().await;
let alice = support::register(&router, "alice", "alice@example.com").await;
let _bob = support::register(&router, "bob", "bob@example.com").await;
let (status, _, body) = support::send(
&router,
support::json_request(
axum::http::Method::POST,
"/api/v1/social/follow",
Some(&alice.token),
serde_json::json!({ "handle": "bob@localhost:3000" }),
),
)
.await;
assert_eq!(status, 200, "follow: {body}");
let following: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM ap_following")
.fetch_one(&pool)
.await
.unwrap();
let followers: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM ap_followers")
.fetch_one(&pool)
.await
.unwrap();
assert_eq!((following, followers), (1, 1));
assert_eq!(queued(&pool, "FollowRequested").await, 1);
}
/// The k_ap path owns its transaction, so the adapter publishes the event
/// itself once the k_ap write has succeeded.
#[cfg(feature = "federation")]
#[tokio::test]
async fn a_remote_block_publishes_its_event_after_the_k_ap_write() {
let (router, pool) = support::server().await;
let alice = support::register(&router, "alice", "alice@example.com").await;
let (status, _, body) = support::send(
&router,
support::json_request(
axum::http::Method::POST,
"/api/v1/social/block",
Some(&alice.token),
serde_json::json!({ "actor_url": "https://remote.example/users/ann" }),
),
)
.await;
assert_eq!(status, 204, "block: {body}");
let blocked: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM blocked_actors")
.fetch_one(&pool)
.await
.unwrap();
assert_eq!(blocked, 1);
assert_eq!(queued(&pool, "ActorBlocked").await, 1);
}