Add generated Q Business client and integration tests#54
Add generated Q Business client and integration tests#54Alan4506 wants to merge 2 commits intoawslabs:developfrom
Conversation
| def qbusiness_app(): | ||
| """Create a Q Business application for the test session and delete it after.""" | ||
| app_id = _create_qbusiness_app() | ||
| yield app_id | ||
| _delete_qbusiness_app(app_id) |
There was a problem hiding this comment.
If _create_qbusiness_app() fails after the application is created (during index or retriever creation), will _delete_qbusiness_app still run to clean up the application?
There was a problem hiding this comment.
Good catch. Updated the fixture to use try/finally so cleanup runs even if creation fails partway through. _delete_qbusiness_app now accepts None and returns early if no app was created. Since deleting the application cascades to its index and retriever, this handles all partial failure cases.
| ChatInputStreamEndOfInputEvent(value=EndOfInputEvent()) | ||
| ) | ||
|
|
||
| await asyncio.sleep(1) |
There was a problem hiding this comment.
Why is the 1-second sleep needed after sending the input stream? Could you add a comment explaining the reason?
There was a problem hiding this comment.
Added a comment explaining the sleep. It gives the service time to process input events before we close the stream. The same pattern is used in the transcribe-streaming and bedrock-runtime bidirectional streaming tests (example). Tests will fail if we remove this.
| """Helper to create a QBusinessClient for a given region.""" | ||
| return QBusinessClient( | ||
| config=Config( | ||
| endpoint_uri=f"https://qbusiness.{region}.api.aws", |
There was a problem hiding this comment.
This is for my own understanding:
- Why is the
endpoint_urihardcoded here? Is it not possible to resolve it automatically?
There was a problem hiding this comment.
Currently we only have a StandardRegionalEndpointsResolver in smithy-aws-core that resolves {prefix}.{region}.amazonaws.com, but Q Business uses .api.aws instead of .amazonaws.com, so it doesn't work here. See smithy_aws_core/endpoints/standard_regional.py.
Description of changes:
This PR adds integration tests for the Q Business service client (
aws-sdk-qbusiness), covering the following:chat_syncchatThe test structure and patterns follow the same conventions established in the Lex Runtime V2 integration tests (PR #51), including session-scoped conftest fixtures for resource setup/teardown and field-level assertions on event types.
Although the PR contains many files, most of them are generated by smithy-python codegen. Please mainly review the integration tests because they are the primary focus of this PR. The Smithy model, generated client code under
src/, andpyproject.tomlare included for reviewer convenience so that tests can be run locally. The actual client release will be handled by internal release automation (through a separate PR that uploads the model).Here is the detailed file breakdown:
codegen/aws-models/qbusiness.json: Smithy model for the Q Business service.clients/aws-sdk-qbusiness/src/: Generated client code. Included for reviewer convenience only; will be replaced by release automation.clients/aws-sdk-qbusiness/pyproject.toml: Generated package configuration.clients/aws-sdk-qbusiness/README.md: Generated package readme.clients/aws-sdk-qbusiness/tests/__init__.py: Generated test package marker.clients/aws-sdk-qbusiness/tests/test_protocol.py: Generated protocol test.clients/aws-sdk-qbusiness/tests/integration/__init__.py: DefinesREGIONandcreate_qbusiness_client()helper shared across integration tests.clients/aws-sdk-qbusiness/tests/integration/conftest.py: Session-scoped pytest fixture that creates a Q Business application, index, and retriever using boto3, and tears them down after. Uses custom botocore waiters since Q Business has no built-in boto3 waiters.clients/aws-sdk-qbusiness/tests/integration/test_non_streaming.py: Tests thechat_syncoperation.clients/aws-sdk-qbusiness/tests/integration/test_bidirectional_streaming.py: Tests thechatoperation.Note: The Q Business client cannot be code-generated without the codegen fix in smithy-lang/smithy-python#682, which is still under review.
Note: The Q Business service sends event types (
intermediateMessageEvent,intermediateGroupEvent) that are not present in the current model. These are handled asChatOutputStreamUnknownthanks to a fix insmithy-python. The changes have been merged into the develop branch but have not been released yet. Tests will fail against the published PyPI versions until the next release.To successfully run the tests locally, follow the steps below:
All tests should pass.
This branch will be rebased once the release automation publishes the client.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.