#!/usr/bin/env python3 """OPT4 source invariants: not compilation or performance proof.""" from pathlib import Path r = Path(__file__).resolve().parents[2] def source(name): return (r / name).read_text(encoding="utf-8") assert 'version = "0.34.0"' in source('Cargo.toml') route = source('src/proxy/forward/route_cache.rs') assert "Cow<'_, str>" in route assert 'routing_uri.path_and_query()' in route assert 'Ok(None) => public_suffix.clone()' in route assert 'std::borrow::Cow::Owned(encoded)' in route for name in ('src/proxy/forward/cache_lookup.rs','src/proxy/forward/success_finish.rs'): assert 'public_suffix: public_suffix.clone()' not in source(name) assert 'public_suffix: public_suffix.to_string()' in source(name) helpers = source('src/proxy/upstream_helpers.rs') assert 'fn wrap_observed_request' in helpers assert 'if body.is_end_stream() { body }' in helpers assert 'let request = request.map(|body| wrap_observed_request' in helpers assert 'fn log_prefix' in helpers assert 'input.is_ascii()' in helpers and 'input.chars().take(max_chars).collect()' in helpers assert 'path: log_prefix(request.uri().path(), 256)' in helpers assert 'pub request_origin_uri: http::Uri' in source('src/config/model.rs') target = source('src/proxy/types.rs') assert 'fn upstream_request_target(\n uri: Uri' in target assert 'return Some(uri);' in target assert 'let mut parts = uri.into_parts();' in target assert 'upstream_request_target(uri, request.headers_mut()' in target assert 'upstream_request_target(\n uri, request.headers_mut()' in source('src/proxy/forward/upstream.rs') forward = source('src/forwarding.rs') assert 'peer_node.as_deref().unwrap_or(&peer_text)' in forward assert 'let mut ips = chain(incoming).unwrap_or_default();' in forward headers = source('src/proxy/headers.rs') assert 'let no_nominations' in headers assert 'eq_ignore_ascii_case(b"close")' in headers assert 'let nominated: Vec' in headers for name, test in [ ('src/proxy/body/tests.rs','optimized_empty_request_keeps_exchange_until_response'), ('src/proxy/body/tests.rs','optimized_nonempty_request_still_meters_data_and_holds_capacity'), ('src/proxy/tests/authority_tests.rs','optimized_log_prefix_preserves_unicode_char_count_and_ascii_bytes'), ('src/proxy/tests/authority_tests.rs','moved_uri_keeps_h1_origin_and_query'), ('src/proxy/headers/tests.rs','absent_and_close_connection_preserve_non_hop_headers'), ]: assert test in source(name), (name, test) for p in (r / 'src').rglob('*.rs'): if '/tests/' in p.as_posix() or p.name == 'tests.rs': continue assert len(p.read_text(encoding='utf-8').splitlines()) <= 500, p assert not source('src/cache/stats.rs').startswith('//!') print('PASS OPT4 source guard (STATIC ONLY; no cargo / no OPT4 benchmark)')