envoy.github.release: three correctness fixes (version regex, status-before-stream, exception chain)#4495
Draft
Copilot wants to merge 2 commits into
Draft
envoy.github.release: three correctness fixes (version regex, status-before-stream, exception chain)#4495Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
✅ Deploy Preview for nifty-bassi-e26446 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
- Fix 8.3: Replace `r"v(\w+)"` with `r"^v(\d+\.\d+\.\d+.*)$"` in manager.py and use fullmatch+group(1) instead of sub() to correctly parse versions like v1.19.0 (previously \w didn't match . so the regex was incorrect) - Fix 4.2: Check HTTP status before streaming download body in assets.py so 404/error responses are not written to disk before the error is reported - Fix 6.1: Use `raise e.args[0] from e` instead of bare `raise e.args[0]` in release.py to preserve the ConcurrentError exception chain Add corresponding tests for each fix: - Updated test_release_manager_parse_version to use fullmatch semantics - Added test_release_manager_parse_version_regex integration test - Added test_release_manager_latest_minors integration test - Updated test_fetcher_save to assert stream.writer not called on non-200 - Updated test_release_push to assert __cause__ is set on ConcurrentError Agent-Logs-Url: https://github.com/envoyproxy/toolshed/sessions/a7bfdad5-6b3e-4180-ae1b-33134aa0554c Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix version regex for proper version parsing
envoy.github.release: three correctness fixes (version regex, status-before-stream, exception chain)
May 11, 2026
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.
Bundles three high-priority correctness bugs from the
py/envoy.github.releasecode review.Fixes
8.3 — Version regex (HIGH)
_version_re = r"v(\w+)"—\wdoesn't match., sov1.19.0parsed asVersion("1")viasub, silently collapsing every minor into the same bucket inGithubReleaseManager.latest.4.2 — Status check before streaming
GithubReleaseAssetsFetcher.savestreamed the response body to disk before checkingdownload.status, writing 404 HTML to the asset path and only then reporting an error. Status is now checked first; the writer is never opened on a non-2xx response. The returned dict shape (name,outfile, optionalerror) is unchanged.6.1 — Exception chain on concurrent push
raise e.args[0]→raise e.args[0] from einGithubRelease.pushso theConcurrentErrorcontext is preserved in tracebacks.Tests
test_release_manager_parse_version: updated to mockfullmatchinstead ofsubtest_release_manager_parse_version_regex: new parametrized integration test (v1.19.0,v0.0.1, pre-releases,v1,notaversion)test_release_manager_latest_minors: new integration test asserting["v1.18.0", "v1.19.0", "v1.19.1", "v2.0.0"]produces correct per-minor bucketstest_fetcher_save: assertsstream.writeris not called on non-200 responsestest_release_push: assertsexc_info.value.__cause__is the originalConcurrentErrorOriginal prompt
Bundle the remaining high-priority correctness findings from the code review in PR #4479 (
py/envoy.distribution.release/REVIEW.md) into a single PR. All three targetpy/envoy.github.release. No behavioural changes beyond the bug fixes; add tests for each.1. Fix version regex (finding 8.3 — HIGH risk)
File:
py/envoy.github.release/envoy/github/release/manager.py(around L25)Currently:
Python's
\wdoes not match., so whenparse_version("v1.19.0")runs:…every release under a given major collapses to
Version("1"), breaking thelatestdict inGithubReleaseManager.latest— any "find latest minor" flow inFetchCommandsilently returns the wrong release. This is a real production correctness bug.Fix: use a proper semver-ish pattern with
re.fullmatchsemantics. Replace the_version_rewith something like:…and update
parse_versionto usefullmatchand extract group 1 directly (rather thansub(r"\1", ...)which silently passes the original string through on non-match). On non-match, log the warning and returnNone(preserving current behaviour for unparseable tags). Make sure the existing_version_format = "v{version}"round-trip still works.Tests: add a parametrized test in
py/envoy.github.release/tests/test_manager.pyforparse_versioncovering at minimum:v1.19.0→Version("1.19.0")v0.0.1→Version("0.0.1")v1.2.3-rc1/v1.2.3.dev0→ correctVersion(orNoneif you choose to reject pre-releases — document the choice)v1→None(or whatever the chosen regex implies — assert explicitly)notaversion→NoneGithubReleaseManager.latestthat exercises tags like["v1.18.0", "v1.19.0", "v1.19.1", "v2.0.0"]and asserts that the resultinglatestdict contains the rightVersionobjects under keys"1.18","1.19","2.0","1.18.0","1.19.0","1.19.1","2.0.0"— i.e. that minors are no longer collapsed.2. Check HTTP status before streaming the download body (finding 4.2)
File:
py/envoy.github.release/envoy/github/release/assets.pyGithubReleaseAssetsFetcher.save(around L55–L71)Currently the response body is streamed to the output file via
stream.writerbeforedownload.statusis checked, so a 404 HTML body is written to the user's asset path and only afterwards reported as an error.Fix: check
download.statusfirst; if non-2xx, callself.fail(...)with the message and return the error result without opening/creating the outfile. Only stream to disk on success.Keep the returned dict shape identical (
name,outfile, optionalerror) so callers inrelease.py:fetch()andformat_responseare unaffected. Note: on the error path,outfileshould still be set to the planned path (so existing call sites don'tKeyError), but the file must NOT have been created.Tests: update/extend
py/envoy.github.release/tests/test_assets.pyto:stream.writeris not called (and no file is created on disk in a tmp_path test)errorset andname/outfilekeys present3. Preserve exception chain on concurrent push (finding 6.1)
File:
py/envoy.github.release/envoy/github/release/release.py(around L200–L201) inGithubRelease.push:Fix:
raise e.args[0] from eso theConcurrentErrorcontext is preserved in the traceback.Tests: update the corresponding test in
py/envoy.github.release/tests/test_release.pyforGithubRelease.pushto assert the raised exception's__cause__is the originalConcurrentErrorinstance.General
py/envoy.distribution.release/REVIEW.mdmarking findings 4.2, 6.1, and 8.3 as resolved (e.g., a small "Resolved in follow-up #" annotation next to each), OR — preferred — delete those three findings from the Findings sections and remove their rows from the "Recommended follow-up PRs" table. Pick one approach and apply consistently.py/envoy.github.releaseandpy/envoy.distribution.releaseand ensure they pass.Context / prior PRs
These already landed and resolved other review findings — do not duplicate their work:
envoy.distribution.release: Cleanups #4483 —envoy.distribution.releasecleanups (metadata, typing, deps)envoy.distribution.release: Code cleanups #4490 —envoy.distribution.releasecode cleanups (dead code, typing migration, no-op test fixes,setup.cfgurl...This pull request was created from Copilot chat.