Repository navigation
Live tests for the Python and asyncio docs code samples - #241
Conversation
The "Cancel workflow runs for commit on error" step (fast-jobs-failure) cancels every workflow of the commit when one fast job fails, so an unrelated failure cancelled the first attempt of other workflows. The JavaScript SDK removed the same step in PR 539. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Adds docs-snippets/, a pytest suite that runs the code samples of the Python and asyncio docs against the real PubNub service and asserts the documented effect. The docs embed the snippet regions with EmbeddedCode. * 311 snippet ids in 193 steps (sync and asyncio), roles open and pam * assertions sit outside the snippet markers, a marker lint enforces it * honesty checks: each step must reach snippet.end and make an assertion * run-suffixed names per step, key and token redaction, janitor, no skips * coverage.json manifest with a --check mode * separate workflow: dry job on Python 3.9 to 3.13, live shards in series under one concurrency group, nightly, fork PRs skip live * setup.py excludes docs-snippets from the package Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
The staged copy under docs-snippets/.run/<id>/ cannot find the checkout from its own harness package, so pytest failed with "No module named 'pubnub'" wherever the package is not installed (the CI runner installs only the dev requirements). The run now sets PYTHONPATH to the repository root. The key status line prints only the roles the shard needs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The presence service resolves a channel group some seconds after it was created and answers 400 "No valid channels specified" until then. The read after the write now retries for up to 45 seconds with the same assertion. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Updated lint job names in live integration workflows to remove reference to port map. - Modified lint function in cli.py to conditionally check for base availability before executing port map checks, providing a fallback message for shallow CI checkouts. - Added base_available function in port_map.py to verify if the base commit exists in the current checkout.
…lity - Replaced instances of aeventually with asettled in various test files to ensure consistent state checks. - Updated related imports to include asettled where necessary. - Enhanced test reliability by ensuring that state checks wait for settled conditions before proceeding.
- Added a new `present` function to ensure user IDs are occupants of specified channels during presence tests. - Updated `seed_parallel_async` to include a concurrency parameter, allowing controlled message publishing with error handling. - Modified presence tests to utilize the new `present` function for improved reliability in state checks.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Refactored comments in `live-integration.yml` for clarity on failure alerts. - Improved documentation in `conftest.py` regarding the offline guard feature. - Removed unused `port-map` functionality from `cli.py` and related files. - Updated README and other documentation files for consistency and clarity. - Enhanced test descriptions and fixed minor issues in various test files. - Deleted obsolete files related to endpoint tier moves and port text changes. These changes streamline the testing process and improve the overall documentation for the live tier tests.
- Replaced the `seed_parallel` function with `seed_many` in multiple test files to publish messages sequentially, ensuring unique timetokens for each publish. - Updated relevant test cases to reflect the change in message seeding method, enhancing reliability in message history checks. These changes improve the accuracy of message publishing tests by preventing duplicate timetokens during concurrent operations.
Take master's Ruff setup (#243) for the validations workflow and the lint command, and restore the cross-workflow cancel step in the Tests workflow, so the only differences from master outside tests/live are the live tier's own files. The test command keeps --ignore=tests/live/ because the live tier needs keys and runs in its own workflow. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
flake8 is no longer installed (requirements-dev.txt follows master). The live workflow now runs `ruff check tests/live`, the README says so, and the encryption page drops two imports that the samples import themselves and uses a Ruff noqa for the blank lines that the published sample keeps. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Introduced a new `test_objects.py` file for asyncio tests, covering various metadata operations including UUID and channel management. - Updated `coverage.json` to include new test cases for the asyncio API reference. - Modified `groups.py` to reference the new asyncio test file. - Cleaned up `snippet-exceptions.json` by removing obsolete entries related to the asyncio docset. These changes enhance the testing framework for asyncio operations, ensuring comprehensive coverage and improved organization of test cases.
- Reformatted the `await pubnub.set_channel_members` call in the `test_set_channel_members_builder` function to enhance code clarity. - This change improves the overall readability of the test case without altering its functionality.
- Updated the `fetch` function in `file_sharing.py` to enforce HTTPS URL fetching, raising a `ValueError` for non-HTTPS URLs. - Improved error handling in `clients.py` by adding debug logging for leave request failures. - Refactored test cases in `test_file_sharing.py` to utilize the updated `fetch` function for URL validation and response checks. - Adjusted payload structures in `test_encryption.py` to improve clarity and consistency in encryption tests. These changes enhance security and debugging capabilities in the test suite.
- Modified the `role` in `coverage.json` for `initialize_access_manager` to include `pam`. - Updated `test_initialize_access_manager` in both asyncio and sync test files to read the secret key from the `PUBNUB_SECRET_KEY` environment variable, ensuring compatibility with the PAM keyset. These changes enhance the security and flexibility of the access manager tests by integrating PAM keyset support.
- Modified `test_initialize_access_manager` in both asyncio and sync test files to read the secret key from the `PUBNUB_SECRET_KEY` environment variable, enhancing security and flexibility in the tests. - Introduced a new helper function in `extractor.py` to commit documentation changes, improving the process of tracking documentation updates. These changes ensure that the tests align with best practices for secret management and streamline documentation handling.
|
|
||
| pubnub = PubNubAsyncio(pnconfig) | ||
| # snippet.end | ||
| a.eq(pnconfig.secret_key, environ['PUBNUB_SECRET_KEY'], 'the sample sets the secret key from the environment') |
There was a problem hiding this comment.
If this assertion ever fails, a.eq prints both values in the message, so the real PAM secret key would end up in the CI log. Can you verify this?
There was a problem hiding this comment.
I've switched both assertions to a.ok(pnconfig.secret_key == environ['PUBNUB_SECRET_KEY'], ...), so a failure only prints the message and no key value. I also checked the other live tests and found no other a.eq on a secret. The recent CI logs show no failing run for this assertion, and GitHub masks the key in them, but I didn't want to depend on that masking.
|
|
||
| pubnub = PubNub(pnconfig) | ||
| # snippet.end | ||
| a.eq(pnconfig.secret_key, environ['PUBNUB_SECRET_KEY'], 'the sample sets the secret key from the environment') |
There was a problem hiding this comment.
If this assertion ever fails, a.eq prints both values in the message, so the real PAM secret key would end up in the CI log. Can you verify this?
- Updated the `test_initialize_access_manager` in both asyncio and sync test files to replace `a.eq` with `a.ok` for asserting the secret key from the environment variable. This change enhances security by preventing the secret key from being logged in CI outputs. These modifications improve the security practices in the test suite while maintaining functionality.
What
Adds
docs-snippets/, a pytest suite that runs the code samples of the Python and asyncio SDK docs against the real PubNub service and asserts the documented effect. The docs embed the snippet regions withEmbeddedCodefrom this repo.What is covered
How it stays honest
snippet.endor when it made no assertionxfail, no fixed sleeps (eventuallyfor reads after writes), subset runs are refused in CIcoverage.jsonlists every snippet id,python -m harness.cli manifest --checkfails when it is stalepython -m harness.auditlists assertions per step, one log file per step is written toreport/<shard>/steps/