use std::future::Future;
pub(super) const STACK_BUDGET_BYTES: usize = 2 * 1024 * 1024;
pub(super) fn model_spec(
model: impl Into<String>,
variant: Option<String>,
context_window_tokens: usize,
) -> lash_core::ModelSpec {
lash_core::ModelSpec::from_token_limits(model, variant, context_window_tokens, None)
.expect("valid model spec")
}
pub(super) fn mock_model_spec() -> lash_core::ModelSpec {
model_spec("mock-model", None, 200_000)
}
pub(super) fn run_async_test_on_stack_budget<F, Fut, T>(name: &str, test: F) -> T
where
F: FnOnce() -> Fut + Send + 'static,
Fut: Future<Output = T> + 'static,
T: Send + 'static,
{
std::thread::Builder::new()
.name(name.to_string())
.stack_size(STACK_BUDGET_BYTES)
.spawn(|| {
let test = Box::pin(test());
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("tokio runtime")
.block_on(test)
})
.expect("spawn stack-budget test thread")
.join()
.expect("stack-budget test thread")
}