From da9679423f24616183298685af428b9e9f029f3e Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Sat, 17 Oct 2026 13:52:50 -0500 Subject: [PATCH 1/3] fix(id): vendor relay kit under tests/fixtures so Nix CI can read it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tests/relay_ops.rs read the relay kit from the repo-root design doc (doc/2026-10-11T03-44-33Z_design_groups_events_delegation/connectivity/relay), which is outside the pkgs/id flake source tree, so all relay_ops tests failed with NotFound in the Nix sandbox on every PR (#238). Vendor the kit under pkgs/id/tests/fixtures/relay and point the tests there. The design doc copy stays canonical; a new drift test fails whenever the doc copy is present and the two have drifted. A missing vendored kit still fails loudly via kit_file's expect. Verified: cargo test --test relay_ops — 22 passed (21 existing + drift). --- .../tests/fixtures/relay/iroh-relay.service | 24 +++++++++ .../relay/iroh-relay.service.d/vps.conf | 6 +++ pkgs/id/tests/fixtures/relay/relay.kit.toml | 35 +++++++++++++ pkgs/id/tests/fixtures/relay/tunnel.toml | 18 +++++++ pkgs/id/tests/fixtures/relay/vps.toml | 29 +++++++++++ pkgs/id/tests/relay_ops.rs | 49 +++++++++++++++++-- 6 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 pkgs/id/tests/fixtures/relay/iroh-relay.service create mode 100644 pkgs/id/tests/fixtures/relay/iroh-relay.service.d/vps.conf create mode 100644 pkgs/id/tests/fixtures/relay/relay.kit.toml create mode 100644 pkgs/id/tests/fixtures/relay/tunnel.toml create mode 100644 pkgs/id/tests/fixtures/relay/vps.toml diff --git a/pkgs/id/tests/fixtures/relay/iroh-relay.service b/pkgs/id/tests/fixtures/relay/iroh-relay.service new file mode 100644 index 000000000..c614879d2 --- /dev/null +++ b/pkgs/id/tests/fixtures/relay/iroh-relay.service @@ -0,0 +1,24 @@ +# systemd unit for iroh-relay, shared by both modes in relay.kit.toml. Install the binary at +# /usr/local/bin/iroh-relay and the mode's config at /etc/iroh-relay/relay.toml before enabling +# the unit. The vps mode also installs iroh-relay.service.d/vps.conf, which grants the port +# capability. The tunnel mode installs none. +[Unit] +Description=iroh relay +After=network-online.target +Wants=network-online.target +# Refuse to start without the config. The relay otherwise starts silently on [::]:80 (S11). +ConditionPathExists=/etc/iroh-relay/relay.toml + +[Service] +ExecStart=/usr/local/bin/iroh-relay --config-path /etc/iroh-relay/relay.toml +# The relay ignores SIGTERM and is hard-killed by it. SIGINT exits cleanly (S11). +KillSignal=SIGINT +User=iroh-relay +Group=iroh-relay +StateDirectory=iroh-relay +Environment=RUST_LOG=info +Restart=always +RestartSec=3 + +[Install] +WantedBy=multi-user.target diff --git a/pkgs/id/tests/fixtures/relay/iroh-relay.service.d/vps.conf b/pkgs/id/tests/fixtures/relay/iroh-relay.service.d/vps.conf new file mode 100644 index 000000000..28e292e15 --- /dev/null +++ b/pkgs/id/tests/fixtures/relay/iroh-relay.service.d/vps.conf @@ -0,0 +1,6 @@ +# Drop-in for the vps mode (relay.kit.toml). The relay binds ports 80 and 443, which are below +# 1024, so the User=iroh-relay account needs CAP_NET_BIND_SERVICE. The tunnel mode binds only +# loopback port 3340 and installs no drop-in, so its unit grants no capability. +[Service] +AmbientCapabilities=CAP_NET_BIND_SERVICE +CapabilityBoundingSet=CAP_NET_BIND_SERVICE diff --git a/pkgs/id/tests/fixtures/relay/relay.kit.toml b/pkgs/id/tests/fixtures/relay/relay.kit.toml new file mode 100644 index 000000000..6e703b904 --- /dev/null +++ b/pkgs/id/tests/fixtures/relay/relay.kit.toml @@ -0,0 +1,35 @@ +# The relay kit's modes. A mode is one way to run iroh-relay on one host. +# +# tunnel setup A, a Cloudflare Tunnel. cloudflared terminates TLS at Cloudflare's edge and +# forwards to the relay's plain HTTP origin on loopback. No inbound port, no UDP. +# vps setup B, a public IPv4 address. TLS on 443, HTTP on 80, QUIC address discovery on +# 7842/udp. +# +# Each mode's values are the ones its config file and unit must carry. tests/relay_ops.rs +# checks the committed config and unit for each mode against this file. +# +# Keys: +# config the relay config for this mode, copied to /etc/iroh-relay/relay.toml +# unit_dropin the unit drop-in to install beside iroh-relay.service, if any +# hostname the public name clients use, as https:// +# http_bind_addr the plain HTTP listener +# https_bind_addr the TLS listener; absent when the mode serves no TLS +# metrics_bind_addr the metrics listener, which must stay on loopback +# qad whether QUIC address discovery is on + +[modes.tunnel] +config = "tunnel.toml" +# The Tunnel's public hostname, set in the Cloudflare dashboard to point at http://localhost:3340. +hostname = "relay.example.org" +http_bind_addr = "127.0.0.1:3340" +metrics_bind_addr = "127.0.0.1:9090" +qad = false + +[modes.vps] +config = "vps.toml" +unit_dropin = "iroh-relay.service.d/vps.conf" +hostname = "relay.example.org" +http_bind_addr = "[::]:80" +https_bind_addr = "[::]:443" +metrics_bind_addr = "127.0.0.1:9090" +qad = true diff --git a/pkgs/id/tests/fixtures/relay/tunnel.toml b/pkgs/id/tests/fixtures/relay/tunnel.toml new file mode 100644 index 000000000..3c109926f --- /dev/null +++ b/pkgs/id/tests/fixtures/relay/tunnel.toml @@ -0,0 +1,18 @@ +# iroh-relay, Cloudflare Tunnel mode (setup A in the connectivity design). Its values are in +# relay.kit.toml under [modes.tunnel]. +# +# Plain HTTP on loopback. cloudflared terminates TLS at Cloudflare's edge and forwards to +# this address, so the relay needs no certificate and no open inbound port. +# +# QUIC address discovery needs UDP, which Tunnel does not carry, so it stays off. Clients +# using this relay must build its RelayConfig with no QUIC port (RelayConfig::new(url, None)). +http_bind_addr = "127.0.0.1:3340" +enable_quic_addr_discovery = false + +# The metrics endpoint defaults to [::]:9090, which is public. Keep it on loopback. +metrics_bind_addr = "127.0.0.1:9090" + +# Optional abuse control. Clients must then send one of these tokens, as a Bearer header or +# as ?token=. Check the key names against iroh-relay's access config before enabling it. +# [access] +# shared_token = ["replace-with-a-long-random-token"] diff --git a/pkgs/id/tests/fixtures/relay/vps.toml b/pkgs/id/tests/fixtures/relay/vps.toml new file mode 100644 index 000000000..61a20dbe7 --- /dev/null +++ b/pkgs/id/tests/fixtures/relay/vps.toml @@ -0,0 +1,29 @@ +# iroh-relay, VPS mode (setup B in the connectivity design). Its values are in relay.kit.toml +# under [modes.vps]. +# +# Needs a public IPv4 address and these open ports: +# 80/tcp ACME challenge and captive-portal check +# 443/tcp relay (WebSocket over TLS) and /ping +# 7842/udp QUIC address discovery, which lets peers find their public addresses for direct paths +# +# Replace relay.example.org and ops@example.org before use. Keep cert_dir on persistent storage: +# Let's Encrypt allows 5 certificates per identical name set per week. +http_bind_addr = "[::]:80" +enable_quic_addr_discovery = true + +# Keep metrics off the public interface. +metrics_bind_addr = "127.0.0.1:9090" + +[tls] +https_bind_addr = "[::]:443" +hostname = "relay.example.org" +cert_mode = "LetsEncrypt" +cert_dir = "/var/lib/iroh-relay/certs" +contact = "ops@example.org" + +# Keep false while testing, so Let's Encrypt staging issues the certificate. Set true for production. +prod_tls = false + +# Optional abuse control, as in tunnel.toml. +# [access] +# shared_token = ["replace-with-a-long-random-token"] diff --git a/pkgs/id/tests/relay_ops.rs b/pkgs/id/tests/relay_ops.rs index 2c55dca48..557309120 100644 --- a/pkgs/id/tests/relay_ops.rs +++ b/pkgs/id/tests/relay_ops.rs @@ -5,8 +5,14 @@ //! `relay.kit.toml` has one table per mode. `tunnel` is a Cloudflare Tunnel //! (no inbound port, plain HTTP on loopback). `vps` is a public address (TLS on //! 80 and 443, QUIC address discovery). A mode's unit is the shared -//! `iroh-relay.service` plus the mode's drop-in, if it has one. The kit lives in -//! the design doc, so the paths are relative to this crate. +//! `iroh-relay.service` plus the mode's drop-in, if it has one. +//! +//! The kit is vendored under `tests/fixtures/relay` so it is inside this +//! crate's source tree: the Nix flake cannot see the design doc copy at the +//! repo root (`doc/2026-10-11T03-44-33Z_design_groups_events_delegation/ +//! connectivity/relay`, #238), which stays canonical. Edit the doc copy and +//! re-copy it here; `test_vendored_kit_matches_the_design_doc_copy` fails +//! whenever the doc copy is present and the two have drifted. //! //! Each check runs on the kit's real files, and also on mutated copies, so a //! check that accepts everything fails. @@ -15,11 +21,25 @@ use std::{net::SocketAddr, path::Path}; -const KIT: &str = concat!( +const KIT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/fixtures/relay"); + +/// The canonical kit, in the design doc at the repo root. Outside this +/// crate's source tree, so it does not exist in the Nix sandbox; the +/// vendored copy above is what the checks read there. +const CANONICAL_KIT: &str = concat!( env!("CARGO_MANIFEST_DIR"), "/../../doc/2026-10-11T03-44-33Z_design_groups_events_delegation/connectivity/relay" ); +/// Every file in the kit, relative to the kit root. +const KIT_FILES: [&str; 5] = [ + "relay.kit.toml", + "tunnel.toml", + "vps.toml", + "iroh-relay.service", + "iroh-relay.service.d/vps.conf", +]; + const KIT_FILE: &str = "relay.kit.toml"; const UNIT: &str = "iroh-relay.service"; /// What both modes must run. The config path is where the unit's @@ -506,3 +526,26 @@ fn test_config_check_accepts_loopback_ipv6() { ); check_config(&config).unwrap(); } + +/// The vendored kit must match the canonical design-doc copy, so the two +/// cannot drift silently. The doc copy lives outside this crate's source +/// tree and is absent in the Nix sandbox; there the vendored copy is the +/// only one and this check has nothing to compare against. When the doc +/// copy IS present, any difference fails loudly. +#[test] +fn test_vendored_kit_matches_the_design_doc_copy() { + let canonical = Path::new(CANONICAL_KIT); + if !canonical.is_dir() { + return; + } + for name in KIT_FILES { + let vendored = kit_file(name); + let original = std::fs::read_to_string(canonical.join(name)) + .expect("every vendored kit file exists in the design doc copy"); + assert_eq!( + vendored, original, + "vendored kit file {name} differs from the design doc copy; \ + edit the doc copy and re-copy it into tests/fixtures/relay" + ); + } +} From dabbd420b85fe877d28be5be7a669f9378f36438 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Sat, 17 Oct 2026 14:21:17 -0500 Subject: [PATCH 2/3] fix(id): re-export unix_ms from world as pub(crate) PR #245 (#193) moved unix_ms to crate::time and imported it into world.rs with a plain private use, so crate::world::unix_ms stopped resolving: the tests in world_session.rs import it through world and cargo check --all-targets --all-features failed on main with E0603 (function import unix_ms is private) in CI's cargo-check and ci checks. The other #245 moves used pub re-exports; this one missed it. Make it pub(crate) use, matching the Isolation re-export beside it. Verified: cargo check --tests passes; cargo check --all-targets --all-features shows no E0603 (locally it only fails on the missing web/dist bundle, which CI provides). --- pkgs/id/src/world.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkgs/id/src/world.rs b/pkgs/id/src/world.rs index 5f036013a..764078b17 100644 --- a/pkgs/id/src/world.rs +++ b/pkgs/id/src/world.rs @@ -19,7 +19,6 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque}; use std::sync::Arc; -use crate::time::unix_ms; use crate::world_caps::{CapError, CapsReport, Decision, Request, Subscription}; use anyhow::{Context, Result, bail, ensure}; use rand::RngExt as _; @@ -32,6 +31,10 @@ use tokio::sync::{broadcast, mpsc, oneshot, watch}; /// in [`crate::groups::worlds`] so the crate builds without this feature. pub use crate::groups::worlds::Isolation; +/// Re-exported so `crate::world::unix_ms` keeps working: the function now +/// lives in [`crate::time`] so the crate builds without this feature. +pub(crate) use crate::time::unix_ms; + /// Bounded limits for one world. #[derive(Clone, Copy, Debug)] pub struct WorldLimits { From b0da981b35fbef548bdea2cb2549d4f4548c1431 Mon Sep 17 00:00:00 2001 From: Muse Sweep Date: Sat, 17 Oct 2026 14:44:00 -0500 Subject: [PATCH 3/3] fix(id): replace unwrap in SaveRateLimiter with unwrap_or(ZERO) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit clippy -D clippy::unwrap_used failed checks.default (just ci) on main at src/web/mod.rs:118, which blocked the ci recipe before test-sandbox could run. The unwrap was safe (guarded by elapsed < cooldown, so checked_sub is always Some there) but the crate denies unwrap_used; use unwrap_or(Duration::ZERO) — the remaining cooldown is ZERO in the unreachable None case. --- pkgs/id/src/web/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/id/src/web/mod.rs b/pkgs/id/src/web/mod.rs index c6731d804..472c57f79 100644 --- a/pkgs/id/src/web/mod.rs +++ b/pkgs/id/src/web/mod.rs @@ -115,7 +115,9 @@ impl SaveRateLimiter { if let Some(last) = map.get(name) { let elapsed = last.elapsed(); if elapsed < self.cooldown { - return Err(self.cooldown.checked_sub(elapsed).unwrap()); + // checked_sub is Some exactly because elapsed < cooldown; + // ZERO is the unreachable fallback (no time remaining). + return Err(self.cooldown.checked_sub(elapsed).unwrap_or(Duration::ZERO)); } } Ok(())