fix(workflow): prevent false positives in cli import check#4048
Closed
KrshnKush wants to merge 2 commits intogoogle:mainfrom
Closed
fix(workflow): prevent false positives in cli import check#4048KrshnKush wants to merge 2 commits intogoogle:mainfrom
KrshnKush wants to merge 2 commits intogoogle:mainfrom
Conversation
Contributor
|
Note Gemini is unable to generate a summary for this pull request due to the file types involved not being currently supported. |
9 tasks
Collaborator
|
Hi @KrshnKush , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share. |
Collaborator
|
Hi @DeanChensj , can you please review this. LGTM , resolves a lot of false positives. |
wuliang229
reviewed
Jan 15, 2026
| set +e | ||
| FILES_WITH_FORBIDDEN_IMPORT=$(grep -lE '^from.*cli.*import.*$' $CHANGED_FILES) | ||
| FILES_WITH_FORBIDDEN_IMPORT=$(grep -lE '^from\s+([^ ]*\.)?cli(\s|\.)' $CHANGED_FILES) | ||
| GREP_EXIT_CODE=$? |
Collaborator
There was a problem hiding this comment.
A few things:
- Instead of "\s+", just match the space character " "
- don't match any pattern before "cli", just match optional "google.adk." or "adk.", i.e. (google.adk.)|(adk.)
- add back the matching of "import"
Collaborator
|
c222a45 should have fixed the issue. |
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.
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