From 6950b8af149c9067c916ca74b11c0ddf6d8c5e57 Mon Sep 17 00:00:00 2001 From: Wes Date: Mon, 13 Jul 2026 09:56:29 -0600 Subject: [PATCH] fix(desktop): keep pairing tests after production items Move the pairing relay test module to the end of the source file so Rust 1.95's items_after_test_module lint does not reject subsequent helpers. Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Wes --- desktop/src-tauri/src/commands/pairing.rs | 76 +++++++++++------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/desktop/src-tauri/src/commands/pairing.rs b/desktop/src-tauri/src/commands/pairing.rs index eef99cb5d..6bddca047 100644 --- a/desktop/src-tauri/src/commands/pairing.rs +++ b/desktop/src-tauri/src/commands/pairing.rs @@ -482,6 +482,44 @@ fn pairing_relay_from_nip11(json: &serde_json::Value) -> PairingRelay { } } +fn parse_auth_challenge(text: &str) -> Option { + let arr: serde_json::Value = serde_json::from_str(text).ok()?; + let arr = arr.as_array()?; + if arr.len() >= 2 && arr[0].as_str()? == "AUTH" { + return arr[1].as_str().map(|s| s.to_string()); + } + None +} + +async fn wait_for_eose(read: &mut S, sub_id: &str, dur: Duration) -> Result<(), String> +where + S: StreamExt> + Unpin, +{ + tokio::time::timeout(dur, async { + loop { + let msg = read + .next() + .await + .ok_or_else(|| "relay closed waiting for EOSE".to_string())? + .map_err(|e| format!("WS error waiting for EOSE: {e}"))?; + if let Message::Text(text) = msg { + if let Ok(arr) = serde_json::from_str::(text.as_str()) { + if let Some(arr) = arr.as_array() { + if arr.len() >= 2 + && arr[0].as_str() == Some("EOSE") + && arr[1].as_str() == Some(sub_id) + { + return Ok(()); + } + } + } + } + } + }) + .await + .map_err(|_| "timeout waiting for EOSE".to_string())? +} + #[cfg(test)] mod pairing_relay_tests { use super::{pairing_relay_from_nip11, probe_pairing_relay, PairingRelay}; @@ -554,41 +592,3 @@ mod pairing_relay_tests { assert_eq!(pairing_relay_from_nip11(&document), PairingRelay::MainRelay); } } - -fn parse_auth_challenge(text: &str) -> Option { - let arr: serde_json::Value = serde_json::from_str(text).ok()?; - let arr = arr.as_array()?; - if arr.len() >= 2 && arr[0].as_str()? == "AUTH" { - return arr[1].as_str().map(|s| s.to_string()); - } - None -} - -async fn wait_for_eose(read: &mut S, sub_id: &str, dur: Duration) -> Result<(), String> -where - S: StreamExt> + Unpin, -{ - tokio::time::timeout(dur, async { - loop { - let msg = read - .next() - .await - .ok_or_else(|| "relay closed waiting for EOSE".to_string())? - .map_err(|e| format!("WS error waiting for EOSE: {e}"))?; - if let Message::Text(text) = msg { - if let Ok(arr) = serde_json::from_str::(text.as_str()) { - if let Some(arr) = arr.as_array() { - if arr.len() >= 2 - && arr[0].as_str() == Some("EOSE") - && arr[1].as_str() == Some(sub_id) - { - return Ok(()); - } - } - } - } - } - }) - .await - .map_err(|_| "timeout waiting for EOSE".to_string())? -}