Refactor config to use test_default
Introduced a `test_default` method to `Config` to provide sane defaults for integration tests. This refactors several test files to use this new method, reducing boilerplate and improving maintainability. Added `LLM_TIMEOUT_SECONDS` to the environment variables and `Config` struct.
This commit is contained in:
@@ -52,6 +52,7 @@ pub struct Config {
|
||||
pub llm_api_key: String,
|
||||
pub llm_model: String,
|
||||
pub llm_temperature: f32,
|
||||
pub llm_timeout_seconds: u64,
|
||||
pub session_timeout_hours: u32,
|
||||
/// Whether to set the `Secure` flag on the session cookie. Default `true`.
|
||||
/// Set `COOKIE_SECURE=false` only for plain-HTTP local development —
|
||||
@@ -85,10 +86,59 @@ impl Config {
|
||||
llm_api_key: optional_env("LLM_API_KEY", ""),
|
||||
llm_model: optional_env("LLM_MODEL", ""),
|
||||
llm_temperature: optional_env_parsed("LLM_TEMPERATURE", 0.0),
|
||||
llm_timeout_seconds: optional_env_parsed("LLM_TIMEOUT_SECONDS", 180),
|
||||
session_timeout_hours: optional_env_parsed("SESSION_TIMEOUT_HOURS", 8),
|
||||
cookie_secure: optional_env_parsed("COOKIE_SECURE", true),
|
||||
}
|
||||
}
|
||||
|
||||
/// True iff all three required fields for the external analysis LLM are
|
||||
/// non-empty. Used to gate the "Fall abschließen" UI and handler — if
|
||||
/// no LLM is configured, the close action must not be reachable.
|
||||
pub fn llm_configured(&self) -> bool {
|
||||
!self.llm_url.is_empty() && !self.llm_api_key.is_empty() && !self.llm_model.is_empty()
|
||||
}
|
||||
|
||||
/// Sane defaults for integration tests. Not a `Default` impl on purpose:
|
||||
/// production code must go through `from_env()`, and `Default::default()`
|
||||
/// carries an implicit "safe fallback" connotation this value does not
|
||||
/// satisfy (empty users, `/tmp` paths). Override fields via
|
||||
/// struct-update syntax:
|
||||
///
|
||||
/// ```ignore
|
||||
/// let cfg = Config {
|
||||
/// data_path: tmp_dir,
|
||||
/// users: vec![my_user],
|
||||
/// ..Config::test_default()
|
||||
/// };
|
||||
/// ```
|
||||
#[doc(hidden)]
|
||||
pub fn test_default() -> Self {
|
||||
Self {
|
||||
server_port: 3000,
|
||||
data_path: PathBuf::from("/tmp"),
|
||||
log_level: "info".into(),
|
||||
log_path: PathBuf::from("/tmp"),
|
||||
log_max_days: 90,
|
||||
users: Vec::new(),
|
||||
api_keys: HashMap::new(),
|
||||
retention_audio_days: 30,
|
||||
retention_transcript_days: 30,
|
||||
retention_document_days: 0,
|
||||
whisper_url: "http://localhost:10300".into(),
|
||||
whisper_timeout_seconds: 120,
|
||||
ollama_url: "http://localhost:11434".into(),
|
||||
ollama_model: "gemma3:4b".into(),
|
||||
ollama_keep_alive: 0,
|
||||
llm_url: String::new(),
|
||||
llm_api_key: String::new(),
|
||||
llm_model: String::new(),
|
||||
llm_temperature: 0.0,
|
||||
llm_timeout_seconds: 180,
|
||||
session_timeout_hours: 8,
|
||||
cookie_secure: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Load users from a TOML file and build the API key lookup map.
|
||||
|
||||
Reference in New Issue
Block a user