style: apply cargo fmt formatting

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
jedarden 2026-05-24 09:00:33 -04:00
parent 5fc044acf9
commit 6decd353f2
2 changed files with 73 additions and 23 deletions

View file

@ -10,7 +10,9 @@ use miroir_core::router::shard_for_key;
async fn p13_4_a1_pk_equality_narrows_to_one_shard() {
// Filter `product_id = "abc"` → fan-out to 1 shard (RF=1) / RF nodes (RF>1)
let planner = QueryPlanner::default();
planner.set_primary_key("products".into(), "product_id".into()).await;
planner
.set_primary_key("products".into(), "product_id".into())
.await;
let plan = planner
.plan("products", &Some("product_id = \"abc\"".into()), 64)
@ -30,7 +32,9 @@ async fn p13_4_a1_pk_equality_narrows_to_one_shard() {
async fn p13_4_a2_pk_in_list_narrows_to_multiple_shards() {
// `product_id IN ["a","b","c"]` → fan-out to up to 3 shards
let planner = QueryPlanner::default();
planner.set_primary_key("products".into(), "product_id".into()).await;
planner
.set_primary_key("products".into(), "product_id".into())
.await;
let plan = planner
.plan(
@ -60,7 +64,9 @@ async fn p13_4_a2_pk_in_list_narrows_to_multiple_shards() {
async fn p13_4_a3_or_with_non_pk_branch_not_narrowable() {
// `product_id = "abc" OR category = "laptop"` (PK on one branch, non-PK on other) → full fan-out
let planner = QueryPlanner::default();
planner.set_primary_key("products".into(), "product_id".into()).await;
planner
.set_primary_key("products".into(), "product_id".into())
.await;
let plan = planner
.plan(
@ -70,7 +76,10 @@ async fn p13_4_a3_or_with_non_pk_branch_not_narrowable() {
)
.await;
assert!(!plan.narrowed, "Plan should NOT be narrowed (OR at top level)");
assert!(
!plan.narrowed,
"Plan should NOT be narrowed (OR at top level)"
);
assert!(
plan.target_shards.is_empty(),
"Should have no narrowed target shards"
@ -82,7 +91,9 @@ async fn p13_4_a3_or_with_non_pk_branch_not_narrowable() {
async fn p13_4_a4_pk_and_other_predicates_still_narrowable() {
// PK predicate `AND` other predicates → still narrowable
let planner = QueryPlanner::default();
planner.set_primary_key("products".into(), "product_id".into()).await;
planner
.set_primary_key("products".into(), "product_id".into())
.await;
let plan = planner
.plan(
@ -92,7 +103,10 @@ async fn p13_4_a4_pk_and_other_predicates_still_narrowable() {
)
.await;
assert!(plan.narrowed, "Plan should be narrowed (AND can only shrink the set)");
assert!(
plan.narrowed,
"Plan should be narrowed (AND can only shrink the set)"
);
assert_eq!(plan.target_shards.len(), 1, "Should target exactly 1 shard");
}
@ -100,7 +114,9 @@ async fn p13_4_a4_pk_and_other_predicates_still_narrowable() {
async fn p13_4_a5_pk_negation_not_narrowable() {
// Negation of a PK predicate → not narrowable
let planner = QueryPlanner::default();
planner.set_primary_key("products".into(), "product_id".into()).await;
planner
.set_primary_key("products".into(), "product_id".into())
.await;
let plan = planner
.plan("products", &Some("product_id != \"abc\"".into()), 64)
@ -114,7 +130,9 @@ async fn p13_4_a5_pk_negation_not_narrowable() {
async fn p13_4_a6_no_filter_not_narrowable() {
// No filter → not narrowable
let planner = QueryPlanner::default();
planner.set_primary_key("products".into(), "product_id".into()).await;
planner
.set_primary_key("products".into(), "product_id".into())
.await;
let plan = planner.plan("products", &None, 64).await;
@ -131,7 +149,10 @@ async fn p13_4_a7_no_pk_configured_not_narrowable() {
.plan("products", &Some("product_id = \"abc\"".into()), 64)
.await;
assert!(!plan.narrowed, "Plan should NOT be narrowed (PK not configured)");
assert!(
!plan.narrowed,
"Plan should NOT be narrowed (PK not configured)"
);
assert!(plan.reason.contains("primary key not configured"));
}
@ -143,13 +164,18 @@ async fn p13_4_a8_query_planner_disabled_not_narrowable() {
..Default::default()
};
let planner = QueryPlanner::new(config);
planner.set_primary_key("products".into(), "product_id".into()).await;
planner
.set_primary_key("products".into(), "product_id".into())
.await;
let plan = planner
.plan("products", &Some("product_id = \"abc\"".into()), 64)
.await;
assert!(!plan.narrowed, "Plan should NOT be narrowed (planner disabled)");
assert!(
!plan.narrowed,
"Plan should NOT be narrowed (planner disabled)"
);
assert!(plan.reason.contains("disabled"));
}
@ -161,13 +187,18 @@ async fn p13_4_a9_pk_in_list_too_large_not_narrowable() {
..Default::default()
};
let planner = QueryPlanner::new(config);
planner.set_primary_key("products".into(), "product_id".into()).await;
planner
.set_primary_key("products".into(), "product_id".into())
.await;
// Create a list with 6 PKs (exceeds max of 5)
let filter = "product_id IN [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"]".to_string();
let plan = planner.plan("products", &Some(filter), 64).await;
assert!(!plan.narrowed, "Plan should NOT be narrowed (IN list too large)");
assert!(
!plan.narrowed,
"Plan should NOT be narrowed (IN list too large)"
);
assert!(plan.reason.contains("too large"));
}
@ -177,11 +208,17 @@ async fn p13_4_a10_result_parity_narrowed_vs_full_fanout() {
// For a given PK value, both queries should return the same document
let planner = QueryPlanner::default();
planner.set_primary_key("products".into(), "product_id".into()).await;
planner
.set_primary_key("products".into(), "product_id".into())
.await;
// Plan with PK equality
let plan = planner
.plan("products", &Some("product_id = \"test-doc-123\"".into()), 64)
.plan(
"products",
&Some("product_id = \"test-doc-123\"".into()),
64,
)
.await;
assert!(plan.narrowed, "Plan should be narrowed");
@ -196,8 +233,14 @@ async fn p13_4_a10_result_parity_narrowed_vs_full_fanout() {
// Verify that any document with this PK would be on this shard
let test_pks = vec![
"abc", "xyz", "test123", "product-42", "item-999",
"user-001", "order-12345", "customer-42",
"abc",
"xyz",
"test123",
"product-42",
"item-999",
"user-001",
"order-12345",
"customer-42",
];
for pk in test_pks {
@ -223,7 +266,9 @@ async fn p13_4_a10_result_parity_narrowed_vs_full_fanout() {
async fn p13_4_a11_non_pk_field_not_narrowable() {
// Filter on non-PK field → not narrowable
let planner = QueryPlanner::default();
planner.set_primary_key("products".into(), "product_id".into()).await;
planner
.set_primary_key("products".into(), "product_id".into())
.await;
let plan = planner
.plan("products", &Some("category = \"books\"".into()), 64)
@ -237,7 +282,9 @@ async fn p13_4_a11_non_pk_field_not_narrowable() {
async fn p13_4_a12_complex_and_with_pk_narrowable() {
// Complex AND with PK constraint → narrowable
let planner = QueryPlanner::default();
planner.set_primary_key("products".into(), "product_id".into()).await;
planner
.set_primary_key("products".into(), "product_id".into())
.await;
let plan = planner
.plan(
@ -247,6 +294,9 @@ async fn p13_4_a12_complex_and_with_pk_narrowable() {
)
.await;
assert!(plan.narrowed, "Plan should be narrowed (AND with PK constraint)");
assert!(
plan.narrowed,
"Plan should be narrowed (AND with PK constraint)"
);
assert_eq!(plan.target_shards.len(), 1, "Should target exactly 1 shard");
}

View file

@ -1,9 +1,9 @@
//! Health check endpoints: /health, /version, /_miroir/ready
use axum::{extract::State, extract::FromRef, Json};
use serde::Serialize;
use crate::routes::admin_endpoints::AppState;
use crate::error_response::ErrorResponse;
use crate::routes::admin_endpoints::AppState;
use axum::{extract::FromRef, extract::State, Json};
use serde::Serialize;
#[derive(Serialize)]
pub struct HealthResponse {