use std::sync::Arc;
use uuid::Uuid;
use super::*;
use crate::shared::api::Embedder;
use crate::shared::api::mock::MockEmbedder;
use crate::shared::session_budget::{SessionBudget, Shape};
const GITHUB_REPO_JSON: &str = include_str!("../../../../../tests/fixtures/github-repo-rust.json");
const GITHUB_REPO_URL: &str = "https://api.github.com/repos/rust-lang/rust";
#[tokio::test]
#[ignore = "requires a running llama-server (MINDFORK_ENGINE_URL)"]
async fn summary_usage_e2e_live() {
let Some(client) =
crate::shared::api::live_client("MINDFORK_ENGINE_URL", "MINDFORK_ENGINE_KEY")
else {
eprintln!("skip: MINDFORK_ENGINE_URL not set");
return;
};
let embedder: Arc<dyn Embedder> = Arc::new(MockEmbedder::new(16));
let (_d, _storage, mut ctx) =
super::super::testkit::ctx_with_backends(Uuid::new_v4(), Arc::new(client), embedder);
let budget = Arc::new(SessionBudget::new(4, Some(16_384)));
ctx.sessions = Some(budget.clone());
let page = body_to_text("application/json", GITHUB_REPO_JSON).expect("the fixture is JSON");
assert!(
crate::shared::tokens::estimate_text(&page.text) as usize
<= ctx.attachment_cfg.max_file_tokens,
"the page must take the inline path, as the fetched one did"
);
let started = std::time::Instant::now();
let out = FetchUrl::default()
.inline_result(&ctx, GITHUB_REPO_URL, None, true, &page)
.await;
eprintln!(
"summary_usage_e2e_live: {:.1} s, ratio {:.2}, sample {:?}\n{}",
started.elapsed().as_secs_f64(),
budget.density(Shape::Summary),
out.prefill,
out.result
);
assert!(
!out.result.contains("\"node_id\""),
"the JSON itself came back, not a summary: {}",
out.result
);
assert!(!out.result.trim().is_empty());
assert!(
budget.density(Shape::Summary) > 1.0,
"a JSON page under-counts: {budget:?}"
);
assert_eq!(budget.density(Shape::Turn), 1.0, "no other kind touched");
assert!(
out.prefill.is_some(),
"the engine's timing rides the outcome"
);
}