Skip to content

fix: validate parent packages option in Python PIP workflow - #963

Merged
roger-zhangg merged 3 commits into
aws:developfrom
roger-zhangg:fix/parent-packages-validation
Nov 25, 2026
Merged

roger-zhangg merged 3 commits into
aws:developfrom
roger-zhangg:fix/parent-packages-validation

Conversation

@roger-zhangg

Copy link
Copy Markdown
Member

Issue #, if available:

Description of changes

Validate the parent_python_packages option before the CreateParentPackages action creates package directories. Malformed values now fail the build with a clear error message instead of producing an unexpected directory layout.

Description of how you validated changes

  • Added unit tests covering valid and malformed values.
  • pytest tests/unit, ruff check aws_lambda_builders, black --check.

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Validate the parent packages option before creating package directories and fail with a clear error for malformed values. Adds unit tests.
@aws-sam-tooling-bot

aws-sam-tooling-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

🧪 Hands-on test: No problems observed in 6 scenarios

Commit 7b15d38 · build LambdaToolingHandsOn-NoDocker:e04ee9f6-084f-4a1e-8c95-474f9eecf2af. The plan's scenarios ran on an isolated build host; a problem is reported only if it reproduced at least twice. Passing scenarios show only that these checks behaved as expected, not that the change is correct.

Scenarios

Scenario Planned check Result Runner's note
S1 Main path: a normal dotted value still nests the build output under the parent packages. ✅ pass Head: LambdaBuilder.build with no manifest and parent_python_packages='foo.bar' printed 'RESULT: OK' and listed art/foo/bar/app.py and src/app.py, with no art/app.py and nothing under outside/. The t…
S2 Fix: an absolute-path value pointing outside the artifacts dir must fail instead of moving the build output outside. ✅ pass Head: an absolute value pointing outside the artifacts dir failed with WorkflowFailedError 'PythonPipBuilder:CreateParentPackages - Invalid parent packages value '/work/scratch/ho/h-s2/outside/pkg'. …
S3 Fix: a symlinked directory already in the artifacts dir (art/foo -> outside) must not let 'foo.bar' create dirs or move… ✅ pass Head: with art/foo symlinked to outside/, the value 'foo.bar' failed with WorkflowFailedError "Invalid parent packages value 'foo.bar'". outside/ was empty, and art/ still held app.py and the foo sym…
S4 Edge cases that must keep working: an absolute path inside the artifacts dir, a relative value with a slash, and a doub… ✅ pass Head and base behave the same. An absolute path inside art/ gives art/pkg/app.py, 'a/b' gives art/a/b/app.py and 'foo..bar' gives art/foo/bar/app.py. All three print 'RESULT: OK' and write nothing un…
S5 Value '.' resolves to the artifacts dir itself. It passes the new check and should hit the existing FileExistsError war… ✅ pass Head and base behave the same for the value '.': both log 'Skipping creating package .../art as it would overwrite existing folder', print 'RESULT: OK' and keep art/app.py at the top level.
S6 The PR's unit tests and the rest of the python_pip unit suite pass, and lint is clean. ✅ pass pytest tests/unit/workflows/python_pip: 157 passed, exit 0. The new TestPythonCreateParentPackagesActionFileSystem cases all passed: 2 parameterized outside-dir cases, the linked-directory case and t…
Runner's notes in full
  • S1: Head: LambdaBuilder.build with no manifest and parent_python_packages='foo.bar' printed 'RESULT: OK' and listed art/foo/bar/app.py and src/app.py, with no art/app.py and nothing under outside/. The test driver lived at /work/scratch/run.py instead of /tmp/ho/run.py and used roots under /work/scratch/ho; its content matches the plan.
  • S2: Head: an absolute value pointing outside the artifacts dir failed with WorkflowFailedError 'PythonPipBuilder:CreateParentPackages - Invalid parent packages value '/work/scratch/ho/h-s2/outside/pkg'. Parent packages must be a dot-separated list...'. art/app.py stayed in place and nothing was written under outside/. Base: 'RESULT: OK' with outside/pkg/app.py and no art/app.py, which confirms the escape on base that the PR fixes.
  • S3: Head: with art/foo symlinked to outside/, the value 'foo.bar' failed with WorkflowFailedError "Invalid parent packages value 'foo.bar'". outside/ was empty, and art/ still held app.py and the foo symlink. Base: 'RESULT: OK' with outside/bar/app.py created and app.py moved out of art/.
  • S4: Head and base behave the same. An absolute path inside art/ gives art/pkg/app.py, 'a/b' gives art/a/b/app.py and 'foo..bar' gives art/foo/bar/app.py. All three print 'RESULT: OK' and write nothing under outside/.
  • S6: pytest tests/unit/workflows/python_pip: 157 passed, exit 0. The new TestPythonCreateParentPackagesActionFileSystem cases all passed: 2 parameterized outside-dir cases, the linked-directory case and the moves-artifacts case. ruff check aws_lambda_builders printed 'All checks passed!' and exited 0.

🤖 Automated hands-on test — not a review approval · model claude-opus-5.5 · Kiro kiro-cli 2.33.1 · build LambdaToolingHandsOn-NoDocker:e04ee9f6-084f-4a1e-8c95-474f9eecf2af · commit 7b15d38

History (2)
Commit Result When (UTC) Build
7b15d38 No problems observed 2026-11-16 19:42 LambdaToolingHandsOn-NoDocker:e04ee9f6-084f-4a1e-8c95-474f9eecf2af
5e37be7 No problems observed 2026-11-11 01:23 LambdaToolingHandsOn-NoDocker:15cfbac1-dd61-4371-9a16-6988d0763d3f

@bnusunny bnusunny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The check blocks paths that escape the build dir, the tests cover both the absolute-path and symlink cases, and CI is green.

@roger-zhangg
roger-zhangg enabled auto-merge (squash) November 25, 2026 21:15
@roger-zhangg
roger-zhangg merged commit d8ed4a5 into aws:develop Nov 25, 2026
124 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants