Skip to content

test: add comprehensive tests for capture module#4

Merged
kwschulz merged 7 commits into
mainfrom
feat/increase-coverage
Jan 30, 2026
Merged

test: add comprehensive tests for capture module#4
kwschulz merged 7 commits into
mainfrom
feat/increase-coverage

Conversation

@kwschulz
Copy link
Copy Markdown
Contributor

Summary

Add comprehensive tests for previously uncovered code to increase coverage towards 82%.

New Test Files

  • test_deps.py: Tests for check_playwright, check_browser_installed, install_browser, install_playwright, install_browser_deps with subprocess mocking
  • test_connectivity.py: Tests for check_device_connectivity and check_basic_auth with urllib mocking
  • test_har_processing.py: Tests for filter_and_compress_har and _add_capture_metadata
  • test_main_entry.py: Tests for __main__.py entry point

Coverage Improvements (unit tests only)

File Before After
capture/deps.py 43% 100%
capture/connectivity.py 22% 100%
capture/browser.py 53% 75%

Test Count

  • Before: 506 tests
  • After: 571 tests (+65 new tests)

Combined coverage (unit + integration) should reach ~80%+.

🤖 Generated with Claude Code

Add tests for previously uncovered code to reach 82% coverage:

- test_deps.py: Tests for check_playwright, check_browser_installed,
  install_browser, install_playwright, install_browser_deps
- test_connectivity.py: Tests for check_device_connectivity and
  check_basic_auth with mocked urllib
- test_har_processing.py: Tests for filter_and_compress_har and
  _add_capture_metadata
- test_main_entry.py: Tests for __main__.py entry point

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 30, 2026

Codecov Report

❌ Patch coverage is 87.80488% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/har_capture/cli/capture.py 52.38% 20 Missing ⚠️

📢 Thoughts on this report? Let us know!

kwschulz and others added 6 commits January 30, 2026 16:30
…oncerns

- Add workflow.py with phase-specific result types:
  - BrowserCheckResult: browser installation check
  - ConnectivityResult: connectivity check
  - AuthResult: authentication detection
  - CaptureResult: capture operation result
- CaptureWorkflowResult composes phase results with convenience properties
- cli/capture.py now thin CLI layer using workflow functions
- Add comprehensive tests for all workflow types and functions (35 tests)

This design makes each type testable in isolation and clarifies
which fields are valid in which phase.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add tests for check_json_fields (nested JSON, lists, redacted values)
- Add tests for check_content (public IPs, MAC addresses, empty content)
- Add tests for validate_har (headers, POST data, gzipped files)
- Add missing assertions for compressed_path/sanitized_path properties
- Total coverage: 81% (up from 78%)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Convert check_json_fields tests to parametrized table
- Convert check_content tests to parametrized table
- Convert validate_har tests to parametrized table
- Add ASCII table comments documenting test cases
- Use # fmt: off/on to preserve column alignment

Follows project's table-driven test pattern from CLAUDE.md.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Covers line 176 in hasher.py - the IPv6 cache lookup path.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tests for _display_header, _display_instructions, _display_results,
and _handle_auth functions. Increases cli/capture.py coverage from
7% to 66%.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add ASCII table documentation for each test group
- Use pytest.mark.parametrize for all test cases
- Add # fmt: off/on to preserve column alignment
- Follows project test conventions from CLAUDE.md

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@kwschulz kwschulz merged commit 44af8ab into main Jan 30, 2026
5 checks passed
@kwschulz kwschulz deleted the feat/increase-coverage branch January 30, 2026 23:02
@kwschulz kwschulz mentioned this pull request Jan 30, 2026
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