Skip to content

SDK bug fixes and test changes; v0.1.18 release#279

Merged
lucaspar merged 17 commits intomasterfrom
lp/sdk-improvements
Apr 30, 2026
Merged

SDK bug fixes and test changes; v0.1.18 release#279
lucaspar merged 17 commits intomasterfrom
lp/sdk-improvements

Conversation

@lucaspar
Copy link
Copy Markdown
Member

SDK bug fixes:

  • HTTP timeout not applied (gateway.py): Client.timeout kwarg was ignored; requests always used default timeout
  • Upload failure with relative local paths (uploads.py): relative paths resolved incorrectly in persistence manager
  • Upload concurrency (uploads.py): sync requests (checksum) blocked the async event loop — offloaded to anyio.to_thread.run_sync
  • Persistence write-error tests: replaced fragile Path.open monkey-patches with chmod permission control

Faster integration tets:

  • pytest-xdist support: added pytest-xdist dependency; split auth fixture into session-scoped client creation + function-scoped auth to avoid responses interception; added xdist groups for RadioHound tests sharing sample data
  • Fail-fast on bad creds: early credential validation in conftest, skips all integration tests if .env missing or invalid

Test quality:

  • File split: test_uploads.py (1400+ lines) split into test_uploads_workflow.py (state machine tests) and test_uploads_persistence.py (persistence tests)
  • Assertion messages added to all bare assert statements across ops tests
  • MagicMock(return_value=...) attribute assignment → .return_value = ... pattern
  • Module-level constants converted to fixtures for safe per-test override under xdist
  • Fixed sleep replaced with polling (0.5s intervals, 30s timeout) in content-identical check
  • @responses.activate decorator → responses fixture injection (pytest-responses pattern)
  • Removed unused imports + loguru placeholder traces

Other:

  • Changelog updated for v0.1.18
  • Network self-signed cert recipe (network/justfile)

lucaspar added 17 commits April 30, 2026 12:16
fix test_load_config_file_found using tmp_path instead of CWD,
convert module-level DRY_RUN/TEST_STATE_PERSISTENCE to fixtures,
remove log.trace placeholders, replace blanket noqa with per-line,
add assertion messages to bare asserts.
refactor FakeFileFactory generator-of-generator to plain list,
cap temp_large_binary_file at fixed 10mb default,
replace time.sleep(2) with polling loop,
fix assert all() to provide detailed failure info,
remove log.trace placeholders and unused helper functions,
add assertion messages to bare asserts,
unify responses fixture style,
remove commented-out test stubs,
replace blanket noqa with per-line suppressions.
split 1882-line test_uploads.py into test_uploads_workflow.py
(32 workflow state machine tests) and test_uploads_persistence.py
(38 persistence manager tests).
- add FBT001/FBT002 to per-file-ignores for test files (boolean
  positional args intentional in pytest fixtures)
- fix E501 line-too-long: duplicated comment, split long f-strings
- fix SLF001 noqa placement: cover both assert line and f-string
  continuation when both access private members
chmod on parent directory has no effect on open(path,'w') for an existing file - write permission on the file itself is needed. Changed parent.chmod(0o555) to file.chmod(0o444) in both
test_remove_persisted_upload_handles_write_error and
test_remove_persisted_uploads_by_checksum_handles_write_error.
regression from v0.1.15 anyio.Path migration: file discovery rglob
yielded relative candidates from unresolved root, but resolved
absolute root was passed to create_file_instance, causing
Path.relative_to() to raise ValueError.

fix by passing unresolved root (same source as rglob) instead.
- add pytest-xdist>=3.6.1 dev dependency
- add heavy marker for large upload tests (>10 MB)
- make test-integration run in parallel with --dist loadgroup
- add test-integration-sequential for original single-process mode
- add test-integration-quick to skip heavy tests
- enable parallel coverage data file mode
- bump version 0.1.17 -> 0.1.18
wrap the synchronous sds_files.upload_file call in asyncio.to_thread
so the event loop can multiplex max_concurrent_uploads workers instead
of being serialised by each blocking requests call
…t groups

- split integration_client into session-scoped object creation (no HTTP)
  and function-scoped auth, so the fixture works with pytest-responses'
  global pytest_runtest_setup hook that fires before session fixtures
- add xdist_group('rh_capture') to tests sharing RadioHound scan group
  to prevent race conditions when tests delete each other's captures
- mark 100 MB upload parametrized case with heavy marker
@lucaspar lucaspar requested a review from klpoland April 30, 2026 19:55
@lucaspar lucaspar self-assigned this Apr 30, 2026
Copilot AI review requested due to automatic review settings April 30, 2026 19:55
@lucaspar lucaspar added ci/cd GH actions, tests, builds, packaging, etc sdk SDK component labels Apr 30, 2026
@semanticdiff-com
Copy link
Copy Markdown

semanticdiff-com Bot commented Apr 30, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  sdk/src/spectrumx/config.py  60% smaller
  sdk/tests/ops/test_captures.py  47% smaller
  sdk/tests/ops/test_files.py  46% smaller
  sdk/tests/ops/test_paginator.py  44% smaller
  sdk/tests/conftest.py  42% smaller
  sdk/src/spectrumx/api/uploads.py  38% smaller
  sdk/tests/test_client.py  23% smaller
  sdk/tests/integration/test_file_ops.py  16% smaller
  sdk/tests/integration/test_captures.py  13% smaller
  sdk/tests/integration/conftest.py  12% smaller
  sdk/tests/test_uploads_persistence.py  11% smaller
  network/README.md Unsupported file format
  network/justfile Unsupported file format
  sdk/.env.example Unsupported file format
  sdk/.gitignore Unsupported file format
  sdk/docs/mkdocs/changelog.md Unsupported file format
  sdk/justfile Unsupported file format
  sdk/pyproject.toml Unsupported file format
  sdk/src/spectrumx/gateway.py  0% smaller
  sdk/tests/integration/integration.env.example Unsupported file format
  sdk/tests/integration/regressions/test_paths.py  0% smaller
  sdk/tests/test_uploads_workflow.py  0% smaller
  sdk/uv.lock Unsupported file format

@lucaspar lucaspar changed the title sdk: fixed http timeout setting being ignored SDK bug fixes and test changes; v0.1.18 release Apr 30, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes SDK configuration/behavior regressions around HTTP request timeouts and upload workflows, and modernizes/parallelizes the SDK test suite (including xdist support) while updating docs and tooling for the v0.1.18 release.

Changes:

  • Fix HTTP timeout propagation by mapping HTTP_TIMEOUTSDSConfig.timeout (defaulting to 300s) and using it in GatewayClient.
  • Fix upload workflow issues (relative-path discovery and async upload concurrency by offloading blocking uploads to a thread).
  • Restructure and harden tests (split upload tests, add clearer assertions, add pytest-xdist + coverage parallel settings, improve integration test fixtures).

Reviewed changes

Copilot reviewed 22 out of 23 changed files in this pull request and generated no comments.

Show a summary per file
File Description
sdk/uv.lock Adds xdist-related locked dependencies; bumps editable package version.
sdk/tests/test_uploads_workflow.py New state-machine-focused tests for UploadWorkload.
sdk/tests/test_uploads_persistence.py Refactors persistence tests; adds/adjusts assertions and error-path coverage.
sdk/tests/test_client.py Adds regression tests ensuring HTTP timeout config is applied.
sdk/tests/ops/test_paginator.py Cleans up placeholder logging; improves assertion messages.
sdk/tests/ops/test_files.py Removes placeholder logging; adopts pytest-responses fixture injection; improves assertions.
sdk/tests/ops/test_captures.py Converts module constants to fixtures for xdist safety; improves test parameterization.
sdk/tests/integration/test_file_ops.py Updates passthrough endpoints, improves assertions, marks heavy test, replaces sleep with polling.
sdk/tests/integration/test_captures.py Adds auth passthrough and xdist grouping; improves assertions; removes dead helper.
sdk/tests/integration/regressions/test_paths.py Adds auth passthrough, improves failure reporting, adds xdist grouping.
sdk/tests/integration/integration.env.example Updates local URLs for API-key generation.
sdk/tests/integration/conftest.py Splits integration client creation vs authentication for pytest-responses/xdist compatibility; fail-fast on bad creds.
sdk/tests/conftest.py Makes large-file fixture deterministic; simplifies fake file factory iteration.
sdk/src/spectrumx/gateway.py Uses shared default HTTP timeout constant for GatewayClient.
sdk/src/spectrumx/config.py Introduces DEFAULT_HTTP_TIMEOUT=300; fixes env key mapping so HTTP_TIMEOUT sets timeout.
sdk/src/spectrumx/api/uploads.py Fixes relative-root discovery bug; offloads blocking upload calls via asyncio.to_thread.
sdk/pyproject.toml Bumps version; adds pytest-xdist; adjusts coverage config for parallel runs; adds heavy marker and ruff test ignores.
sdk/justfile Adds parallel integration test recipes and cleans .coverage.*.
sdk/docs/mkdocs/changelog.md Updates v0.1.18 changelog content/date and adds fix notes.
sdk/.gitignore Ignores agents/ directory.
sdk/.env.example Updates HTTP_TIMEOUT example to 300 seconds.
network/justfile Adds gen-certs recipe for self-signed TLS cert generation.
network/README.md Documents the new gen-certs recipe usage.
Comments suppressed due to low confidence (3)

sdk/tests/test_uploads_persistence.py:822

  • This test uses chmod(0o444) on the persisted uploads file to force a write error. That’s not reliable across platforms (notably Windows) and, unless xdg_state_home is patched, it writes into the real user/CI XDG state directory. Patch spectrumx.api.uploads.xdg_state_home to a tmp_path location for isolation, and/or simulate the write failure by patching the specific Path.open(..., 'w') call to raise OSError in a platform-independent way.
    sdk/tests/test_uploads_persistence.py:992
  • This test depends on chmod(0o000) to trigger a read failure. File permission changes don’t behave consistently on Windows (and can be affected by the underlying filesystem/umask), which can make the assertion on log_user_warning flaky. Prefer simulating the OSError by patching Path.open for this specific file, or skip/xfail this test on platforms where chmod-based permission errors aren’t reliable.
    sdk/tests/test_uploads_persistence.py:1018
  • This test uses chmod(0o444) to force a write error, which is not consistently enforced on Windows and can lead to flaky behavior (the file may still be writable via ACLs). Prefer a deterministic approach (e.g., patch the Path.open(..., 'w') call for this file to raise OSError) or guard the chmod-based approach with a platform check.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lucaspar lucaspar merged commit d4a32d0 into master Apr 30, 2026
4 checks passed
@lucaspar lucaspar deleted the lp/sdk-improvements branch April 30, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/cd GH actions, tests, builds, packaging, etc sdk SDK component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants