fix(workflow): scope _deploy cleanup to what it actually changed - #149
Open
LukasGold wants to merge 1 commit into
Open
fix(workflow): scope _deploy cleanup to what it actually changed#149LukasGold wants to merge 1 commit into
LukasGold wants to merge 1 commit into
Conversation
- PREFECT_API_URL was popped even when the gateway shim never ran - httpx.AsyncClient.__init__ leaked if shim setup or the loop raised - replace unawaited/skipped deploy tests with 11 executing tests - workflow.py coverage 26% -> 43% - drop permanently skipped test_deploy_runner
Contributor
Release previewMerging this PR would release v2.0.3 (current: Changelog preview (truncated)## v2.0.3 (2026-08-28)
### Bug Fixes
- **workflow**: Scope _deploy cleanup to what it actually changed
([`4f0593e`](https://github.com/OpenSemanticLab/osw-python/commit/4f0593e47b7a2dd42f304429f2ffb9b5eb5fe47c))
### Testing
- Rename oold.py to oold_test.py so its tests are collected
([`20072a9`](https://github.com/OpenSemanticLab/osw-python/commit/20072a9249cd97126a222c62a70f84e0433343ef))
Preview via python-semantic-release and conventional commits. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
tests/utils/workflow_test.pyhad no real coverage of the deploy path:test_deploy_servebuilt the_deploy(...)coroutine and deliberately never awaited it, andtest_deploy_runnerwas@pytest.mark.skip. Soflow.to_deployment(),.apply()andserve()never ran, andsrc/osw/utils/workflow.pysat at 26%.Awaiting
_deployfor the first time uncovered two bugs, both fixed here.Bugs fixed
Both are the same defect class: cleanup scoped narrower than the state it cleans up. Each was pinned with a failing test before the fix.
PREFECT_API_URLdeleted when the shim never ran. The gateway shim is entered only when_is_apigateway_url(gateway_url) and param.osw is not None, but the cleanup gated theenviron.popon the URL shape alone. Calling_deploywithosw=Noneon a machine configured against an ApiGateway silently deleted the caller'sPREFECT_API_URL. Fixed with an_api_url_overriddenflag set at the point of mutation, so the cleanup condition cannot drift from the entry condition.httpx.AsyncClient.__init__patch leaked. The patch went live during shim setup, buttry:wrapped onlyawait serve(...). Any exception in between -install_gateway_hook()hittingPermissionErroron read-only site-packages,to_deployment(), orapply()against an unreachable server - left the patch installed for the rest of the process.try:now starts immediately aftergateway_urlis computed, with all three sentinels initialised above it.Source change is 6 added lines plus a re-indent; no logic changed in the reflow.
Tests
11 tests replace the 2 non-tests, run under
prefect_test_harness()withservemonkeypatched so no live server is needed:test_deploy_serve- awaits_deploy, then reads the deployment back from the Prefect API to proveapply()really registered ittest_deploy_defaults_deployment_name,test_deploy_sync_wrapper(sync, sincedeploy()callsasyncio.run),test_deploy_registers_flow_with_oswtest_deploy_apigateway_shim_restores_httpx- asserts the patch is both applied and restored, by identitytest_deploy_preserves_ambient_prefect_api_url,test_deploy_restores_previous_prefect_api_url,test_deploy_restores_httpx_when_deployment_fails,test_deploy_restores_httpx_when_gateway_hook_fails- the four regression testsAlso: the shared mutable module-level
deploy_parambecame amake_deploy_param()factory, because_deploywrites todeploy_config.nameand the shared object leaked state between tests.Notes
test_deploy_runner, which was permanently skipped and shelled out toprefect config set._deployhas no serve-vs-runner branch; it always ends inawait serve(...), anddeploy()is only asys.version_infobranch on how to spin the event loop. The old test names implied otherwise.src/osw/utils/workflow.py: 26% -> 43% (236 -> 177 missed of 353 statements).make checkgreen.