envoy.dependency.check: tighten TypedDict schema and add metadata validation#4442
Closed
Copilot wants to merge 3 commits into
Closed
envoy.dependency.check: tighten TypedDict schema and add metadata validation#4442Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
✅ Deploy Preview for nifty-bassi-e26446 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
… metadata Agent-Logs-Url: https://github.com/envoyproxy/toolshed/sessions/3db1a8d9-3d6c-40e4-9f7d-944f47b9dc24 Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
Agent-Logs-Url: https://github.com/envoyproxy/toolshed/sessions/3db1a8d9-3d6c-40e4-9f7d-944f47b9dc24 Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix TypedDict schema mismatch and add input validation
envoy.dependency.check: tighten TypedDict schema and add metadata validation
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.
urlsandsha256were marked optional inDependencyMetadataDict(total=False) despite being accessed unconditionally, causing silentKeyErrors on malformed input. No validation ran before dependency objects were constructed.Changes
typing.pyurls: list[str]andsha256: strtoBaseDependencyMetadataDict(required)cpe: str | Noneoptional in thetotal=Falsesubclassexceptions.pyDependencyMetadataError(Exception)for schema validation failuresabstract/checker.pyREQUIRED_DEPENDENCY_METADATA_KEYSconstant (module-level + class attribute for subclass override)_validate_dependency_metadata(data)— collects all errors before raising once with an aggregated message:dependency_metadatacalls validation before returning loaded JSON@runner.catches(...)onrunnow includesDependencyMetadataErrorfor clean CLI exitTests
test_checker_dependency_metadatato assert validation is invokedtest_checker_run_catchesto coverDependencyMetadataErrortest_checker__validate_dependency_metadata(valid data, missing key, multiple errors, non-dict value)test_checker_run_catches_dependency_metadata_errortests/test_exceptions.pyassertingDependencyMetadataErroris anExceptionsubclassOriginal prompt
Follow-up to the code-review notes in
py/envoy.dependency.check/REVIEW.md(PR #4422). This is the report's recommended follow-up PR #3: fix theTypedDictschema mismatch and add input validation so malformed dependency metadata is reported clearly rather than producing crypticKeyErrors deep inside the checker loop.Background
envoy/dependency/check/typing.pycurrently splits the dependency metadata schema into a required base and atotal=Falseextension:But in
envoy/dependency/check/abstract/dependency.pybothurlsandsha256are accessed unconditionally:So a malformed input file silently raises
KeyErrormid-check. Findings 7.1 and 11.2 ofREVIEW.mdcover this.Scope
All edits in
py/envoy.dependency.check/. Two related changes, one PR.1. Tighten the
TypedDictschema (finding 7.1)File:
envoy/dependency/check/typing.py.urlsandsha256are required by the rest of the codebase — promote them to required fields.cpeis genuinely optional — keep it optional.Suggested shape:
This keeps
cpeoptional via thetotal=Falsesubclass pattern that the codebase already uses, while makingurlsandsha256part of the required base. mypy will now flag any unconditional access tocpe(there shouldn't be any).2. Pre-flight schema validation on the input JSON (finding 11.2)
File:
envoy/dependency/check/abstract/checker.py.dependency_metadatacurrently does:After loading the JSON, validate that every entry contains the required keys (
release_date,version,urls,sha256) before the checker constructsDependencyobjects. On failure, raise a new exception type with a clear message that names the offending dependency and the missing key(s).Implementation suggestions (use whichever fits cleanly — keep it lightweight, no new third-party deps):
Add a new exception in
envoy/dependency/check/exceptions.py, e.g.:In
abstract/checker.py, add a class attribute listing the required keys (don't hard-code them inline more than once):Run validation as part of
dependency_metadata(or in a dedicated_validate_dependency_metadatahelper called from there). Collect all errors per dependency and raise once with a multi-line message — surfacing every problem in one run is much friendlier than failing on the first one. Example shape:Wire it through the existing
@runner.catches(...)onrunso the user gets a clean exit message rather than a traceback. Addexceptions.DependencyMetadataErrorto the catches tuple alongsideexceptions.GithubTokenError.Keep the validation simple and structural (presence + basic type). Do NOT add a heavy schema library (jsonschema, pydantic, etc.) — a hand-rolled pass is sufficient and matches the codebase style.
Tests
Update / add tests under
py/envoy.dependency.check/tests/:tests/test_abstract_checker.py:test_checker__validate_dependency_metadata— parametrised cases:DependencyMetadataError, message names the dep id and missing key.This pull request was created from Copilot chat.