Skip to content

Conversation

@sanity
Copy link
Collaborator

@sanity sanity commented Dec 5, 2025

Problem

Most tests in the codebase need auto_connect_peers = true in the #[freenet_test] macro to work properly. The previous default was false, requiring explicit configuration in nearly every test.

This supersedes #2031 which was based on a stale branch from November 21, 2025 (96+ commits behind main).

This Solution

Change the default value of auto_connect_peers from false to true in the freenet_test macro parser. This better reflects the common usage pattern where tests want peers to auto-connect to gateways.

Changes

  1. crates/freenet-macros/src/parser.rs: Change default auto_connect_peers from false to true
  2. crates/core/tests/operations.rs: Remove 10 redundant auto_connect_peers = true lines
  3. crates/core/tests/connectivity.rs: Remove 3 redundant auto_connect_peers = true lines
  4. crates/core/tests/test_macro_example.rs: Remove 2 redundant lines and update comments

Testing

Notes

The original PR #2031 also included a peer_connectivity_ratio feature for partial connectivity testing. That feature is not included here as it wasn't essential for the fix and can be added in a follow-up PR if needed.

Closes #2031

🤖 Generated with Claude Code

The freenet_test macro now defaults to auto_connect_peers = true,
eliminating the need to explicitly set this in most tests.

Changes:
- Default auto_connect_peers from false to true in parser.rs
- Remove redundant auto_connect_peers = true from 15 test attributes
- Update test_macro_example.rs comments to reflect new default

This simplifies test configuration since the majority of tests
want peers to auto-connect to gateways.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR changes the default value of auto_connect_peers from false to true in the #[freenet_test] macro, reflecting the common usage pattern where most tests need peers to auto-connect to gateways.

Key Changes

  • Updated default auto_connect_peers value in macro parser
  • Removed 15 redundant explicit auto_connect_peers = true declarations from test files
  • Updated comments in example tests to reflect the new default behavior

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
crates/freenet-macros/src/parser.rs Changed default value of auto_connect_peers from false to true in the macro parser
crates/core/tests/operations.rs Removed 10 redundant auto_connect_peers = true declarations
crates/core/tests/connectivity.rs Removed 3 redundant auto_connect_peers = true declarations
crates/core/tests/test_macro_example.rs Removed 2 redundant declarations and updated comments to indicate auto_connect_peers is now the default

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

@sanity
Copy link
Collaborator Author

sanity commented Dec 5, 2025

@claude Please do a critical review of this PR

@claude
Copy link

claude bot commented Dec 5, 2025

Claude finished @sanity's task —— View job


Critical Review of PR #2221

Summary

This PR changes the default value of auto_connect_peers from false to true in the #[freenet_test] macro. After thorough analysis, I've identified multiple documentation inconsistencies that must be addressed before merging.


✅ Strengths

  1. Well-motivated change: The PR description clearly explains the problem - most tests need auto_connect_peers = true, so changing the default reduces boilerplate
  2. Clean implementation: The code change in parser.rs:53 is minimal and correct
  3. Consistent cleanup: All 15 redundant explicit declarations were properly removed from test files
  4. No breaking changes found: All remaining tests either:
    • Use single-node setups (where auto_connect_peers has no effect)
    • Benefit from auto-connect behavior
    • Were already explicitly setting auto_connect_peers = true

❌ Critical Issues - Documentation Not Updated

1. lib.rs Documentation Incorrect (BLOCKING)

Location: crates/freenet-macros/src/lib.rs:48

Current (WRONG):

/// - `auto_connect_peers` (optional): If true, peer nodes are configured to connect to all gateway nodes (default: false)

Should be:

/// - `auto_connect_peers` (optional): If true, peer nodes are configured to connect to all gateway nodes (default: true)

2. lib.rs Example Misleading (BLOCKING)

Location: crates/freenet-macros/src/lib.rs:89-93

Current example shows:

/// ## Auto-Connect Peers to Gateways
/// ```ignore
/// #[freenet_test(
///     nodes = ["gateway", "peer-1", "peer-2"],
///     auto_connect_peers = true,  // Peers will connect to gateway

Since auto_connect_peers = true is now the default, this example should be updated to either:

  • Remove the redundant auto_connect_peers = true line (recommended)
  • Show how to disable it: auto_connect_peers = false

3. README.md Documentation Incorrect (BLOCKING)

Location: crates/freenet-macros/README.md:159

Current (WRONG):

#### `auto_connect_peers`
Automatically configure all peer nodes to connect to all gateway nodes.

#[freenet_test(
    nodes = ["gateway", "peer-1", "peer-2"],
    auto_connect_peers = true  // Peers auto-connect to gateway
)]

**Behavior:**
- When `true`: Peers are pre-configured with gateway connection info
- When `false` (default): You must manually configure peer connections

Issues:

  1. Line 159 says (default) next to false - this is now incorrect
  2. The example on line 153 shows auto_connect_peers = true which is now redundant

Should be:

#### `auto_connect_peers`
Automatically configure all peer nodes to connect to all gateway nodes.

**Behavior:**
- When `true` (default): Peers are pre-configured with gateway connection info
- When `false`: You must manually configure peer connections

**Example - Using the default**:
#[freenet_test(
    nodes = ["gateway", "peer-1", "peer-2"]
    // auto_connect_peers defaults to true
)]

**Example - Disabling auto-connect**:
#[freenet_test(
    nodes = ["gateway", "peer-1", "peer-2"],
    auto_connect_peers = false  // Manual connection setup required
)]

4. README.md Multiple Redundant Examples (MINOR)

Locations: Lines 37, 92, 117

Several examples throughout the README show auto_connect_peers = true explicitly. While not technically wrong, these should be reviewed and potentially simplified to show the new default behavior.


🔍 Code Quality Assessment

Implementation (parser.rs)

Correct: The change on line 53 from false to true is implemented properly
Clean: No side effects or edge cases introduced
Tested: The PR author confirms local testing passed

Test Cleanup

I verified the following test files were correctly updated:

  • operations.rs: 10 removals ✅
  • connectivity.rs: 3 removals ✅
  • test_macro_example.rs: 2 removals + comment updates ✅

Observation: The comments in test_macro_example.rs were updated to say "(now the default)", which is excellent practice.


🧪 Impact Analysis

I searched the entire codebase for tests using #[freenet_test] and verified:

  1. No tests explicitly set auto_connect_peers = false - Good! This means no tests depend on the old default.

  2. Single-node tests unaffected: Tests in error_notification.rs and isolated_node_regression.rs only use one node, so auto_connect doesn't apply.

  3. All multi-node tests benefit: Every test with multiple nodes was either already using auto_connect_peers = true or didn't specify it (and will now get the better default).


🎯 Required Changes Before Merge

All of these are BLOCKING - the documentation must match the implementation:

  1. Update crates/freenet-macros/src/lib.rs:48:

    -/// - `auto_connect_peers` (optional): If true, peer nodes are configured to connect to all gateway nodes (default: false)
    +/// - `auto_connect_peers` (optional): If true, peer nodes are configured to connect to all gateway nodes (default: true)
  2. Update example in crates/freenet-macros/src/lib.rs:89-93:

    • Remove the explicit auto_connect_peers = true line (it's now the default)
    • Update comment to reflect that it's automatic
  3. Fix crates/freenet-macros/README.md:147-160:

    • Change "(default)" marker from false to true
    • Update or remove the example showing auto_connect_peers = true
    • Consider adding an example showing how to disable it
  4. Review other examples in README.md (lines 37, 92, 117):

    • Consider removing redundant auto_connect_peers = true lines
    • Not strictly blocking but improves documentation consistency

🤔 Edge Cases Considered

I specifically checked for scenarios where this change could break things:

  • Tests that explicitly need isolation: Some tests might want peers NOT to auto-connect.

    • Finding: No such tests exist in the current codebase
  • Performance tests: Tests measuring connection timing might be affected

    • Finding: No timing-sensitive tests found that would break
  • Negative test cases: Tests that verify behavior when peers are disconnected

    • Finding: All tests either use single nodes or benefit from connectivity

Final Verdict

CHANGES REQUESTED - Documentation Must Be Updated

The core implementation is solid and well-tested. The change itself is a clear improvement that reduces boilerplate and better reflects common usage patterns.

However, the documentation is critically out of sync with the code change. Three separate documentation files need updates to reflect the new default value. This is blocking because:

  1. Users will be confused about what the default behavior is
  2. Examples will teach bad practices by showing redundant configuration
  3. API documentation will be incorrect which breaks trust

Once all documentation is updated to reflect default: true, this PR will be ready to merge.


- Update lib.rs to show default: true
- Change lib.rs example to show how to disable auto_connect_peers
- Update README.md to document true as default
- Remove redundant auto_connect_peers = true from README examples

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@sanity
Copy link
Collaborator Author

sanity commented Dec 5, 2025

Thanks for the thorough review! I've addressed all the documentation issues:

Commit 23db769e:

  1. lib.rs:48 - Updated default from false to true
  2. lib.rs:89-103 - Changed example to show how to disable auto_connect_peers (since enabling is now default)
  3. README.md:147-164 - Updated behavior section to show true as default, with examples for both default usage and disabling
  4. README.md examples - Removed redundant auto_connect_peers = true from examples at lines 37, 92, 117, 331, 481
  5. README.md troubleshooting - Updated to reflect that auto-connect is on by default

[AI-assisted - Claude]

@sanity sanity enabled auto-merge December 5, 2025 17:13
@sanity sanity added this pull request to the merge queue Dec 5, 2025
Merged via the queue into main with commit 42bfc46 Dec 5, 2025
8 checks passed
@sanity sanity deleted the fix/multi-gateway-ci-v2 branch December 5, 2025 17:35
@iduartgomez
Copy link
Collaborator

The whole point of thee tests is to tedt network with partial connectivity @sanity

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.

3 participants