Skip to content

test: add pytest coverage for network_toolkit's socket-based tools - #15

Merged
brett-buskirk merged 1 commit into
mainfrom
test/network-toolkit-socket-tools
Jul 4, 2026
Merged

test: add pytest coverage for network_toolkit's socket-based tools#15
brett-buskirk merged 1 commit into
mainfrom
test/network-toolkit-socket-tools

Conversation

@brett-buskirk

Copy link
Copy Markdown
Owner

Summary

Second of three PRs for Phase 4 (v0.4.0 — Tests & quality, part of #5). Adds pytest coverage for
network_toolkit's socket-based tools, which had zero tests before this — only
network_packet_sniffer had a suite (134 tests). SSH tool coverage (ssh/client, ssh/server,
ssh/reverse_shell) needs a materially different fixture (generated keys, real paramiko server) and
lands in a follow-up PR.

New files, matching network_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 — a classic
stale-default-argument gotcha, only observable once something (like pytest's capsys) actually
redirects sys.stdout after the module loads. Fixed by looking it up inside the function instead.

Test plan

  • Full pytest suite: 167 passed (134 existing + 33 new)
  • No stray processes, threads, or bound ports left behind after any test
  • ruff check . — clean
  • mypy src/ — clean

🤖 Generated with Claude Code

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>
@brett-buskirk brett-buskirk self-assigned this Jul 4, 2026
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

✅ AgentGate: Passed

10 files changed  ·  +523 -3 lines

No issues found.

Generated by AgentGate

@brett-buskirk
brett-buskirk merged commit 94b0c1e into main Jul 4, 2026
2 checks passed
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>
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.

1 participant