Skip to content

tests: raise sdk-python coverage from 73% to 100%#1

Merged
TeoSlayer merged 1 commit into
mainfrom
add-test-coverage
May 27, 2026
Merged

tests: raise sdk-python coverage from 73% to 100%#1
TeoSlayer merged 1 commit into
mainfrom
add-test-coverage

Conversation

@TeoSlayer
Copy link
Copy Markdown
Contributor

Summary

Adds four new test files that bring the four production modules in pilotprotocol/ from 73% → 100% line coverage. No production code was modified.

File Stmts Before After
pilotprotocol/__init__.py 7 71% 100%
pilotprotocol/_runtime.py 216 83% 100%
pilotprotocol/cli.py 15 0% 100%
pilotprotocol/client.py 413 71% 100%
TOTAL 651 73% 100%

Test count: 124 → 204 passing (90 skipped fuzz tests unchanged).

New test files

  • tests/test_cli.py (8 tests) — every console-script entry point (run_pilotctl, run_daemon, run_gateway, run_updater) with subprocess.call stubbed so no real binaries run. Verifies argv passthrough, non-zero exit propagation, and that the binary list matches pyproject.toml console_scripts.
  • tests/test_services.py (31 tests) — the high-level Driver helpers send_message (port 1001 data-exchange framing), send_file (TypeFile payload layout), publish_event (port 1002 subscribe-then-publish), and subscribe_event (frame parsing + callback mode + every short-read termination + clean EOF + unhandled-error propagation). Uses a FakeConn that records writes and serves canned reads — never touches libpilot or a daemon.
  • tests/test_runtime_edges.py (32 tests) — the seeder edge cases the main test file skipped: ETXTBSY skip + reraise of other OSError, atomic-install cleanup on os.replace failure, _ensure_default_config race with another writer, _daemon_running config + socket-close failure paths, _runtime_root PILOT_HOME both branches, runtime_binary / runtime_library wheel fallbacks, _semver_tuple parser edges, ensure_runtime_seeded cache + force=True bypass.
  • tests/test_client_edges.py (9 tests) — _find_library ~/.pilot/bin branch, _void_ptr_to_bytes + _free helpers, Conn.read size validation (<= 0 returns empty without an FFI call, > 16MB capped to 16MB), and the __version__ PackageNotFoundError fallback to "unknown".

Approach

All libpilot calls are mocked at the ctypes.CDLL boundary via the same FakeLib pattern the existing test_client.py uses. Service helpers are tested by replacing Driver.dial with a fake that returns a FakeConn, so the wire-format assertions can run without a socket or shared library. The runtime seeder tests redirect PILOT_HOME and _pkg_bin_dir into a tmpdir so no ~/.pilot/ mutation happens on the host.

Test plan

  • pytest --cov=pilotprotocol --cov-report=term reports 100% on all four modules
  • All 204 tests pass, 0 regressions (90 pre-existing skips unchanged)
  • No production code changed (git diff main -- pilotprotocol/ is empty)
  • CI workflow at .github/workflows/ci.yml already runs pytest --cov=pilotprotocol so this PR automatically uploads the new coverage to Codecov

Adds four new test files covering the modules and branches the existing
suite skipped:

- tests/test_cli.py: every console-script entry point (run_pilotctl,
  run_daemon, run_gateway, run_updater), with subprocess.call stubbed
  so no real binaries run.
- tests/test_services.py: the high-level Driver helpers send_message,
  send_file, publish_event, subscribe_event. Verifies wire framing,
  hostname-resolution branches, ACK-read failure handling, and the
  three terminal cases of subscribe_event (clean EOF, error swallow,
  unhandled propagation).
- tests/test_runtime_edges.py: 5-state seeder ETXTBSY skip path,
  atomic-install cleanup, _ensure_default_config race, _daemon_running
  socket-close swallow, and the runtime_binary / runtime_library
  wheel fallbacks.
- tests/test_client_edges.py: _find_library ~/.pilot/bin branch,
  _void_ptr_to_bytes / _free helpers, Conn.read size <= 0 + 16MB cap,
  and the __version__ PackageNotFoundError fallback.

All four production modules now report 100% line coverage. Test count
goes from 124 to 204 passing (90 still skipped from the pre-existing
fuzz suite). No production code was modified.
@TeoSlayer TeoSlayer merged commit 93584ea into main May 27, 2026
1 check passed
@TeoSlayer TeoSlayer deleted the add-test-coverage branch May 27, 2026 23:51
@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

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.

2 participants