use super::*;
#[test]
fn an_unset_variable_takes_the_offline_default() {
let selection = select_embedder(None).expect("an unset variable is not a caller error");
match selection {
EmbedderSelection::Ready(name, embedder) => {
assert_eq!(name, "hash", "the default backend is the offline one");
assert_eq!(
embedder.dimension(),
crate::DEFAULT_DIMENSION,
"the default embedder is built at the crate's default dimension"
);
}
other @ EmbedderSelection::NeedsRemoteConfig(_) => {
panic!("an unset variable must resolve to a ready embedder, got {other:?}")
}
}
}
#[test]
fn hash_is_ready_with_no_configuration_and_no_network() {
let selection = select_embedder(Some("hash")).expect("`hash` is an accepted backend");
assert!(
matches!(selection, EmbedderSelection::Ready("hash", _)),
"`hash` needs no URL and no model, so it comes back ready to use"
);
}
#[test]
fn ollama_defers_to_the_caller_for_url_and_model() {
let selection = select_embedder(Some("ollama")).expect("`ollama` is an accepted backend");
assert!(
matches!(selection, EmbedderSelection::NeedsRemoteConfig("ollama")),
"only the caller knows the URL and model, so the library names the \
backend and stops there"
);
}
#[test]
fn openai_defers_to_the_caller_for_url_and_model() {
let selection = select_embedder(Some("openai")).expect("`openai` is an accepted backend");
assert!(
matches!(selection, EmbedderSelection::NeedsRemoteConfig("openai")),
"the name must reach the caller intact: it is what the daemon dispatches \
on, and a backend that came back as `ollama` would be silently served by \
the wrong protocol"
);
}
#[test]
fn an_empty_value_is_refused_like_any_other_unknown_name() {
let err = select_embedder(Some("")).expect_err("an empty backend name is not a selection");
assert!(
err.contains("hash") && err.contains("ollama") && err.contains("openai"),
"the refusal must name the accepted forms, got: {err}"
);
}
#[test]
fn an_unknown_backend_names_the_accepted_forms() {
let err = select_embedder(Some("lmstudio")).expect_err("`lmstudio` is not a backend name");
assert!(
err.contains("lmstudio"),
"the refusal must quote what was asked for, got: {err}"
);
assert!(
err.contains("hash") && err.contains("ollama") && err.contains("openai"),
"the refusal must name the accepted forms, got: {err}"
);
}