test: test app from bootstrap, prune wiring tests

This commit is contained in:
2026-10-25 22:30:40 +01:00
parent 5256c6e851
commit 1e6e9ddf6b
11 changed files with 650 additions and 2086 deletions

View File

@@ -21,8 +21,4 @@ pub use event_bus::EventBusBackend;
pub use repositories::Repositories;
pub use server::{ServerApp, build_server, build_server_on};
pub use tracing_setup::init_tracing;
pub use worker::{WorkerApp, build_worker};
#[cfg(test)]
#[path = "tests/build.rs"]
mod build_tests;
pub use worker::{WorkerApp, build_worker, build_worker_on};

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,13 @@
use std::sync::Arc;
use application::config::AppConfig as AppSettings;
use application::{
MovieDiscoveryIndexer, SearchCleanupHandler, SearchReindexHandler, worker::WorkerService,
};
use domain::ports::{EventHandler, MovieEnrichmentClient, PeriodicJob, PersonEnrichmentClient};
use domain::value_objects::InstanceIdentity;
use crate::{database, event_bus};
use crate::database::{self, DatabaseOutput};
use crate::event_bus;
pub struct WorkerApp {
pub service: WorkerService,
@@ -17,9 +17,27 @@ pub struct WorkerApp {
/// spawned) and the consumer. Run it with `service.run(shutdown)`.
pub async fn build_worker(config: &config::AppConfig) -> anyhow::Result<WorkerApp> {
database::warn_if_database_backend_set();
let app_config = AppSettings::from(config);
let instance = InstanceIdentity::new(app_config.base_url.clone());
let instance = InstanceIdentity::new(config.server.base_url.clone());
let db = database::build_database_adapters(&config.database.url, &instance).await?;
assemble(config, db, instance).await
}
/// Builds the same worker as [`build_worker`] on a caller-provided pool.
/// Migrations run on it exactly as they do for the normal path.
pub async fn build_worker_on(
config: &config::AppConfig,
pool: sqlx::SqlitePool,
) -> anyhow::Result<WorkerApp> {
let instance = InstanceIdentity::new(config.server.base_url.clone());
let db = database::build_database_adapters_on(pool, &instance).await?;
assemble(config, db, instance).await
}
async fn assemble(
config: &config::AppConfig,
db: DatabaseOutput,
#[cfg_attr(not(feature = "federation"), allow(unused_variables))] instance: InstanceIdentity,
) -> anyhow::Result<WorkerApp> {
let metadata_client = metadata::create(&config.metadata)?;
let poster_fetcher = poster_fetcher::create(&config.metadata)?;
let object_storage = object_storage::create(&config.storage)?;
@@ -40,7 +58,6 @@ pub async fn build_worker(config: &config::AppConfig) -> anyhow::Result<WorkerAp
.clone()
.map(|c| c as Arc<dyn PersonEnrichmentClient>);
let db = database::build_database_adapters(&config.database.url, &instance).await?;
let (event_publisher_arc, consumer_arc) =
event_bus::create_channel(&db.db_pool, config).await?;