test(arr): make the engine gate test ask the build

Turning on --all-features compiled every translation backend, so the test
asserting that a known-but-uncompiled engine is refused had nothing left to
refuse and failed. It hardcoded "deepl" and a comment that no feature was
on, which stopped being true in the same commit that made CI see it.

It now picks whichever engine this build did not compile, and when all of
them are compiled asserts the complementary truth instead: a compiled
engine is accepted. Meaningful under either feature set.
This commit is contained in:
Miguel Palhas
2026-08-25 01:08:15 +01:00
parent db9ae271cb
commit f773489fd7
+35 -3
View File
@@ -302,13 +302,24 @@ mod tests {
assert_eq!(refetched, updated);
}
/// Whether a known engine is selectable depends on which `translate-*`
/// features this binary was built with, so the test asks the build rather
/// than assuming. With no feature on, every engine is uncompiled and must
/// be refused; with all of them on there is nothing to refuse, and the
/// complementary truth — a compiled engine is accepted — is what holds.
#[tokio::test]
async fn an_uncompiled_engine_is_a_422_naming_the_field() {
let compiled = arr_subs::compiled_engines();
let Some(uncompiled) = arr_subs::ENGINES
.iter()
.find(|engine| !compiled.contains(*engine))
else {
return a_compiled_engine_is_accepted().await;
};
let (_dir, base) = application().await;
let mut payload = valid_input();
// No `translate-*` feature is enabled by default (arr-subs's
// Cargo.toml), so every named engine is rejected as uncompiled.
payload["translation_engine"] = serde_json::json!("deepl");
payload["translation_engine"] = serde_json::json!(uncompiled);
let response = reqwest::Client::new()
.put(format!("{base}/api/settings/subtitles"))
.json(&payload)
@@ -326,6 +337,27 @@ mod tests {
);
}
/// The other side of the feature gate: an engine this binary *did*
/// compile in is selectable. Called directly when no engine is uncompiled.
async fn a_compiled_engine_is_accepted() {
let compiled = arr_subs::compiled_engines();
let Some(engine) = compiled.first() else {
return;
};
let (_dir, base) = application().await;
let mut payload = valid_input();
payload["translation_engine"] = serde_json::json!(engine);
let response = reqwest::Client::new()
.put(format!("{base}/api/settings/subtitles"))
.json(&payload)
.send()
.await
.expect("put settings");
assert_eq!(response.status(), StatusCode::OK, "{engine} is compiled in");
}
#[tokio::test]
async fn an_unknown_engine_name_is_a_422() {
let (_dir, base) = application().await;