diff --git a/src/rate_limit.rs b/src/rate_limit.rs index ea005de..1521acc 100644 --- a/src/rate_limit.rs +++ b/src/rate_limit.rs @@ -938,4 +938,61 @@ mod tests { ); } } + + /// How many of `tries` requests the limiter admits for `user`. + fn admits(limiter: &UserRateLimiter, user: &str, tries: usize) -> usize { + (0..tries) + .filter(|_| limiter.enforce_user(user).is_ok()) + .count() + } + + /// A wall-window roll must not bill one request to two shared rows: the + /// fold reports only a bucket's *unreported* delta, so when the wall + /// window rolls under a still-live local window, the new row receives + /// nothing the old row had already taken. (Rebuilt over the control + /// database — `rate_limit` is a control table — after the SurrealDB port + /// dropped it along with the embedded engine.) + #[tokio::test] + async fn a_wall_epoch_roll_charges_no_request_twice() { + const MAX: u32 = 5; + let tenants = crate::database::init_test_tenants().await; + let db = tenants.control().clone(); + let limiter = UserRateLimiter::per_user_minute(MAX); + let window = Duration::from_secs(60); + let epoch = current_epoch(window); + assert_eq!(window.as_millis() as i64, 60_000, "epochs are 60s apart"); + + // A burst early in the client's local window, folded into row `epoch`. + for _ in 0..MAX { + assert!(limiter.enforce_user("user:a").is_ok()); + } + sync_once("test", &limiter.buckets, window, epoch, &db).await; + + // The wall clock rolls while that local window is still running. + sync_once("test", &limiter.buckets, window, epoch + 60_000, &db).await; + + // The local window lapses, so the client opens a fresh one — inside + // the *same* new wall window — and spends one request in it. + tokio::time::pause(); + tokio::time::advance(Duration::from_secs(61)).await; + tokio::time::resume(); + assert_eq!(admits(&limiter, "user:a", 1), 1, "a fresh local window"); + sync_once("test", &limiter.buckets, window, epoch + 60_000, &db).await; + + let rows = + sqlx::query_scalar::<_, i64>("SELECT hits FROM rate_limit ORDER BY window_start") + .fetch_all(&db) + .await + .expect("read shared counters"); + assert_eq!( + rows, + vec![i64::from(MAX), 1], + "the new wall row may hold only what was admitted inside it" + ); + assert_eq!( + admits(&limiter, "user:a", 4), + 4, + "the client spent 1 of {MAX} in this window and must keep the rest" + ); + } } diff --git a/tests/ai_bridge.rs b/tests/ai_bridge.rs index 1441f8c..46c116e 100644 --- a/tests/ai_bridge.rs +++ b/tests/ai_bridge.rs @@ -865,7 +865,6 @@ async fn fetch_certificate(ai: Option) -> (axum::http::StatusCode, Val chatbot_limit: Default::default(), exam_presence: Default::default(), board_hub: Default::default(), - db_up: Default::default(), ai, metrics: hezarfen_backend::telemetry::Metrics::noop(), }); @@ -985,7 +984,7 @@ use axum::Router; use axum::http::StatusCode; use hezarfen_backend::constant::{AI_CHAT_CAPABILITY, DEFAULT_MAX_CHATBOT_MESSAGE_LEN}; use hezarfen_backend::database::Database; -use surrealdb::types::RecordId; +use uuid::Uuid; /// A router wired to `bridge`, plus a handle to its in-memory database. async fn chat_app(bridge: &AiBridge) -> (Router, Database) { @@ -999,7 +998,6 @@ async fn chat_app(bridge: &AiBridge) -> (Router, Database) { chatbot_limit: Default::default(), exam_presence: Default::default(), board_hub: Default::default(), - db_up: Default::default(), ai: Some(bridge.clone()), metrics: hezarfen_backend::telemetry::Metrics::noop(), }); @@ -1119,15 +1117,18 @@ async fn the_history_a_service_receives_is_oldest_first_without_the_new_turn() { "complete" ); - db.query( - "CREATE chatbot_message:h3 SET thread_id = $conv, user_id = $usr, role = 'assistant', - content = '', status = 'pending', created_at = 1002;", + // History is ordered by `created_at`, so this seeded row's 1002 timestamp + // sorts it before everything the turns above minted — the never-answered + // prior turn the new prompt must not duplicate into. + sqlx::query( + "INSERT INTO chatbot_message (id, thread_id, user_id, role, content, status, created_at) \ + VALUES ($1, $2, $3, 'assistant', '', 'pending', 1002)", ) - .bind(("conv", RecordId::new("chatbot_thread", thread.as_str()))) - .bind(("usr", RecordId::new("user", user.as_str()))) + .bind(Uuid::now_v7()) + .bind(Uuid::parse_str(&thread).expect("thread id")) + .bind(Uuid::parse_str(&user).expect("user id")) + .execute(&db) .await - .expect("seed history") - .check() .expect("seed history"); let mid = ask(&app, &cookie, &thread, "ikinci soru").await; @@ -1559,10 +1560,11 @@ async fn a_router_status_rides_back_as_an_ok_answer_not_a_refusal() { #[tokio::test] async fn a_down_database_socket_is_refused_as_unavailable_rather_than_parked() { - // This path skips the HTTP layers, the db guard among them, so it re-checks - // liveness itself: a query issued while the socket is down does not fail, - // it parks until the socket returns. A service has to be told to retry - // instead of waiting out its own deadline on a read nobody is running. + // This path skips the HTTP layers, so the bridge resolves the school's + // registry row itself, on the control database, before every read. Take + // that table away and the read is refused as `unavailable` — promptly, + // never parked waiting on a store nobody is running — instead of hanging + // out the service's own deadline. let bridge = bridge().await; let service = connect_service( &bridge, @@ -1571,10 +1573,13 @@ async fn a_down_database_socket_is_refused_as_unavailable_rather_than_parked() { ) .await; await_workers(&bridge, 1).await; - let health = hezarfen_backend::state::DbHealth::default(); - let (_app, _db) = common::app_with_ai_health(Some(bridge.clone()), health.clone()).await; + let (_app, _db, tenants) = common::app_with_ai_tenants(Some(bridge.clone())).await; + let control = tenants.control(); - health.set(false); + sqlx::query("ALTER TABLE school RENAME TO school_out") + .execute(control) + .await + .expect("take the registry away"); match api_read(&service.conn, read_of("/notes", None)).await { ApiResponse::Err { code, id, .. } => { assert_eq!(code, "unavailable"); @@ -1583,9 +1588,12 @@ async fn a_down_database_socket_is_refused_as_unavailable_rather_than_parked() { other => panic!("a read against a down database must be refused: {other:?}"), } - // And that refusal is the flag's doing, not a broken bridge: the same read - // on the same stream-opening service answers once the socket is back. - health.set(true); + // And that refusal is the outage's doing, not a broken bridge: the same + // read on the same stream-opening service answers once the store is back. + sqlx::query("ALTER TABLE school_out RENAME TO school") + .execute(control) + .await + .expect("give the registry back"); let (status, _) = ok_answer(api_read(&service.conn, read_of("/notes", None)).await); assert_eq!(status, 200); } diff --git a/tests/ai_protocol.rs b/tests/ai_protocol.rs index 62b6681..4a40c0f 100644 --- a/tests/ai_protocol.rs +++ b/tests/ai_protocol.rs @@ -954,9 +954,7 @@ async fn a_chat_request_names_the_askers_school_role() { let service = raw::handshake(&bridge, &raw::hello("tutor", "chat.reply")).await; await_workers(&bridge, 1).await; - let tenants = hezarfen_backend::database::init_mem_tenants() - .await - .expect("in-memory deployment"); + let tenants = hezarfen_backend::database::init_test_tenants().await; let db = tenants .get(&hezarfen_backend::tenant::Slug::try_new(hezarfen_backend::tenant::DEMO_SLUG).unwrap()) .await @@ -970,7 +968,6 @@ async fn a_chat_request_names_the_askers_school_role() { chatbot_limit: Default::default(), exam_presence: Default::default(), board_hub: Default::default(), - db_up: Default::default(), ai: Some(bridge.clone()), metrics: hezarfen_backend::telemetry::Metrics::noop(), }); diff --git a/tests/e2e.rs b/tests/e2e.rs index 45ad3a9..ba8402f 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -6,8 +6,11 @@ use hezarfen_backend::rate_limit::RateLimitConfig; use hezarfen_backend::state::AppState; use hezarfen_backend::tenant::{DEMO_SLUG, Slug}; use hezarfen_backend::{build_router, database}; +mod common; + use reqwest::{Client, StatusCode}; use serde_json::{Value, json}; +use uuid::Uuid; /// Start the server on a random port. Returns its base URL (e.g. /// `http://127.0.0.1:54321`) plus a handle to its database, so a test can grant @@ -18,9 +21,7 @@ async fn spawn_server() -> (String, Database) { /// [`spawn_server`], with the AI bridge the chatbot relays through wired in. async fn spawn_server_with_ai(ai: Option) -> (String, Database) { - let tenants = database::init_mem_tenants() - .await - .expect("in-memory deployment"); + let tenants = database::init_test_tenants().await; let db = tenants .get(&Slug::try_new(DEMO_SLUG).unwrap()) .await @@ -48,7 +49,6 @@ async fn spawn_server_with_ai(ai: Option) -> (St chatbot_limit: Default::default(), exam_presence: Default::default(), board_hub: Default::default(), - db_up: Default::default(), ai, metrics: hezarfen_backend::telemetry::Metrics::noop(), }); @@ -69,12 +69,11 @@ async fn spawn_server_with_ai(ai: Option) -> (St /// Grant `user` a role directly (the manual bootstrap path). async fn promote(db: &Database, user: &str, role: &str) { - db.query("UPDATE user SET role = $r WHERE username = $u") - .bind(("r", role.to_string())) - .bind(("u", user.to_string())) + sqlx::query("UPDATE app_user SET role = $1 WHERE username = $2") + .bind(role) + .bind(user) + .execute(db) .await - .unwrap() - .check() .unwrap(); } @@ -2201,41 +2200,34 @@ async fn board_frame_of_type(ws: &mut WsStream, kind: &str) -> Value { } } -fn board_record(board: &str) -> surrealdb::types::RecordId { - surrealdb::types::RecordId::new("board", board.to_string()) -} - /// The stored stroke ids of one epoch, in mint order, read straight out of the /// database — the only proof that survives a lying frame. async fn stored_stroke_ids(db: &Database, board: &str, epoch: i64) -> Vec { - let mut result = db - .query( - "SELECT VALUE record::id(id) FROM board_stroke \ - WHERE board = $b AND epoch = $e AND kind = 'stroke' ORDER BY id", - ) - .bind(("b", board_record(board))) - .bind(("e", epoch)) - .await - .unwrap() - .check() - .unwrap(); - result.take::>(0).unwrap() + sqlx::query_scalar::<_, Uuid>( + "SELECT id FROM board_stroke \ + WHERE board = $1 AND epoch = $2 AND kind = 'stroke' ORDER BY id", + ) + .bind(Uuid::parse_str(board).unwrap()) + .bind(epoch) + .fetch_all(db) + .await + .unwrap() + .into_iter() + .map(|id| id.to_string()) + .collect() } /// The stored payloads of one epoch, in mint order. async fn stored_payloads(db: &Database, board: &str, epoch: i64) -> Vec { - let mut result = db - .query( - "SELECT VALUE payload FROM board_stroke \ - WHERE board = $b AND epoch = $e AND kind = 'stroke' ORDER BY id", - ) - .bind(("b", board_record(board))) - .bind(("e", epoch)) - .await - .unwrap() - .check() - .unwrap(); - result.take::>(0).unwrap() + sqlx::query_scalar::<_, String>( + "SELECT payload FROM board_stroke \ + WHERE board = $1 AND epoch = $2 AND kind = 'stroke' ORDER BY id", + ) + .bind(Uuid::parse_str(board).unwrap()) + .bind(epoch) + .fetch_all(db) + .await + .unwrap() } /// Draw one mark and wait for its ack, ignoring the fan-out of everyone else's @@ -2332,28 +2324,17 @@ async fn a_participants_clear_is_refused_and_the_socket_keeps_drawing() { vec!["before".to_string(), "after".to_string()] ); // The refusal wrote nothing: no clear marker, and the epoch never moved. - let mut result = room - .db - .query("SELECT VALUE epoch FROM $b") - .bind(("b", board_record(board))) + let epochs = sqlx::query_scalar::<_, i64>("SELECT epoch FROM board WHERE id = $1") + .bind(Uuid::parse_str(board).unwrap()) + .fetch_all(&room.db) .await - .unwrap() - .check() .unwrap(); - assert_eq!(result.take::>(0).unwrap(), vec![0]); - let mut result = room - .db - .query("SELECT VALUE id FROM board_stroke WHERE kind = 'clear'") + assert_eq!(epochs, vec![0]); + let clears = sqlx::query_scalar::<_, Uuid>("SELECT id FROM board_stroke WHERE kind = 'clear'") + .fetch_all(&room.db) .await - .unwrap() - .check() .unwrap(); - assert!( - result - .take::>(0) - .unwrap() - .is_empty() - ); + assert!(clears.is_empty()); // A lock is creator-only on the same terms, and equally non-fatal. ws_send(&mut veli, json!({ "type": "lock", "locked": true })).await; @@ -2563,13 +2544,9 @@ async fn the_door_is_a_404_for_an_outsider_and_an_unknown_board() { "a non-participant must not learn the board exists" ); assert_eq!( - board_open( - base, - "01JZZZZZZZZZZZZZZZZZZZZZZZ", - Some(&room.creator_cookie) - ) - .await - .err(), + board_open(base, common::ABSENT_ID, Some(&room.creator_cookie)) + .await + .err(), Some(404), "indistinguishable from an unknown board" ); @@ -2614,20 +2591,14 @@ async fn a_parent_cannot_enter_the_room_or_draw() { .unwrap(); // Beside `veli`, who stays: the two differ only by role, so the refusal // below cannot be blamed on the roster. - room.db - .query("UPDATE $b SET participants = [$v, $u]") - .bind(("b", board_record(board))) - .bind(( - "v", - surrealdb::types::RecordId::new("user", room.veli_id.clone()), - )) - .bind(( - "u", - surrealdb::types::RecordId::new("user", me["id"].as_str().unwrap().to_string()), - )) + sqlx::query("UPDATE board SET participants = $1 WHERE id = $2") + .bind(vec![ + Uuid::parse_str(&room.veli_id).unwrap(), + Uuid::parse_str(me["id"].as_str().unwrap()).unwrap(), + ]) + .bind(Uuid::parse_str(board).unwrap()) + .execute(&room.db) .await - .unwrap() - .check() .unwrap(); assert_eq!( @@ -2637,7 +2608,7 @@ async fn a_parent_cannot_enter_the_room_or_draw() { ); // Not a 403 anywhere: identical to a board that was never minted. assert_eq!( - board_open(base, "01JZZZZZZZZZZZZZZZZZZZZZZZ", Some(&cookie)) + board_open(base, common::ABSENT_ID, Some(&cookie)) .await .err(), Some(404) @@ -2671,12 +2642,11 @@ async fn a_removed_participant_can_no_longer_draw() { // The silent removal first: write the roster straight into the database, // so no frame is published and only the per-stroke gate can catch it. - room.db - .query("UPDATE $b SET participants = []") - .bind(("b", board_record(board))) + sqlx::query("UPDATE board SET participants = $1 WHERE id = $2") + .bind(Vec::::new()) + .bind(Uuid::parse_str(board).unwrap()) + .execute(&room.db) .await - .unwrap() - .check() .unwrap(); ws_send( &mut veli, @@ -3856,9 +3826,7 @@ async fn probe_a_suspended_school_refuses_websocket_upgrades() { ); // So is the exam room, on any id. assert_eq!( - ws_open(&base, "01J8XZ0K3Q8G7X2M4N5P6R7S8T", Some(&cookie)) - .await - .err(), + ws_open(&base, common::ABSENT_ID, Some(&cookie)).await.err(), Some(403), "the exam socket opened for a suspended school" ); diff --git a/tests/rate_limit.rs b/tests/rate_limit.rs index 7bb2db8..ccce830 100644 --- a/tests/rate_limit.rs +++ b/tests/rate_limit.rs @@ -16,11 +16,9 @@ use hezarfen_backend::{build_router, database}; use serde_json::{Value, json}; use tower::ServiceExt; -/// App with the given limits, backed by a fresh in-memory database. +/// App with the given limits, backed by a fresh per-test Postgres deployment. async fn app_with(rate_limit: RateLimitConfig) -> Router { - let tenants = database::init_mem_tenants() - .await - .expect("in-memory deployment"); + let tenants = database::init_test_tenants().await; build_router(AppState { db: tenants.control().clone(), tenants, @@ -30,7 +28,6 @@ async fn app_with(rate_limit: RateLimitConfig) -> Router { chatbot_limit: Default::default(), exam_presence: Default::default(), board_hub: Default::default(), - db_up: Default::default(), ai: None, metrics: hezarfen_backend::telemetry::Metrics::noop(), }) @@ -383,29 +380,31 @@ async fn keyless_clients_share_one_budget_once_the_map_is_saturated() { // --- the window outlives the process ------------------------------------ // -// Two `UserRateLimiter`s over one database stand in for the process before and -// after a restart: two separate sets of in-memory buckets sharing only the -// `rate_limit` table, which is what stops a restart mid-window from handing -// every client a fresh budget. Time is paused, so a round of the sync task is -// driven by advancing past `RATE_SYNC_INTERVAL_SECS` — and because the task -// blocks on the database (not on time) mid-round, the short sleep afterwards -// cannot resolve until the round has finished. Assertions are on admissions, -// never on which limiter won a race: the embedded engine can drop one of two -// concurrent writes and still answer `Ok`. +// Two `UserRateLimiter`s over one control database stand in for the process +// before and after a restart: two separate sets of in-memory buckets sharing +// only the `rate_limit` table, which is what stops a restart mid-window from +// handing every client a fresh budget. Time is paused, so a round of the sync +// task is driven by advancing past `RATE_SYNC_INTERVAL_SECS` — and because the +// task blocks on the database (not on time) mid-round, the short sleep +// afterwards cannot resolve until the round has finished. Assertions stay on +// admissions and on the rows the fold wrote: which limiter's statement lands +// first cannot matter, a round is one atomic statement per limiter. use hezarfen_backend::constant::RATE_SYNC_INTERVAL_SECS; use hezarfen_backend::database::Database; use hezarfen_backend::rate_limit::UserRateLimiter; -use hezarfen_backend::state::DbHealth; +use hezarfen_backend::tenant::Tenants; use std::time::Duration; -/// A migrated in-memory database, with the clock frozen only afterwards: the -/// embedded engine has internal deadlines of its own and cannot start up under -/// a paused clock ("Insert node failed after 5 attempts due to timeout"). -async fn shared_db() -> Database { - let db = database::init_mem().await.expect("in-memory db"); +/// A fresh per-test deployment — the trio shares its **control** database, +/// where the `rate_limit` table lives — with the clock frozen only afterwards: +/// every pool dials on the real clock, since a paused clock never fires a +/// connect deadline and a stalled dial would hang the test. +async fn shared_db() -> (Tenants, Database) { + let tenants = database::init_test_tenants().await; + let db = tenants.control().clone(); tokio::time::pause(); - db + (tenants, db) } /// Let the sync task run one round: fire its timer, then hand it *real* time @@ -419,8 +418,22 @@ async fn sync_round() { tokio::task::yield_now().await; tokio::time::advance(Duration::from_secs(RATE_SYNC_INTERVAL_SECS)).await; tokio::time::resume(); - tokio::time::sleep(Duration::from_millis(250)).await; + tokio::time::sleep(Duration::from_millis(750)).await; + tokio::time::pause(); +} + +/// The `rate_limit` rows, read in a resumed window: a pool statement run +/// directly under the paused clock cannot dial — auto-advance fires the +/// connect deadline the instant the runtime idles — so every direct +/// statement here hands the clock back first. +async fn read_shared_hits(db: &Database) -> Vec { + tokio::time::resume(); + let rows = sqlx::query_scalar::<_, i64>("SELECT hits FROM rate_limit") + .fetch_all(db) + .await + .expect("read shared counters"); tokio::time::pause(); + rows } /// One fixed wall window for every round below. The sync task reads the real @@ -435,15 +448,14 @@ const PINNED_WINDOW: i64 = 60_000; /// Two limiters of one tier, sharing `db` and one wall window — the process /// before a restart and the process after, which is the only way one deployment /// runs two sets of buckets over one `rate_limit` row. -fn two_processes(max: u32, db: &Database) -> (UserRateLimiter, UserRateLimiter, DbHealth) { - let health = DbHealth::default(); +fn two_processes(max: u32, db: &Database) -> (UserRateLimiter, UserRateLimiter) { let (a, b) = ( UserRateLimiter::per_user_minute(max), UserRateLimiter::per_user_minute(max), ); - a.share_pinned("test", db.clone(), health.clone(), PINNED_WINDOW); - b.share_pinned("test", db.clone(), health.clone(), PINNED_WINDOW); - (a, b, health) + a.share_pinned("test", db.clone(), PINNED_WINDOW); + b.share_pinned("test", db.clone(), PINNED_WINDOW); + (a, b) } /// How many of `tries` requests a limiter admits for `user`. @@ -455,8 +467,8 @@ fn admits(limiter: &UserRateLimiter, user: &str, tries: usize) -> usize { #[tokio::test] async fn a_restarted_process_inherits_the_windows_spend() { - let db = shared_db().await; - let (a, b, _health) = two_processes(6, &db); + let (_tenants, db) = shared_db().await; + let (a, b) = two_processes(6, &db); // Each spends freely until its first sync — the accepted one-interval // overshoot, and the whole reason the shared row exists at all. @@ -473,17 +485,14 @@ async fn a_restarted_process_inherits_the_windows_spend() { ); // And the shared row agrees with what was actually admitted. - let mut rows = db - .query("SELECT VALUE hits FROM rate_limit") - .await - .expect("read shared counters"); - assert_eq!(rows.take::>(0).unwrap(), vec![spent as i64]); + let rows = read_shared_hits(&db).await; + assert_eq!(rows, vec![spent as i64]); } #[tokio::test] async fn a_process_that_never_admitted_still_learns_the_budget_is_gone() { - let db = shared_db().await; - let (a, b, _health) = two_processes(4, &db); + let (_tenants, db) = shared_db().await; + let (a, b) = two_processes(4, &db); // b spends one request, so it has a bucket to sync; a spends the rest. assert_eq!(admits(&b, "user:a", 1), 1); @@ -501,9 +510,18 @@ async fn a_process_that_never_admitted_still_learns_the_budget_is_gone() { #[tokio::test] async fn a_down_database_leaves_each_process_on_its_local_budget() { - let db = shared_db().await; - let (a, b, health) = two_processes(3, &db); - health.set(false); + let (_tenants, db) = shared_db().await; + let (a, b) = two_processes(3, &db); + + // The shared store goes down: the fold's table is taken away — the one + // statement a round needs fails outright — and comes back without either + // limiter being restarted. + tokio::time::resume(); + sqlx::query("ALTER TABLE rate_limit RENAME TO rate_limit_out") + .execute(&db) + .await + .expect("take the shared table away"); + tokio::time::pause(); // Nothing is shared while the database is down — and nothing stalls: both // limiters keep serving their own budgets at full speed. @@ -515,28 +533,28 @@ async fn a_down_database_leaves_each_process_on_its_local_budget() { assert_eq!(admits(&a, "user:a", 1), 0, "the local budget still binds"); assert_eq!(admits(&b, "user:a", 1), 0); - // Nothing was written, so the row the sync would have made does not exist. - let mut rows = db - .query("SELECT VALUE hits FROM rate_limit") + // The table comes back before the read, so the assertion reads the state + // the outage left: no round landed, so there is no row at all — and the + // unreported deltas are still sitting in the buckets. + tokio::time::resume(); + sqlx::query("ALTER TABLE rate_limit_out RENAME TO rate_limit") + .execute(&db) .await - .expect("read shared counters"); - assert_eq!(rows.take::>(0).unwrap(), Vec::::new()); + .expect("give the shared table back"); + tokio::time::pause(); + let rows = read_shared_hits(&db).await; + assert_eq!(rows, Vec::::new()); - // Recovery needs no restart: the next round shares again. - health.set(true); + // Recovery needs no restart: the next round carries the deltas, and the + // shared row holds everything both processes admitted while it was down. sync_round().await; - let mut rows = db - .query("SELECT VALUE hits FROM rate_limit") - .await - .expect("read shared counters"); - assert_eq!(rows.take::>(0).unwrap(), vec![6]); + let rows = read_shared_hits(&db).await; + assert_eq!(rows, vec![6]); } /// Boot the app on a real TCP port, `ConnectInfo` wired exactly like `main`. async fn spawn_server(rate_limit: RateLimitConfig) -> String { - let tenants = database::init_mem_tenants() - .await - .expect("in-memory deployment"); + let tenants = database::init_test_tenants().await; let app = build_router(AppState { db: tenants.control().clone(), tenants, @@ -546,7 +564,6 @@ async fn spawn_server(rate_limit: RateLimitConfig) -> String { chatbot_limit: Default::default(), exam_presence: Default::default(), board_hub: Default::default(), - db_up: Default::default(), ai: None, metrics: hezarfen_backend::telemetry::Metrics::noop(), });