Repository navigation
refactor: network seam for protocol tests - #3
Merged
Merged
Conversation
Clock replaces the two now_ms functions. The app reads the system clock; tests get one that follows tokio's paused time, so waits and the wall clock move together. The nudge rate limit uses tokio's Instant for the same reason. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The engine reaches its peer through net::Network, Conn and the two stream types instead of iroh directly. Building the endpoint, the LAN filter, mDNS and advertising the name move to net.rs. Core::start_with keeps its signature and calls start_on, which takes the network and the clock, so tests can run on another network. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
net::Lan is a second adapter for the network port, compiled only for tests: nodes discover each other by name, connect at once, and stream through channels, with QUIC's abrupt close. Protocol tests run two engines on it with tokio's paused clock; the first pairs two peers and sends a message each way, in milliseconds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pairing: one code on both screens, declined, timing out after two minutes, cancelled by the asker, a trusted key paired again without a prompt, and someone already paired refusing a third person. Sessions: when the dialer loses its connection and the other side doesn't notice, the new session replaces the old one, and ending the old one leaves the new one alone (the generation check; the test fails without it). The in-memory network gets Lan::drop_out for this, and closes a connection when the last handle to one side is dropped, as QUIC does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The dialer's session runs inside dial_loop, which shutdown aborts. The session's writer and file tasks were only stopped at its normal end, so after a shutdown the file fetcher waited forever, holding the engine and its log open. They now stop when the session is dropped, too. Found by the protocol tests: restarting the app within one process left the old one's database open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Catch-up after one side was off, with receipts surviving the restart; sessions dropping and coming back three times without a message shown twice; a peer restoring an old backup getting the rest again, with seen going back down to what it had; and a vanishing message that waits an hour unseen, then goes from both sides five seconds after it's seen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A peer played frame by frame stands in for other builds: one from before 0.6 gets neither vanishing messages nor files, one on 0.6 gets vanishing messages but not files, and a frame from a newer build is skipped without ending the session. Files: a picture arrives after its message; a transfer resumes from the first byte it lacks; a file that doesn't match its hash isn't kept; one deleted on its way isn't kept either; and one the sender no longer has ends up gone on both sides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It now checks what only the real network can: mDNS discovery with names, pairing over QUIC, a message each way, a restart that redials and catches up, and a picture on a stream of its own. Receipts, reactions, edits, typing, nudges, away, clearing, do not disturb, vanishing messages and missing files are covered by the protocol tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
README's layout lists net.rs, clock.rs and the protocol tests. AGENTS.md asks for a protocol test with each protocol change. GLOSSARY.md adds peer, pairing, session and catch-up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
The engine reaches its peer through a network port instead of using iroh directly. That lets the session protocol run in tests on an in-memory network, with paused time.
Each port type is an enum with one variant per adapter. The memory variant compiles only for tests.
Found and fixed: at shutdown, the dialer's session was dropped partway through. Its file fetcher kept running and held the engine and its log open. The session's tasks now stop however the session ends (
fix:commit).two_peers.rsshrinks to a smoke test of what only the real network can check: mDNS discovery, pairing over QUIC, a message each way, a restart that redials and catches up, and a picture.GLOSSARY.mdadds peer, pairing, session and catch-up.Evidence
Before: the only engine test was
two_peers: one sequential scenario on real mDNS and QUIC, taking about 10 s.After: 20 protocol tests run in about 0.5 s, and
two_peerstakes about 5 s. The new tests cover:The session replacement test fails when the
generationcheck is removed:The lost-history test failed about half the time before the fix, depending on which randomly keyed side dialled. It passed 10 out of 10 runs after.
Every commit passes
cargo fmt --check,clippy -D warningsandcargo teston its own (checked one commit at a time on Windows).bun run checkpasses.Merge Danger
Door: two-way
There's no wire or schema change. The app's network code moved behind the port, but its behaviour is unchanged:
two_peerspasses on real iroh.Blast Radius: connections
Everything that dials, accepts, discovers or streams now goes through
net.rs. CI's macOS job skips the mDNS test, so on macOS only the protocol tests cover this. A quick manual check of pairing and a picture between a Mac and Windows before the next release would be worthwhile.🤖 Generated with Claude Code