refactor(server): plumb Arc<Settings> through workers and routes
Config sheds its 14 Bucket-B fields (retention, whisper, ollama, llm) and gains a sibling Arc<Settings> in AppState, loaded from settings.toml at startup via Settings::load_or_default. Workers (transcribe, analyze, recovery, auto_trigger) and routes (health, bulk, case_actions, user_web) take settings as a separate parameter or State<> extractor; Config::llm_configured moves to Settings::llm_configured. TestConfig::build_pair() returns (Arc<Config>, Arc<Settings>); the new create_router_with_settings / create_router_and_session_store_with_settings helpers wire both into integration tests that exercise LLM/Whisper/Ollama. The legacy single-Arc create_router falls back to Settings::default() so the 17 non-LLM tests stay untouched. Verified: cargo build clean, clippy --all-targets clean, 318 tests pass.
This commit is contained in:
@@ -23,27 +23,32 @@ use common::{
|
||||
// Fixture helpers
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
fn cfg_llm(label: &'static str) -> std::sync::Arc<doctate_server::config::Config> {
|
||||
type CfgPair = (
|
||||
std::sync::Arc<doctate_server::config::Config>,
|
||||
std::sync::Arc<doctate_server::settings::Settings>,
|
||||
);
|
||||
|
||||
fn cfg_llm(label: &'static str) -> CfgPair {
|
||||
TestConfig::new()
|
||||
.with_label(label)
|
||||
.with_user(test_user("dr_a"))
|
||||
.with_llm("http://unused")
|
||||
.build()
|
||||
.build_pair()
|
||||
}
|
||||
|
||||
fn cfg_llm_admin(label: &'static str) -> std::sync::Arc<doctate_server::config::Config> {
|
||||
fn cfg_llm_admin(label: &'static str) -> CfgPair {
|
||||
TestConfig::new()
|
||||
.with_label(label)
|
||||
.with_user(test_admin("dr_a"))
|
||||
.with_llm("http://unused")
|
||||
.build()
|
||||
.build_pair()
|
||||
}
|
||||
|
||||
fn cfg_without_llm(label: &'static str) -> std::sync::Arc<doctate_server::config::Config> {
|
||||
fn cfg_without_llm(label: &'static str) -> CfgPair {
|
||||
TestConfig::new()
|
||||
.with_label(label)
|
||||
.with_user(test_user("dr_a"))
|
||||
.build()
|
||||
.build_pair()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -52,8 +57,8 @@ fn cfg_without_llm(label: &'static str) -> std::sync::Arc<doctate_server::config
|
||||
|
||||
#[tokio::test]
|
||||
async fn analyze_without_cookie_redirects_to_login() {
|
||||
let cfg = cfg_llm("a");
|
||||
let app = doctate_server::create_router(cfg);
|
||||
let (cfg, settings) = cfg_llm("a");
|
||||
let app = doctate_server::create_router_with_settings(cfg, settings);
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let resp = app
|
||||
.oneshot(
|
||||
@@ -70,14 +75,14 @@ async fn analyze_without_cookie_redirects_to_login() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn analyze_foreign_case_returns_404() {
|
||||
let cfg = cfg_llm("b");
|
||||
let (cfg, settings) = cfg_llm("b");
|
||||
// Seed a case owned by someone else.
|
||||
let foreign_case = "22222222-2222-2222-2222-222222222222";
|
||||
let foreign_dir = cfg.data_path.join("dr_other").join(foreign_case);
|
||||
std::fs::create_dir_all(&foreign_dir).unwrap();
|
||||
seed_recording(&foreign_dir, "2026-04-15T10-00-00Z", Some("text"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let resp = app
|
||||
@@ -94,8 +99,8 @@ async fn analyze_foreign_case_returns_404() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn analyze_invalid_uuid_returns_400() {
|
||||
let cfg = cfg_llm("c");
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (cfg, settings) = cfg_llm("c");
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let resp = app
|
||||
@@ -112,12 +117,12 @@ async fn analyze_invalid_uuid_returns_400() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn analyze_case_without_recordings_returns_400() {
|
||||
let cfg = cfg_llm("d");
|
||||
let (cfg, settings) = cfg_llm("d");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
// No .m4a files.
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let resp = app
|
||||
@@ -134,13 +139,13 @@ async fn analyze_case_without_recordings_returns_400() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn analyze_case_with_missing_transcript_returns_400() {
|
||||
let cfg = cfg_llm("e");
|
||||
let (cfg, settings) = cfg_llm("e");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("ok"));
|
||||
seed_recording(&case_dir, "2026-04-15T10-05-00Z", None); // still transcribing
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let resp = app
|
||||
@@ -157,12 +162,12 @@ async fn analyze_case_with_missing_transcript_returns_400() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn analyze_case_without_llm_returns_503() {
|
||||
let cfg = cfg_without_llm("f");
|
||||
let (cfg, settings) = cfg_without_llm("f");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("ok"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let resp = app
|
||||
@@ -183,7 +188,7 @@ async fn analyze_case_without_llm_returns_503() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn analyze_case_happy_path_writes_input_and_redirects() {
|
||||
let cfg = cfg_llm("g");
|
||||
let (cfg, settings) = cfg_llm("g");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(
|
||||
@@ -197,7 +202,7 @@ async fn analyze_case_happy_path_writes_input_and_redirects() {
|
||||
Some("Korrektur: links, nicht rechts."),
|
||||
);
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let resp = app
|
||||
@@ -234,12 +239,12 @@ async fn analyze_case_happy_path_writes_input_and_redirects() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn analyze_case_second_time_returns_409() {
|
||||
let cfg = cfg_llm("h");
|
||||
let (cfg, settings) = cfg_llm("h");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("text"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let first = app
|
||||
@@ -268,14 +273,14 @@ async fn analyze_case_second_time_returns_409() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn analyze_case_skips_blank_transcript_from_recordings() {
|
||||
let cfg = cfg_llm("i");
|
||||
let (cfg, settings) = cfg_llm("i");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("echt"));
|
||||
seed_recording(&case_dir, "2026-04-15T10-05-00Z", Some(" ")); // blank
|
||||
seed_recording(&case_dir, "2026-04-15T10-10-00Z", Some("auch echt"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let resp = app
|
||||
@@ -328,12 +333,12 @@ async fn analyze_worker_writes_document_via_wiremock() {
|
||||
.mount(&mock)
|
||||
.await;
|
||||
|
||||
let cfg = TestConfig::new()
|
||||
let (_cfg, settings) = TestConfig::new()
|
||||
.with_label("analyze-w")
|
||||
.with_data_path(tmp.clone())
|
||||
.with_user(test_user("dr_a"))
|
||||
.with_llm(mock.uri())
|
||||
.build();
|
||||
.build_pair();
|
||||
|
||||
let (tx, rx) = analyze::channel();
|
||||
let client = reqwest::Client::new();
|
||||
@@ -341,7 +346,7 @@ async fn analyze_worker_writes_document_via_wiremock() {
|
||||
let vocab = Arc::new(doctate_server::gazetteer::Gazetteer::empty());
|
||||
let handle = tokio::spawn(analyze::worker::run(
|
||||
rx,
|
||||
cfg,
|
||||
settings,
|
||||
client,
|
||||
busy,
|
||||
vocab,
|
||||
@@ -420,19 +425,19 @@ async fn analyze_worker_normalizes_llm_output() {
|
||||
.mount(&mock)
|
||||
.await;
|
||||
|
||||
let cfg = TestConfig::new()
|
||||
let (_cfg, settings) = TestConfig::new()
|
||||
.with_label("analyze-gaz")
|
||||
.with_data_path(tmp.clone())
|
||||
.with_user(test_user("dr_a"))
|
||||
.with_llm(mock.uri())
|
||||
.build();
|
||||
.build_pair();
|
||||
|
||||
let (tx, rx) = analyze::channel();
|
||||
let client = reqwest::Client::new();
|
||||
let busy = Arc::new(std::sync::atomic::AtomicBool::new(false));
|
||||
let handle = tokio::spawn(analyze::worker::run(
|
||||
rx,
|
||||
cfg,
|
||||
settings,
|
||||
client,
|
||||
busy,
|
||||
vocab,
|
||||
@@ -553,14 +558,14 @@ async fn recovery_skips_completed_analysis() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn analyze_deletes_old_document_and_writes_fresh_input() {
|
||||
let cfg = cfg_llm("rn-5");
|
||||
let (cfg, settings) = cfg_llm("rn-5");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
std::fs::write(case_dir.join(DOCUMENT_FILE), "altes Dokument").unwrap();
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("erste Aufnahme"));
|
||||
seed_recording(&case_dir, "2026-04-15T10-05-00Z", Some("zweite Aufnahme"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let resp = app
|
||||
@@ -591,12 +596,12 @@ async fn analyze_deletes_old_document_and_writes_fresh_input() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn close_writes_marker_and_hides_case() {
|
||||
let cfg = cfg_llm("close-1");
|
||||
let (cfg, settings) = cfg_llm("close-1");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("ok"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let resp = app
|
||||
@@ -629,12 +634,12 @@ async fn close_writes_marker_and_hides_case() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn closed_case_returns_404_on_detail() {
|
||||
let cfg = cfg_llm("close-2");
|
||||
let (cfg, settings) = cfg_llm("close-2");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("ok"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let resp = app
|
||||
@@ -658,12 +663,12 @@ async fn closed_case_returns_404_on_detail() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn reopen_removes_marker_and_restores_case() {
|
||||
let cfg = cfg_llm("reopen-1");
|
||||
let (cfg, settings) = cfg_llm("reopen-1");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("ok"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
// Close, then reopen via the explicit endpoint.
|
||||
@@ -705,12 +710,12 @@ async fn reopen_removes_marker_and_restores_case() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn show_closed_query_includes_closed_cases() {
|
||||
let cfg = cfg_llm("show-closed");
|
||||
let (cfg, settings) = cfg_llm("show-closed");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("a closed one"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
// Close first.
|
||||
@@ -761,12 +766,12 @@ async fn show_closed_query_includes_closed_cases() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn closed_case_detail_with_show_closed_returns_200() {
|
||||
let cfg = cfg_llm("show-detail");
|
||||
let (cfg, settings) = cfg_llm("show-detail");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("x"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let _ = app
|
||||
@@ -804,12 +809,12 @@ async fn closed_case_detail_with_show_closed_returns_200() {
|
||||
async fn close_redirects_back_to_referer_query() {
|
||||
// Close from the show-closed listing must keep ?show_closed=1 so
|
||||
// the user stays in the view they were in.
|
||||
let cfg = cfg_llm("close-ref-q");
|
||||
let (cfg, settings) = cfg_llm("close-ref-q");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("ok"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let mut req = csrf_form_post(paths::case_close(case_id), &cookie, &csrf, "");
|
||||
@@ -833,12 +838,12 @@ async fn close_from_detail_redirects_to_list_preserving_query() {
|
||||
// Close from /web/cases/{uuid}?show_closed=1 must NOT redirect back
|
||||
// to the detail page (it 404s after the close). The uuid segment
|
||||
// is stripped; the query survives so the user lands in show-closed.
|
||||
let cfg = cfg_llm("close-ref-det");
|
||||
let (cfg, settings) = cfg_llm("close-ref-det");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("ok"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let mut req = csrf_form_post(paths::case_close(case_id), &cookie, &csrf, "");
|
||||
@@ -866,12 +871,12 @@ async fn reopen_redirects_back_to_referer() {
|
||||
// User reopens a case from the show-closed listing. The redirect
|
||||
// must preserve `?show_closed=1` so the user stays in that view
|
||||
// instead of being ejected back to the default open-only listing.
|
||||
let cfg = cfg_llm("reopen-ref");
|
||||
let (cfg, settings) = cfg_llm("reopen-ref");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("ok"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let _ = app
|
||||
@@ -903,12 +908,12 @@ async fn reopen_redirects_back_to_referer() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn reopen_is_noop_on_open_case() {
|
||||
let cfg = cfg_llm("reopen-2");
|
||||
let (cfg, settings) = cfg_llm("reopen-2");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("ok"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let resp = app
|
||||
@@ -927,12 +932,12 @@ async fn reopen_is_noop_on_open_case() {
|
||||
#[tokio::test]
|
||||
async fn purge_closed_removes_directory() {
|
||||
// purge-closed is admin-only (matches the UI, which hides the bar).
|
||||
let cfg = cfg_llm_admin("purge-1");
|
||||
let (cfg, settings) = cfg_llm_admin("purge-1");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("ok"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let _ = app
|
||||
@@ -965,12 +970,12 @@ async fn purge_closed_removes_directory() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn purge_requires_confirm_param() {
|
||||
let cfg = cfg_llm_admin("purge-2");
|
||||
let (cfg, settings) = cfg_llm_admin("purge-2");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("ok"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let _ = app
|
||||
@@ -998,7 +1003,7 @@ async fn purge_requires_confirm_param() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn purge_closed_keeps_open_cases() {
|
||||
let cfg = cfg_llm_admin("purge-3");
|
||||
let (cfg, settings) = cfg_llm_admin("purge-3");
|
||||
let closed_id = "11111111-1111-1111-1111-111111111111";
|
||||
let open_id = "22222222-2222-2222-2222-222222222222";
|
||||
let dir_closed = seed_case(&cfg.data_path, "dr_a", closed_id);
|
||||
@@ -1006,7 +1011,7 @@ async fn purge_closed_keeps_open_cases() {
|
||||
seed_recording(&dir_closed, "2026-04-15T10-00-00Z", Some("a"));
|
||||
seed_recording(&dir_open, "2026-04-15T10-00-00Z", Some("b"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let _ = app
|
||||
@@ -1040,12 +1045,12 @@ async fn purge_closed_keeps_open_cases() {
|
||||
#[tokio::test]
|
||||
async fn purge_closed_rejected_for_non_admin() {
|
||||
// Default `test_user` is role=doctor.
|
||||
let cfg = cfg_llm("purge-nonadmin");
|
||||
let (cfg, settings) = cfg_llm("purge-nonadmin");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "2026-04-15T10-00-00Z", Some("ok"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
// Close the case first so there is something for purge to target.
|
||||
@@ -1077,7 +1082,7 @@ async fn purge_closed_rejected_for_non_admin() {
|
||||
async fn bulk_close_shares_one_closed_at_timestamp() {
|
||||
// Bulk actions are admin-only since the UI hides the selection
|
||||
// from non-admins; the handler enforces the same gate.
|
||||
let cfg = cfg_llm_admin("bulk-c");
|
||||
let (cfg, settings) = cfg_llm_admin("bulk-c");
|
||||
let case_a = "11111111-1111-1111-1111-111111111111";
|
||||
let case_b = "22222222-2222-2222-2222-222222222222";
|
||||
let dir_a = seed_case(&cfg.data_path, "dr_a", case_a);
|
||||
@@ -1085,7 +1090,7 @@ async fn bulk_close_shares_one_closed_at_timestamp() {
|
||||
seed_recording(&dir_a, "2026-04-15T10-00-00Z", Some("a"));
|
||||
seed_recording(&dir_b, "2026-04-15T10-05-00Z", Some("b"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let body = format!(
|
||||
@@ -1111,7 +1116,7 @@ async fn bulk_close_shares_one_closed_at_timestamp() {
|
||||
#[tokio::test]
|
||||
async fn bulk_analyze_processes_each_selected_case() {
|
||||
// Bulk analyze is admin-only (UI + handler).
|
||||
let cfg = cfg_llm_admin("bulk-a");
|
||||
let (cfg, settings) = cfg_llm_admin("bulk-a");
|
||||
let case_a = "11111111-1111-1111-1111-111111111111";
|
||||
let case_b = "22222222-2222-2222-2222-222222222222";
|
||||
let dir_a = seed_case(&cfg.data_path, "dr_a", case_a);
|
||||
@@ -1119,7 +1124,7 @@ async fn bulk_analyze_processes_each_selected_case() {
|
||||
seed_recording(&dir_a, "2026-04-15T10-00-00Z", Some("a"));
|
||||
seed_recording(&dir_b, "2026-04-15T10-05-00Z", Some("b"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let body = format!(
|
||||
@@ -1160,7 +1165,7 @@ async fn recovery_skips_closed_cases() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn reset_case_clears_derived_and_unfails_audio() {
|
||||
let cfg = cfg_llm_admin("reset-admin");
|
||||
let (cfg, settings) = cfg_llm_admin("reset-admin");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
|
||||
@@ -1177,7 +1182,7 @@ async fn reset_case_clears_derived_and_unfails_audio() {
|
||||
std::fs::write(dir.join(DOCUMENT_FILE), "# Doc\n").unwrap();
|
||||
std::fs::write(dir.join(ANALYSIS_INPUT_FILE), "{}").unwrap();
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let resp = app
|
||||
@@ -1209,13 +1214,13 @@ async fn reset_case_clears_derived_and_unfails_audio() {
|
||||
#[tokio::test]
|
||||
async fn reset_case_requires_admin() {
|
||||
// Default `test_user` has role=doctor, not admin.
|
||||
let cfg = cfg_llm("reset-nonadmin");
|
||||
let (cfg, settings) = cfg_llm("reset-nonadmin");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&dir, "2026-04-15T09-00-00Z", Some("hallo"));
|
||||
std::fs::write(dir.join(DOCUMENT_FILE), "# Doc\n").unwrap();
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let resp = app
|
||||
@@ -1236,12 +1241,12 @@ async fn reset_case_requires_admin() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn bulk_reset_processes_multiple_cases_admin_only() {
|
||||
let cfg = TestConfig::new()
|
||||
let (cfg, settings) = TestConfig::new()
|
||||
.with_label("bulk-reset")
|
||||
.with_user(test_admin("dr_a"))
|
||||
.with_user(test_user("dr_b"))
|
||||
.with_llm("http://unused")
|
||||
.build();
|
||||
.build_pair();
|
||||
let case_a = "11111111-1111-1111-1111-111111111111";
|
||||
let case_b = "22222222-2222-2222-2222-222222222222";
|
||||
let dir_a = seed_case(&cfg.data_path, "dr_a", case_a);
|
||||
@@ -1256,7 +1261,7 @@ async fn bulk_reset_processes_multiple_cases_admin_only() {
|
||||
seed_recording(&dir_c, "2026-04-15T11-00-00Z", Some("c"));
|
||||
std::fs::write(dir_c.join(DOCUMENT_FILE), "C").unwrap();
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
|
||||
// Admin: bulk reset succeeds.
|
||||
let (cookie_admin, csrf_admin) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
@@ -1304,12 +1309,12 @@ async fn bulk_reset_processes_multiple_cases_admin_only() {
|
||||
#[tokio::test]
|
||||
async fn bulk_close_rejected_for_non_admin() {
|
||||
// Default `test_user` is role=doctor.
|
||||
let cfg = cfg_llm("bulk-close-nonadmin");
|
||||
let (cfg, settings) = cfg_llm("bulk-close-nonadmin");
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let dir = seed_case(&cfg.data_path, "dr_a", case_id);
|
||||
seed_recording(&dir, "2026-04-15T10-00-00Z", Some("a"));
|
||||
|
||||
let (app, store) = doctate_server::create_router_and_session_store(cfg);
|
||||
let (app, store) = doctate_server::create_router_and_session_store_with_settings(cfg, settings);
|
||||
let (cookie, csrf) = login_with_csrf(&app, &store, "dr_a", "s").await;
|
||||
|
||||
let body = format!("action={}&case_id={case_id}", BulkAction::Close);
|
||||
@@ -1370,12 +1375,12 @@ async fn analyze_works_against_ollama_style_endpoint_without_api_key() {
|
||||
// Ollama-style config: explicitly empty api_key — `with_llm_explicit`
|
||||
// lets the builder carry "" through, whereas `with_llm` would default
|
||||
// to the hosted-provider test key.
|
||||
let cfg = TestConfig::new()
|
||||
let (_cfg, settings) = TestConfig::new()
|
||||
.with_label("analyze-ollama")
|
||||
.with_data_path(tmp.clone())
|
||||
.with_user(test_user("dr_a"))
|
||||
.with_llm_explicit(mock.uri(), "", "llama3.3:70b")
|
||||
.build();
|
||||
.build_pair();
|
||||
|
||||
let (tx, rx) = analyze::channel();
|
||||
let client = reqwest::Client::new();
|
||||
@@ -1383,7 +1388,7 @@ async fn analyze_works_against_ollama_style_endpoint_without_api_key() {
|
||||
let vocab = Arc::new(doctate_server::gazetteer::Gazetteer::empty());
|
||||
let handle = tokio::spawn(analyze::worker::run(
|
||||
rx,
|
||||
cfg,
|
||||
settings,
|
||||
client,
|
||||
busy,
|
||||
vocab,
|
||||
|
||||
Reference in New Issue
Block a user