verify-action-build: unified walker over composite action graph (closes #744)#750
Open
verify-action-build: unified walker over composite action graph (closes #744)#750
Conversation
Closes #744. Each security check previously did its own recursion over the nested action graph: `analyze_nested_actions` and `analyze_binary_downloads_recursive` each re-fetched the same `action.yml` files, re-parsed the same `uses:` refs, and carried their own `_depth` / `_visited` bookkeeping. As more checks are added (e.g. the compatible-licensing check from #686), that cost compounds: N checks × M nested actions = N × M redundant fetches. This commit introduces a single depth-first pre-order walker, `walk_actions`, that yields one `VisitedAction` per unique `org/repo/sub_path@commit` reached from the root. Each check is now a pure function that consumes the iterator: for visited in walk_actions(root_org, root_repo, root_commit, root_sub_path): do_check(visited) The walker enforces the shared descent rules in one place: local and docker refs are terminal stubs, non-hash-pinned refs are yielded but not descended, trusted orgs (`actions`, `github`) at depth > 0 are yielded as stubs without fetching their `action.yml`, and depth is capped at 3. `analyze_nested_actions` and `analyze_binary_downloads_recursive` are rewritten as pure consumers of the walker — no recursion, no private `_depth` / `_visited` / `_checked` kwargs. They can be called by a caller that enumerates visits once and dispatches to multiple checks. `fetch_action_yml` is also `@lru_cache`-wrapped so any remaining same-commit fetch inside a check (e.g. the nested-action display check's lazy type lookup for a trusted-org ref) reuses the walker's earlier hit. All 135 existing tests pass unchanged, and end-to-end verification still flags the unverified `tc.downloadTool` call in `posit-dev/setup-air` as before. Generated-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
Author
|
cc: @dave2wave |
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.
Closes #744.
Summary
Replace the per-check recursions in
utils/verify_action_build/security.pywith a single depth-first pre-order walker —walk_actions— that yields oneVisitedActionper uniqueorg/repo/sub_path@commit. Each security check becomes a pure function over visits:Motivation (from #744)
analyze_nested_actionsandanalyze_binary_downloads_recursiveeach re-fetchedaction.ymlfiles and re-parsed the sameuses:refs, with private_depth/_visitedbookkeeping. As more checks land (e.g. the compatible-licensing check from #686), that cost compounds.Changes
walk_actions(new,security.py) — DFS pre-order generator that yieldsVisitedActiondataclasses (org,repo,commit_hash,sub_path,depth,action_yml,action_type,incoming_ref,parent_yml,approved,trusted). Enforces the shared descent rules in one place:./…) and docker (docker://…) refs are terminal stubsactions,github) at depth > 0 are yielded as stubs without fetching theiraction.ymlanalyze_binary_downloads_recursive— rewritten as a pure consumer of the walker; no recursion, no_depth/_visitedkwargs.analyze_nested_actions— same treatment. Preserves existing display ordering (pre-order matches the old nested printout) and thechecked_actionslist returned to the summary table.fetch_action_ymlis@lru_cache-wrapped — any remaining same-commit fetch inside a check (e.g. the lazy type lookup for a trusted-org ref in the nested-action display) reuses the walker's earlier hit.Test plan
uv run --with pytest python -m pytest tests/ -quv run utils/verify-action-build.py --from-pr 724 --cistill reportssrc/download/download-version.tsline 39 as an unverifiedtc.downloadToolcall and exits 1Future follow-up
With the walker in place, the compatible-licensing check from #686 can be added as another pure function over visits instead of building a third recursive walk.