Skip to content

Conversation

@tjb9dc
Copy link
Collaborator

@tjb9dc tjb9dc commented Nov 20, 2025

Very initial version of wire tests in python behind a feature flag. Utilizes the wiremock approach to testing. Enabled for the exhaustive no-custom-config feature.

Needs some reworking on how we are utilizing examples.

tjb9dc and others added 7 commits November 20, 2025 12:04
Adds pytest-based wire test generation that validates SDK methods against WireMock. Each test creates a client, makes an API call, and verifies the request was properly sent.

- Implements generateServiceTestFile() with autouse fixture for test setup
- Generates helper functions for WireMock interaction (reset, verify)
- Creates test functions for each endpoint with examples
- Adds enable_wire_tests config option to both Python v1 and v2
- Includes seed test fixtures for exhaustive validation

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

Co-Authored-By: Claude <[email protected]>
Wire test files were missing imports for pytest, requests, typing, and the generated client. This was because:
- The Python AST only supports "from X import Y" style imports
- References with empty modulePath are skipped by the import generator
- Simple "import X" statements need to be added as raw code blocks

Solution:
- Added raw code blocks for pytest and requests imports
- Used reference tracking for typing and client imports
- Created helper to register references for AST-managed imports

All test files now have complete import statements at the top.

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

Co-Authored-By: Claude <[email protected]>
…type issues

Fixed mypy errors in wire tests by:
- Adding types-requests as dev dependency only when enable_wire_tests is true
- Properly typing request_body as Dict[str, Any] to handle nested dicts
- Converting JSON boolean 'true/false' to Python 'True/False' in test data
- Added jsonToPython() helper to properly convert JSON to Python syntax

Implementation:
- Plumbed enable_wire_tests flag through Project -> PyProjectToml -> DependenciesBlock
- Conditionally adds types-requests = "^2.31.0" only when wire tests are enabled
- Fixed formatValue() to handle booleans correctly (True/False not true/false)
- Added proper type annotations for all variables

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

Co-Authored-By: Claude <[email protected]>
Fixed two issues in generated wire tests:
1. Import path: Changed from `from seed.exhaustive import SeedExhaustive`
   to `from seed import SeedExhaustive` (correct module path)
2. Service access: Now properly navigates service hierarchy
   (e.g., `client.endpoints.container.method()` instead of `client.method()`)

Implementation:
- Updated getClientModulePath() to return just [organization] instead of [org, workspace]
- Added service parameter to test generation functions
- Build service path from service.name.fernFilepath.allParts using snake_case
- Construct proper client accessor path: "client.{servicePath}.{methodName}()"

Examples of generated paths:
- Top-level service: client.no_auth.post_with_no_auth()
- Nested service: client.endpoints.container.get_and_return_list_of_primitives()

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

Co-Authored-By: Claude <[email protected]>
Wire tests import and use the requests library to communicate with WireMock's
admin API for resetting request journals and verifying request counts.

Previously only added types-requests (type stubs), but need the actual library too.

Changed: Added `requests = "^2.31.0"` alongside `types-requests = "^2.31.0"`
in dev dependencies when enable_wire_tests is true.

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

Co-Authored-By: Claude <[email protected]>
Added automatic Docker container management using docker-compose healthchecks
and pytest session fixtures.

**docker-compose.test.yml**:
- Added healthcheck that tests WireMock admin health endpoint
- Checks every 2s with 15 retries (30s total wait time)
- 5s start period before first health check

**conftest.py**:
- Session-scoped pytest fixture manages container lifecycle
- Uses `docker compose up -d --wait` to wait for healthcheck to pass
- Automatically starts WireMock before any tests run
- Cleans up container with `docker compose down -v` after all tests complete
- Proper error handling with stderr output

This eliminates manual polling and ensures WireMock is fully ready before
tests begin. Docker handles all the retry logic and timeout management.

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

Co-Authored-By: Claude <[email protected]>
…decorators

Fixes wire test generation to properly map request parameters and headers:

- Remove @pytest.mark.asyncio decorators from synchronous test functions
- Use IR property definitions to map wire names to SDK parameter names (e.g., uuid -> uuid_, base64 -> base_64)
- Distinguish between flattened object types and single request parameters
- Add header parameter support with proper name conversion (X-TEST-HEADER -> x_test_header)
- Use discriminated union visitor pattern for request body types

All 49 wire tests now pass.

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

Co-Authored-By: Claude <[email protected]>
@github-actions
Copy link

🌱 Seed Test Selector

Select languages to run seed tests for:

  • Python
  • TypeScript
  • Java
  • Go
  • Ruby
  • C#
  • PHP
  • Swift
  • Rust
  • OpenAPI
  • Postman

How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR.

@tjb9dc tjb9dc changed the title chore(python): MVP of python wire tests chore(python): First stab at python wire tests Nov 20, 2025
@devin-ai-integration devin-ai-integration bot changed the title chore(python): First stab at python wire tests feat(python): implement wire tests with docker availability handling Nov 20, 2025
tjb9dc and others added 2 commits November 20, 2025 19:30
…e tests

Updates the Python seed Dockerfile to use docker:dind base image:
- Enables wire tests to spin up WireMock containers via docker compose
- Follows same pattern as Go seed Dockerfile
- Installs Python 3.12, Poetry, Node.js on Alpine Linux
- Starts dockerd in background via entrypoint script

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

Co-Authored-By: Claude <[email protected]>
@tjb9dc tjb9dc changed the title feat(python): implement wire tests with docker availability handling feat(python): Add wire tests Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants