test: port TS tests for 4 low-coverage modules#23
Conversation
Port TypeScript tests to Python for coverage improvement: - GChat format_converter: 37 tests covering to_ast, from_ast, render_postable, extract_plain_text (36% -> 80%+ target) - GChat workspace_events: 19 tests covering CRUD subscriptions, decode_pub_sub_message, auth token flows (47% -> 80%+ target) - Teams adapter: 42 tests covering fetch_messages, open_dm, _cache_user_context, _get_access_token, _get_graph_token, _validate_service_url, HTTP helpers (51% -> 70%+ target) - shared/buffer_utils: 19 tests covering to_buffer, to_buffer_sync, buffer_to_data_uri (27% -> 80%+ target) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces several new test files to increase code coverage across the SDK, specifically targeting buffer utilities, Google Chat format conversion, Google Chat workspace events, and the Teams adapter. The feedback focuses on improving the robustness of exception testing in test_buffer_utils.py by replacing try...except blocks with pytest.raises to avoid silent passes, and removing a redundant variable assignment in test_teams_coverage.py.
| try: | ||
| await to_buffer("invalid", "slack") | ||
| except ValidationError as e: | ||
| assert e.adapter == "slack" |
There was a problem hiding this comment.
This test uses a try...except block to verify that an exception is raised, but it lacks a failure condition if the exception is not raised. If to_buffer were to return normally (e.g., due to a regression where throw_on_unsupported defaults to False), the test would silently pass. Using pytest.raises is more idiomatic and ensures the test fails if the expected exception is missing.
with pytest.raises(ValidationError) as excinfo:
await to_buffer("invalid", "slack")
assert excinfo.value.adapter == "slack"| try: | ||
| to_buffer_sync("invalid", "teams") | ||
| except ValidationError as e: | ||
| assert e.adapter == "teams" |
There was a problem hiding this comment.
Similar to the async version, this try...except pattern for testing exceptions is prone to silent passes if the function fails to raise the expected ValidationError. Refactoring to use pytest.raises makes the test more robust and readable.
with pytest.raises(ValidationError) as excinfo:
to_buffer_sync("invalid", "teams")
assert excinfo.value.adapter == "teams"| tid = "teams:abc:def" | ||
| # Encode a proper thread ID | ||
| tid = adapter.encode_thread_id( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 96c8b41b7e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| try: | ||
| await to_buffer("invalid", "slack") | ||
| except ValidationError as e: | ||
| assert e.adapter == "slack" |
There was a problem hiding this comment.
Assert the expected exception is raised
test_includes_platform_in_error uses a try/except without any failure path when no exception is raised, so the test will pass even if to_buffer stops raising ValidationError. That makes this regression check ineffective and can hide breakages in error handling (the same pattern is repeated in the sync variant); use pytest.raises(...) and assert on the captured exception instead.
Useful? React with 👍 / 👎.
Summary
to_ast,from_ast,render_postable,extract_plain_text-- ported frommarkdown.test.tscreate_space_subscription,list_space_subscriptions,delete_space_subscription,decode_pub_sub_message,_get_access_token-- ported fromworkspace-events.test.tsfetch_messages,fetch_channel_messages,open_dm,_cache_user_context,_get_access_token,_get_graph_token,_validate_service_url, HTTP helpers, Graph message mapping -- ported fromindex.test.tsto_buffer,to_buffer_sync,buffer_to_data_uri-- ported frombuffer-utils.test.tsTest plan
🤖 Generated with Claude Code