test: add pytest coverage for network_toolkit's socket-based tools - #15
Merged
Conversation
New test files, matching packet-sniffer's existing flat tests/ convention and loopback-only/no-root-required style: test_common.py, test_netcat.py, test_tcp_client.py, test_tcp_server.py, test_tcp_proxy.py, test_udp_client.py, test_cli.py. Found and fixed one real bug while writing the cli.py tests: _print_usage() captured sys.stdout in a default argument at import time instead of looking it up per call, so it silently bypassed any stdout redirection (a classic stale-default-argument gotcha; only observable once something -- like pytest's capsys -- actually redirects sys.stdout after the module loads). Verified: full suite green (167 tests: 134 existing + 33 new); no stray processes, threads, or bound ports left behind after any test; ruff/mypy clean on the new files. Part of #5 -- SSH tool coverage lands in a follow-up PR. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
✅ AgentGate: Passed10 files changed · +523 -3 lines No issues found. Generated by AgentGate |
3 tasks
brett-buskirk
added a commit
that referenced
this pull request
Jul 4, 2026
…nflicts PRs #14 and #15 landed on main while this branch was open. Both this branch and #15 edited the same CHANGELOG.md/ROADMAP.md lines (the "SSH tool coverage lands in a follow-up PR" placeholder #15 left, which this PR is that follow-up) -- resolved by keeping this branch's fuller SSH-coverage description and checking off the ROADMAP box.
brett-buskirk
added a commit
that referenced
this pull request
Jul 4, 2026
Third of three PRs for Phase 4 (v0.4.0 -- Tests & quality, #5). Adds tests/conftest.py (a shared run_ssh_session fixture: generates a throwaway RSA host key, spins up a real network_toolkit.ssh.server.Server on loopback, and drives it with a per-test controller callback) plus: - test_ssh_client.py: ssh/server.py's own Server class doesn't implement check_channel_exec_request (it's built for the reverse-shell pairing, not SSHClient.exec_command()), so this uses a small dedicated exec-capable ServerInterface to exercise ssh_command()'s real connect + exec_command + output-reading behavior end-to-end, plus main()'s prompt-wiring. - test_ssh_server.py: Server's auth/channel-request logic directly, plus a real paramiko client authenticating through the shared fixture. - test_ssh_reverse_shell.py: a full controller/agent round trip against the real ssh/server.py Server (the actual intended pairing), plus main()'s prompt-wiring. Verified: full suite green (146 tests: 134 existing + 12 new -- this branch predates PR #15's socket-tool tests, so the eventual combined total across all three PRs will be 179); no leftover key files, lingering listener sockets, or stray processes after any test; ruff clean on the new files (mypy is scoped to src/ only per this project's convention, unaffected by test-only changes). Part of #5 Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Closed
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
Second of three PRs for Phase 4 (v0.4.0 — Tests & quality, part of #5). Adds
pytestcoverage fornetwork_toolkit's socket-based tools, which had zero tests before this — onlynetwork_packet_snifferhad a suite (134 tests). SSH tool coverage (ssh/client,ssh/server,ssh/reverse_shell) needs a materially different fixture (generated keys, real paramiko server) andlands in a follow-up PR.
New files, matching
network_packet_sniffer's existing flattests/convention andloopback-only/no-root-required style:
test_common.py,test_netcat.py,test_tcp_client.py,test_tcp_server.py,test_tcp_proxy.py,test_udp_client.py,test_cli.py.Found and fixed one real bug while writing the
cli.pytests:_print_usage()capturedsys.stdoutin a default argument at import time instead of looking it up per call — a classicstale-default-argument gotcha, only observable once something (like pytest's
capsys) actuallyredirects
sys.stdoutafter the module loads. Fixed by looking it up inside the function instead.Test plan
pytestsuite: 167 passed (134 existing + 33 new)ruff check .— cleanmypy src/— clean🤖 Generated with Claude Code