From f773489fd749b7c9307f34c24bd546de3a9f89ae Mon Sep 17 00:00:00 2001 From: Miguel Palhas Date: Tue, 25 Aug 2026 01:08:15 +0100 Subject: [PATCH] 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. --- crates/arr-api/src/subtitle_settings.rs | 38 +++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/crates/arr-api/src/subtitle_settings.rs b/crates/arr-api/src/subtitle_settings.rs index dc9e9e4..bb15fc3 100644 --- a/crates/arr-api/src/subtitle_settings.rs +++ b/crates/arr-api/src/subtitle_settings.rs @@ -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;