fix(freshness-monitor): deploy.sh preflight test step now sees runtime deps#337
Merged
Merged
Conversation
…e deps Problem: PR #335 placed the preflight test step (`python3 -m pytest test_handler.py`) BEFORE the pip install step. The test imports index.py which imports yaml + boto3 + alpha_engine_lib.{alerts, artifact_freshness} at module load — none of which are guaranteed in the caller's bare python. Brian's run hit ModuleNotFoundError on yaml because his shell python lacked pyyaml. Same root cause applied to the registry validator (also imports yaml). Fix: restructure step ordering so deps install before consumers run: 0a. Syntax-check handler (no imports — works on bare python) 0b. Verify ae-config clone present (path check only) 1. Install runtime deps into $PKG via pip --target 1a. Validate registry with PYTHONPATH=$PKG (yaml available) 1b. Install pytest into separate $TEST_DEPS dir; run handler tests with PYTHONPATH=$PKG:$TEST_DEPS (all deps available; pytest NOT bundled into Lambda zip) 1c. Copy handler + zip Lambda package (unchanged) The $TEST_DEPS separate dir keeps pytest + its transitive deps out of the final Lambda zip — only runtime deps from requirements.txt end up in the deployable artifact. Both temp dirs cleaned via the existing trap. End-to-end dry-run verified: index.py syntax OK ✅ ARTIFACT_REGISTRY.yaml validated: 48 artifacts + 27 grandfathered paths 12 passed in 0.08s Packaged function.zip (22498727 bytes) Why this matters: deploy.sh is the only path operators have to ship this Lambda; if the preflight fails on Brian's machine the entire arc's Phase 6 deploy is blocked. This is a one-character-deep bug class (`if [[ -f test_handler.py ]]; then python3 -m pytest` assumes deps available) that bit because PR #335 mirrored the sf-telegram-notifier deploy.sh pattern without noting that sf-telegram-notifier's test stubs all its 3rd-party imports via sys.modules whereas this Lambda's test exercises real lib substrate. Composes with the Phase 6 OBSERVE-mode deploy that's the only remaining item on the artifact-freshness-monitor arc. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes the
ModuleNotFoundError: No module named 'yaml'failure when runningbash infrastructure/lambdas/freshness-monitor/deploy.shagainst a Python environment that doesn't have the Lambda's runtime deps pre-installed.Root cause
PR #335 placed the preflight test step (
python3 -m pytest test_handler.py) BEFORE the pip-install step. The test importsindex.pywhich importsyaml+boto3+alpha_engine_lib.{alerts,artifact_freshness}at module load — none of which are guaranteed in the caller's bare python. Same issue applied to the registry validator (also imports yaml).The pattern was mirrored from
sf-telegram-notifier/deploy.sh, but that Lambda's test_handler.py STUBS all its 3rd-party imports viasys.modules(onlypytestis a real dep). The freshness-monitor's test exercises real lib substrate (ArtifactSpec,CheckResult,check_freshness) so stubbing those defeats the test's purpose — installing the deps is the right answer.Fix
Restructure step ordering so deps install before consumers run:
$PKG$PKGPYTHONPATH=$PKGpytest→$TEST_DEPS; run handler tests withPYTHONPATH=$PKG:$TEST_DEPSThe
$TEST_DEPSseparate dir keepspytest+ its transitive deps out of the final Lambda zip — onlyrequirements.txtdeps end up in the deployable artifact. Both temp dirs cleaned via the existingtrap.Verified
End-to-end dry-run on the operator machine (homebrew python3):
Why this matters
deploy.shis the only path operators have to ship this Lambda; if the preflight fails on Brian's machine the artifact-freshness-monitor arc's Phase 6 deploy is blocked. This is a one-character-deep bug class (if [[ -f test_handler.py ]]; then python3 -m pytestassumes deps available) that bit because PR #335 mirrored the sf-telegram-notifier deploy.sh pattern without noting the test-stubbing difference.Test plan
bash infrastructure/lambdas/freshness-monitor/deploy.sh --dry-run— clean end-to-endpytest infrastructure/lambdas/freshness-monitor/test_handler.py(in lib venv) — 12 passing--bootstrapand instantiates the Lambda🤖 Generated with Claude Code