fix(cli): Discover newly staged agents during validation - #6929
Open
yousefalbanna1 wants to merge 1 commit into
Open
fix(cli): Discover newly staged agents during validation#6929yousefalbanna1 wants to merge 1 commit into
yousefalbanna1 wants to merge 1 commit into
Conversation
Python's import finder can retain stale directory contents when an agent package is created after the parent directory has already been scanned. Invalidate import caches before validation so newly staged agent packages can be imported reliably.
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.
Problem:
_validate_agent_import()can fail to import a newly created agent package when Python has already cached the contents of the package's parent directory.In that case, the package and
agent.pyexist, butimportlib.import_module()can still raiseModuleNotFoundError.Solution:
Invalidate Python's import caches immediately before importing the agent package.
A regression test was added that primes the import cache before creating the package and verifies that validation can still discover the new agent.
Testing Plan
Unit Tests:
I have added unit tests for my change.
All unit tests pass locally.
python -m pytest tests/unittests/cli/utils/test_cli_deploy.py::TestValidateAgentImport -q— 12 passed.python -m pytest tests/unittests/cli/utils/test_cli_deploy.py -q— 98 passed.tox:tests/unittests/test_import_loading.py.The same two Python 3.12 failures reproduce on the unmodified base commit
6eb1d35d.Pre-commit checks for the changed files — passed.
Manual End-to-End (E2E) Tests:
Built the package with
uv build, installed the generated wheel in a clean virtual environment, and verified that ADK imports successfully and the updated validation code is present.A cloud deployment was not performed.
Additional context
The two Python 3.12 tox failures are unrelated to this change and reproduce on the unmodified base commit.