#!/usr/bin/env python3 """Source invariants for 0.34.0 RPS optimizations (NOT a Rust build or RPS test). These guards reject accidental removal of important branch/safety conditions. They must be paired with ``cargo test`` and live black-box HTTP acceptance. """ from pathlib import Path import json ROOT = Path(__file__).resolve().parents[2] def source(path): return (ROOT / path).read_text(encoding="utf-8") # Random request identifiers retain CSPRNG entropy, SHA-256, format and sequence. identifier = source("src/proxy/request_id.rs") assert "rand::random()" in identifier assert "hash.update(sequence.to_be_bytes());" in identifier assert "hash.update(nonce);" in identifier assert "request_id_hex(&hash.finalize())" in identifier assert "SysRng.try_fill_bytes" not in identifier # Compiled/validated target authority survives request URI construction. config = source("src/config/backend.rs") model = source("src/config/model.rs") request = source("src/proxy/types.rs") assert "let request_origin_uri: http::Uri = request_origin.parse()?;" in config assert "request_origin_uri," in config assert "pub request_origin_uri: http::Uri," in model assert "let path: http::uri::PathAndQuery = suffix.parse().ok()?;" in request assert "let mut parts = backend.request_origin_uri.clone().into_parts();" in request assert "parts.path_and_query = Some(path);" in request assert "Uri::from_parts(parts).ok()" in request # No new unbounded caches or disabled LB safety gates. pool = source("src/balance/pool_core.rs") assert "if self.members.len() == 1 && !self.cookie_affinity()" in pool assert "try_acquire_active(member.definition.max_concurrent_requests)" in pool assert "m.state.healthy()" in pool assert "scheduling.get_mut(member.definition.id.as_str())" in pool assert "scheduling.entry(member.definition.id.clone())" in pool health = source("src/balance/lease_runtime.rs") assert "async fn probe(member: Arc, settings: Arc)" in health assert "checks.spawn(probe(Arc::clone(member), health.clone()))" in health assert "tokio::time::timeout" in health # Configurable keep-alive policy, exact recycle-request threshold and age backup. upstream = source("src/upstream/client.rs") assert "self.current.load_full()" in upstream assert "request_due || age_due" in upstream assert "let now = monotonic_millis();" in upstream assert "let age_ms = now.saturating_sub(self.generation_started_ms.load(Ordering::Relaxed));" in upstream assert "fn maintain_rotation_at(" in upstream assert "self.factory.keepalive.pool_recycle_requests" in upstream assert "self.factory.keepalive.pool_recycle_seconds" in upstream assert "pool_max_idle_per_host(if keepalive.enabled" in upstream assert "retry_canceled_requests(false)" in upstream assert "observe_protocol" in upstream # Request/response streamed payloads retain accounting and timeout/cancellation. body = source("src/proxy/body.rs") assert "request_backend: Option>" in body assert "this.request_backend = exchange.backend" in body assert "lease.bytes(count, true)" in body assert "lease.bytes(count, false)" in body assert "exchange.request_bytes.fetch_add(count" in body assert "exchange.response_bytes.fetch_add(count" in body assert "get_or_insert_with(|| Box::pin(sleep_until(this.deadline)))" in body assert "this.finish();" in body # Persist history and preserve live streaming/sink drop accounting. logs = source("src/logging/format.rs") assert "let has_viewers = self.live.receiver_count() != 0;" in logs assert "let has_sink = self.settings.load().enabled();" in logs assert "external.take().expect(\"entry\")" in logs assert "self.live.send(entry.clone())" in logs assert "self.sink.try_send(entry)" in logs assert "self.sink_dropped.fetch_add(1" in logs # Never weaken routing, identity, HTTP version and cache eligibility while tuning. route = source("src/proxy/forward/route_cache.rs") assert "admin_session_passthrough" in route assert "cache_plan.request_policy" in route assert "exchange.set_cache_enabled" in route assert "exchange.set_transform_enabled" in route assert "upstream_uri(&backend, &origin_suffix)" in route assert "headers::strip_hop_by_hop" in route assert "pool.select_wait(context.client_ip" in route or ".select_wait(context.client_ip" in route assert "pool.select_member_wait(id)" in route assert "max_idle_per_host: 64" in source("src/balance/model.rs") assert "pool_recycle_requests: 25_000" in source("src/balance/model.rs") assert "(1..=64).contains(&k.max_idle_per_host)" in source("src/balance/model.rs") assert "keepalive.max_idle_per_host ?? 64" in source("src/admin/web/vhosts/editor.js") openapi = json.loads(source("src/admin/openapi.json")) api_keepalive = openapi["components"]["schemas"] assert any(isinstance(schema, dict) and "keepalive" in schema.get("properties", {}) and schema["properties"]["keepalive"].get("properties", {}) .get("max_idle_per_host", {}).get("default") == 64 for schema in api_keepalive.values()) assert "| `max_idle_per_host` | 64 | 1..64 |" in source("docs/VHOSTS.md") assert '"keepalive": { "max_idle_per_host": 4 }' in source("src/balance/tests.rs") assert "self.route.get_mut()" in source("src/proxy/body.rs") assert "let client_ip = self" in source("src/proxy/body.rs") assert "if !headers.contains_key(http::header::COOKIE)" in source("src/proxy/headers.rs") assert "if !headers.contains_key(http::header::SET_COOKIE)" in source("src/proxy/headers.rs") assert 'version = "0.34.0"' in source("Cargo.toml") # Full exchange duration histogram still exports cumulative Prometheus series, # but only one exclusive bucket is updated per request; per-vhost and Docker # exporters must reconstruct bucket counts from exactly the same interface. histogram = source("src/metrics/vhost.rs") exporter = source("src/prometheus/docker_misc.rs") assert "let bucket = DURATION_BUCKETS_US.partition_point" in histogram assert "self.buckets[bucket].fetch_add(1, Ordering::Relaxed);" in histogram assert "pub fn duration_histogram(&self)" in histogram assert exporter.count("let (buckets, count) = m.duration_histogram();") == 2 assert "rust_proxy_vhost_exchange_duration_seconds_bucket" in exporter assert "rust_proxy_docker_vhost_exchange_duration_seconds_bucket" in exporter assert "exclusive_bins_reconstruct_exact_prometheus_cumulative_boundaries" in source("src/metrics/vhost/tests.rs") for file in (ROOT / "src").rglob("*.rs"): if "/tests/" in file.as_posix() or file.name == "tests.rs": continue assert len(file.read_text(encoding="utf-8").splitlines()) <= 500, file print("PASS RPS hot-path source invariants (STATIC ONLY; new binary not compiled)")