Page probe: an ignored test that serves the real router over a scripted model for a browser

This commit is contained in:
Meta Vens 2026-12-02 21:03:43 +01:00
commit c3e9e2956e

View file

@ -1685,4 +1685,62 @@ mod tests {
}
assert_eq!(files, vec!["runtime.rs".to_owned()]);
}
/// A probe for the page, not part of the suite: serves the real router over
/// a scripted model so a browser can be pointed at it. `GHOSTLIGHT_PROBE_PORT`
/// names the loopback port, `GHOSTLIGHT_PROBE_SECONDS` how long it serves,
/// and `GHOSTLIGHT_PROBE_MODE=seeding` leaves a vault Begin seeding for good.
/// `/probe/login` sets alice's session cookie, standing in for Heimdall.
#[tokio::test(flavor = "multi_thread")]
#[ignore]
async fn serve_the_page_for_a_browser_probe() {
struct NoVaults;
impl crate::begin::Vaults for NoVaults {
fn names(&self) -> Vec<String> {
vec![]
}
fn open(&self, _: &str) -> anyhow::Result<crate::begin::VaultSeed> {
anyhow::bail!("no vault")
}
fn evidence(&self, _: &str) -> anyhow::Result<Arc<dyn ghostlight::EvidenceSource>> {
anyhow::bail!("no vault")
}
}
let seeding = std::env::var("GHOSTLIGHT_PROBE_MODE").as_deref() == Ok("seeding");
let port: u16 = std::env::var("GHOSTLIGHT_PROBE_PORT").unwrap().parse().unwrap();
let seconds: u64 = std::env::var("GHOSTLIGHT_PROBE_SECONDS").map_or(1200, |value| value.parse().unwrap());
let narration = "The ash on the road is warm underfoot, and the gate ahead stands open as if it had been waiting. \
Smoke leans from the chimneys of the low town beyond it. A woman at the toll hut watches you without pretending not to.\n\n\
\"You are late,\" she says, and does not say for what. Behind her a child counts coins into a tin, loudly, so you will hear.";
let script = vec![
output("r0", vec![call_event("c0", END_TURN_TOOL, json!({}))]),
output("proj-0", vec![text_event(narration)]),
output("r1", vec![call_event("c1", ASK_PLAYER_TOOL, json!({"question": "Which way do you take?"}))]),
output("r2", vec![call_event("c2", END_TURN_TOOL, json!({}))]),
output("proj-1", vec![text_event("You take the lower road, and the dogs do not bark.")]),
];
let mut app = if seeding { app_over(deferred_rig(), &["alice"]).await } else { app(script, &["alice"]).await };
if !seeding {
app.state.vaults = Arc::new(NoVaults);
}
let cookie = app.cookies[0].clone();
let router = service_router(app.state.clone()).route(
"/probe/login",
axum::routing::get(move || {
let cookie = cookie.clone();
async move {
(
StatusCode::SEE_OTHER,
[
(header::LOCATION, "/".to_owned()),
(header::SET_COOKIE, format!("{COOKIE_NAME}={cookie}; Path=/; HttpOnly; SameSite=Lax")),
],
)
}
}),
);
let listener = tokio::net::TcpListener::bind(("127.0.0.1", port)).await.unwrap();
let serve = axum::serve(listener, router.into_make_service_with_connect_info::<std::net::SocketAddr>());
let _ = tokio::time::timeout(Duration::from_secs(seconds), serve).await;
}
}