Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(test): pin the candidate-key precedence in voice_test_provider\n\n`validate_provider_key` had no test caller at all — the only references in the\ntree were its definition and its single call site — so the branch the "Test Key"\nbutton exists for was unenforced: a key the user has just typed, for a provider\nthey have not saved yet, must be the key that gets validated.\n\nWith the candidate ignored the modal reports on whatever was already stored, or\nsays "no API key configured" about a key the user is looking at, while still\nanswering through the normal `ok` envelope.\n\nThe endpoint is `http://127.0.0.1:1`, which refuses immediately, so "got past\nthe key check and tried to reach the provider" is distinguishable from "stopped\nat the key check" with no mock server, no network and no wall-clock cost.\n\nRefs #5947, #5896\n

M3gA-Mind367cdd069e6c
diff --git a/src/openhuman/voice/schemas_tests.rs b/src/openhuman/voice/schemas_tests.rs
index e6cbd7cbf8..90353dc3a3 100644
--- a/src/openhuman/voice/schemas_tests.rs
+++ b/src/openhuman/voice/schemas_tests.rs
@@ -583,3 +583,66 @@ fn set_providers_params_all_optional() {
assert!(parsed.stt_model.is_none());
assert!(parsed.tts_voice.is_none());
}
+
+// ── `validate_provider_key`: the candidate-key half of #5947 ────────────────
+//
+// `validate_provider_key` had no test caller at all — the only references in
+// the tree were its definition and the one handler call site. What that left
+// unpinned is the branch the "Test Key" button exists for: a key the user has
+// just typed, for a provider they have not saved yet, must be the key that
+// gets validated. Invert the two match arms and the modal silently validates
+// whatever was already stored (or reports "no API key configured" for a key the
+// user is looking at), while still answering `ok` — a wrong answer about a
+// credential, which is the worst shape this code can fail in.
+//
+// `127.0.0.1:1` is the observation trick: it refuses immediately, so "the
+// validator got past the key check and tried to reach the provider" is
+// distinguishable from "the validator stopped at the key check" with no mock
+// server, no network and no wall-clock cost.
+
+fn candidate_precedence_config(slug: &str) -> crate::openhuman::config::Config {
+ use crate::openhuman::config::schema::voice_providers::VoiceProviderCreds;
+
+ let mut config = crate::openhuman::config::Config::default();
+ config.voice_providers.push(VoiceProviderCreds {
+ slug: slug.to_string(),
+ endpoint: "http://127.0.0.1:1".to_string(),
+ ..Default::default()
+ });
+ config
+}
+
+/// A candidate key must win over an absent stored key (#5947, #5896).
+#[tokio::test]
+async fn validate_provider_key_prefers_the_candidate_over_an_absent_stored_key() {
+ let slug = "e2e-candidate-precedence";
+ let config = candidate_precedence_config(slug);
+
+ // Nothing stored, no candidate: the validator must stop at the key check.
+ // This is the control — it proves the slug resolves and that the "no key"
+ // answer is what the absent-key path produces.
+ let without = super::helpers::validate_provider_key(slug, &config, None)
+ .await
+ .expect_err("no key anywhere cannot be a valid provider");
+ assert!(
+ without.contains("no API key configured"),
+ "control: with nothing stored and no candidate the validator must stop \
+ at the key check, got {without:?}"
+ );
+
+ // Same config, same absent stored key — only a candidate is added.
+ let with =
+ super::helpers::validate_provider_key(slug, &config, Some("candidate-not-yet-saved"))
+ .await
+ .expect_err("127.0.0.1:1 refuses, so the request cannot succeed");
+ assert!(
+ !with.contains("no API key configured"),
+ "a candidate key must be used when nothing is stored for the slug; \
+ got {with:?}, which means the candidate was ignored and the absent \
+ stored key won — the modal would report on a key the user never typed"
+ );
+ assert!(
+ with.contains("request failed"),
+ "the candidate must carry the validator through to the provider request, got {with:?}"
+ );
+}