From d3e4c3e82c10ac38eef9711ab8e82633432fc2b4 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 20:18:19 +0100 Subject: [PATCH] Seeded Begin tests: one deferred app per api outcome, the brief outranks the premise Co-Authored-By: Claude Sonnet 5.5 --- crates/ghostlight-dungeon/src/api.rs | 70 +++++++++++++++----------- crates/ghostlight-dungeon/src/begin.rs | 18 ++++++- 2 files changed, 57 insertions(+), 31 deletions(-) diff --git a/crates/ghostlight-dungeon/src/api.rs b/crates/ghostlight-dungeon/src/api.rs index 3851581..96786e2 100644 --- a/crates/ghostlight-dungeon/src/api.rs +++ b/crates/ghostlight-dungeon/src/api.rs @@ -980,46 +980,56 @@ mod tests { assert_eq!(status, StatusCode::UNAUTHORIZED); } - /// Spec test: POST /api/begin on a vault returns the timeline before the - /// seed has finished; the timeline list reads Seeding, then Ready; and a - /// failed seed reads Failed with a reason that names no endpoint. - #[tokio::test] - async fn a_vault_begin_returns_at_once_and_the_timeline_reads_seeding_then_ready_or_failed() { - let app = app_over(deferred_rig(), &["alice"]).await; - let cookie = app.cookies[0].clone(); - let begin = |key: Uuid| json!({"key": key, "title": "Ashfall", "name": "Deru", "vault": "delvehold"}); - let status_of = async |timeline: &str| { - let (status, _, body) = call(&app, Method::GET, "/api/timelines", Some(&cookie), None).await; - assert_eq!(status, StatusCode::OK); - body["timelines"] - .as_array() - .unwrap() - .iter() - .find(|row| row["timeline"] == timeline) - .map(|row| (row["status"].as_str().unwrap().to_owned(), row["reason"].clone())) - }; + async fn timeline_status(app: &App, cookie: &str, timeline: &str) -> Option<(String, Value)> { + let (status, _, body) = call(app, Method::GET, "/api/timelines", Some(cookie), None).await; + assert_eq!(status, StatusCode::OK); + body["timelines"] + .as_array() + .unwrap() + .iter() + .find(|row| row["timeline"] == timeline) + .map(|row| (row["status"].as_str().unwrap().to_owned(), row["reason"].clone())) + } - let (code, _, body) = call(&app, Method::POST, "/api/begin", Some(&cookie), Some(begin(Uuid::new_v4()))).await; + async fn begin_vault_over_http(app: &App, cookie: &str) -> String { + let body = json!({"key": Uuid::new_v4(), "title": "Ashfall", "name": "Deru", "vault": "delvehold"}); + let (code, _, body) = call(app, Method::POST, "/api/begin", Some(cookie), Some(body)).await; assert_eq!(code, StatusCode::OK, "{body}"); assert_eq!(body["reached"], "seeding"); - let timeline = body["timeline"].as_str().unwrap().to_owned(); - assert_eq!(status_of(&timeline).await.unwrap().0, "seeding"); + body["timeline"].as_str().unwrap().to_owned() + } + + /// Spec test: POST /api/begin on a vault returns the timeline before the + /// seed has finished, and the timeline list reads Seeding, then Ready. + #[tokio::test] + async fn a_vault_begin_returns_at_once_and_the_timeline_reads_seeding_then_ready() { + let app = app_over(deferred_rig(), &["alice"]).await; + let cookie = app.cookies[0].clone(); + let timeline = begin_vault_over_http(&app, &cookie).await; + assert_eq!(timeline_status(&app, &cookie, &timeline).await.unwrap().0, "seeding"); let host = app.state.timelines.host(&timeline).await.unwrap(); let draft = host.world.snapshot().await.unwrap(); app.rig.port.push(Ok(author("seed-1", &draft, &["a", "b"]))); app.rig.port.push(Ok(author("seed-2", &draft, &["c", "d"]))); - eventually(async || (status_of(&timeline).await.unwrap().0 == "ready").then_some(())).await; - - let (code, _, body) = call(&app, Method::POST, "/api/begin", Some(&cookie), Some(begin(Uuid::new_v4()))).await; - assert_eq!(code, StatusCode::OK, "{body}"); - let failing = body["timeline"].as_str().unwrap().to_owned(); - app.rig.port.push(Err("http://10.0.0.7:9/secret endpoint down")); - let (state, reason) = eventually(async || { - status_of(&failing).await.filter(|(state, _)| state == "failed") + eventually(async || { + (timeline_status(&app, &cookie, &timeline).await.unwrap().0 == "ready").then_some(()) + }) + .await; + } + + /// Spec test: a scripted seed fault reads Failed with a reason and no + /// endpoint text. + #[tokio::test] + async fn a_failed_seed_reads_failed_with_a_reason_and_no_endpoint() { + let app = app_over(deferred_rig(), &["alice"]).await; + let cookie = app.cookies[0].clone(); + let timeline = begin_vault_over_http(&app, &cookie).await; + app.rig.port.push(Err("http://10.0.0.7:9/secret endpoint down")); + let (_, reason) = eventually(async || { + timeline_status(&app, &cookie, &timeline).await.filter(|(state, _)| state == "failed") }) .await; - assert_eq!(state, "failed"); let reason = reason.as_str().unwrap(); assert!(reason.contains("seed") && !reason.contains("10.0.0.7"), "{reason}"); } diff --git a/crates/ghostlight-dungeon/src/begin.rs b/crates/ghostlight-dungeon/src/begin.rs index af10664..9333572 100644 --- a/crates/ghostlight-dungeon/src/begin.rs +++ b/crates/ghostlight-dungeon/src/begin.rs @@ -663,7 +663,8 @@ pub(crate) mod tests { } async fn begin_vault(rig: &Rig, key: Uuid) -> Begun { - begin(&rig.catalog, &rig.timelines, &OneVault::new(), &rig.seeding, &principal("alice"), request(key, Some("delvehold"))) + let request = BeginRequest { brief: None, ..request(key, Some("delvehold")) }; + begin(&rig.catalog, &rig.timelines, &OneVault::new(), &rig.seeding, &principal("alice"), request) .await .unwrap() } @@ -759,6 +760,21 @@ pub(crate) mod tests { assert_eq!(rig.seeding.status(&begun.timeline), Some(SeedStatus::Seeding)); } + /// The owner's brief is the seed's brief; the vault's premise is only what + /// stands in when there is none. + #[tokio::test] + async fn the_owners_brief_outranks_the_vaults_premise() { + let rig = deferred_rig(); + let begun = begin(&rig.catalog, &rig.timelines, &OneVault::new(), &rig.seeding, &principal("alice"), request(Uuid::new_v4(), Some("delvehold"))) + .await + .unwrap(); + assert_eq!(begun.reached, "seeding"); + let seen = eventually(async || rig.port.seen_requests().into_iter().next()).await; + let prompt = prompt_text(&seen); + assert!(prompt.contains("A cold harbor town."), "the owner's brief"); + assert!(!prompt.contains("A cold harbor, from the vault."), "not the premise"); + } + #[tokio::test] async fn begin_without_a_profile_activates_unseeded_and_asks_no_model() { let rig = rig(vec![]);