fix(workflow): prevent false positives in cli import check #4048
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
The CI check for forbidden
clipackage imports uses an overly broad regex pattern^from.*cli.*import.*$that incorrectly matches any import containing the substring "cli". This causes false positives for legitimate imports like:from a2a.client import Clientfrom a2a.client.card_resolver import A2ACardResolverfrom mycli import somethingThese are valid imports from packages named
client,mycli, etc., not the forbiddenclipackage.PR where issue was found: #4023
Solution:
Updated the regex pattern to
^from\s+([^ ]*\.)?cli(\s|\.)which correctly matches only imports from a package literally namedcli:^from\s+- matches "from" followed by whitespace([^ ]*\.)?- optionally matches a module path prefix (e.g.,google.adk.)cli- the literal "cli" package name(\s|\.)- must be followed by whitespace (forimport) or a dot (for submodules)Testing Plan
Unit Tests:
Manual Verification:
Tested the regex patterns against various import statements:
from a2a.client import Clientfrom client import somethingfrom mycli import foofrom precli.something import barfrom cli import somethingfrom google.adk.cli import barfrom google.adk.cli.utils import bazChecklist
Additional context
Files changed:
.github/workflows/check-file-contents.yml- Fixed regex pattern for cli import detection