Skip to content

Cover the untested error branches in the deserialise paths #49

Description

@FAZuH

Part of the whole-repo test-suite audit (2026-09-30). Test error paths, not just happy paths: every branch that can fail needs a test.

What to build

Negative tests for every reject path in the three deserialise/parse surfaces, and a test that pins the on-disk state format.

Findings

crates/natmap/src/models.rs and crates/natmap/tests/model.rs contain no unwrap_err or is_err at all. Untested:

  1. Unknown "proto":"xyz" deserialising into TransportProtocol (models.rs:30,119,248,268). The rejecting arm lives at crates/lab-lib/src/protocol.rs:34 and has only a doc test.
  2. Missing required fields: DnatRequest.ext_ip/int_ip/ports, SnatRequest.ext_if, HairpinRequest.ext_ip, RProxyLocalConfig.template, ForwardRemoteConfig.port.
  3. u16 out of range: ForwardLocalConfig.port, ForwardRemoteConfig.port, ext_ports entries, DockerAddMapRequest.host_port/container_port.
  4. u32 out of range: PolicyRouteConfig.table and its request twin.
  5. DaemonState (models.rs:338) state-file compatibility. policy_routes carries #[serde(default)] at :348; mapping, dnats, snats and hairpins do not. A state file written before policy_routes existed loads; a file missing any other top-level key hard-errors. This is a real on-disk format at /var/lib/natmap/state.json, and the forward path is untested.

crates/auto-discover/src/config.rs: the entire YAML surface is untested. Both existing tests (:458, :485) construct DiscoveryConfig structs directly; neither deserialises YAML. Untested: an unknown type: value, a missing node.name, a missing required type:, a missing template, and a port out of range.

src/cmd/dns_parser.rs:

  • :52 caps[2].parse().unwrap_or(1): the TTL-parse-failure fallback to 1 is untested.
  • :146 parts[0][1..].parse().unwrap_or(0): a non-numeric TLSA port label (_abc._tcp.mail) is untested.
  • :170 TXT.captures_iter on an unterminated quote ("abc, no closing ") is untested. parse_txt_data_no_quotes (:501) covers zero quotes, not a broken one.

Acceptance criteria

  • Every listed branch has a test that fails when the branch is removed
  • DaemonState compatibility is pinned: a state file with and without policy_routes both load, and a file missing a required top-level key is rejected
  • The auto_discover YAML surface has at least one test that goes through serde_yaml
  • Test data is realistic (unicode, empty strings, boundary ports), per the guidelines
  • Test names follow standards.md §3.6
  • cargo test -p lab-ops_natmap, cargo test -p lab-ops_auto-discover, cargo test -p lab-ops --lib pass

Blocked by

None (can start immediately).

Also: docs/dev/testing.md:53 undercounts the suite by roughly 4× (it says 88 inline unit tests; the real figure is 421 tests). Correct it while in this file.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified, ready for an AFK agent

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions