use super::{
Doors,
tests::{blob, fanned, fulltext, one_slot, two_slots},
};
use crate::{
index::{Elected, ElectionLabel},
model::NodeKind,
};
fn ident(name: &str) -> syn::Ident {
syn::Ident::new(name, proc_macro2::Span::call_site())
}
fn single(field: &str) -> Elected {
Elected::new(
ident(field),
ElectionLabel::Embedding,
syn::parse_quote!(::ingraph::Embedding<f32, 4, Clip>),
None,
)
}
fn two_singles() -> crate::index::IndexModel {
let mut model = one_slot();
model.embeddings = vec![single("clip"), single("poster")];
model
}
#[test]
fn the_law_is_a_table_over_two_counts() {
for (fulltext, vector, expected) in [
(0, 0, (false, false, false)),
(1, 0, (false, false, false)),
(2, 0, (true, false, false)),
(0, 1, (false, false, false)),
(0, 2, (false, true, false)),
(1, 1, (false, false, true)),
(2, 1, (true, false, true)),
(1, 2, (false, true, true)),
(2, 2, (true, true, true)),
] {
let doors = Doors::of(fulltext, vector);
assert_eq!(
(doors.fulltext, doors.vector, doors.mixed),
expected,
"({fulltext}, {vector})",
);
}
}
#[test]
fn the_mixed_door_needs_both_modalities() {
for routes in 2..6 {
assert!(!Doors::of(routes, 0).mixed, "{routes} full-text routes");
assert!(!Doors::of(0, routes).mixed, "{routes} vector routes");
}
}
#[test]
fn a_single_route_tier_fuses_nothing_and_loses_nothing() {
let tier = one_slot();
assert!(!tier.tier().doors().any());
let emitted = tier.emit().to_string();
assert!(
emitted.contains("retrieve_keys_by_image_embedding"),
"the plain door stopped emitting: {emitted}",
);
assert!(
!emitted.contains("vector_fuse"),
"a one-route tier grew a fused door: {emitted}",
);
}
#[test]
fn a_fulltext_declaration_is_one_route() {
let tier = fulltext();
assert_eq!(tier.searchable.len(), 2, "the fixture elects two fields");
assert!(
!tier.tier().doors().any(),
"two elected COLUMNS were read as two routes",
);
}
#[test]
fn a_set_election_does_not_enter_a_fused_door() {
let tier = two_slots();
assert_eq!(tier.embeddings.len(), 2, "the fixture elects two fields");
assert_eq!(tier.tier().fused_routes().count(), 1);
assert!(
!tier.tier().doors().any(),
"a set election was counted as a route",
);
assert!(two_singles().tier().doors().vector);
}
#[test]
fn a_non_retrieving_kind_has_no_doors() {
assert!(!blob().tier().doors().any());
assert_eq!(blob().tier().doors(), Doors::of(0, 0));
}
#[test]
fn a_fanned_slot_is_one_route_of_its_parent() {
let tier = fanned();
assert_eq!(tier.tier().fused_routes().count(), 1);
assert!(!tier.tier().doors().any());
}
#[test]
fn the_evidence_enum_is_one_variant_per_route() {
let emitted = two_singles()
.tier()
.emit()
.to_string()
.split_whitespace()
.collect::<String>();
assert!(
emitted.contains("enumCaptionsFusedEvidence<__INGRAPH_SCORE_CLIP__,__INGRAPH_SCORE_POSTER__,>"),
"{emitted}",
);
assert!(
emitted.contains("Clip(__INGRAPH_SCORE_CLIP__),"),
"{emitted}"
);
assert!(
emitted.contains("Poster(__INGRAPH_SCORE_POSTER__),"),
"{emitted}",
);
for silent in [one_slot(), fulltext(), blob()] {
let kind = silent.kind;
let emitted = silent.tier().emit().to_string();
assert!(
!emitted.contains("FusedEvidence"),
"{kind:?} mints evidence for a door it does not have: {emitted}",
);
}
}
#[test]
fn the_fused_refusal_names_the_route_that_spoke_it() {
let emitted = two_singles()
.tier()
.emit()
.to_string()
.split_whitespace()
.collect::<String>();
assert!(
emitted.contains("enumCaptionsFusedError<__INGRAPH_ERROR_CLIP__,__INGRAPH_ERROR_POSTER__,>"),
"{emitted}",
);
assert!(
emitted.contains("Clip(__INGRAPH_ERROR_CLIP__),"),
"{emitted}"
);
assert!(
emitted.contains("Poster(__INGRAPH_ERROR_POSTER__),"),
"{emitted}",
);
for silent in [one_slot(), fulltext(), blob()] {
let kind = silent.kind;
let emitted = silent.tier().emit().to_string();
assert!(
!emitted.contains("FusedError"),
"{kind:?} mints a fused refusal for a door it does not have: {emitted}",
);
}
}
#[test]
fn the_evidence_type_is_rostered() {
let types: Vec<String> = two_singles()
.tier()
.emitted_types()
.into_iter()
.map(|name| name.to_string())
.collect();
assert!(
types.contains(&"CaptionsFusedEvidence".to_owned()),
"{types:?}",
);
assert!(
types.contains(&"CaptionsFusedError".to_owned()),
"{types:?}"
);
for absent in ["CaptionsFusedEvidence", "CaptionsFusedError"] {
assert!(
!one_slot()
.tier()
.emitted_types()
.iter()
.any(|name| name == absent),
"a one-route tier rosters `{absent}`, a type it does not emit",
);
}
}
#[test]
fn the_fused_doors_are_rostered() {
let names: Vec<String> = two_singles()
.emitted_methods()
.into_iter()
.map(|emitted| emitted.name.to_string())
.collect();
for owed in ["vector_fuse", "vector_fuse_similar"] {
assert!(names.contains(&owed.to_owned()), "{names:?}");
}
assert!(
!one_slot()
.emitted_methods()
.iter()
.any(|emitted| emitted.name == "vector_fuse"),
"a one-route tier rosters a door it does not emit",
);
assert_eq!(
NodeKind::Vector,
two_singles().kind,
"the fixture is the kind the doors are about",
);
}