use std::sync::Mutex;
use cellos_core::ports::ExportSink;
use cellos_core::ExportReceiptTargetKind;
use cellos_export_http::HttpExportSink;
static ENV_LOCK: Mutex<()> = Mutex::new(());
fn lock() -> std::sync::MutexGuard<'static, ()> {
ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner())
}
#[test]
fn smoke_construct_https_sink_succeeds() {
let _g = lock();
std::env::remove_var("CELLOS_CA_BUNDLE");
let sink = HttpExportSink::new("https://example.invalid/upload", "smoke-cell", None, 1, 0)
.expect("smoke: https base URL must be accepted");
assert_eq!(sink.target_kind(), Some(ExportReceiptTargetKind::Http));
}
#[test]
fn smoke_destination_hint_expands_placeholders() {
let _g = lock();
std::env::remove_var("CELLOS_CA_BUNDLE");
let sink = HttpExportSink::new(
"https://example.invalid/{cell_id}/{artifact_name}",
"smoke-cell",
None,
1,
0,
)
.expect("construct sink");
let hint = sink.destination_hint("smoke.txt").expect("hint");
assert_eq!(hint, "https://example.invalid/smoke-cell/smoke.txt");
}
#[test]
fn smoke_from_env_errors_when_base_url_missing() {
let _g = lock();
std::env::remove_var("CELLOS_EXPORT_HTTP_BASE_URL");
std::env::remove_var("CELLOS_EXPORT_HTTP_BEARER_TOKEN");
let err = match HttpExportSink::from_env("smoke-cell") {
Ok(_) => panic!("smoke: from_env must error when base URL not set"),
Err(e) => e,
};
assert!(
err.to_string().contains("CELLOS_EXPORT_HTTP_BASE_URL"),
"expected env-var name in error, got: {err}"
);
}