pub mod projection {
pub use marius_projection::Projection;
}
pub mod collector {
pub use marius_collector::Collector;
}
include!(concat!(env!("OUT_DIR"), "/generated_schema.rs"));
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
#[ignore]
async fn test_fetch_content_core() {
let pool = sqlx::PgPool::connect(
&std::env::var("DATABASE_URL").unwrap()
).await.unwrap();
let ids = vec![1i64, 2, 3];
let results = ContentCoreProjection::fetch_batch(&pool, &ids)
.await
.unwrap();
assert!(!results.is_empty(), "Aucun enregistrement — DML appliqué ?");
let (storage, varlena) = &results[0];
let mut buf = String::with_capacity(CONTENT_CORE_TOTAL_CAP);
ContentCoreProjection::render(storage, varlena, &mut buf);
println!("ContentCore[0] : {buf}");
assert!(buf.contains("content-core"), "classe CSS absente");
assert!(buf.contains("<dt>document_id</dt>"), "champ document_id absent");
}
#[tokio::test]
#[ignore]
async fn test_fetch_product_core() {
let pool = sqlx::PgPool::connect(
&std::env::var("DATABASE_URL").unwrap()
).await.unwrap();
let ids = vec![1i64, 2, 3];
let results = CommerceProductCoreProjection::fetch_batch(&pool, &ids)
.await
.unwrap();
assert!(!results.is_empty());
let (storage, varlena) = &results[0];
let mut buf = String::with_capacity(COMMERCE_PRODUCT_CORE_TOTAL_CAP);
CommerceProductCoreProjection::render(storage, varlena, &mut buf);
println!("ProductCore[0] : {buf}");
assert!(buf.contains("commerce-product_core"), "classe CSS absente");
assert!(buf.contains("<dt>id</dt>"), "champ id absent");
}
#[test]
fn test_content_core_no_realloc() {
let storage = ContentCoreStorageRow {
published_at: i64::MIN, created_at: i64::MIN,
modified_at: i64::MIN,
document_id: i32::MIN, author_entity_id: i32::MIN,
status: i16::MIN, is_readable: false, is_commentable: false,
is_visible_comments: false,
};
let varlena = ContentCoreVarlenOwned {
..Default::default()
};
let initial_cap = CONTENT_CORE_TOTAL_CAP;
let mut buf = String::with_capacity(initial_cap);
ContentCoreProjection::render(&storage, &varlena, &mut buf);
assert_eq!(
buf.capacity(), initial_cap,
"REALLOC détecté sur ContentCore : capacity {} → {}.\n\
Fragment-Forge sous-estime la capacité.\n\
Longueur réelle du HTML : {} octets.",
initial_cap, buf.capacity(), buf.len()
);
assert!(buf.starts_with("<article"), "tag ouvrant manquant");
assert!(buf.ends_with("</article>"), "tag fermant manquant");
println!(
"[no-realloc] ContentCore : cap={}, len={}, ratio={:.0}%",
initial_cap, buf.len(),
buf.len() as f64 / initial_cap as f64 * 100.0
);
}
#[test]
fn test_product_core_no_realloc() {
let storage = CommerceProductCoreStorageRow {
price_cents: i64::MIN,
id: i32::MIN,
stock: i32::MIN,
media_id: i32::MIN,
is_available: false,
};
let initial_cap = COMMERCE_PRODUCT_CORE_TOTAL_CAP;
let mut buf = String::with_capacity(initial_cap);
CommerceProductCoreProjection::render(&storage, &(), &mut buf);
assert_eq!(
buf.capacity(), initial_cap,
"REALLOC détecté sur CommerceProductCore : capacity {} → {}.\n\
Longueur réelle : {} octets.",
initial_cap, buf.capacity(), buf.len()
);
assert!(buf.starts_with("<article"), "tag ouvrant manquant");
assert!(buf.ends_with("</article>"), "tag fermant manquant");
println!(
"[no-realloc] ProductCore : cap={}, len={}, ratio={:.0}%",
initial_cap, buf.len(),
buf.len() as f64 / initial_cap as f64 * 100.0
);
}
#[test]
fn test_content_core_realistic_ratio() {
let storage = ContentCoreStorageRow {
published_at: 1_700_000_000_000_000i64,
created_at: 1_700_000_000_000_000i64,
modified_at: 1_700_000_000_000_000i64,
document_id: 42,
author_entity_id: 7,
status: 1,
is_readable: true,
is_commentable: true,
is_visible_comments: true,
};
let varlena = ContentCoreVarlenOwned {
..Default::default()
};
let mut buf = String::new();
ContentCoreProjection::render(&storage, &varlena, &mut buf);
let ratio = buf.len() as f64 / CONTENT_CORE_TOTAL_CAP as f64 * 100.0;
println!(
"[ratio] ContentCore réaliste : {}/{} = {:.0}%",
buf.len(), CONTENT_CORE_TOTAL_CAP, ratio
);
if ratio < 10.0 {
eprintln!(
"[ratio] AVERTISSEMENT : ratio {:.0}% < 10% — DYNAMIC_CAP dominé par des colonnes TEXT larges (fallback 10 000 × escape factor 5 = 50 000B). Vérifier fetch_varlena_cols et envisager des contraintes CHECK explicites.",
ratio
);
}
assert!(ratio > 3.0,
"DYNAMIC_CAP pathologiquement sur-estimé : {ratio:.0}% (ratio < 3% indique une colonne TEXT sans contrainte avec fallback excessif)");
assert!(ratio < 95.0,
"DYNAMIC_CAP trop juste : {ratio:.0}%");
}
#[test]
fn test_product_core_realistic_ratio() {
let storage = CommerceProductCoreStorageRow {
price_cents: 1999,
id: 42,
stock: 150,
media_id: 7,
is_available: true,
};
let mut buf = String::new();
CommerceProductCoreProjection::render(&storage, &(), &mut buf);
let ratio = buf.len() as f64 / COMMERCE_PRODUCT_CORE_TOTAL_CAP as f64 * 100.0;
println!(
"[ratio] ProductCore réaliste : {}/{} = {:.0}%",
buf.len(), COMMERCE_PRODUCT_CORE_TOTAL_CAP, ratio
);
assert!(ratio > 30.0,
"DYNAMIC_CAP massivement sur-estimé : {ratio:.0}%");
}
}