Skip to content

Add comprehensive tests for tree size validation#13

Open
0x687931 wants to merge 109 commits intokevinmcaleer:mainfrom
0x687931:feature/test-tree-limits
Open

Add comprehensive tests for tree size validation#13
0x687931 wants to merge 109 commits intokevinmcaleer:mainfrom
0x687931:feature/test-tree-limits

Conversation

@0x687931
Copy link
Copy Markdown

Summary

Implements comprehensive test suite for fetch_tree() tree size limit validation as specified in Fix #2. Tests validate that the OTA client properly rejects trees that exceed configured size or file count limits.

Test Coverage

Core Test Cases (as required):

  1. test_fetch_tree_normal_size: 100 files under 200-file limit → succeeds
  2. test_fetch_tree_too_many_files: 500 files over 200-file limit → raises OTAError with helpful message
  3. test_fetch_tree_size_limit_via_header: Large Content-Length header → raises OTAError before parsing
  4. test_fetch_tree_custom_limits: Custom config limits (50 files) → properly enforced
  5. test_fetch_tree_helpful_error_message: Error messages include actual count, limit, and guidance

Additional Edge Cases:

  • test_fetch_tree_custom_limits_passes: Custom limits allow valid trees through
  • test_fetch_tree_default_limits: Default limits work when config doesn't specify
  • test_fetch_tree_empty_tree: Empty trees handled correctly
  • test_fetch_tree_at_exact_limit: Trees at exact limit succeed
  • test_fetch_tree_one_over_limit: Trees one file over limit fail

Implementation Notes

  • Follows established test patterns from test_path_filtering.py and test_verify.py
  • Uses monkeypatch for dependency isolation (no real network calls)
  • Mock response objects (Resp, RespWithContentLength) simulate GitHub API responses
  • Validates both error detection and helpful error messaging
  • Tests both file count limits (max_tree_files) and byte size limits (max_tree_bytes)

Test File

  • Location: /Users/am/Documents/GitHub/ota/tests/test_tree_limits.py
  • Lines: 370
  • Test count: 10 comprehensive test functions

Dependencies

These tests expect the fetch_tree() method to be updated with validation logic that:

  1. Checks Content-Length header against max_tree_bytes config (if set)
  2. Parses tree response and validates file count against max_tree_files config
  3. Raises OTAError with helpful messages including actual values, limits, and guidance

Ready to run with pytest tests/test_tree_limits.py once validation is implemented.

Generated with Claude Code

…dater-functionality

Refactor MicroPython OTA updater with release manifests and verification
…set-creation

feat: support manifestless updates using Git tree
…or-ota-client

Add dual channel OTA client with verification and rollback
…re-download

Add startup rollback checks and manifest signing
…ort-error

Add MicroPython compatibility flag and drop future annotations
…for-pico-w

Add MicroPython os.path shim and test instructions
…use-path-helper-xp43dw

Refactor path handling in OTA client
…use-path-helper

Refactor path handling in OTA client
…_client.py

Handle non-200 responses in OTA JSON fetch
…n-_get

feat: support configurable HTTP timeouts
…put-options

Clarify JSON configuration in README
…or-micropython

Handle MicroPython timeout semantics
0x687931 and others added 30 commits September 6, 2025 12:45
…le-for-updates

feat: allow forcing updates and clarify config
…nore-.git-entries

Exclude Git metadata from manifest
…ion-error

chore: add pyproject for packaging
…ease-version

Log release version when updating stable manifest
…lper-method

feat: shorten debug commit hashes
…and-usage

Centralize path filtering across OTA operations
…handling-functions

Add tests for path filtering and candidate selection
…h-validation

Add path normalization to prevent traversal in OTA paths
…/ignore-lists

Normalize OTA allow/ignore path handling
…ltering

docs: document path filtering semantics
…gging

Add info-level messaging and refine debug output
…-normalize-paths

Normalize path checks and improve OTA error handling
…cks-in-ota.py

Log filters and restrict manifest to allowed files
  The OTA updater is now version 3.0.0 with production-ready delta updates and multi-connectivity framework. All critical
  reliability improvements from the IoT expert review have been implemented, tested, and documented. The system is optimized for
   harsh remote deployments including solar-powered sensors, off-grid monitoring stations, and battery-powered IoT devices.
Implements test suite for fetch_tree() tree size limits validation:

- test_fetch_tree_normal_size: Validates 100 files under limit passes
- test_fetch_tree_too_many_files: Validates 500 files over limit raises OTAError
- test_fetch_tree_size_limit_via_header: Validates Content-Length checking
- test_fetch_tree_custom_limits: Validates custom config limits are respected
- test_fetch_tree_helpful_error_message: Ensures error messages include guidance
- Additional edge case tests: empty trees, exact limits, one-over-limit

Tests follow established patterns from tests/test_path_filtering.py and
tests/test_verify.py, using monkeypatch for dependency isolation and
pytest.raises for error validation.

Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <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.

Update on new release?

1 participant