use std::path::PathBuf;
use std::time::Duration;
use cloud::reconciler::pond_publish::publish_to_pond;
use cloud::reconciler::s3_driver::{
up_s3_driver, S3DriverOptions, DEV_ACCESS_KEY, DEV_SECRET_KEY,
};
fn workspace_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.find(|d| d.join(".yah/services").is_dir())
.expect("monorepo root (an ancestor containing .yah/services)")
.to_path_buf()
}
#[tokio::test]
async fn dev_assets_are_served_through_the_s3_driver_endpoint() {
let Some(bin) = std::env::var_os("YAH_RECONCILER_E2E_BIN").map(PathBuf::from) else {
eprintln!("skipping: set YAH_RECONCILER_E2E_BIN to a built yah-s3-fs binary");
return;
};
assert!(bin.exists(), "YAH_RECONCILER_E2E_BIN={} not found", bin.display());
let repo = workspace_root();
let dist = repo.join("app/yah/web/marketing/dist");
assert!(
dist.join("html/index.html").exists(),
"expected a built marketing dist under {} — run its build first",
dist.display(),
);
let scratch = tempfile::tempdir().expect("scratch workspace");
let bucket = "yah-marketing";
let driver = up_s3_driver(
scratch.path(),
vec![bucket.to_string()],
&S3DriverOptions {
binary: Some(bin),
ready_timeout: Some(Duration::from_secs(30)),
},
)
.await
.expect("yah-s3-fs comes up");
let result = publish_and_probe(&driver.endpoint, bucket, &dist).await;
driver.teardown().await;
result.expect("dev publish + unsigned GET");
}
async fn publish_and_probe(
endpoint: &str,
bucket: &str,
dist: &std::path::Path,
) -> anyhow::Result<()> {
local_driver::pond_minio::ensure_bucket_public(
endpoint,
bucket,
DEV_ACCESS_KEY,
DEV_SECRET_KEY,
)
.await?;
let report =
publish_to_pond(dist, endpoint, bucket, DEV_ACCESS_KEY, DEV_SECRET_KEY, None).await?;
anyhow::ensure!(
report.uploaded.iter().any(|k| k == "index.html"),
"publish did not produce an index.html key: {:?}",
report.uploaded,
);
let url = format!("{}/{}/index.html", endpoint.trim_end_matches('/'), bucket);
let resp = reqwest::Client::new().get(&url).send().await?;
anyhow::ensure!(
resp.status().is_success(),
"unsigned GET {url} → {}",
resp.status(),
);
let content_type = resp
.headers()
.get(reqwest::header::CONTENT_TYPE)
.and_then(|v| v.to_str().ok())
.unwrap_or_default()
.to_string();
anyhow::ensure!(
content_type.starts_with("text/html"),
"served index.html as {content_type:?} — a browser downloads that instead of rendering it",
);
let body = resp.text().await?;
anyhow::ensure!(body.contains("<html"), "served body is not the built page");
Ok(())
}