Skip to content

test(node): cover resolve_config three-layer merge and invariants - #365

Merged
thiras merged 1 commit into
mainfrom
test/config-resolution
Apr 30, 2026
Merged

thiras merged 1 commit into
mainfrom
test/config-resolution

Conversation

@thiras

@thiras thiras commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Add 31 unit tests inside crates/node/src/config/mod.rs::tests covering
the previously untested paths through resolve_config and its per-section
helpers (resolve_identity, resolve_network, resolve_blockchain,
resolve_cache, resolve_payment, resolve_observability,
resolve_gossip). The integration test at
crates/node/tests/config_validate.rs is left untouched.

Closes #217.

Cases covered

  • CLI overrides file for every helper:
    • resolve_identity_cli_region_overrides_file
    • resolve_network_cli_bind_port_overrides_file
    • resolve_blockchain_cli_rpc_url_overrides_file
    • resolve_cache_cli_cache_dir_overrides_file_and_expands_tilde (also
      asserts tilde expansion fires)
    • resolve_cache_cli_size_overrides_file_size
    • resolve_payment_cli_rate_overrides_file_rate
    • resolve_observability_cli_log_level_overrides_file
    • resolve_observability_cli_metrics_port_overrides_file
  • File used when CLI omits (one per helper):
    • resolve_identity_falls_back_to_file_when_cli_absent
    • resolve_network_uses_file_when_cli_absent
    • resolve_blockchain_uses_file_rpc_url_when_cli_absent
    • resolve_cache_uses_file_cache_dir_when_cli_absent /
      resolve_cache_uses_file_size_when_cli_absent
    • resolve_payment_uses_file_when_cli_absent
    • resolve_observability_uses_file_log_level_when_cli_absent
  • Defaults fill when both omit — pin every documented default
    constant (DEFAULT_BIND_PORT, DEFAULT_CACHE_SIZE_MB,
    DEFAULT_MAX_BLOB_SIZE_MB, DEFAULT_RATE_PER_MB,
    DEFAULT_METRICS_PORT, DEFAULT_ADMIN_PORT,
    DEFAULT_ANNOUNCE_INTERVAL_SEC, DEFAULT_PEER_TTL_SEC).
  • Tilde expansion through CLI override of cache.cache_dir (in
    resolve_cache_cli_cache_dir_overrides_file_and_expands_tilde).
  • Default config-file path fallback —
    load_file_config_returns_default_when_path_is_none_and_default_absent
    asserts FileConfig::default() is returned when the documented
    default location does not exist. Mutating $HOME is not safe under
    edition 2024 + workspace unsafe_code lints, so the test eprintln-
    skips with a clear message if the local default file happens to
    exist. load_file_config_errors_when_explicit_path_missing,
    load_file_config_reads_and_parses_explicit_path, and
    load_file_config_errors_on_bad_toml cover the explicit-path branches.
  • Required-field-missing errors —
    resolve_blockchain_errors_when_rpc_url_missing,
    _when_payment_channel_address_missing,
    _when_staking_registry_address_missing, plus
    _treats_empty_string_rpc_url_as_missing to lock the
    .filter(|s| !s.is_empty()) guard.
  • Cross-section invariants:
    • resolve_config_errors_when_subscribe_global_set_without_region
      drives ensure_region_when_publishing_global end-to-end.
    • resolve_config_errors_when_bind_port_equals_metrics_port drives
      validate_port_layout end-to-end. The full per-port matrix
      (bind=metrics, bind=admin, metrics=admin, both-zero, etc.) is
      already covered at the helper level by pre-existing tests.
  • Cache mutex —
    resolve_config_errors_when_origin_url_and_path_both_set confirms
    the resolver enforces the (Some, Some) rejection at startup, not
    only later in runtime/mod.rs.

End-to-end happy path is exercised by
resolve_config_end_to_end_three_layer_merge, which writes a TOML
fixture, sets --bind-port on the CLI, and asserts the merged result
shows CLI > file > default for representative fields across all seven
sections.

Test plan

  • cargo fmt -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo nextest run -p decdn-node config::tests — 103 passed
  • cargo nextest run -p decdn-node — 165 passed, 0 skipped
  • pre-commit hooks (rustfmt + clippy + cargo-deny) all pass

Add 31 unit tests inside `crates/node/src/config/mod.rs::tests` covering
the previously untested merge precedence, default-fallback, tilde
expansion, required-field, and cross-section invariant paths exercised
by `resolve_config` and its per-section helpers.

Cases added:
- CLI > file precedence for every helper (identity.region,
  network.bind_port, blockchain.rpc_url, cache.cache_dir [+tilde],
  cache size knobs, payment.rate_per_mb, observability.log_level/
  metrics_port).
- File-only fallback for each helper.
- Default constants (`DEFAULT_BIND_PORT`, `DEFAULT_CACHE_SIZE_MB`,
  `DEFAULT_MAX_BLOB_SIZE_MB`, `DEFAULT_RATE_PER_MB`,
  `DEFAULT_METRICS_PORT`, `DEFAULT_ADMIN_PORT`,
  `DEFAULT_ANNOUNCE_INTERVAL_SEC`, `DEFAULT_PEER_TTL_SEC`).
- `cache.cache_dir` tilde expansion fires through CLI override.
- `load_file_config` happy path, explicit-missing-error, bad-TOML-error,
  and the implicit-None branch when no default config exists.
- Required-field-missing diagnostics for `rpc_url`,
  `payment_channel_address`, and `staking_registry_address`.
- End-to-end `resolve_config` runs covering the global/region invariant,
  port-collision invariant, and origin_url/origin_path mutual exclusion.

The integration test at `crates/node/tests/config_validate.rs` is left
untouched.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Closes #217
Copilot AI review requested due to automatic review settings April 30, 2026 20:15

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive suite of unit tests for the configuration resolution logic in crates/node/src/config/mod.rs, covering the merging of CLI arguments, file-based configurations, and default values across various modules. Feedback was provided regarding a test that relies on the local filesystem state (the user's home directory), which may lead to non-deterministic results across different environments; isolating these tests using temporary directories is recommended.

Comment thread crates/node/src/config/mod.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds unit-test coverage for the node config resolver (resolve_config) and its per-section resolve_* helpers, focusing on three-layer precedence (CLI > file > defaults) and key invariants/errors in the startup config path (issue #217).

Changes:

  • Introduces helper constructors for “empty” CLI args and full RunArgs assembly inside config::tests.
  • Adds extensive unit tests covering CLI-vs-file precedence, default fallbacks, required-field errors, and end-to-end resolve_config invariants.
  • Adds targeted tests for load_file_config explicit-path parsing/error branches and the implicit default-path fallback behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/node/src/config/mod.rs Resolved
Comment thread crates/node/src/config/mod.rs Resolved
@thiras
thiras merged commit 45070fd into main Apr 30, 2026
14 checks passed
@thiras
thiras deleted the test/config-resolution branch April 30, 2026 20:43
thiras added a commit that referenced this pull request Apr 30, 2026
Resolves conflicts with PRs #363/#364/#365/#366 that landed on main while
this branch was in review. Conflict resolution:

- crates/node/Cargo.toml: keep both new dev-deps (nix from this branch
  for SIGHUP integration tests, wiremock from #366 for the rpc-watchdog
  test).
- crates/node/src/runtime/mod.rs: union the test-module clippy allows
  ([unwrap_used, expect_used, panic, indexing_slicing]); keep both new
  test bodies (rpc_watchdog_tracks_endpoint_transitions from #366 plus
  shutdown_streams_recv_resolves_on_sigterm from this branch).
- Test fixtures across config/mod.rs, runtime/reload.rs, and
  tests/sighup_signal.rs gained the rpc_watchdog_interval_sec field
  (Option::None for FileConfig literals; literal 30u64 for ResolvedBlockchain).

Verified post-merge: cargo fmt --check, cargo clippy --workspace
--all-targets -- -D warnings, cargo nextest run -p decdn-node (179/179),
RUSTDOCFLAGS=-D warnings cargo doc --workspace --no-deps --document-private-items,
all clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No test coverage for config resolution three-layer merge logic

2 participants