feat: idempotent handlers, deterministic activity ids

This commit is contained in:
2026-10-26 01:27:03 +01:00
parent 7f9c252d35
commit 4cb2972f63
11 changed files with 719 additions and 19 deletions

View File

@@ -38,3 +38,34 @@ pub fn watchlist_entry_url(
))
.expect("base_url is always a valid URL prefix")
}
#[cfg(test)]
mod tests {
use super::*;
/// k-ap derives the Create activity id from the object id (UUIDv5), so
/// re-handling an event only re-sends the same activity id if our object
/// ids are pure functions of the entity. Update/Delete/Move ids are minted
/// randomly inside k-ap 0.5 with no override (see ADR-0015): those repeat
/// semantically idempotent activities under a fresh id.
#[test]
fn activitypub_object_ids_are_stable_across_event_redelivery() {
let instance = InstanceIdentity::new("https://diary.example");
let review = ReviewId::from_uuid(uuid::Uuid::new_v4());
let user = uuid::Uuid::new_v4();
let movie = uuid::Uuid::new_v4();
assert_eq!(
review_url(&instance, &review),
review_url(&instance, &review)
);
assert_eq!(
goal_url(&instance, user, 2026),
goal_url(&instance, user, 2026)
);
assert_eq!(
watchlist_entry_url(&instance, user, movie),
watchlist_entry_url(&instance, user, movie)
);
}
}