use std::sync::Arc;
use tracing_subscriber::Layer;
use tracing_subscriber::layer::SubscriberExt;
use vlorql::VlorQl;
use vlorql_core::observability::VlorqMetrics;
use vlorql_llm::MockLlmClient;
use crate::common::{base_plan, snapshot};
#[tokio::test]
async fn query_span_contains_vlorql_query() {
let metrics = Arc::new(VlorqMetrics::new());
let facade = VlorQl::builder()
.with_schema(snapshot())
.with_dialect_name("sqlite")
.with_llm_client(MockLlmClient::success(base_plan()))
.with_metrics(metrics)
.with_max_retries(0)
.build()
.expect("facade should build");
let (compiled, _usage) = facade
.query("show user ids")
.await
.expect("valid mock plan should compile");
assert!(compiled.sql.contains("SELECT"));
assert!(compiled.sql.contains("users"));
}
#[tokio::test]
async fn compile_span_has_dialect_attribute() {
let layer = tracing_subscriber::fmt::layer()
.with_test_writer()
.with_filter(tracing_subscriber::filter::filter_fn(|meta| {
meta.target().starts_with("vlorql")
}));
let subscriber = tracing_subscriber::registry().with(layer);
let _guard = tracing::subscriber::set_default(subscriber);
let metrics = Arc::new(VlorqMetrics::new());
let facade = VlorQl::builder()
.with_schema(snapshot())
.with_dialect_name("sqlite")
.with_llm_client(MockLlmClient::success(base_plan()))
.with_metrics(metrics)
.with_max_retries(0)
.build()
.expect("facade should build");
let (compiled, _usage) = facade
.query("show user ids")
.await
.expect("valid mock plan should compile");
assert!(compiled.sql.contains("SELECT"));
}