uv/crates/uv-cli
Scott Sanderson 7154800e0c
Detect infinite recursion in uv run. (#11386)
<!--
Thank you for contributing to uv! To help us out with reviewing, please
consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

Handle potential infinite recursion if `uv run` recursively invokes `uv
run`. This can happen if the shebang line of a script includes `uv run`,
but does not pass `--script`.

Handled by adding a new environment variable `UV_RUN_RECURSION_DEPTH`,
which contains a counter of the number of times that uv run has been
recursively invoked. If unset, it defaults to zero, and each time uv run
starts a subprocess we increment the counter, erroring if the value is
greater than a configurable (but not currently exposed or documented)
threshold.

Closes https://github.com/astral-sh/uv/issues/11220.

## Test Plan

I've added a snapshot test to `uv/crates/uv/tests/it/run` that tests the
end-to-end recursion detection flow. I've currently made it a unix-only
test because I'm not sure offhand how uv run will interact with shebang
lines on windows.

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
2025-02-12 18:58:43 +00:00
..
src Detect infinite recursion in uv run. (#11386) 2025-02-12 18:58:43 +00:00
build.rs Fix commits_since_last_tag in version info (#9730) 2024-12-09 09:43:27 -06:00
Cargo.toml chore(uv): more env var mappings (#8193) 2024-10-15 07:59:03 -04:00