Skip to content

Conversation

@sanity
Copy link
Collaborator

@sanity sanity commented Dec 10, 2025

Problem

The crates/core/src/node module had low unit test coverage, particularly mod.rs at 3.34% and network_bridge.rs at 80.37%. This makes it harder to catch regressions and understand expected behavior of core node components.

This Solution

Add comprehensive unit tests focusing on testable pure logic without requiring complex network mocking:

Coverage Improvements

File Before After Improvement
node/mod.rs 3.34% 23.19% +19.85%
node/network_bridge.rs 80.37% 89.05% +8.68%
node/network_bridge/priority_select.rs 60.45% 76.87% +16.42%

Tests Added

node/mod.rs:

  • PeerId tests (equality based on address, ordering, hashing, serialization, display)
  • InitPeerNode construction tests
  • is_operation_completed function with various error conditions
  • Hostname resolution tests (including edge cases like trailing dots, invalid ports)

node/network_bridge.rs:

  • ConnectionError variant tests (clone, display, debug, from conversions)
  • Channel notification flow tests
  • Channel capacity under load tests
  • Sender cloning behavior tests

Files Still Needing Coverage

The following files have 0% coverage and would benefit from future test work:

  • p2p_impl.rs - Requires network mocking
  • p2p_protoc.rs - Requires libp2p protocol mocking
  • in_memory.rs - Test infrastructure code

These are harder to test in isolation because they involve real network I/O and complex async coordination. The existing integration tests exercise much of this code.

Testing

All 78 node module tests pass:

cargo test --lib 'node::' -- --test-threads=4 test result: ok. 78 passed; 0 failed; 0 ignored 

[AI-assisted - Claude]

Add comprehensive unit tests to improve test coverage: - node/mod.rs: 3.34% → 23.19% (+19.85%) - PeerId tests (equality, ordering, hashing, serialization, display) - InitPeerNode construction tests - is_operation_completed function tests - Hostname resolution tests with edge cases - node/network_bridge.rs: 80.37% → 89.05% (+8.68%) - ConnectionError variant tests (clone, display, debug, from conversions) - Channel notification flow tests - Channel capacity and sender cloning tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
use super::*;

#[test]
fn test_connection_error_clone() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

idk if I fiund much utility in this kind of test tbh

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Any of them or just this one?

@sanity sanity added this pull request to the merge queue Dec 10, 2025
Merged via the queue into main with commit 5243d77 Dec 10, 2025
12 checks passed
@sanity sanity deleted the node-testability branch December 10, 2025 15:01
sanity added a commit that referenced this pull request Dec 10, 2025
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants