Skip to content

fix: align executable lookup on Windows with other platforms - #964

Open
roger-zhangg wants to merge 2 commits into
aws:developfrom
roger-zhangg:fix/executable-lookup
Open

roger-zhangg wants to merge 2 commits into
aws:developfrom
roger-zhangg:fix/executable-lookup

Conversation

@roger-zhangg

Copy link
Copy Markdown
Member

Issue #, if available:

Description of changes

Align executable lookup on Windows with Linux and macOS:

  • which() resolves executables only from PATH and the configured executable search paths; it no longer prepends the working directory on Windows.
  • Empty PATH entries (for example from a trailing separator) are ignored.
  • Resolved paths are returned as absolute paths.
  • The Python UV workflow uses the same lookup instead of shutil.which.

Project-local tools that are intentionally supported (e.g. gradlew, a project esbuild) are unaffected, since they are found via explicit executable search paths.

Description of how you validated changes

  • Added unit tests for the Windows lookup, empty PATH entries, absolute paths, and the UV workflow lookup.
  • pytest tests/unit tests/functional, 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.

@roger-zhangg
roger-zhangg requested a review from a team as a code owner November 11, 2026 01:17
@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 bf6d36e · build LambdaToolingHandsOn-NoDocker:c179ba13-1ffa-48ec-9596-4350d79c0a75. 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 The PR's new and changed unit tests for which() and the UV OSUtils pass, along with the resolver tests that call which(… ✅ pass tests/unit/test_utils.py, tests/unit/workflows/python_uv/test_utils.py and tests/unit/test_path_resolver.py on head: 70 passed, 5 subtests passed. TestWhich.test_windows_lookup_uses_only_search_paths…
S2 Empty PATH entries (trailing, leading, doubled separator) no longer make which() find an executable in the working dire… ✅ pass Head: every PATH variant ('/tmp/wt/bin:', ':/tmp/wt/bin', '/tmp/wt/bin::/usr/bin', '/tmp/wt/bin') with cwd=/tmp/wt/work prints '-> []'. Base: the three variants with an empty entry print "-> ['tool']…
S3 which() returns absolute paths for matches found through relative executable_search_paths or relative PATH entries. A c… ✅ pass Head: search_paths=['work'] -> ['/tmp/wt/work/tool'], PATH=work -> ['/tmp/wt/work/tool'], search_paths=['.'] -> ['/tmp/wt/work/tool'], which('./tool') -> './tool' (plain string, unchanged), missing -…
S4 The UV workflow's OSUtils.which still finds the installed uv as the same absolute path shutil.which gives, and handles … ✅ pass Head OSUtils.which('uv') -> '/work/scratch/venv-head/bin/uv', equal to shutil.which, absolute. cwd-only uv with PATH='/tmp/wt/bin:' -> None (base: 'uv', from shutil.which treating the empty entry as …
S5 Real UV builds still work after the switch: the repo's integration test builds a requirements.txt project with uv found… ✅ pass Head: 10 selected tests passed (test_workflow_uses_requirements_txt_file and 4 parametrized test_workflow_selects_lambda_compatible_wheel cases, each in 2 experimental-flag classes), none skipped for…
S6 No regressions in the other workflows that call which() (custom make, gradle, maven, dotnet, esbuild, rust, path resolv… ✅ pass Head: pytest tests/unit tests/functional -> 1201 passed, 64 subtests passed, exit 0. No failures in which, PathResolver or executable resolver tests.
Runner's notes in full
  • S1: tests/unit/test_utils.py, tests/unit/workflows/python_uv/test_utils.py and tests/unit/test_path_resolver.py on head: 70 passed, 5 subtests passed. TestWhich.test_windows_lookup_uses_only_search_paths, test_ignores_empty_path_entries, test_returns_absolute_paths and TestOSUtils.test_which_returns_first_match all PASSED. The Windows change is only covered by this mocked unit test; it was not exercised on a real Windows host.
  • S2: Head: every PATH variant ('/tmp/wt/bin:', ':/tmp/wt/bin', '/tmp/wt/bin::/usr/bin', '/tmp/wt/bin') with cwd=/tmp/wt/work prints '-> []'. Base: the three variants with an empty entry print "-> ['tool']" (the working-directory executable is found), the last prints '-> []'. Matches the expected behavior change.
  • S3: Head: search_paths=['work'] -> ['/tmp/wt/work/tool'], PATH=work -> ['/tmp/wt/work/tool'], search_paths=['.'] -> ['/tmp/wt/work/tool'], which('./tool') -> './tool' (plain string, unchanged), missing -> []. Base returns relative paths: 'work/tool', 'work/tool', './tool'; './tool' and missing are identical. As the plan's risk note says, a command with a directory part still returns a relative string on head.
  • S4: Head OSUtils.which('uv') -> '/work/scratch/venv-head/bin/uv', equal to shutil.which, absolute. cwd-only uv with PATH='/tmp/wt/bin:' -> None (base: 'uv', from shutil.which treating the empty entry as cwd). './uv' -> './uv' on both. Missing command -> None on both. Empty PATH -> None on both. No tracebacks.
  • S5: Head: 10 selected tests passed (test_workflow_uses_requirements_txt_file and 4 parametrized test_workflow_selects_lambda_compatible_wheel cases, each in 2 experimental-flag classes), none skipped for 'uv not available'. The requirements test asserts six.py and six-1.16.0.dist-info are in the artifacts dir. Base: same 10 passed. Runs took under 0.5s, likely due to the uv cache.

🤖 Automated hands-on test — not a review approval · model claude-opus-5.5 · Kiro kiro-cli 2.33.1 · build LambdaToolingHandsOn-NoDocker:c179ba13-1ffa-48ec-9596-4350d79c0a75 · commit bf6d36e

History (4)
Commit Result When (UTC) Build
bf6d36e No problems observed 2026-11-23 22:20 LambdaToolingHandsOn-NoDocker:c179ba13-1ffa-48ec-9596-4350d79c0a75
d1afd0e Problems reproduced: Unused 'import shutil' left in python_uv/utils.py makes 'ruff check aws_lambda_… 2026-11-23 19:39 LambdaToolingHandsOn-NoDocker:352e2172-a55b-4194-8144-0961047a968e
5574e9a No problems observed 2026-11-16 19:49 LambdaToolingHandsOn-NoDocker:9a47ac10-5613-4162-89aa-ad3e4467d557
0e806f8 No problems observed 2026-11-11 01:23 LambdaToolingHandsOn-NoDocker:0049fecf-2aca-4733-882b-74a3cdb712f2

@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.

The code change looks right, but test_returns_absolute_paths fails on every Windows unit job, so CI is red because of this PR. See the inline comment.

Comment thread tests/unit/test_utils.py Outdated
self._create_executable(self.working_dir / "tool")

with patch.dict(os.environ, {"PATH": str(self.path_dir)}):
self.assertEqual(which("tool", executable_search_paths=["."]), [os.path.join(os.getcwd(), "tool")])

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.

This fails on Windows: which() only tries tool + each PATHEXT entry there, so an extensionless tool is never found and the result is []. test_ignores_empty_path_entries above has the same problem: on Windows it passes whether or not the empty PATH entry is skipped. Create tool.CMD and patch PATHEXT like test_windows_lookup_uses_only_search_paths does, or mark these two tests as non-Windows.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, fixed in 5574e9a. Both tests now create the file name that which() looks for on the current platform: tool.CMD with PATHEXT patched on Windows, and tool elsewhere. On Windows, test_ignores_empty_path_entries now checks the empty entry for real. I confirmed that both tests fail without the change in utils.py, on Linux and with sys.platform set to win32. I also rebased onto the latest develop.

reedham-aws
reedham-aws previously approved these changes Nov 17, 2026
bnusunny
bnusunny previously approved these changes Nov 17, 2026
@roger-zhangg
roger-zhangg dismissed stale reviews from bnusunny and reedham-aws via d1afd0e November 23, 2026 19:32
@roger-zhangg
roger-zhangg enabled auto-merge (squash) November 23, 2026 19:32

@aws-sam-tooling-bot aws-sam-tooling-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧪 Hands-on test reproduced 1 new problem on commit d1afd0e. Commands and evidence are in the hands-on comment.

  1. [BUG] Unused 'import shutil' left in python_uv/utils.py makes 'ruff check aws_lambda_builders' fail (F401) · low · aws_lambda_builders/workflows/python_uv/utils.py:8

🤖 Automated hands-on test — not a review approval

which() no longer prepends the working directory to the search path on Windows, ignores empty PATH entries, and returns absolute paths. The Python UV workflow now uses the same lookup. Adds unit tests.
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