feat: atomic wrapup, movie, integration writes

Ride writes: WrapUpRequested/Completed (wrapup create/set_complete),
MovieDiscovered (resolve upsert, new+ext id only), PosterSynced (poster
handler upsert), MovieDeleted (delete_movie), WatchEventIngested (save).
Deps drop event_publisher: wrapup, ingest, delete_review, watchlist add,
review logger.

Remaining .publish( sites:
announce-only: users/delete_account UserDeleted, person/get +
get_credits PersonEnrichmentRequested, jobs/enrichment_staleness,
http-axum search, movies/sync_poster + poster_sync_handler +
image-converter backfill + users/update_profile ImageStored (object
storage), activitypub federation_event_bridge (reacting to events).
rides write, deferred: social/execute (see report),
activitypub review_handler MovieEnrichmentRequested (after
save_remote_review).
This commit is contained in:
2026-10-26 01:02:34 +01:00
parent 2f133afb96
commit 6c295866a0
51 changed files with 1281 additions and 329 deletions

View File

@@ -2,7 +2,7 @@ use crate::support::request_wrap_up_command;
use chrono::NaiveDate;
use domain::events::DomainEvent;
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
use domain::testing::{InMemoryWrapUpRepository, NoopEventPublisher};
use domain::testing::{InMemoryWrapUpRepository, RefusingWrapUpWrites};
use domain::value_objects::WrapUpId;
use uuid::Uuid;
@@ -11,13 +11,9 @@ use std::sync::Arc;
use application::wrapup::deps::GenerateWrapUpDeps;
use application::wrapup::{commands::RequestWrapUpCommand, generate};
fn deps(
repo: &Arc<InMemoryWrapUpRepository>,
events: &Arc<NoopEventPublisher>,
) -> GenerateWrapUpDeps {
fn deps(repo: &Arc<InMemoryWrapUpRepository>) -> GenerateWrapUpDeps {
GenerateWrapUpDeps {
wrapup_repo: Arc::clone(repo) as _,
event_publisher: Arc::clone(events) as _,
}
}
@@ -26,25 +22,22 @@ fn past_cmd() -> RequestWrapUpCommand {
}
#[tokio::test]
async fn creates_pending_record_and_emits_event() {
async fn creates_pending_record_and_records_its_event_together() {
let repo = InMemoryWrapUpRepository::new();
let events = NoopEventPublisher::new();
let id = generate::execute(&deps(&repo, &events), past_cmd())
.await
.unwrap();
let id = generate::execute(&deps(&repo), past_cmd()).await.unwrap();
let stored = repo.store.lock().unwrap();
assert_eq!(stored.len(), 1);
assert_eq!(stored[0].id, id);
assert_eq!(stored[0].status, WrapUpStatus::Pending);
let published = events.published();
assert!(
published
.iter()
.any(|e| matches!(e, DomainEvent::WrapUpRequested { .. }))
);
let recorded = repo.recorded_events();
assert_eq!(recorded.len(), 1);
assert!(matches!(
&recorded[0],
DomainEvent::WrapUpRequested { wrapup_id, .. } if *wrapup_id == id
));
}
#[tokio::test]
@@ -62,13 +55,11 @@ async fn reuses_existing_ready_wrapup() {
created_at: chrono::Utc::now().naive_utc(),
completed_at: None,
});
let events = NoopEventPublisher::new();
let id = generate::execute(&deps(&repo, &events), past_cmd())
.await
.unwrap();
let id = generate::execute(&deps(&repo), past_cmd()).await.unwrap();
assert_eq!(id, existing_id);
assert_eq!(repo.store.lock().unwrap().len(), 1);
assert!(repo.recorded_events().is_empty());
}
#[tokio::test]
@@ -86,11 +77,7 @@ async fn replaces_failed_wrapup() {
completed_at: None,
});
let events = NoopEventPublisher::new();
let id = generate::execute(&deps(&repo, &events), past_cmd())
.await
.unwrap();
let id = generate::execute(&deps(&repo), past_cmd()).await.unwrap();
let stored = repo.store.lock().unwrap();
assert_eq!(stored.len(), 1);
@@ -101,10 +88,23 @@ async fn replaces_failed_wrapup() {
#[tokio::test]
async fn rejects_future_end_date() {
let repo = InMemoryWrapUpRepository::new();
let events = NoopEventPublisher::new();
let err = generate::execute(&deps(&repo, &events), request_wrap_up_command(None, 2030))
let err = generate::execute(&deps(&repo), request_wrap_up_command(None, 2030))
.await
.unwrap_err();
assert!(err.to_string().contains("future"));
}
#[tokio::test]
async fn a_refused_create_propagates_and_records_nothing() {
let inner = InMemoryWrapUpRepository::new();
let deps = GenerateWrapUpDeps {
wrapup_repo: RefusingWrapUpWrites::new(Arc::clone(&inner)),
};
let result = generate::execute(&deps, past_cmd()).await;
assert!(result.is_err());
assert!(inner.store.lock().unwrap().is_empty());
assert!(inner.recorded_events().is_empty());
}

View File

@@ -56,7 +56,7 @@ fn record(
async fn ready_report_returns_report_when_ready() {
let repo = InMemoryWrapUpRepository::new();
let user_id = Uuid::new_v4();
repo.create(&record(Some(user_id), 2024, WrapUpStatus::Ready, true))
repo.create(&record(Some(user_id), 2024, WrapUpStatus::Ready, true), &[])
.await
.unwrap();
@@ -72,12 +72,10 @@ async fn ready_report_returns_report_when_ready() {
async fn ready_report_is_not_found_when_status_not_ready() {
let repo = InMemoryWrapUpRepository::new();
let user_id = Uuid::new_v4();
repo.create(&record(
Some(user_id),
2024,
WrapUpStatus::Generating,
false,
))
repo.create(
&record(Some(user_id), 2024, WrapUpStatus::Generating, false),
&[],
)
.await
.unwrap();
@@ -96,9 +94,12 @@ async fn ready_report_is_not_found_when_report_absent() {
// Status is Ready but `report` is None — an inconsistent-but-representable
// state the old handler guarded against explicitly (`match record.report {
// Some(r) => ..., None => 404 }`), separate from the status gate above.
repo.create(&record(Some(user_id), 2024, WrapUpStatus::Ready, false))
.await
.unwrap();
repo.create(
&record(Some(user_id), 2024, WrapUpStatus::Ready, false),
&[],
)
.await
.unwrap();
let deps = GetReadyReportDeps { wrapup_repo: repo };
@@ -122,7 +123,7 @@ async fn ready_report_is_not_found_when_no_record_exists() {
#[tokio::test]
async fn ready_report_global_scope_ignores_user_id() {
let repo = InMemoryWrapUpRepository::new();
repo.create(&record(None, 2024, WrapUpStatus::Ready, true))
repo.create(&record(None, 2024, WrapUpStatus::Ready, true), &[])
.await
.unwrap();

View File

@@ -1,7 +1,7 @@
use chrono::{NaiveDate, Utc};
use domain::models::wrapup::{WrapUpRecord, WrapUpStatus};
use domain::ports::WrapUpRepository;
use domain::testing::{InMemoryWrapUpRepository, InMemoryWrapUpStatsQuery, NoopEventPublisher};
use domain::testing::{InMemoryWrapUpRepository, InMemoryWrapUpStatsQuery, RefusingWrapUpWrites};
use domain::value_objects::WrapUpId;
use application::wrapup::{deps::HandleWrapUpRequestedDeps, handle_requested};
@@ -22,11 +22,10 @@ async fn skips_if_already_ready() {
created_at: Utc::now().naive_utc(),
completed_at: None,
};
repo.create(&record).await.unwrap();
repo.create(&record, &[]).await.unwrap();
let deps = HandleWrapUpRequestedDeps {
wrapup_repo: repo.clone(),
event_publisher: NoopEventPublisher::new(),
wrapup_stats: InMemoryWrapUpStatsQuery::new(),
};
@@ -46,7 +45,6 @@ async fn skips_if_already_ready() {
async fn generates_wrapup_and_marks_complete() {
let repo = InMemoryWrapUpRepository::new();
let stats = InMemoryWrapUpStatsQuery::new();
let events = NoopEventPublisher::new();
let wrapup_id = WrapUpId::generate();
let uid = uuid::Uuid::new_v4();
@@ -61,11 +59,10 @@ async fn generates_wrapup_and_marks_complete() {
created_at: Utc::now().naive_utc(),
completed_at: None,
};
repo.create(&record).await.unwrap();
repo.create(&record, &[]).await.unwrap();
let deps = HandleWrapUpRequestedDeps {
wrapup_repo: repo.clone(),
event_publisher: events.clone(),
wrapup_stats: stats.clone(),
};
@@ -85,13 +82,13 @@ async fn generates_wrapup_and_marks_complete() {
assert_eq!(final_rec.status, WrapUpStatus::Ready);
assert!(final_rec.report.is_some());
// Verify event was published
let published = events.published();
assert!(
published
.iter()
.any(|e| matches!(e, domain::events::DomainEvent::WrapUpCompleted { .. }))
);
// The completion event is recorded together with the completed row.
let recorded = repo.recorded_events();
assert_eq!(recorded.len(), 1);
assert!(matches!(
&recorded[0],
domain::events::DomainEvent::WrapUpCompleted { wrapup_id: id } if *id == wrapup_id
));
}
#[tokio::test]
@@ -110,11 +107,10 @@ async fn skips_if_already_generating() {
created_at: Utc::now().naive_utc(),
completed_at: None,
};
repo.create(&record).await.unwrap();
repo.create(&record, &[]).await.unwrap();
let deps = HandleWrapUpRequestedDeps {
wrapup_repo: repo.clone(),
event_publisher: NoopEventPublisher::new(),
wrapup_stats: InMemoryWrapUpStatsQuery::new(),
};
@@ -132,4 +128,42 @@ async fn skips_if_already_generating() {
// Status should still be Generating (not changed to Ready)
let final_rec = repo.get_by_id(&wrapup_id).await.unwrap().unwrap();
assert_eq!(final_rec.status, WrapUpStatus::Generating);
assert!(repo.recorded_events().is_empty());
}
#[tokio::test]
async fn a_refused_completion_propagates_and_records_nothing() {
let inner = InMemoryWrapUpRepository::new();
let wrapup_id = WrapUpId::generate();
let record = WrapUpRecord {
id: wrapup_id.clone(),
user_id: None,
start_date: NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
end_date: NaiveDate::from_ymd_opt(2024, 12, 31).unwrap(),
status: WrapUpStatus::Pending,
report: None,
error_message: None,
created_at: Utc::now().naive_utc(),
completed_at: None,
};
inner.create(&record, &[]).await.unwrap();
let deps = HandleWrapUpRequestedDeps {
wrapup_repo: RefusingWrapUpWrites::new(inner.clone()),
wrapup_stats: InMemoryWrapUpStatsQuery::new(),
};
let result = handle_requested::execute(
&deps,
wrapup_id.clone(),
None,
NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
NaiveDate::from_ymd_opt(2024, 12, 31).unwrap(),
)
.await;
assert!(result.is_err());
let rec = inner.get_by_id(&wrapup_id).await.unwrap().unwrap();
assert_ne!(rec.status, WrapUpStatus::Ready);
assert!(rec.report.is_none());
assert!(inner.recorded_events().is_empty());
}