test(coverage): hermetic unit tests for high-risk pure logic#21
Open
UberMetroid wants to merge 1 commit into
Open
test(coverage): hermetic unit tests for high-risk pure logic#21UberMetroid wants to merge 1 commit into
UberMetroid wants to merge 1 commit into
Conversation
Backend coverage (cargo test -p backend, +65 hermetic tests): * services::query - ASN/IP/domain classification across 14 cases (CIDR, brackets, IPv4-out-of-range, IPv6 bracket/CIDR, case insensitivity). * routes::whois::parser - generic Verisign-style and EURid regional fixtures via parser_tests.rs; IPv4/IPv6 extraction and dedupe. * routes::whois::parser::extract_ips_from_raw, parse_eu_whois, parse_generic_whois exposed as pub(crate) for testing seams. * routes::asn::parser - RIPEstat fixtures covering RIR mapping, holder/description fallbacks, contacts chain, ARIN address builder, PeeringDB extraction, date fallbacks. Split across parser_tests.rs and parser_contacts_tests.rs to honour the 250-line cap. * routes::asn::helpers - build_arin_address, extract_created, extract_last_modified with field-priority fixtures. * routes::lookup - handle_lookup unknown-input branch returns 400 with documented JSON payload via an extracted unknown_query_response helper. * routes::auth - is_authenticated / verify_pin::generate_session_id covers open access, missing creds, active/invalid cookie, x-pin header. * state - sliding-window rate limiter: per-IP isolation, budget exhaustion, window eviction, garbage collection. Adds a make_test_state helper that builds an AppState with a real ServerConfig (no env loading required). Frontend coverage (cargo test -p frontend, +23 tests, no new framework): * types_tests - camelCase serde round-trips for WhoisData, IpData (full + minimal), AsnData; rejects unknown tag. * whois_and_navigation_helpers - format_date RFC3339 / simple-Z / fallback branches; get_registrar_fn against vCard-shape fixtures including missing fn, empty inner array, non-array payloads. All tests are host-runnable under cargo test --workspace; no live network/DNS calls, no wiremock, no wasm-bindgen-test, no new dependency. CI fmt/clippy gates were not added because existing master code fails both; per-file rustfmt --check and clippy audit introduced zero new warnings on the touched files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds hermetic unit tests for the highest-risk pure logic in
studio2201/trace. All tests are host-runnable undercargo test --workspace; no live network/DNS calls, no wiremock, nowasm-bindgen-test, no new framework dependency.Backend (
cargo test -p backend): 65 new testsservices::query::detect_query_typeunknownclassification across CIDR, brackets, IPv4-out-of-range, IPv6 bracket/CIDR, leading-AScase insensitivity,:-without-., numeric-vs-domain edge cases.routes::whois::parser(newparser_tests.rs)host/dnslines. Inner helpers exposed aspub(crate)as a small testability seam.routes::asn::parser(newparser_tests.rs+parser_contacts_tests.rs)RIPE/ARIN/APNIC/LACNIC/AFRINIC/Unknown), holder/description fallback chain, email/abuse fallback chain, ARIN address builder, remarks-as-address fallback, PeeringDB website/traffic-ratio, date fallback chain. Split across two files to honour the 250-line cap.routes::asn::helpersbuild_arin_address,extract_created,extract_last_modifiedfield-priority fixtures.routes::lookup::handle_lookupunknown_query_responsehelper.routes::auth::is_authenticated/verify_pin::generate_session_idx-pinheader match/mismatch. Session ID is 32 hex chars and differs across calls.state::AppState::check_rate_limitandclean_old_rate_limitsmake_test_statehelper that constructs anAppStatewith a realServerConfigwithout touching environment.Frontend (
cargo test -p frontend): 23 new teststypes(newtypes_tests.rs)LookupResponse::Whois/Ip(full + minimal) /Asn; rejects unknowntypetag.whois_and_navigation_helpers(added inlinemod tests)format_dateover RFC3339, simple-Z, fallback separator, passthrough;get_registrar_fnover fn-present, first-fn-wins, fn-missing, empty inner array, non-array payloads.Validation
The diff is 1539 insertions across 15 files (4 new files, 11 modified); no production-logic changes outside the
pub(crate)seam on threeparserhelpers and an extractedunknown_query_responsetestability helper inlookup.rs.CI gates
Deliberately not added. Existing master code fails
cargo fmt --all -- --checkand triggers clippy warnings (collapsible_if,needless_borrows_for_generic_args) inbackend/src/bin/sh/data.rsandbackend/tests/container_smoke.rs. Adding either as a strict gate would block this PR and every subsequent PR until those are fixed in a separate change.Limitations
whois_lookup,try_ip_lookup,fetch_asn_datahappy paths,verify_pinlockout behaviour, the smoke tests) remain uncovered; testing them would require a wiremock/server fixture or amockito/httpmock-class dependency, both of which violate the "no new framework" rule. Refactoring those code paths into testable seams would be a non-trivial change and is out of scope here.get_query_param,get_hash,scroll_to_elementdepend onweb_sys::window()which isNoneon the host; left untested.Staterate-limiter tests useDuration::from_millis(1)windows with sleeps, so timestamps are not exact but the eviction contract is verified.