mod defaults;
mod deployment;
mod env_types;
mod migrations;
mod sources;
mod validation;
use super::env_overrides::{parse_env_bool, parse_env_u32, split_csv};
use super::*;
use crate::config::types::{DeploymentCapabilities, DeploymentMode};
use std::env;
use std::ffi::OsString;
use std::sync::{Mutex, OnceLock};
pub(super) fn with_locked_env(test: impl FnOnce()) {
static ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
let _guard = ENV_LOCK
.get_or_init(|| Mutex::new(()))
.lock()
.expect("env lock poisoned");
test();
}
pub(super) fn valid_test_config() -> Config {
let mut config = Config::default();
config.business.product_name = "TestProduct".to_string();
config.business.product_keywords = vec!["test".to_string()];
config.business.product_description = "A test product".to_string();
config.business.industry_topics = vec!["testing".to_string()];
config.llm.provider = "ollama".to_string();
config.x_api.client_id = "test-id".to_string();
config
}
pub(super) struct ScopedEnvVar {
key: &'static str,
previous: Option<OsString>,
}
impl ScopedEnvVar {
pub fn set(key: &'static str, value: &str) -> Self {
let previous = env::var_os(key);
env::set_var(key, value);
Self { key, previous }
}
}
impl Drop for ScopedEnvVar {
fn drop(&mut self) {
match self.previous.take() {
Some(previous) => env::set_var(self.key, previous),
None => env::remove_var(self.key),
}
}
}