use super::{openapi_or_skip, validate_ref};
use qql_core::parser::Parser;
use qql_plan::plan::plan;
use qql_plan::routing::try_route;
#[test]
fn document_with_model_is_openapi_valid() {
let Some(openapi) = openapi_or_skip() else {
return;
};
let stmt = Parser::parse(
"QUERY TEXT 'hello world' MODEL 'jinaai/jina-embeddings-v2-base-en' FROM docs LIMIT 5;",
)
.unwrap();
let json = try_route(&stmt).unwrap().body_json().unwrap();
let nearest = &json["query"]["nearest"];
assert!(nearest.is_object(), "nearest must be an object: {nearest}");
assert_eq!(nearest["text"], "hello world");
assert_eq!(nearest["model"], "jinaai/jina-embeddings-v2-base-en");
validate_ref(&openapi, "Document", nearest);
validate_ref(&openapi, "Query", &json["query"]);
}
#[test]
fn image_with_model_is_openapi_valid() {
let Some(openapi) = openapi_or_skip() else {
return;
};
let stmt = Parser::parse(
"QUERY IMAGE 'https://example.com/photo.jpg' MODEL 'Qdrant/clip-ViT-B-32-vision' FROM docs USING image_vec LIMIT 5;",
)
.unwrap();
let json = try_route(&stmt).unwrap().body_json().unwrap();
let nearest = &json["query"]["nearest"];
assert!(nearest.is_object(), "nearest must be an object: {nearest}");
assert_eq!(nearest["image"], "https://example.com/photo.jpg");
assert_eq!(nearest["model"], "Qdrant/clip-ViT-B-32-vision");
validate_ref(&openapi, "Image", nearest);
validate_ref(&openapi, "Query", &json["query"]);
}
#[test]
fn document_without_model_plans_successfully() {
let result = plan(&Parser::parse("QUERY 'hello' FROM docs USING dense LIMIT 5;").unwrap());
assert!(
result.is_ok(),
"plan should succeed without MODEL: {}",
result.unwrap_err()
);
}
#[test]
fn image_without_model_plans_successfully() {
let result = plan(
&Parser::parse(
"QUERY IMAGE 'https://example.com/photo.jpg' FROM docs USING image_vec LIMIT 5;",
)
.unwrap(),
);
assert!(
result.is_ok(),
"plan should succeed without MODEL: {}",
result.unwrap_err()
);
}
#[test]
fn document_with_empty_model_plans_successfully() {
let result =
plan(&Parser::parse("QUERY TEXT 'hello' MODEL '' FROM docs USING dense LIMIT 5;").unwrap());
assert!(result.is_ok());
}
#[test]
fn hybrid_with_model_propagates_to_both_prefetches() {
let Some(openapi) = openapi_or_skip() else {
return;
};
let stmt = Parser::parse(
"QUERY HYBRID TEXT 'search' MODEL 'bge' DENSE dense SPARSE sparse FUSION RRF FROM docs LIMIT 10;",
)
.unwrap();
let json = try_route(&stmt).unwrap().body_json().unwrap();
let prefetch = json["prefetch"].as_array().unwrap();
assert_eq!(prefetch.len(), 2);
for (i, pf) in prefetch.iter().enumerate() {
let nearest = &pf["query"]["nearest"];
assert!(
nearest.is_object(),
"prefetch[{i}] nearest must be Document object, got {nearest}"
);
assert_eq!(nearest["model"], "bge");
validate_ref(&openapi, "Document", nearest);
}
validate_ref(&openapi, "QueryRequest", &json);
}