From 31b1bcd673a616300d4a65be441fe7dc2a246882 Mon Sep 17 00:00:00 2001 From: piquel Date: Wed, 4 Nov 2026 11:55:06 +0100 Subject: [PATCH] chore(rust): every crate's test helpers sit behind one test-util feature --- apps/auth-service/Cargo.toml | 2 +- crates/database/Cargo.toml | 2 +- crates/database/src/connection/mod.rs | 2 +- crates/database/src/exclusive/mod.rs | 4 ++-- crates/database/src/lib.rs | 4 ++-- crates/database/src/repositories/audit/mod.rs | 4 ++-- crates/database/src/repositories/deliveries/mod.rs | 2 +- crates/database/src/repositories/events/mod.rs | 4 ++-- crates/database/src/repositories/recoveries.rs | 4 ++-- crates/database/src/repositories/tokens/mod.rs | 2 +- crates/database/src/repositories/users/mod.rs | 4 ++-- crates/database/src/transaction.rs | 2 +- docs/architecture/database-crate.md | 4 ++-- just/db.just | 2 +- 14 files changed, 21 insertions(+), 21 deletions(-) diff --git a/apps/auth-service/Cargo.toml b/apps/auth-service/Cargo.toml index ab021d593..f098b6452 100644 --- a/apps/auth-service/Cargo.toml +++ b/apps/auth-service/Cargo.toml @@ -39,7 +39,7 @@ webauthn-rs-proto.workspace = true piquel-auth = { workspace = true, features = ["axum", "test-util"] } rcgen.workspace = true tokio-rustls.workspace = true -piquel-repository = { workspace = true, features = ["test-support"] } +piquel-repository = { workspace = true, features = ["test-util"] } piquel-telemetry = { workspace = true, features = ["test-util"] } serde_urlencoded.workspace = true tower.workspace = true diff --git a/crates/database/Cargo.toml b/crates/database/Cargo.toml index d79dda26c..0a1cf66b9 100644 --- a/crates/database/Cargo.toml +++ b/crates/database/Cargo.toml @@ -21,7 +21,7 @@ uuid.workspace = true [features] # Helpers that let other crates' tests observe stored state, and move a # recovery's clock. -test-support = [] +test-util = [] [lints] workspace = true diff --git a/crates/database/src/connection/mod.rs b/crates/database/src/connection/mod.rs index dd45c014c..42867284f 100644 --- a/crates/database/src/connection/mod.rs +++ b/crates/database/src/connection/mod.rs @@ -347,7 +347,7 @@ impl Database { } } -#[cfg(feature = "test-support")] +#[cfg(feature = "test-util")] impl Database { /// Connects to `config`'s database in a schema of its own, created and migrated /// for this call, so a test can change history that the whole database shares, diff --git a/crates/database/src/exclusive/mod.rs b/crates/database/src/exclusive/mod.rs index fe3a11585..03dda5ebd 100644 --- a/crates/database/src/exclusive/mod.rs +++ b/crates/database/src/exclusive/mod.rs @@ -27,11 +27,11 @@ pub enum LockKey { /// overlapping `migrate` runs take turns. Migrations = 7, /// The job runner panic test; no release takes it. - #[cfg(feature = "test-support")] + #[cfg(feature = "test-util")] Test = -1, /// The job runner exclusivity test, apart from [`Self::Test`] since tests /// sharing a database run at once; no release takes it. - #[cfg(feature = "test-support")] + #[cfg(feature = "test-util")] ExclusivityTest = -2, } diff --git a/crates/database/src/lib.rs b/crates/database/src/lib.rs index 381c395f4..504530c99 100644 --- a/crates/database/src/lib.rs +++ b/crates/database/src/lib.rs @@ -2,7 +2,7 @@ //! //! Applications receive typed repositories and never a pool, executor, row, or //! `SQLx` error. Repositories expose only the operations used by the service, plus -//! read-only helpers behind the `test-support` feature for other crates' tests. +//! read-only helpers behind the `test-util` feature for other crates' tests. /// Validated `PostgreSQL` transport and bounded connection pools. mod connection; /// Typed persistence and connection failures. @@ -20,7 +20,7 @@ pub use connection::{Database, DatabaseConfig, RuntimeRole}; pub(crate) use connection::{Limit, Scope}; pub use error::{DatabaseConnectionError, DatabaseError}; pub use exclusive::{ExclusiveConnection, LockKey}; -#[cfg(feature = "test-support")] +#[cfg(feature = "test-util")] pub use repositories::audit::Tamper; pub use repositories::{ AccountDeletionRepository, AdministratorRepository, AuditRepository, DashboardRepository, diff --git a/crates/database/src/repositories/audit/mod.rs b/crates/database/src/repositories/audit/mod.rs index f286729c9..62d32d00f 100644 --- a/crates/database/src/repositories/audit/mod.rs +++ b/crates/database/src/repositories/audit/mod.rs @@ -490,7 +490,7 @@ impl DatabaseTransaction<'_> { /// A change an attacker with database access could make, for verification tests. /// [`AuditRepository::tamper`] applies it with the guard triggers disabled, so run /// it only on a database of its own (see `Database::isolated`). -#[cfg(feature = "test-support")] +#[cfg(feature = "test-util")] #[derive(Clone, Debug)] pub enum Tamper { /// Replaces the payload of the event at a position. @@ -516,7 +516,7 @@ pub enum Tamper { ErasePersonalData(u64), } -#[cfg(feature = "test-support")] +#[cfg(feature = "test-util")] impl AuditRepository<'_> { /// Applies `tamper` with the guard triggers disabled. /// diff --git a/crates/database/src/repositories/deliveries/mod.rs b/crates/database/src/repositories/deliveries/mod.rs index 9b3991370..ca1685b76 100644 --- a/crates/database/src/repositories/deliveries/mod.rs +++ b/crates/database/src/repositories/deliveries/mod.rs @@ -322,7 +322,7 @@ impl DeliveryRepository<'_> { /// # Errors /// /// Returns [`DatabaseError`] if the query fails. - #[cfg(feature = "test-support")] + #[cfg(feature = "test-util")] pub async fn payloads( &mut self, destination: &str, diff --git a/crates/database/src/repositories/events/mod.rs b/crates/database/src/repositories/events/mod.rs index 58e5e3cc8..94b514b81 100644 --- a/crates/database/src/repositories/events/mod.rs +++ b/crates/database/src/repositories/events/mod.rs @@ -488,7 +488,7 @@ impl EventRepository<'_> { /// # Errors /// /// Returns [`DatabaseError`] if the query fails or a stored event does not decode. - #[cfg(feature = "test-support")] + #[cfg(feature = "test-util")] pub async fn history_for_client( &mut self, client_id: &ClientId, @@ -529,7 +529,7 @@ impl EventRepository<'_> { /// # Errors /// /// Returns [`DatabaseError`] if the query fails. - #[cfg(any(test, feature = "test-support"))] + #[cfg(any(test, feature = "test-util"))] pub async fn insert_written_elsewhere( &mut self, subject: UserId, diff --git a/crates/database/src/repositories/recoveries.rs b/crates/database/src/repositories/recoveries.rs index 643459790..1a7c59ad8 100644 --- a/crates/database/src/repositories/recoveries.rs +++ b/crates/database/src/repositories/recoveries.rs @@ -420,7 +420,7 @@ impl RecoveryRepository<'_> { /// # Errors /// /// Returns [`DatabaseError`] if the update fails. - #[cfg(feature = "test-support")] + #[cfg(feature = "test-util")] pub async fn expire(&mut self, id: RecoveryId) -> Result<(), DatabaseError> { run!( self, @@ -439,7 +439,7 @@ impl RecoveryRepository<'_> { /// # Errors /// /// Returns [`DatabaseError`] if the update fails. - #[cfg(feature = "test-support")] + #[cfg(feature = "test-util")] pub async fn backdate_completion( &mut self, id: RecoveryId, diff --git a/crates/database/src/repositories/tokens/mod.rs b/crates/database/src/repositories/tokens/mod.rs index 220230291..b2ec5c352 100644 --- a/crates/database/src/repositories/tokens/mod.rs +++ b/crates/database/src/repositories/tokens/mod.rs @@ -447,7 +447,7 @@ impl TokenRepository<'_> { /// # Errors /// /// Returns [`DatabaseError`] if the query fails. - #[cfg(feature = "test-support")] + #[cfg(feature = "test-util")] pub async fn lock_family(&mut self, id: TokenId) -> Result<(), DatabaseError> { run!( self, diff --git a/crates/database/src/repositories/users/mod.rs b/crates/database/src/repositories/users/mod.rs index c1f14cfa0..7fd063f92 100644 --- a/crates/database/src/repositories/users/mod.rs +++ b/crates/database/src/repositories/users/mod.rs @@ -49,7 +49,7 @@ pub struct InsertUser { pub display_name: String, } -#[cfg(any(test, feature = "test-support"))] +#[cfg(any(test, feature = "test-util"))] impl InsertUser { /// An account whose handle is `prefix` and a random suffix, for tests. /// @@ -259,7 +259,7 @@ impl UserRepository<'_> { /// # Errors /// /// Returns [`DatabaseError`] if the query fails. - #[cfg(feature = "test-support")] + #[cfg(feature = "test-util")] pub async fn age_handle_change(&mut self, id: UserId, days: i32) -> Result<(), DatabaseError> { run!( self, diff --git a/crates/database/src/transaction.rs b/crates/database/src/transaction.rs index eb5ae022e..b436d8c81 100644 --- a/crates/database/src/transaction.rs +++ b/crates/database/src/transaction.rs @@ -79,7 +79,7 @@ impl<'a> DatabaseTransaction<'a> { /// # Errors /// /// Returns [`DatabaseError`] if the query fails. - #[cfg(feature = "test-support")] + #[cfg(feature = "test-util")] pub async fn blocked_transactions(&mut self) -> Result { sqlx::query_scalar!( // `pg_locks` is read afresh by every query; `pg_stat_activity` would diff --git a/docs/architecture/database-crate.md b/docs/architecture/database-crate.md index 002838248..97fa3a74f 100644 --- a/docs/architecture/database-crate.md +++ b/docs/architecture/database-crate.md @@ -210,7 +210,7 @@ The purge's queries use indexes, including the actor's user ID in `domain_events`, so its cost does not grow with everyone's history. Tests that use `TEST_DATABASE_URL` are explicitly marked ignored by the ordinary unit test runner; other crates' tests read stored state -through helpers behind the `test-support` feature. `just db test` runs them in a +through helpers behind the `test-util` feature. `just db test` runs them in a throwaway PostgreSQL cluster, or against an explicit, disposable `TEST_DATABASE_URL`. ## Time limits @@ -476,7 +476,7 @@ one that would move it back fails. Personal data is not covered, so retention keeps deleting `event_personal_data` freely. Verification tests need history no other test shares: `Database::isolated` (behind -`test-support`) migrates a schema of its own, and `audit().tamper` applies the +`test-util`) migrates a schema of its own, and `audit().tamper` applies the changes an attacker could make, with the trigger disabled. ### Security history diff --git a/just/db.just b/just/db.just index bf4e50850..acf6d50b5 100644 --- a/just/db.just +++ b/just/db.just @@ -20,7 +20,7 @@ prepare-check: prepare: @just db scratch just db _prepare -# Test targets and the `test-support` feature are included so checked queries +# Test targets and the `test-util` feature are included so checked queries # compiled only for tests are cached too. [positional-arguments] _prepare *ARGS: