A: wire peer check to the real client and probe a real socket in tests

B1/B2 are merged, so `real_transport` builds the `ReqwestTransport` with the
configured limits and deny list instead of bailing. Binary tests now probe a
real loopback server: ok with latency, rejected credential, unreachable peer
and an unknown name, none of which may print the token.
This commit is contained in:
ari committed 2026-10-19 22:31:29 -04:00
1 parent e2ff40beae
commit 92ad3c8128
2 files changed
+142 -14

No files matched your search

+8 -6
View File
@@ -7,12 +7,13 @@
use std::sync::Arc;
use std::time::Duration;
use anyhow::{bail, Result};
use anyhow::{Context, Result};
use clap::Subcommand;
use crate::config::Config;
use crate::peers::config;
use crate::peers::health::check_once;
use crate::peers::registry::ReqwestTransport;
use crate::peers::transport::PeerTransport;
use crate::peers::types::{ApiStatus, AuthState, PeerConfig, PeersConfig, ServerStatus};
@@ -36,7 +37,7 @@ pub async fn run(cmd: PeerCmd, config: &Config) -> Result<()> {
let peer = configured_peer(&config.peers, &name)?;
// Only this peer's credential is needed to probe it.
config::validate_peer_token(peer).map_err(|err| anyhow::anyhow!("{err}"))?;
let transport = real_transport()?;
let transport = real_transport(&config.peers)?;
print!(
"{}",
check_report(transport.as_ref(), &config.peers, &name).await?
@@ -46,10 +47,11 @@ pub async fn run(cmd: PeerCmd, config: &Config) -> Result<()> {
Ok(())
}
/// The real transport lands with the peer client workstream. Until then the
/// binary can list peers but cannot contact one.
fn real_transport() -> Result<Arc<dyn PeerTransport>> {
bail!("peer check: transport not available (the peer client is not wired yet)")
/// The real client, built with the configured limits and deny list. One
/// process-wide instance is enough for a single probe.
fn real_transport(cfg: &PeersConfig) -> Result<Arc<dyn PeerTransport>> {
let transport = ReqwestTransport::new(cfg).context("building the peer client")?;
Ok(Arc::new(transport))
}
/// One row per configured peer, sorted by name. Shows the path of the token