From 6e7e074418478ff88512d269795d47ca0de70d3d Mon Sep 17 00:00:00 2001 From: aecsocket Date: Sun, 2 Nov 2025 19:18:55 +0000 Subject: [PATCH 1/7] Expose test utils to Labrinth dependents --- Cargo.lock | 1 + apps/labrinth/Cargo.toml | 6 +- .../common => src/test}/api_common/generic.rs | 24 +++--- .../common => src/test}/api_common/mod.rs | 8 +- .../common => src/test}/api_common/models.rs | 8 +- .../test}/api_common/request_data.rs | 4 +- .../{tests/common => src/test}/api_v2/mod.rs | 8 +- .../common => src/test}/api_v2/project.rs | 26 +++---- .../test}/api_v2/request_data.rs | 6 +- .../{tests/common => src/test}/api_v2/tags.rs | 20 +++-- .../{tests/common => src/test}/api_v2/team.rs | 18 ++--- .../{tests/common => src/test}/api_v2/user.rs | 2 +- .../common => src/test}/api_v2/version.rs | 22 +++--- .../common => src/test}/api_v3/collections.rs | 8 +- .../common => src/test}/api_v3/limits.rs | 12 ++- .../{tests/common => src/test}/api_v3/mod.rs | 8 +- .../common => src/test}/api_v3/oauth.rs | 14 ++-- .../test}/api_v3/oauth_clients.rs | 18 ++--- .../test}/api_v3/organization.rs | 8 +- .../common => src/test}/api_v3/project.rs | 28 ++++--- .../test}/api_v3/request_data.rs | 6 +- .../{tests/common => src/test}/api_v3/tags.rs | 24 +++--- .../{tests/common => src/test}/api_v3/team.rs | 18 ++--- .../{tests/common => src/test}/api_v3/user.rs | 2 +- .../common => src/test}/api_v3/version.rs | 22 +++--- .../{tests/common => src/test}/asserts.rs | 17 +---- .../{tests/common => src/test}/database.rs | 10 +-- .../{tests/common => src/test}/dummy_data.rs | 16 ++-- .../{tests/common => src/test}/environment.rs | 3 +- apps/labrinth/src/test/mod.rs | 75 +++++++++++++++++++ .../{tests/common => src/test}/pats.rs | 4 +- .../{tests/common => src/test}/permissions.rs | 4 +- .../{tests/common => src/test}/scopes.rs | 2 +- .../{tests/common => src/test}/search.rs | 12 ++- apps/labrinth/tests/common.rs | 32 ++++++++ apps/labrinth/tests/common/mod.rs | 75 ------------------- apps/labrinth/tests/v2/error.rs | 3 +- 37 files changed, 284 insertions(+), 290 deletions(-) rename apps/labrinth/{tests/common => src/test}/api_common/generic.rs (92%) rename apps/labrinth/{tests/common => src/test}/api_common/mod.rs (99%) rename apps/labrinth/{tests/common => src/test}/api_common/models.rs (99%) rename apps/labrinth/{tests/common => src/test}/api_common/request_data.rs (85%) rename apps/labrinth/{tests/common => src/test}/api_v2/mod.rs (85%) rename apps/labrinth/{tests/common => src/test}/api_v2/project.rs (97%) rename apps/labrinth/{tests/common => src/test}/api_v2/request_data.rs (96%) rename apps/labrinth/{tests/common => src/test}/api_v2/tags.rs (93%) rename apps/labrinth/{tests/common => src/test}/api_v2/team.rs (98%) rename apps/labrinth/{tests/common => src/test}/api_v2/user.rs (95%) rename apps/labrinth/{tests/common => src/test}/api_v2/version.rs (98%) rename apps/labrinth/{tests/common => src/test}/api_v3/collections.rs (96%) rename apps/labrinth/{tests/common => src/test}/api_v3/limits.rs (87%) rename apps/labrinth/{tests/common => src/test}/api_v3/mod.rs (86%) rename apps/labrinth/{tests/common => src/test}/api_v3/oauth.rs (97%) rename apps/labrinth/{tests/common => src/test}/api_v3/oauth_clients.rs (97%) rename apps/labrinth/{tests/common => src/test}/api_v3/organization.rs (96%) rename apps/labrinth/{tests/common => src/test}/api_v3/project.rs (98%) rename apps/labrinth/{tests/common => src/test}/api_v3/request_data.rs (96%) rename apps/labrinth/{tests/common => src/test}/api_v3/tags.rs (91%) rename apps/labrinth/{tests/common => src/test}/api_v3/team.rs (98%) rename apps/labrinth/{tests/common => src/test}/api_v3/user.rs (95%) rename apps/labrinth/{tests/common => src/test}/api_v3/version.rs (98%) rename apps/labrinth/{tests/common => src/test}/asserts.rs (69%) rename apps/labrinth/{tests/common => src/test}/database.rs (98%) rename apps/labrinth/{tests/common => src/test}/dummy_data.rs (98%) rename apps/labrinth/{tests/common => src/test}/environment.rs (98%) rename apps/labrinth/{tests/common => src/test}/pats.rs (98%) rename apps/labrinth/{tests/common => src/test}/permissions.rs (99%) rename apps/labrinth/{tests/common => src/test}/scopes.rs (99%) rename apps/labrinth/{tests/common => src/test}/search.rs (97%) create mode 100644 apps/labrinth/tests/common.rs delete mode 100644 apps/labrinth/tests/common/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 792031ea2e..0e48f3fb45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4679,6 +4679,7 @@ dependencies = [ "itertools 0.14.0", "jemalloc_pprof", "json-patch 4.1.0", + "labrinth", "lettre", "meilisearch-sdk", "modrinth-maxmind", diff --git a/apps/labrinth/Cargo.toml b/apps/labrinth/Cargo.toml index 9502fbdcc5..f17c3bbf23 100644 --- a/apps/labrinth/Cargo.toml +++ b/apps/labrinth/Cargo.toml @@ -12,6 +12,7 @@ path = "src/main.rs" [dependencies] actix-cors = { workspace = true } actix-files = { workspace = true } +actix-http = { workspace = true, optional = true } actix-multipart = { workspace = true } actix-rt = { workspace = true } actix-web = { workspace = true } @@ -135,7 +136,7 @@ zip = { workspace = true } zxcvbn = { workspace = true } [dev-dependencies] -actix-http = { workspace = true } +labrinth = { path = ".", features = ["test"] } [build-dependencies] chrono = { workspace = true } @@ -150,5 +151,8 @@ tikv-jemallocator = { workspace = true, features = [ "unprefixed_malloc_on_supported_platforms", ] } +[features] +test = ["dep:actix-http"] + [lints] workspace = true diff --git a/apps/labrinth/tests/common/api_common/generic.rs b/apps/labrinth/src/test/api_common/generic.rs similarity index 92% rename from apps/labrinth/tests/common/api_common/generic.rs rename to apps/labrinth/src/test/api_common/generic.rs index 2c1ca2a9ca..9b044b1d9f 100644 --- a/apps/labrinth/tests/common/api_common/generic.rs +++ b/apps/labrinth/src/test/api_common/generic.rs @@ -1,13 +1,13 @@ use std::collections::HashMap; -use crate::common::{api_v2::ApiV2, api_v3::ApiV3, dummy_data::TestFile}; -use actix_web::dev::ServiceResponse; -use async_trait::async_trait; -use labrinth::models::ids::ProjectId; -use labrinth::models::{ +use crate::models::ids::ProjectId; +use crate::models::{ projects::VersionType, teams::{OrganizationPermissions, ProjectPermissions}, }; +use crate::test::{api_v2::ApiV2, api_v3::ApiV3, dummy_data::TestFile}; +use actix_web::dev::ServiceResponse; +use async_trait::async_trait; use super::{ Api, ApiProject, ApiTags, ApiTeams, ApiUser, ApiVersion, @@ -81,7 +81,7 @@ delegate_api_variant!( [add_gallery_item, ServiceResponse, id_or_slug: &str, image: ImageData, featured: bool, title: Option, description: Option, ordering: Option, pat: Option<&str>], [remove_gallery_item, ServiceResponse, id_or_slug: &str, image_url: &str, pat: Option<&str>], [edit_gallery_item, ServiceResponse, id_or_slug: &str, image_url: &str, patch: HashMap, pat: Option<&str>], - [create_report, ServiceResponse, report_type: &str, id: &str, item_type: crate::common::api_common::models::CommonItemType, body: &str, pat: Option<&str>], + [create_report, ServiceResponse, report_type: &str, id: &str, item_type: crate::test::api_common::models::CommonItemType, body: &str, pat: Option<&str>], [get_report, ServiceResponse, id: &str, pat: Option<&str>], [get_reports, ServiceResponse, ids: &[&str], pat: Option<&str>], [get_user_reports, ServiceResponse, pat: Option<&str>], @@ -100,9 +100,9 @@ delegate_api_variant!( #[async_trait(?Send)] impl ApiTags for GenericApi { [get_loaders, ServiceResponse,], - [get_loaders_deserialized_common, Vec,], + [get_loaders_deserialized_common, Vec,], [get_categories, ServiceResponse,], - [get_categories_deserialized_common, Vec,], + [get_categories_deserialized_common, Vec,], } ); @@ -110,18 +110,18 @@ delegate_api_variant!( #[async_trait(?Send)] impl ApiTeams for GenericApi { [get_team_members, ServiceResponse, team_id: &str, pat: Option<&str>], - [get_team_members_deserialized_common, Vec, team_id: &str, pat: Option<&str>], + [get_team_members_deserialized_common, Vec, team_id: &str, pat: Option<&str>], [get_teams_members, ServiceResponse, ids: &[&str], pat: Option<&str>], [get_project_members, ServiceResponse, id_or_slug: &str, pat: Option<&str>], - [get_project_members_deserialized_common, Vec, id_or_slug: &str, pat: Option<&str>], + [get_project_members_deserialized_common, Vec, id_or_slug: &str, pat: Option<&str>], [get_organization_members, ServiceResponse, id_or_title: &str, pat: Option<&str>], - [get_organization_members_deserialized_common, Vec, id_or_title: &str, pat: Option<&str>], + [get_organization_members_deserialized_common, Vec, id_or_title: &str, pat: Option<&str>], [join_team, ServiceResponse, team_id: &str, pat: Option<&str>], [remove_from_team, ServiceResponse, team_id: &str, user_id: &str, pat: Option<&str>], [edit_team_member, ServiceResponse, team_id: &str, user_id: &str, patch: serde_json::Value, pat: Option<&str>], [transfer_team_ownership, ServiceResponse, team_id: &str, user_id: &str, pat: Option<&str>], [get_user_notifications, ServiceResponse, user_id: &str, pat: Option<&str>], - [get_user_notifications_deserialized_common, Vec, user_id: &str, pat: Option<&str>], + [get_user_notifications_deserialized_common, Vec, user_id: &str, pat: Option<&str>], [get_notification, ServiceResponse, notification_id: &str, pat: Option<&str>], [get_notifications, ServiceResponse, ids: &[&str], pat: Option<&str>], [mark_notification_read, ServiceResponse, notification_id: &str, pat: Option<&str>], diff --git a/apps/labrinth/tests/common/api_common/mod.rs b/apps/labrinth/src/test/api_common/mod.rs similarity index 99% rename from apps/labrinth/tests/common/api_common/mod.rs rename to apps/labrinth/src/test/api_common/mod.rs index 3ac1732866..d24eb79473 100644 --- a/apps/labrinth/tests/common/api_common/mod.rs +++ b/apps/labrinth/src/test/api_common/mod.rs @@ -6,16 +6,16 @@ use self::models::{ }; use self::request_data::{ImageData, ProjectCreationRequestData}; use super::dummy_data::TestFile; -use actix_web::dev::ServiceResponse; -use async_trait::async_trait; -use labrinth::models::ids::ProjectId; -use labrinth::{ +use crate::models::ids::ProjectId; +use crate::{ LabrinthConfig, models::{ projects::VersionType, teams::{OrganizationPermissions, ProjectPermissions}, }, }; +use actix_web::dev::ServiceResponse; +use async_trait::async_trait; pub mod generic; pub mod models; diff --git a/apps/labrinth/tests/common/api_common/models.rs b/apps/labrinth/src/test/api_common/models.rs similarity index 99% rename from apps/labrinth/tests/common/api_common/models.rs rename to apps/labrinth/src/test/api_common/models.rs index 454983c2b5..4c80e1b1c1 100644 --- a/apps/labrinth/tests/common/api_common/models.rs +++ b/apps/labrinth/src/test/api_common/models.rs @@ -1,10 +1,8 @@ -use ariadne::ids::UserId; -use chrono::{DateTime, Utc}; -use labrinth::models::ids::{ +use crate::models::ids::{ ImageId, NotificationId, OrganizationId, ProjectId, ReportId, TeamId, ThreadId, ThreadMessageId, VersionId, }; -use labrinth::{ +use crate::{ auth::AuthProvider, models::{ projects::{ @@ -16,6 +14,8 @@ use labrinth::{ users::{Badges, Role, User, UserPayoutData}, }, }; +use ariadne::ids::UserId; +use chrono::{DateTime, Utc}; use rust_decimal::Decimal; use serde::Deserialize; // Fields shared by every version of the API. diff --git a/apps/labrinth/tests/common/api_common/request_data.rs b/apps/labrinth/src/test/api_common/request_data.rs similarity index 85% rename from apps/labrinth/tests/common/api_common/request_data.rs rename to apps/labrinth/src/test/api_common/request_data.rs index 3bfc886aa3..d85b0884f7 100644 --- a/apps/labrinth/tests/common/api_common/request_data.rs +++ b/apps/labrinth/src/test/api_common/request_data.rs @@ -1,9 +1,9 @@ // The structures for project/version creation. // These are created differently, but are essentially the same between versions. -use labrinth::util::actix::MultipartSegment; +use crate::util::actix::MultipartSegment; -use crate::common::dummy_data::TestFile; +use crate::test::dummy_data::TestFile; pub struct ProjectCreationRequestData { pub slug: String, diff --git a/apps/labrinth/tests/common/api_v2/mod.rs b/apps/labrinth/src/test/api_v2/mod.rs similarity index 85% rename from apps/labrinth/tests/common/api_v2/mod.rs rename to apps/labrinth/src/test/api_v2/mod.rs index e197c4b761..67b7ecb865 100644 --- a/apps/labrinth/tests/common/api_v2/mod.rs +++ b/apps/labrinth/src/test/api_v2/mod.rs @@ -2,9 +2,9 @@ use super::{ api_common::{Api, ApiBuildable}, environment::LocalService, }; +use crate::LabrinthConfig; use actix_web::{App, dev::ServiceResponse, test}; use async_trait::async_trait; -use labrinth::LabrinthConfig; use std::rc::Rc; use utoipa_actix_web::AppExt; @@ -26,12 +26,10 @@ impl ApiBuildable for ApiV2 { let app = App::new() .into_utoipa_app() .configure(|cfg| { - labrinth::utoipa_app_config(cfg, labrinth_config.clone()) + crate::utoipa_app_config(cfg, labrinth_config.clone()) }) .into_app() - .configure(|cfg| { - labrinth::app_config(cfg, labrinth_config.clone()) - }); + .configure(|cfg| crate::app_config(cfg, labrinth_config.clone())); let test_app: Rc = Rc::new(test::init_service(app).await); diff --git a/apps/labrinth/tests/common/api_v2/project.rs b/apps/labrinth/src/test/api_v2/project.rs similarity index 97% rename from apps/labrinth/tests/common/api_v2/project.rs rename to apps/labrinth/src/test/api_v2/project.rs index d27eb9adc2..476889b112 100644 --- a/apps/labrinth/tests/common/api_v2/project.rs +++ b/apps/labrinth/src/test/api_v2/project.rs @@ -1,15 +1,17 @@ use std::{collections::HashMap, fmt::Write}; -use crate::{ - assert_status, - common::{ - api_common::{ - Api, ApiProject, AppendsOptionalPat, - models::{CommonItemType, CommonProject, CommonVersion}, - request_data::{ImageData, ProjectCreationRequestData}, - }, - dummy_data::TestFile, +use crate::test::asserts::assert_status; +use crate::test::{ + api_common::{ + Api, ApiProject, AppendsOptionalPat, + models::{CommonItemType, CommonProject, CommonVersion}, + request_data::{ImageData, ProjectCreationRequestData}, }, + dummy_data::TestFile, +}; +use crate::{ + models::v2::{projects::LegacyProject, search::LegacySearchResults}, + util::actix::AppendsMultipart, }; use actix_http::StatusCode; use actix_web::{ @@ -18,13 +20,9 @@ use actix_web::{ }; use async_trait::async_trait; use bytes::Bytes; -use labrinth::{ - models::v2::{projects::LegacyProject, search::LegacySearchResults}, - util::actix::AppendsMultipart, -}; use serde_json::json; -use crate::common::database::MOD_USER_PAT; +use crate::test::database::MOD_USER_PAT; use super::{ ApiV2, diff --git a/apps/labrinth/tests/common/api_v2/request_data.rs b/apps/labrinth/src/test/api_v2/request_data.rs similarity index 96% rename from apps/labrinth/tests/common/api_v2/request_data.rs rename to apps/labrinth/src/test/api_v2/request_data.rs index 11841ead97..e2e7156c41 100644 --- a/apps/labrinth/tests/common/api_v2/request_data.rs +++ b/apps/labrinth/src/test/api_v2/request_data.rs @@ -1,13 +1,13 @@ use serde_json::json; -use crate::common::{ +use crate::models::ids::ProjectId; +use crate::test::{ api_common::request_data::{ ProjectCreationRequestData, VersionCreationRequestData, }, dummy_data::TestFile, }; -use labrinth::models::ids::ProjectId; -use labrinth::util::actix::{MultipartSegment, MultipartSegmentData}; +use crate::util::actix::{MultipartSegment, MultipartSegmentData}; pub fn get_public_project_creation_data( slug: &str, diff --git a/apps/labrinth/tests/common/api_v2/tags.rs b/apps/labrinth/src/test/api_v2/tags.rs similarity index 93% rename from apps/labrinth/tests/common/api_v2/tags.rs rename to apps/labrinth/src/test/api_v2/tags.rs index c68aed17cf..4184832d8c 100644 --- a/apps/labrinth/tests/common/api_v2/tags.rs +++ b/apps/labrinth/src/test/api_v2/tags.rs @@ -1,22 +1,20 @@ +use crate::routes::v2::tags::{ + CategoryData, DonationPlatformQueryData, GameVersionQueryData, LoaderData, +}; use actix_http::StatusCode; use actix_web::{ dev::ServiceResponse, test::{self, TestRequest}, }; use async_trait::async_trait; -use labrinth::routes::v2::tags::{ - CategoryData, DonationPlatformQueryData, GameVersionQueryData, LoaderData, -}; -use crate::{ - assert_status, - common::{ - api_common::{ - Api, ApiTags, AppendsOptionalPat, - models::{CommonCategoryData, CommonLoaderData}, - }, - database::ADMIN_USER_PAT, +use crate::test::asserts::assert_status; +use crate::test::{ + api_common::{ + Api, ApiTags, AppendsOptionalPat, + models::{CommonCategoryData, CommonLoaderData}, }, + database::ADMIN_USER_PAT, }; use super::ApiV2; diff --git a/apps/labrinth/tests/common/api_v2/team.rs b/apps/labrinth/src/test/api_v2/team.rs similarity index 98% rename from apps/labrinth/tests/common/api_v2/team.rs rename to apps/labrinth/src/test/api_v2/team.rs index eeb70342a9..ff251e7cf6 100644 --- a/apps/labrinth/tests/common/api_v2/team.rs +++ b/apps/labrinth/src/test/api_v2/team.rs @@ -1,19 +1,17 @@ -use actix_http::StatusCode; -use actix_web::{dev::ServiceResponse, test}; -use async_trait::async_trait; -use labrinth::models::{ +use crate::models::{ teams::{OrganizationPermissions, ProjectPermissions}, v2::{notifications::LegacyNotification, teams::LegacyTeamMember}, }; +use actix_http::StatusCode; +use actix_web::{dev::ServiceResponse, test}; +use async_trait::async_trait; use serde_json::json; -use crate::{ - assert_status, - common::api_common::{ - Api, ApiTeams, AppendsOptionalPat, - models::{CommonNotification, CommonTeamMember}, - }, +use crate::test::api_common::{ + Api, ApiTeams, AppendsOptionalPat, + models::{CommonNotification, CommonTeamMember}, }; +use crate::test::asserts::assert_status; use super::ApiV2; diff --git a/apps/labrinth/tests/common/api_v2/user.rs b/apps/labrinth/src/test/api_v2/user.rs similarity index 95% rename from apps/labrinth/tests/common/api_v2/user.rs rename to apps/labrinth/src/test/api_v2/user.rs index d0da67c6e4..5262e38ef4 100644 --- a/apps/labrinth/tests/common/api_v2/user.rs +++ b/apps/labrinth/src/test/api_v2/user.rs @@ -1,5 +1,5 @@ use super::ApiV2; -use crate::common::api_common::{Api, ApiUser, AppendsOptionalPat}; +use crate::test::api_common::{Api, ApiUser, AppendsOptionalPat}; use actix_web::{dev::ServiceResponse, test}; use async_trait::async_trait; diff --git a/apps/labrinth/tests/common/api_v2/version.rs b/apps/labrinth/src/test/api_v2/version.rs similarity index 98% rename from apps/labrinth/tests/common/api_v2/version.rs rename to apps/labrinth/src/test/api_v2/version.rs index 92b73d44e6..a544dba9d9 100644 --- a/apps/labrinth/tests/common/api_v2/version.rs +++ b/apps/labrinth/src/test/api_v2/version.rs @@ -5,14 +5,16 @@ use super::{ ApiV2, request_data::{self, get_public_version_creation_data}, }; +use crate::models::ids::ProjectId; +use crate::test::asserts::assert_status; +use crate::test::{ + api_common::{Api, ApiVersion, AppendsOptionalPat, models::CommonVersion}, + dummy_data::TestFile, +}; use crate::{ - assert_status, - common::{ - api_common::{ - Api, ApiVersion, AppendsOptionalPat, models::CommonVersion, - }, - dummy_data::TestFile, - }, + models::{projects::VersionType, v2::projects::LegacyVersion}, + routes::v2::version_file::FileUpdateData, + util::actix::AppendsMultipart, }; use actix_http::StatusCode; use actix_web::{ @@ -20,12 +22,6 @@ use actix_web::{ test::{self, TestRequest}, }; use async_trait::async_trait; -use labrinth::models::ids::ProjectId; -use labrinth::{ - models::{projects::VersionType, v2::projects::LegacyVersion}, - routes::v2::version_file::FileUpdateData, - util::actix::AppendsMultipart, -}; use serde_json::json; pub fn url_encode_json_serialized_vec(elements: &[String]) -> String { diff --git a/apps/labrinth/tests/common/api_v3/collections.rs b/apps/labrinth/src/test/api_v3/collections.rs similarity index 96% rename from apps/labrinth/tests/common/api_v3/collections.rs rename to apps/labrinth/src/test/api_v3/collections.rs index 38fce969d8..41dfc31319 100644 --- a/apps/labrinth/tests/common/api_v3/collections.rs +++ b/apps/labrinth/src/test/api_v3/collections.rs @@ -1,16 +1,16 @@ +use crate::models::{collections::Collection, v3::projects::Project}; use actix_http::StatusCode; use actix_web::{ dev::ServiceResponse, test::{self, TestRequest}, }; use bytes::Bytes; -use labrinth::models::{collections::Collection, v3::projects::Project}; use serde_json::json; -use crate::{ - assert_status, - common::api_common::{Api, AppendsOptionalPat, request_data::ImageData}, +use crate::test::api_common::{ + Api, AppendsOptionalPat, request_data::ImageData, }; +use crate::test::asserts::assert_status; use super::ApiV3; diff --git a/apps/labrinth/tests/common/api_v3/limits.rs b/apps/labrinth/src/test/api_v3/limits.rs similarity index 87% rename from apps/labrinth/tests/common/api_v3/limits.rs rename to apps/labrinth/src/test/api_v3/limits.rs index 3e2aa670b5..8237068af6 100644 --- a/apps/labrinth/tests/common/api_v3/limits.rs +++ b/apps/labrinth/src/test/api_v3/limits.rs @@ -1,13 +1,11 @@ +use crate::models::v3::user_limits::UserLimits; use actix_http::StatusCode; use actix_web::test; -use labrinth::models::v3::user_limits::UserLimits; -use crate::{ - assert_status, - common::{ - api_common::{Api, AppendsOptionalPat}, - api_v3::ApiV3, - }, +use crate::test::asserts::assert_status; +use crate::test::{ + api_common::{Api, AppendsOptionalPat}, + api_v3::ApiV3, }; impl ApiV3 { diff --git a/apps/labrinth/tests/common/api_v3/mod.rs b/apps/labrinth/src/test/api_v3/mod.rs similarity index 86% rename from apps/labrinth/tests/common/api_v3/mod.rs rename to apps/labrinth/src/test/api_v3/mod.rs index 1f28896de0..fa99718fdb 100644 --- a/apps/labrinth/tests/common/api_v3/mod.rs +++ b/apps/labrinth/src/test/api_v3/mod.rs @@ -2,9 +2,9 @@ use super::{ api_common::{Api, ApiBuildable}, environment::LocalService, }; +use crate::LabrinthConfig; use actix_web::{App, dev::ServiceResponse, test}; use async_trait::async_trait; -use labrinth::LabrinthConfig; use std::rc::Rc; use utoipa_actix_web::AppExt; @@ -31,12 +31,10 @@ impl ApiBuildable for ApiV3 { let app = App::new() .into_utoipa_app() .configure(|cfg| { - labrinth::utoipa_app_config(cfg, labrinth_config.clone()) + crate::utoipa_app_config(cfg, labrinth_config.clone()) }) .into_app() - .configure(|cfg| { - labrinth::app_config(cfg, labrinth_config.clone()) - }); + .configure(|cfg| crate::app_config(cfg, labrinth_config.clone())); let test_app: Rc = Rc::new(test::init_service(app).await); diff --git a/apps/labrinth/tests/common/api_v3/oauth.rs b/apps/labrinth/src/test/api_v3/oauth.rs similarity index 97% rename from apps/labrinth/tests/common/api_v3/oauth.rs rename to apps/labrinth/src/test/api_v3/oauth.rs index 434f6aff35..48343ad43f 100644 --- a/apps/labrinth/tests/common/api_v3/oauth.rs +++ b/apps/labrinth/src/test/api_v3/oauth.rs @@ -1,20 +1,18 @@ use std::collections::HashMap; +use crate::auth::oauth::{ + OAuthClientAccessRequest, RespondToOAuthClientScopes, TokenRequest, + TokenResponse, +}; use actix_http::StatusCode; use actix_web::http::header::{AUTHORIZATION, LOCATION}; use actix_web::{ dev::ServiceResponse, test::{self, TestRequest}, }; -use labrinth::auth::oauth::{ - OAuthClientAccessRequest, RespondToOAuthClientScopes, TokenRequest, - TokenResponse, -}; -use crate::{ - assert_status, - common::api_common::{Api, AppendsOptionalPat}, -}; +use crate::test::api_common::{Api, AppendsOptionalPat}; +use crate::test::asserts::assert_status; use super::ApiV3; diff --git a/apps/labrinth/tests/common/api_v3/oauth_clients.rs b/apps/labrinth/src/test/api_v3/oauth_clients.rs similarity index 97% rename from apps/labrinth/tests/common/api_v3/oauth_clients.rs rename to apps/labrinth/src/test/api_v3/oauth_clients.rs index 2afedb108a..db83f0194f 100644 --- a/apps/labrinth/tests/common/api_v3/oauth_clients.rs +++ b/apps/labrinth/src/test/api_v3/oauth_clients.rs @@ -1,21 +1,19 @@ -use actix_http::StatusCode; -use actix_web::{ - dev::ServiceResponse, - test::{self, TestRequest}, -}; -use labrinth::{ +use crate::{ models::{ oauth_clients::{OAuthClient, OAuthClientAuthorization}, pats::Scopes, }, routes::v3::oauth_clients::OAuthClientEdit, }; +use actix_http::StatusCode; +use actix_web::{ + dev::ServiceResponse, + test::{self, TestRequest}, +}; use serde_json::json; -use crate::{ - assert_status, - common::api_common::{Api, AppendsOptionalPat}, -}; +use crate::test::api_common::{Api, AppendsOptionalPat}; +use crate::test::asserts::assert_status; use super::ApiV3; diff --git a/apps/labrinth/tests/common/api_v3/organization.rs b/apps/labrinth/src/test/api_v3/organization.rs similarity index 96% rename from apps/labrinth/tests/common/api_v3/organization.rs rename to apps/labrinth/src/test/api_v3/organization.rs index b208db2178..f98ae20d5c 100644 --- a/apps/labrinth/tests/common/api_v3/organization.rs +++ b/apps/labrinth/src/test/api_v3/organization.rs @@ -1,7 +1,8 @@ -use crate::{ - assert_status, - common::api_common::{Api, AppendsOptionalPat, request_data::ImageData}, +use crate::models::{organizations::Organization, v3::projects::Project}; +use crate::test::api_common::{ + Api, AppendsOptionalPat, request_data::ImageData, }; +use crate::test::asserts::assert_status; use actix_http::StatusCode; use actix_web::{ dev::ServiceResponse, @@ -9,7 +10,6 @@ use actix_web::{ }; use ariadne::ids::UserId; use bytes::Bytes; -use labrinth::models::{organizations::Organization, v3::projects::Project}; use serde_json::json; use super::ApiV3; diff --git a/apps/labrinth/tests/common/api_v3/project.rs b/apps/labrinth/src/test/api_v3/project.rs similarity index 98% rename from apps/labrinth/tests/common/api_v3/project.rs rename to apps/labrinth/src/test/api_v3/project.rs index 0513206f8d..58121dfdb4 100644 --- a/apps/labrinth/tests/common/api_v3/project.rs +++ b/apps/labrinth/src/test/api_v3/project.rs @@ -1,5 +1,10 @@ use std::{collections::HashMap, fmt::Write}; +use crate::{ + models::{organizations::Organization, projects::Project}, + search::SearchResults, + util::actix::AppendsMultipart, +}; use actix_http::StatusCode; use actix_web::{ dev::ServiceResponse, @@ -8,25 +13,18 @@ use actix_web::{ use async_trait::async_trait; use bytes::Bytes; use chrono::{DateTime, Utc}; -use labrinth::{ - models::{organizations::Organization, projects::Project}, - search::SearchResults, - util::actix::AppendsMultipart, -}; use rust_decimal::Decimal; use serde_json::json; -use crate::{ - assert_status, - common::{ - api_common::{ - Api, ApiProject, AppendsOptionalPat, - models::{CommonItemType, CommonProject, CommonVersion}, - request_data::{ImageData, ProjectCreationRequestData}, - }, - database::MOD_USER_PAT, - dummy_data::TestFile, +use crate::test::asserts::assert_status; +use crate::test::{ + api_common::{ + Api, ApiProject, AppendsOptionalPat, + models::{CommonItemType, CommonProject, CommonVersion}, + request_data::{ImageData, ProjectCreationRequestData}, }, + database::MOD_USER_PAT, + dummy_data::TestFile, }; use super::{ diff --git a/apps/labrinth/tests/common/api_v3/request_data.rs b/apps/labrinth/src/test/api_v3/request_data.rs similarity index 96% rename from apps/labrinth/tests/common/api_v3/request_data.rs rename to apps/labrinth/src/test/api_v3/request_data.rs index c9774dd0f0..a3bc0eb4f7 100644 --- a/apps/labrinth/tests/common/api_v3/request_data.rs +++ b/apps/labrinth/src/test/api_v3/request_data.rs @@ -1,13 +1,13 @@ use serde_json::json; -use crate::common::{ +use crate::models::ids::ProjectId; +use crate::test::{ api_common::request_data::{ ProjectCreationRequestData, VersionCreationRequestData, }, dummy_data::TestFile, }; -use labrinth::models::ids::ProjectId; -use labrinth::util::actix::{MultipartSegment, MultipartSegmentData}; +use crate::util::actix::{MultipartSegment, MultipartSegmentData}; pub fn get_public_project_creation_data( slug: &str, diff --git a/apps/labrinth/tests/common/api_v3/tags.rs b/apps/labrinth/src/test/api_v3/tags.rs similarity index 91% rename from apps/labrinth/tests/common/api_v3/tags.rs rename to apps/labrinth/src/test/api_v3/tags.rs index b2eda4ac1a..7100d5ada5 100644 --- a/apps/labrinth/tests/common/api_v3/tags.rs +++ b/apps/labrinth/src/test/api_v3/tags.rs @@ -1,24 +1,22 @@ +use crate::routes::v3::tags::{GameData, LoaderData}; +use crate::{ + database::models::loader_fields::LoaderFieldEnumValue, + routes::v3::tags::CategoryData, +}; use actix_http::StatusCode; use actix_web::{ dev::ServiceResponse, test::{self, TestRequest}, }; use async_trait::async_trait; -use labrinth::routes::v3::tags::{GameData, LoaderData}; -use labrinth::{ - database::models::loader_fields::LoaderFieldEnumValue, - routes::v3::tags::CategoryData, -}; -use crate::{ - assert_status, - common::{ - api_common::{ - Api, ApiTags, AppendsOptionalPat, - models::{CommonCategoryData, CommonLoaderData}, - }, - database::ADMIN_USER_PAT, +use crate::test::asserts::assert_status; +use crate::test::{ + api_common::{ + Api, ApiTags, AppendsOptionalPat, + models::{CommonCategoryData, CommonLoaderData}, }, + database::ADMIN_USER_PAT, }; use super::ApiV3; diff --git a/apps/labrinth/tests/common/api_v3/team.rs b/apps/labrinth/src/test/api_v3/team.rs similarity index 98% rename from apps/labrinth/tests/common/api_v3/team.rs rename to apps/labrinth/src/test/api_v3/team.rs index 4bae47029c..770f1889a1 100644 --- a/apps/labrinth/tests/common/api_v3/team.rs +++ b/apps/labrinth/src/test/api_v3/team.rs @@ -1,19 +1,17 @@ -use actix_http::StatusCode; -use actix_web::{dev::ServiceResponse, test}; -use async_trait::async_trait; -use labrinth::models::{ +use crate::models::{ notifications::Notification, teams::{OrganizationPermissions, ProjectPermissions, TeamMember}, }; +use actix_http::StatusCode; +use actix_web::{dev::ServiceResponse, test}; +use async_trait::async_trait; use serde_json::json; -use crate::{ - assert_status, - common::api_common::{ - Api, ApiTeams, AppendsOptionalPat, - models::{CommonNotification, CommonTeamMember}, - }, +use crate::test::api_common::{ + Api, ApiTeams, AppendsOptionalPat, + models::{CommonNotification, CommonTeamMember}, }; +use crate::test::asserts::assert_status; use super::ApiV3; diff --git a/apps/labrinth/tests/common/api_v3/user.rs b/apps/labrinth/src/test/api_v3/user.rs similarity index 95% rename from apps/labrinth/tests/common/api_v3/user.rs rename to apps/labrinth/src/test/api_v3/user.rs index dbfe3bc2da..56bee18944 100644 --- a/apps/labrinth/tests/common/api_v3/user.rs +++ b/apps/labrinth/src/test/api_v3/user.rs @@ -1,7 +1,7 @@ use actix_web::{dev::ServiceResponse, test}; use async_trait::async_trait; -use crate::common::api_common::{Api, ApiUser, AppendsOptionalPat}; +use crate::test::api_common::{Api, ApiUser, AppendsOptionalPat}; use super::ApiV3; diff --git a/apps/labrinth/tests/common/api_v3/version.rs b/apps/labrinth/src/test/api_v3/version.rs similarity index 98% rename from apps/labrinth/tests/common/api_v3/version.rs rename to apps/labrinth/src/test/api_v3/version.rs index d3eeb7c434..2060e3a47c 100644 --- a/apps/labrinth/tests/common/api_v3/version.rs +++ b/apps/labrinth/src/test/api_v3/version.rs @@ -5,14 +5,16 @@ use super::{ ApiV3, request_data::{self, get_public_version_creation_data}, }; +use crate::models::ids::ProjectId; +use crate::test::asserts::assert_status; +use crate::test::{ + api_common::{Api, ApiVersion, AppendsOptionalPat, models::CommonVersion}, + dummy_data::TestFile, +}; use crate::{ - assert_status, - common::{ - api_common::{ - Api, ApiVersion, AppendsOptionalPat, models::CommonVersion, - }, - dummy_data::TestFile, - }, + models::{projects::VersionType, v3::projects::Version}, + routes::v3::version_file::FileUpdateData, + util::actix::AppendsMultipart, }; use actix_http::StatusCode; use actix_web::{ @@ -20,12 +22,6 @@ use actix_web::{ test::{self, TestRequest}, }; use async_trait::async_trait; -use labrinth::models::ids::ProjectId; -use labrinth::{ - models::{projects::VersionType, v3::projects::Version}, - routes::v3::version_file::FileUpdateData, - util::actix::AppendsMultipart, -}; use serde_json::json; pub fn url_encode_json_serialized_vec(elements: &[String]) -> String { diff --git a/apps/labrinth/tests/common/asserts.rs b/apps/labrinth/src/test/asserts.rs similarity index 69% rename from apps/labrinth/tests/common/asserts.rs rename to apps/labrinth/src/test/asserts.rs index b284905517..e8412dfa31 100644 --- a/apps/labrinth/tests/common/asserts.rs +++ b/apps/labrinth/src/test/asserts.rs @@ -1,10 +1,9 @@ -use crate::common::get_json_val_str; +use crate::models::v3::projects::Version; +use crate::test::get_json_val_str; use itertools::Itertools; -use labrinth::models::v3::projects::Version; use super::api_common::models::CommonVersion; -#[macro_export] macro_rules! assert_status { ($response:expr, $status:expr) => { assert_eq!( @@ -16,17 +15,7 @@ macro_rules! assert_status { }; } -#[macro_export] -macro_rules! assert_any_status_except { - ($response:expr, $status:expr) => { - assert_ne!( - $response.status(), - $status, - "{:#?}", - $response.response().body() - ); - }; -} +pub(crate) use assert_status; pub fn assert_version_ids(versions: &[Version], expected_ids: Vec) { let version_ids = versions diff --git a/apps/labrinth/tests/common/database.rs b/apps/labrinth/src/test/database.rs similarity index 98% rename from apps/labrinth/tests/common/database.rs rename to apps/labrinth/src/test/database.rs index d4877d0181..d7696c5149 100644 --- a/apps/labrinth/tests/common/database.rs +++ b/apps/labrinth/src/test/database.rs @@ -1,11 +1,11 @@ -use labrinth::database::ReadOnlyPgPool; -use labrinth::database::redis::RedisPool; -use labrinth::search; +use crate::database::ReadOnlyPgPool; +use crate::database::redis::RedisPool; +use crate::search; use sqlx::{PgPool, postgres::PgPoolOptions}; use std::time::Duration; use url::Url; -use crate::common::{dummy_data, environment::TestEnvironment}; +use crate::test::{dummy_data, environment::TestEnvironment}; use super::{api_v3::ApiV3, dummy_data::DUMMY_DATA_UPDATE}; @@ -40,7 +40,7 @@ pub struct TemporaryDatabase { pub pool: PgPool, pub ro_pool: ReadOnlyPgPool, pub redis_pool: RedisPool, - pub search_config: labrinth::search::SearchConfig, + pub search_config: crate::search::SearchConfig, pub database_name: String, } diff --git a/apps/labrinth/tests/common/dummy_data.rs b/apps/labrinth/src/test/dummy_data.rs similarity index 98% rename from apps/labrinth/tests/common/dummy_data.rs rename to apps/labrinth/src/test/dummy_data.rs index d44bd839c4..3211f32e2e 100644 --- a/apps/labrinth/tests/common/dummy_data.rs +++ b/apps/labrinth/src/test/dummy_data.rs @@ -1,17 +1,15 @@ use std::io::{Cursor, Write}; -use crate::{ - assert_status, - common::{api_common::Api, api_v3, database::USER_USER_PAT}, -}; -use actix_http::StatusCode; -use actix_web::test::{self, TestRequest}; -use labrinth::models::ids::ProjectId; -use labrinth::models::{ +use crate::models::ids::ProjectId; +use crate::models::{ oauth_clients::OAuthClient, organizations::Organization, projects::{Project, Version}, }; +use crate::test::asserts::assert_status; +use crate::test::{api_common::Api, api_v3, database::USER_USER_PAT}; +use actix_http::StatusCode; +use actix_web::test::{self, TestRequest}; use serde_json::json; use zip::{CompressionMethod, ZipWriter, write::FileOptions}; @@ -289,7 +287,7 @@ pub async fn add_dummy_data(api: &ApiV3, db: TemporaryDatabase) -> DummyData { // Adds basic dummy data to the database directly with sql (user, pats) let pool = &db.pool.clone(); - labrinth::test::db::add_dummy_data(pool).await.unwrap(); + crate::test::db::add_dummy_data(pool).await.unwrap(); let (alpha_project, alpha_version) = add_project_alpha(api).await; let (beta_project, beta_version) = add_project_beta(api).await; diff --git a/apps/labrinth/tests/common/environment.rs b/apps/labrinth/src/test/environment.rs similarity index 98% rename from apps/labrinth/tests/common/environment.rs rename to apps/labrinth/src/test/environment.rs index ec40799191..d3ed396663 100644 --- a/apps/labrinth/tests/common/environment.rs +++ b/apps/labrinth/src/test/environment.rs @@ -5,7 +5,8 @@ use super::{ database::{FRIEND_USER_ID, TemporaryDatabase, USER_USER_PAT}, dummy_data, }; -use crate::{assert_status, common::setup}; +use crate::test::asserts::assert_status; +use crate::test::setup; use actix_http::StatusCode; use actix_web::dev::ServiceResponse; use futures::Future; diff --git a/apps/labrinth/src/test/mod.rs b/apps/labrinth/src/test/mod.rs index dec10232bd..1a10812e7e 100644 --- a/apps/labrinth/src/test/mod.rs +++ b/apps/labrinth/src/test/mod.rs @@ -1 +1,76 @@ +use crate::queue::email::EmailQueue; +use crate::util::anrok; +use crate::util::gotenberg::GotenbergClient; +use crate::{LabrinthConfig, file_hosting}; +use crate::{check_env_vars, clickhouse}; +use modrinth_maxmind::MaxMind; +use std::sync::Arc; + +pub mod api_common; +pub mod api_v2; +pub mod api_v3; +pub mod asserts; +pub mod database; pub mod db; +pub mod dummy_data; +pub mod environment; +pub mod pats; +pub mod permissions; +pub mod scopes; +pub mod search; + +// Testing equivalent to 'setup' function, producing a LabrinthConfig +// If making a test, you should probably use environment::TestEnvironment::build() (which calls this) +pub async fn setup(db: &database::TemporaryDatabase) -> LabrinthConfig { + println!("Setting up labrinth config"); + + dotenvy::dotenv().ok(); + + if check_env_vars() { + println!("Some environment variables are missing!"); + } + + let _ = rustls::crypto::aws_lc_rs::default_provider().install_default(); + + let pool = db.pool.clone(); + let ro_pool = db.ro_pool.clone(); + let redis_pool = db.redis_pool.clone(); + let search_config = db.search_config.clone(); + let file_host: Arc = + Arc::new(file_hosting::MockHost::new()); + let mut clickhouse = clickhouse::init_client().await.unwrap(); + + let maxmind_reader = MaxMind::new().await; + + let stripe_client = + stripe::Client::new(dotenvy::var("STRIPE_API_KEY").unwrap()); + + let anrok_client = anrok::Client::from_env().unwrap(); + let email_queue = + EmailQueue::init(pool.clone(), redis_pool.clone()).unwrap(); + let gotenberg_client = + GotenbergClient::from_env().expect("Failed to create Gotenberg client"); + + crate::app_setup( + pool.clone(), + ro_pool.clone(), + redis_pool.clone(), + search_config, + &mut clickhouse, + file_host.clone(), + maxmind_reader, + stripe_client, + anrok_client, + email_queue, + gotenberg_client, + false, + ) +} + +pub fn get_json_val_str(val: impl serde::Serialize) -> String { + serde_json::to_value(val) + .unwrap() + .as_str() + .unwrap() + .to_string() +} diff --git a/apps/labrinth/tests/common/pats.rs b/apps/labrinth/src/test/pats.rs similarity index 98% rename from apps/labrinth/tests/common/pats.rs rename to apps/labrinth/src/test/pats.rs index 75691817a8..aab5dbc878 100644 --- a/apps/labrinth/tests/common/pats.rs +++ b/apps/labrinth/src/test/pats.rs @@ -1,8 +1,8 @@ -use chrono::Utc; -use labrinth::{ +use crate::{ database::{self, models::generate_pat_id}, models::pats::Scopes, }; +use chrono::Utc; use super::database::TemporaryDatabase; diff --git a/apps/labrinth/tests/common/permissions.rs b/apps/labrinth/src/test/permissions.rs similarity index 99% rename from apps/labrinth/tests/common/permissions.rs rename to apps/labrinth/src/test/permissions.rs index dc5eaebad3..651322f76f 100644 --- a/apps/labrinth/tests/common/permissions.rs +++ b/apps/labrinth/src/test/permissions.rs @@ -1,11 +1,11 @@ +use crate::models::teams::{OrganizationPermissions, ProjectPermissions}; use actix_http::StatusCode; use actix_web::{dev::ServiceResponse, test}; use futures::Future; use itertools::Itertools; -use labrinth::models::teams::{OrganizationPermissions, ProjectPermissions}; use serde_json::json; -use crate::common::{ +use crate::test::{ api_common::ApiTeams, database::{ADMIN_USER_PAT, generate_random_name}, }; diff --git a/apps/labrinth/tests/common/scopes.rs b/apps/labrinth/src/test/scopes.rs similarity index 99% rename from apps/labrinth/tests/common/scopes.rs rename to apps/labrinth/src/test/scopes.rs index 5d74db6007..24f0aefc22 100644 --- a/apps/labrinth/tests/common/scopes.rs +++ b/apps/labrinth/src/test/scopes.rs @@ -1,6 +1,6 @@ +use crate::models::pats::Scopes; use actix_web::{dev::ServiceResponse, test}; use futures::Future; -use labrinth::models::pats::Scopes; use super::{ api_common::Api, database::USER_USER_ID_PARSED, diff --git a/apps/labrinth/tests/common/search.rs b/apps/labrinth/src/test/search.rs similarity index 97% rename from apps/labrinth/tests/common/search.rs rename to apps/labrinth/src/test/search.rs index c6c0035edd..45ce34f7f0 100644 --- a/apps/labrinth/tests/common/search.rs +++ b/apps/labrinth/src/test/search.rs @@ -3,13 +3,11 @@ use std::{collections::HashMap, sync::Arc}; use actix_http::StatusCode; use serde_json::json; -use crate::{ - assert_status, - common::{ - api_common::{Api, ApiProject, ApiVersion}, - database::{FRIEND_USER_PAT, MOD_USER_PAT, USER_USER_PAT}, - dummy_data::{DUMMY_CATEGORIES, TestFile}, - }, +use crate::test::asserts::assert_status; +use crate::test::{ + api_common::{Api, ApiProject, ApiVersion}, + database::{FRIEND_USER_PAT, MOD_USER_PAT, USER_USER_PAT}, + dummy_data::{DUMMY_CATEGORIES, TestFile}, }; use super::{api_v3::ApiV3, environment::TestEnvironment}; diff --git a/apps/labrinth/tests/common.rs b/apps/labrinth/tests/common.rs new file mode 100644 index 0000000000..e07d5b1ccb --- /dev/null +++ b/apps/labrinth/tests/common.rs @@ -0,0 +1,32 @@ +//! Re-exports all [`labrinth::test`] items for compatibility. +//! +//! Previously, tests used `mod common` and `common::item` imports for testing. +//! This has been moved into [`labrinth::test`] under a feature flag, and this +//! module remains for backwards compatibility with tests which expect the +//! `common` module. + +pub use labrinth::test::*; + +#[macro_export] +macro_rules! assert_status { + ($response:expr, $status:expr) => { + assert_eq!( + $response.status(), + $status, + "{:#?}", + $response.response().body() + ); + }; +} + +#[macro_export] +macro_rules! assert_any_status_except { + ($response:expr, $status:expr) => { + assert_ne!( + $response.status(), + $status, + "{:#?}", + $response.response().body() + ); + }; +} diff --git a/apps/labrinth/tests/common/mod.rs b/apps/labrinth/tests/common/mod.rs deleted file mode 100644 index 79958f7aab..0000000000 --- a/apps/labrinth/tests/common/mod.rs +++ /dev/null @@ -1,75 +0,0 @@ -use labrinth::queue::email::EmailQueue; -use labrinth::util::anrok; -use labrinth::util::gotenberg::GotenbergClient; -use labrinth::{LabrinthConfig, file_hosting}; -use labrinth::{check_env_vars, clickhouse}; -use modrinth_maxmind::MaxMind; -use std::sync::Arc; - -pub mod api_common; -pub mod api_v2; -pub mod api_v3; -pub mod asserts; -pub mod database; -pub mod dummy_data; -pub mod environment; -pub mod pats; -pub mod permissions; -pub mod scopes; -pub mod search; - -// Testing equivalent to 'setup' function, producing a LabrinthConfig -// If making a test, you should probably use environment::TestEnvironment::build() (which calls this) -pub async fn setup(db: &database::TemporaryDatabase) -> LabrinthConfig { - println!("Setting up labrinth config"); - - dotenvy::dotenv().ok(); - - if check_env_vars() { - println!("Some environment variables are missing!"); - } - - let _ = rustls::crypto::aws_lc_rs::default_provider().install_default(); - - let pool = db.pool.clone(); - let ro_pool = db.ro_pool.clone(); - let redis_pool = db.redis_pool.clone(); - let search_config = db.search_config.clone(); - let file_host: Arc = - Arc::new(file_hosting::MockHost::new()); - let mut clickhouse = clickhouse::init_client().await.unwrap(); - - let maxmind_reader = MaxMind::new().await; - - let stripe_client = - stripe::Client::new(dotenvy::var("STRIPE_API_KEY").unwrap()); - - let anrok_client = anrok::Client::from_env().unwrap(); - let email_queue = - EmailQueue::init(pool.clone(), redis_pool.clone()).unwrap(); - let gotenberg_client = - GotenbergClient::from_env().expect("Failed to create Gotenberg client"); - - labrinth::app_setup( - pool.clone(), - ro_pool.clone(), - redis_pool.clone(), - search_config, - &mut clickhouse, - file_host.clone(), - maxmind_reader, - stripe_client, - anrok_client, - email_queue, - gotenberg_client, - false, - ) -} - -pub fn get_json_val_str(val: impl serde::Serialize) -> String { - serde_json::to_value(val) - .unwrap() - .as_str() - .unwrap() - .to_string() -} diff --git a/apps/labrinth/tests/v2/error.rs b/apps/labrinth/tests/v2/error.rs index da98df471f..8cafa91ab0 100644 --- a/apps/labrinth/tests/v2/error.rs +++ b/apps/labrinth/tests/v2/error.rs @@ -1,15 +1,16 @@ -use crate::assert_status; use crate::common::api_common::ApiProject; use actix_http::StatusCode; use actix_web::test; use bytes::Bytes; +use crate::assert_status; use crate::common::database::USER_USER_PAT; use crate::common::{ api_v2::ApiV2, environment::{TestEnvironment, with_test_environment}, }; + #[actix_rt::test] pub async fn error_404_empty() { with_test_environment( From fdd20e4656985c7c675b27ca6c11ca756162427a Mon Sep 17 00:00:00 2001 From: aecsocket Date: Sun, 2 Nov 2025 19:27:18 +0000 Subject: [PATCH 2/7] Feature gate `labrinth::test` --- apps/labrinth/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/labrinth/src/lib.rs b/apps/labrinth/src/lib.rs index 672161b9be..5bddfa857c 100644 --- a/apps/labrinth/src/lib.rs +++ b/apps/labrinth/src/lib.rs @@ -37,10 +37,12 @@ pub mod routes; pub mod scheduler; pub mod search; pub mod sync; -pub mod test; pub mod util; pub mod validate; +#[cfg(feature = "test")] +pub mod test; + #[derive(Clone)] pub struct Pepper { pub pepper: String, From d7c4115df97ec55d28dfeb149e428c24a0675fba Mon Sep 17 00:00:00 2001 From: aecsocket Date: Sun, 2 Nov 2025 19:55:43 +0000 Subject: [PATCH 3/7] Unify db migrators --- apps/labrinth/src/test/database.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/labrinth/src/test/database.rs b/apps/labrinth/src/test/database.rs index d7696c5149..9da2bda963 100644 --- a/apps/labrinth/src/test/database.rs +++ b/apps/labrinth/src/test/database.rs @@ -1,5 +1,5 @@ -use crate::database::ReadOnlyPgPool; use crate::database::redis::RedisPool; +use crate::database::{MIGRATOR, ReadOnlyPgPool}; use crate::search; use sqlx::{PgPool, postgres::PgPoolOptions}; use std::time::Duration; @@ -82,8 +82,7 @@ impl TemporaryDatabase { println!("Running migrations on temporary database"); // Performs migrations - let migrations = sqlx::migrate!("./migrations"); - migrations.run(&pool).await.expect("Migrations failed"); + MIGRATOR.run(&pool).await.expect("Migrations failed"); println!("Migrations complete"); @@ -182,8 +181,7 @@ impl TemporaryDatabase { } // Run migrations on the template - let migrations = sqlx::migrate!("./migrations"); - migrations.run(&pool).await.expect("Migrations failed"); + MIGRATOR.run(&pool).await.expect("Migrations failed"); if !dummy_data_exists { // Add dummy data From 014eaee99e6f12cd7845535e34a932466ee60f43 Mon Sep 17 00:00:00 2001 From: aecsocket Date: Mon, 3 Nov 2025 13:24:19 +0000 Subject: [PATCH 4/7] Expose `NotificationBuilder::insert_many_deliveries` --- apps/labrinth/src/database/models/notification_item.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/labrinth/src/database/models/notification_item.rs b/apps/labrinth/src/database/models/notification_item.rs index bf3d5e7d10..ce3d627d51 100644 --- a/apps/labrinth/src/database/models/notification_item.rs +++ b/apps/labrinth/src/database/models/notification_item.rs @@ -160,7 +160,7 @@ impl NotificationBuilder { Ok(()) } - async fn insert_many_deliveries( + pub async fn insert_many_deliveries( transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>, redis: &RedisPool, notification_ids: &[i64], From 6a999bbded2cb107dd6f61eb4a0792bfa34a27d3 Mon Sep 17 00:00:00 2001 From: aecsocket Date: Fri, 7 Nov 2025 18:09:57 +0000 Subject: [PATCH 5/7] Add logging utils to common crate --- Cargo.lock | 8 ++-- apps/labrinth/Cargo.toml | 4 +- apps/labrinth/src/main.rs | 53 +-------------------- packages/modrinth-util/Cargo.toml | 4 ++ packages/modrinth-util/src/lib.rs | 2 + packages/modrinth-util/src/log.rs | 77 +++++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 58 deletions(-) create mode 100644 packages/modrinth-util/src/log.rs diff --git a/Cargo.lock b/Cargo.lock index 0e48f3fb45..e0c98c3248 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4660,7 +4660,6 @@ dependencies = [ "clickhouse", "color-eyre", "color-thief", - "console-subscriber", "const_format", "dashmap", "deadpool-redis", @@ -4683,6 +4682,7 @@ dependencies = [ "lettre", "meilisearch-sdk", "modrinth-maxmind", + "modrinth-util", "muralpay", "murmur2", "paste", @@ -4716,8 +4716,6 @@ dependencies = [ "totp-rs", "tracing", "tracing-actix-web", - "tracing-ecs", - "tracing-subscriber", "url", "urlencoding", "utoipa", @@ -5227,10 +5225,14 @@ name = "modrinth-util" version = "0.0.0" dependencies = [ "actix-web", + "console-subscriber", "derive_more 2.0.1", "dotenvy", "eyre", "serde", + "tracing", + "tracing-ecs", + "tracing-subscriber", ] [[package]] diff --git a/apps/labrinth/Cargo.toml b/apps/labrinth/Cargo.toml index f17c3bbf23..bed033df07 100644 --- a/apps/labrinth/Cargo.toml +++ b/apps/labrinth/Cargo.toml @@ -37,7 +37,6 @@ clap = { workspace = true, features = ["derive"] } clickhouse = { workspace = true, features = ["time", "uuid"] } color-eyre = { workspace = true } color-thief = { workspace = true } -console-subscriber = { workspace = true } const_format = { workspace = true } dashmap = { workspace = true } deadpool-redis.workspace = true @@ -72,6 +71,7 @@ json-patch = { workspace = true } lettre = { workspace = true } meilisearch-sdk = { workspace = true, features = ["reqwest"] } modrinth-maxmind = { workspace = true } +modrinth-util = { workspace = true } muralpay = { workspace = true, features = ["utoipa"] } murmur2 = { workspace = true } paste = { workspace = true } @@ -120,8 +120,6 @@ tokio-stream = { workspace = true } totp-rs = { workspace = true, features = ["gen_secret"] } tracing = { workspace = true } tracing-actix-web = { workspace = true } -tracing-ecs = { workspace = true } -tracing-subscriber = { workspace = true } url = { workspace = true } urlencoding = { workspace = true } utoipa = { workspace = true } diff --git a/apps/labrinth/src/main.rs b/apps/labrinth/src/main.rs index 799a202dbf..469c998ce0 100644 --- a/apps/labrinth/src/main.rs +++ b/apps/labrinth/src/main.rs @@ -19,13 +19,8 @@ use labrinth::{check_env_vars, clickhouse, database, file_hosting}; use std::ffi::CStr; use std::str::FromStr; use std::sync::Arc; -use tracing::level_filters::LevelFilter; use tracing::{Instrument, error, info, info_span}; use tracing_actix_web::TracingLogger; -use tracing_ecs::ECSLayerBuilder; -use tracing_subscriber::EnvFilter; -use tracing_subscriber::layer::SubscriberExt; -use tracing_subscriber::util::SubscriberInitExt; use utoipa::OpenApi; use utoipa_actix_web::AppExt; use utoipa_swagger_ui::SwaggerUi; @@ -59,59 +54,13 @@ struct Args { run_background_task: Option, } -#[derive(Debug, Clone, Default, PartialEq, Eq)] -enum OutputFormat { - #[default] - Human, - Json, -} - -impl FromStr for OutputFormat { - type Err = (); - - fn from_str(s: &str) -> Result { - match s { - "human" => Ok(Self::Human), - "json" => Ok(Self::Json), - _ => Err(()), - } - } -} - #[actix_rt::main] async fn main() -> std::io::Result<()> { let args = Args::parse(); color_eyre::install().expect("failed to install `color-eyre`"); dotenvy::dotenv().ok(); - let console_layer = console_subscriber::spawn(); - let env_filter = EnvFilter::builder() - .with_default_directive(LevelFilter::INFO.into()) - .from_env_lossy(); - - let output_format = - dotenvy::var("LABRINTH_FORMAT").map_or(OutputFormat::Human, |format| { - format - .parse::() - .unwrap_or_else(|_| panic!("invalid output format '{format}'")) - }); - - match output_format { - OutputFormat::Human => { - tracing_subscriber::registry() - .with(console_layer) - .with(env_filter) - .with(tracing_subscriber::fmt::layer()) - .init(); - } - OutputFormat::Json => { - tracing_subscriber::registry() - .with(console_layer) - .with(env_filter) - .with(ECSLayerBuilder::default().stdout()) - .init(); - } - } + modrinth_util::log::init().expect("failed to initialize logging"); if check_env_vars() { error!("Some environment variables are missing!"); diff --git a/packages/modrinth-util/Cargo.toml b/packages/modrinth-util/Cargo.toml index 1c453c4c75..631c59368f 100644 --- a/packages/modrinth-util/Cargo.toml +++ b/packages/modrinth-util/Cargo.toml @@ -6,10 +6,14 @@ repository.workspace = true [dependencies] actix-web = { workspace = true } +console-subscriber = { workspace = true } derive_more = { workspace = true, features = ["display", "error", "from"] } dotenvy = { workspace = true } eyre = { workspace = true } serde = { workspace = true, features = ["derive"] } +tracing = { workspace = true } +tracing-ecs = { workspace = true } +tracing-subscriber = { workspace = true } [lints] workspace = true diff --git a/packages/modrinth-util/src/lib.rs b/packages/modrinth-util/src/lib.rs index ca934079d1..bb0c8c76da 100644 --- a/packages/modrinth-util/src/lib.rs +++ b/packages/modrinth-util/src/lib.rs @@ -1,6 +1,8 @@ #![doc = include_str!("../README.md")] mod error; +pub mod log; + pub use error::*; use eyre::{Result, eyre}; diff --git a/packages/modrinth-util/src/log.rs b/packages/modrinth-util/src/log.rs new file mode 100644 index 0000000000..2baafb1289 --- /dev/null +++ b/packages/modrinth-util/src/log.rs @@ -0,0 +1,77 @@ +//! Service logging utilities. + +use std::str::FromStr; + +use eyre::{Result, eyre}; +use tracing::level_filters::LevelFilter; +use tracing_ecs::ECSLayerBuilder; +use tracing_subscriber::{ + EnvFilter, layer::SubscriberExt, util::SubscriberInitExt, +}; + +use crate::{Context, env_var}; + +/// How this service will output logs to the terminal output. +/// +/// See [`init`]. +#[derive(Debug, Clone, Default, PartialEq, Eq)] +enum OutputFormat { + /// Human-readable format using [`tracing_subscriber::fmt::layer`]. + #[default] + Human, + /// Elastic Common Schema JSON output using [`ECSLayerBuilder`]. + Json, +} + +impl FromStr for OutputFormat { + type Err = (); + + fn from_str(s: &str) -> Result { + match s { + "human" => Ok(Self::Human), + "json" => Ok(Self::Json), + _ => Err(()), + } + } +} + +/// Key for the environment variable that determines the output format. +pub const OUTPUT_FORMAT_ENV_VAR: &str = "MODRINTH_OUTPUT_FORMAT"; + +/// Initializes logging for Modrinth services. +/// +/// This uses [`OUTPUT_FORMAT_ENV_VAR`] to determine the [`OutputFormat`] to +/// use - see that type for details of each possible format. +/// +/// # Errors +/// +/// Errors if logging could not be initialized. +pub fn init() -> Result<()> { + let output_format = match env_var(OUTPUT_FORMAT_ENV_VAR) { + Ok(format) => format + .parse::() + .map_err(|_| eyre!("invalid output format '{format}'"))?, + Err(_) => OutputFormat::Human, + }; + + let console_layer = console_subscriber::spawn(); + let env_filter = EnvFilter::builder() + .with_default_directive(LevelFilter::INFO.into()) + .from_env_lossy(); + + let result = match output_format { + OutputFormat::Human => tracing_subscriber::registry() + .with(console_layer) + .with(env_filter) + .with(tracing_subscriber::fmt::layer()) + .try_init(), + OutputFormat::Json => tracing_subscriber::registry() + .with(console_layer) + .with(env_filter) + .with(ECSLayerBuilder::default().stdout()) + .try_init(), + }; + result.wrap_err("failed to initialize tracing registry")?; + + Ok(()) +} From 9e5aa909c1b43fca924f145a56c900a4e120a4d0 Mon Sep 17 00:00:00 2001 From: aecsocket Date: Fri, 7 Nov 2025 18:26:53 +0000 Subject: [PATCH 6/7] Remove unused console-subscriber layer --- .cargo/config.toml | 5 +- Cargo.lock | 210 +----------------------------- Cargo.toml | 1 - packages/modrinth-util/Cargo.toml | 1 - packages/modrinth-util/src/log.rs | 3 - 5 files changed, 3 insertions(+), 217 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 17380505b5..bdeac036f2 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,9 +1,6 @@ -[build] -rustflags = ["--cfg", "tokio_unstable"] - # Windows has stack overflows when calling from Tauri, so we increase the default stack size used by the compiler [target.'cfg(windows)'] -rustflags = ["--cfg", "tokio_unstable", "-C", "link-args=/STACK:16777220"] +rustflags = ["-C", "link-args=/STACK:16777220"] [target.x86_64-pc-windows-msvc] linker = "rust-lld" diff --git a/Cargo.lock b/Cargo.lock index e0c98c3248..65d75c5067 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -671,28 +671,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "async-stream" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476" -dependencies = [ - "async-stream-impl", - "futures-core", - "pin-project-lite", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", -] - [[package]] name = "async-stripe" version = "0.41.0" @@ -914,53 +892,6 @@ dependencies = [ "thiserror 2.0.17", ] -[[package]] -name = "axum" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" -dependencies = [ - "async-trait", - "axum-core", - "bytes", - "futures-util", - "http 1.3.1", - "http-body 1.0.1", - "http-body-util", - "itoa", - "matchit", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "rustversion", - "serde", - "sync_wrapper", - "tower 0.5.2", - "tower-layer", - "tower-service", -] - -[[package]] -name = "axum-core" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http 1.3.1", - "http-body 1.0.1", - "http-body-util", - "mime", - "pin-project-lite", - "rustversion", - "sync_wrapper", - "tower-layer", - "tower-service", -] - [[package]] name = "backtrace" version = "0.3.76" @@ -1697,45 +1628,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "console-api" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8030735ecb0d128428b64cd379809817e620a40e5001c54465b99ec5feec2857" -dependencies = [ - "futures-core", - "prost", - "prost-types", - "tonic", - "tracing-core", -] - -[[package]] -name = "console-subscriber" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6539aa9c6a4cd31f4b1c040f860a1eac9aa80e7df6b05d506a6e7179936d6a01" -dependencies = [ - "console-api", - "crossbeam-channel", - "crossbeam-utils", - "futures-task", - "hdrhistogram", - "humantime", - "hyper-util", - "prost", - "prost-types", - "serde", - "serde_json", - "thread_local", - "tokio", - "tokio-stream", - "tonic", - "tracing", - "tracing-core", - "tracing-subscriber", -] - [[package]] name = "const-oid" version = "0.9.6" @@ -3647,19 +3539,6 @@ dependencies = [ "hashbrown 0.15.5", ] -[[package]] -name = "hdrhistogram" -version = "7.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d" -dependencies = [ - "base64 0.21.7", - "byteorder", - "flate2", - "nom 7.1.3", - "num-traits", -] - [[package]] name = "heck" version = "0.4.1" @@ -3875,12 +3754,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" -[[package]] -name = "humantime" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424" - [[package]] name = "hyper" version = "0.14.32" @@ -3962,19 +3835,6 @@ dependencies = [ "webpki-roots 1.0.3", ] -[[package]] -name = "hyper-timeout" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0" -dependencies = [ - "hyper 1.7.0", - "hyper-util", - "pin-project-lite", - "tokio", - "tower-service", -] - [[package]] name = "hyper-tls" version = "0.6.0" @@ -5029,12 +4889,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" -[[package]] -name = "matchit" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" - [[package]] name = "maxminddb" version = "0.26.0" @@ -5225,7 +5079,6 @@ name = "modrinth-util" version = "0.0.0" dependencies = [ "actix-web", - "console-subscriber", "derive_more 2.0.1", "dotenvy", "eyre", @@ -6746,15 +6599,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "prost-types" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52c2c1bf36ddb1a1c396b3601a3cec27c2462e45f07c386894ec3ccf5332bd16" -dependencies = [ - "prost", -] - [[package]] name = "protobuf" version = "3.7.2" @@ -7335,7 +7179,7 @@ dependencies = [ "tokio-native-tls", "tokio-rustls 0.26.4", "tokio-util", - "tower 0.5.2", + "tower", "tower-http", "tower-service", "url", @@ -10032,36 +9876,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df8b2b54733674ad286d16267dcfc7a71ed5c776e4ac7aa3c3e2561f7c637bf2" -[[package]] -name = "tonic" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52" -dependencies = [ - "async-stream", - "async-trait", - "axum", - "base64 0.22.1", - "bytes", - "h2 0.4.12", - "http 1.3.1", - "http-body 1.0.1", - "http-body-util", - "hyper 1.7.0", - "hyper-timeout", - "hyper-util", - "percent-encoding", - "pin-project", - "prost", - "socket2 0.5.10", - "tokio", - "tokio-stream", - "tower 0.4.13", - "tower-layer", - "tower-service", - "tracing", -] - [[package]] name = "totp-rs" version = "5.7.0" @@ -10076,26 +9890,6 @@ dependencies = [ "sha2", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "indexmap 1.9.3", - "pin-project", - "pin-project-lite", - "rand 0.8.5", - "slab", - "tokio", - "tokio-util", - "tower-layer", - "tower-service", - "tracing", -] - [[package]] name = "tower" version = "0.5.2" @@ -10124,7 +9918,7 @@ dependencies = [ "http-body 1.0.1", "iri-string", "pin-project-lite", - "tower 0.5.2", + "tower", "tower-layer", "tower-service", ] diff --git a/Cargo.toml b/Cargo.toml index 0db90446c7..cbabe4261f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,6 @@ clap = "4.5.48" clickhouse = "0.14.0" color-eyre = "0.6.5" color-thief = "0.2.2" -console-subscriber = "0.4.1" const_format = "0.2.34" daedalus = { path = "packages/daedalus" } dashmap = "6.1.0" diff --git a/packages/modrinth-util/Cargo.toml b/packages/modrinth-util/Cargo.toml index 631c59368f..a5af7bc7a0 100644 --- a/packages/modrinth-util/Cargo.toml +++ b/packages/modrinth-util/Cargo.toml @@ -6,7 +6,6 @@ repository.workspace = true [dependencies] actix-web = { workspace = true } -console-subscriber = { workspace = true } derive_more = { workspace = true, features = ["display", "error", "from"] } dotenvy = { workspace = true } eyre = { workspace = true } diff --git a/packages/modrinth-util/src/log.rs b/packages/modrinth-util/src/log.rs index 2baafb1289..0cd8068709 100644 --- a/packages/modrinth-util/src/log.rs +++ b/packages/modrinth-util/src/log.rs @@ -54,19 +54,16 @@ pub fn init() -> Result<()> { Err(_) => OutputFormat::Human, }; - let console_layer = console_subscriber::spawn(); let env_filter = EnvFilter::builder() .with_default_directive(LevelFilter::INFO.into()) .from_env_lossy(); let result = match output_format { OutputFormat::Human => tracing_subscriber::registry() - .with(console_layer) .with(env_filter) .with(tracing_subscriber::fmt::layer()) .try_init(), OutputFormat::Json => tracing_subscriber::registry() - .with(console_layer) .with(env_filter) .with(ECSLayerBuilder::default().stdout()) .try_init(), From 0aef6408cf7245e3869dafa04245a769ae3532fb Mon Sep 17 00:00:00 2001 From: aecsocket Date: Fri, 7 Nov 2025 18:49:32 +0000 Subject: [PATCH 7/7] fix CI --- apps/labrinth/src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/labrinth/src/main.rs b/apps/labrinth/src/main.rs index 469c998ce0..210f5a5207 100644 --- a/apps/labrinth/src/main.rs +++ b/apps/labrinth/src/main.rs @@ -17,7 +17,6 @@ use labrinth::util::ratelimit::rate_limit_middleware; use labrinth::utoipa_app_config; use labrinth::{check_env_vars, clickhouse, database, file_hosting}; use std::ffi::CStr; -use std::str::FromStr; use std::sync::Arc; use tracing::{Instrument, error, info, info_span}; use tracing_actix_web::TracingLogger;