Skip to content

py-fuzzer: allow relative executable paths#18915

Merged
sharkdp merged 2 commits intomainfrom
david/fuzzer-relative-paths
Jun 24, 2025
Merged

py-fuzzer: allow relative executable paths#18915
sharkdp merged 2 commits intomainfrom
david/fuzzer-relative-paths

Conversation

@sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Jun 24, 2025

Summary

I tried running py-fuzzer using executables in the current working directory, but that failed with:

▶ uvx --from ./python/py-fuzzer --reinstall fuzz --test-executable ./ty_feature --bin=ty --baseline-executable ./ty_main --only-new-bugs 0-500
Usage: fuzz [-h] [--only-new-bugs] [--quiet] [--test-executable TEST_EXECUTABLE] [--baseline-executable BASELINE_EXECUTABLE] --bin {ruff,ty} seeds [seeds ...]
fuzz: error: Bad argument passed to `--baseline-executable`: no such file or executable PosixPath('ty_main')
 "Bad argument passed to `--baseline-executable`: no such file or executable PosixPath('ty_main')"

Using .absolute() on the Path fixes this.

Test Plan

Successful py-fuzzer run with the invocation above.

@sharkdp sharkdp requested a review from AlexWaygood as a code owner June 24, 2025 12:32
@sharkdp sharkdp added the internal An internal refactor or improvement label Jun 24, 2025
@sharkdp sharkdp force-pushed the david/fuzzer-relative-paths branch from 5b44ee1 to d40d6bd Compare June 24, 2025 12:32
@AlexWaygood
Copy link
Member

Or we could call resolve() eagerly when parsing the CLI arguments?

diff --git a/python/py-fuzzer/fuzz.py b/python/py-fuzzer/fuzz.py
index 226cab31fa..5359e28273 100644
--- a/python/py-fuzzer/fuzz.py
+++ b/python/py-fuzzer/fuzz.py
@@ -54,9 +54,7 @@ def ty_contains_bug(code: str, *, ty_executable: Path) -> bool:
         input_file = Path(tempdir, "input.py")
         input_file.write_text(code)
         completed_process = subprocess.run(
-            [ty_executable.resolve(), "check", input_file],
-            capture_output=True,
-            text=True,
+            [ty_executable, "check", input_file], capture_output=True, text=True
         )
     return completed_process.returncode not in {0, 1, 2}
 
@@ -308,6 +306,10 @@ class ResolvedCliArgs:
     quiet: bool
 
 
+def resolved_path(p: str) -> Path:
+    return Path(p).resolve()
+
+
 def parse_args() -> ResolvedCliArgs:
     """Parse command-line arguments"""
     parser = argparse.ArgumentParser(
@@ -339,7 +341,7 @@ def parse_args() -> ResolvedCliArgs:
             "Executable to test. "
             "Defaults to a fresh build of the currently checked-out branch."
         ),
-        type=Path,
+        type=resolved_path,
     )
     parser.add_argument(
         "--baseline-executable",
@@ -348,7 +350,7 @@ def parse_args() -> ResolvedCliArgs:
             "Defaults to whatever version is installed "
             "in the Python environment."
         ),
-        type=Path,
+        type=resolved_path,
     )
     parser.add_argument(
         "--bin",
@@ -369,9 +371,7 @@ def parse_args() -> ResolvedCliArgs:
             )
         try:
             subprocess.run(
-                [args.baseline_executable.resolve(), "--version"],
-                check=True,
-                capture_output=True,
+                [args.baseline_executable, "--version"], check=True, capture_output=True
             )
         except FileNotFoundError:
             parser.error(

@github-actions
Copy link
Contributor

github-actions bot commented Jun 24, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@MichaReiser
Copy link
Member

Or use absolute because we don't need to resolve symlinks ;)

@sharkdp sharkdp merged commit 0edbd6c into main Jun 24, 2025
35 checks passed
@sharkdp sharkdp deleted the david/fuzzer-relative-paths branch June 24, 2025 13:16
dcreager added a commit that referenced this pull request Jun 24, 2025
* main:
  [ty] Fix false positives when subscripting an object inferred as having an `Intersection` type (#18920)
  [`flake8-use-pathlib`] Add autofix for `PTH202` (#18763)
  [ty] Add relative import completion tests
  [ty] Clarify what "cursor" means
  [ty] Add a cursor test builder
  [ty] Enforce sort order of completions (#18917)
  [formatter] Fix missing blank lines before decorated classes in .pyi files (#18888)
  Apply fix availability and applicability when adding to `DiagnosticGuard` and remove `NoqaCode::rule` (#18834)
  py-fuzzer: allow relative executable paths (#18915)
  [ty] Change `environment.root` to accept multiple paths (#18913)
  [ty] Rename `src.root` setting to `environment.root` (#18760)
  Use file path for detecting package root (#18914)
  Consider virtual path for various server actions (#18910)
  [ty] Introduce `UnionType::try_from_elements` and `UnionType::try_map` (#18911)
  [ty] Support narrowing on `isinstance()`/`issubclass()` if the second argument is a dynamic, intersection, union or typevar type (#18900)
  [ty] Add decorator check for implicit attribute assignments (#18587)
  [`ruff`] Trigger `RUF037` for empty string and byte strings (#18862)
  [ty] Avoid duplicate diagnostic in unpacking (#18897)
  [`pyupgrade`] Extend version detection to include `sys.version_info.major` (`UP036`) (#18633)
  [`ruff`] Frozen Dataclass default should be valid (`RUF009`) (#18735)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants