From 754e6239daeb3de16b6e324706ee57ac68bdf6f4 Mon Sep 17 00:00:00 2001 From: Edouard Vanbelle Date: Wed, 24 Jun 2026 02:44:25 +0200 Subject: [PATCH] fix(drive): correct integration test --- src/application/services/subject_group_service.rs | 10 +++++++++- .../repositories/pg/file_blob_read_repository.rs | 6 +++++- src/infrastructure/services/dedup_service.rs | 8 +++++++- src/infrastructure/services/pg_acl_engine.rs | 8 +++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/application/services/subject_group_service.rs b/src/application/services/subject_group_service.rs index f895a688..db021e0f 100644 --- a/src/application/services/subject_group_service.rs +++ b/src/application/services/subject_group_service.rs @@ -563,7 +563,15 @@ mod integration_tests { let pool = Arc::new(pool); let repo = Arc::new(SubjectGroupPgRepository::new(pool.clone())); let user_storage = Arc::new(UserPgRepository::new(pool.clone())); - SubjectGroupService::new(repo, pool, user_storage) + // The engine is wired so `add_member` / `remove_member` can invalidate + // their stale `user_groups_cache` entries (the production path). + // A stub engine is enough — these tests never trigger an authz SQL + // round-trip, only the in-memory cache invalidation calls. The stub's + // lazy invalid pool would panic if reached, surfacing any drift if a + // future test starts exercising real authz lookups. + let engine = + Arc::new(crate::infrastructure::services::pg_acl_engine::PgAclEngine::new_stub()); + SubjectGroupService::new(repo, pool, user_storage, engine) } async fn first_admin(pool: &sqlx::PgPool) -> Uuid { diff --git a/src/infrastructure/repositories/pg/file_blob_read_repository.rs b/src/infrastructure/repositories/pg/file_blob_read_repository.rs index d7e5f94c..af31116f 100644 --- a/src/infrastructure/repositories/pg/file_blob_read_repository.rs +++ b/src/infrastructure/repositories/pg/file_blob_read_repository.rs @@ -345,7 +345,11 @@ impl FileBlobReadRepository { } /// Creates a stub instance for testing — never hits PG. - #[cfg(test)] + /// Available in both standard unit-test (`cfg(test)`) and integration + /// (`cfg(integration_tests)`) builds; `PgAclEngine::new_stub` chains + /// into this stub and is needed from the integration-test module of + /// `subject_group_service`. + #[cfg(any(test, integration_tests))] pub fn new_stub() -> Self { use crate::infrastructure::services::dedup_service::DedupService; Self { diff --git a/src/infrastructure/services/dedup_service.rs b/src/infrastructure/services/dedup_service.rs index 17db89f0..eefa1045 100644 --- a/src/infrastructure/services/dedup_service.rs +++ b/src/infrastructure/services/dedup_service.rs @@ -291,7 +291,13 @@ impl DedupService { } /// Creates a stub instance for testing — never hits PG or the filesystem. - #[cfg(any(test, feature = "integration_tests"))] + /// + /// Gated for both build modes integration tests are reachable from: + /// the raw `cfg(integration_tests)` flag used by CI / justfile + /// (`RUSTFLAGS='--cfg integration_tests'`) and the + /// `feature = "integration_tests"` form for callers that flip the + /// cargo feature instead. Standard `cfg(test)` keeps unit-test use. + #[cfg(any(test, integration_tests, feature = "integration_tests"))] pub fn new_stub() -> Self { use crate::infrastructure::services::local_blob_backend::LocalBlobBackend; let stub_pool = Arc::new( diff --git a/src/infrastructure/services/pg_acl_engine.rs b/src/infrastructure/services/pg_acl_engine.rs index 2a0ece24..06a3903d 100644 --- a/src/infrastructure/services/pg_acl_engine.rs +++ b/src/infrastructure/services/pg_acl_engine.rs @@ -201,7 +201,13 @@ impl PgAclEngine { /// without a real PostgreSQL pool. Connecting to the lazy pool will /// fail at runtime — only safe in tests that exercise types, not actual /// authz queries. - #[cfg(test)] + /// + /// Visible under both `cfg(test)` (the standard unit-test build) and + /// `cfg(integration_tests)` (the gated-by-RUSTFLAGS integration + /// build). The `SubjectGroupService` integration tests construct the + /// service with a stub engine, since they only exercise the engine's + /// in-memory cache invalidation calls — never its SQL paths. + #[cfg(any(test, integration_tests))] pub fn new_stub() -> Self { let pool = sqlx::pool::PoolOptions::::new() .max_connections(1)