getappmap / navie-benchmark

Navie benchmarks
MIT License
0 stars 0 forks source link

Solver errors if the generated test name is a directory #71

Closed kgilpin closed 3 weeks ago

kgilpin commented 1 month ago

https://github.com/getappmap/navie-benchmark/actions/runs/11240112133/job/31248724973#step:7:650

  File "/home/runner/work/navie-benchmark/navie-benchmark/solver/workflow/solve_test.py", line 248, in generate
    return generator.apply(test_file_path, test_patch)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/navie-benchmark/navie-benchmark/solver/workflow/generate_test.py", line 248, in apply
    with open(test_file_name, "w") as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^
IsADirectoryError: [Errno 21] Is a directory: 'tests/backends'
github-actions[bot] commented 1 month ago

Title: Handle IsADirectoryError When Generated Test Name is a Directory

Problem:

The application encounters an IsADirectoryError when attempting to open a file using a path that is a directory. Specifically, this occurs in the workflow when applying a generated test patch. The error trace indicates that the process tries to write a test file to a path that is mistakenly recognized as a directory.

Analysis:

The root cause of this issue is the use of an incorrect file path that points to a directory instead of a file. This can arise when generating test file names and not verifying whether they refer to existing directories. The error surfaced in the generate_test.py module where the code tries to open a path for writing but encounters a directory. This suggests a need for additional checks or transformations regarding generated test file paths to ensure they are valid file paths and do not collide with directory paths.

The issue likely happens because the naming convention for tests in some scenarios does not check if the test name could be a directory. This necessitates ensuring that the generated paths conform only to files by performing pre-checks or safeguarding the file operations.

Proposed Changes:

  1. Location: solver/workflow/generate_test.py

    • Before opening a path in write mode, implement a check to ascertain whether the path resolves to a directory on the filesystem. If it does, apply a corrective action, like altering the generated filename to avoid directory-name clashes.
    • Implement logic to ensure the file path has a valid filename, possibly by appending a standard suffix or filename if the generated path is ambiguous as a file or directory.
  2. Location: solver/workflow/solve_test.py

    • From the error trace, around the lines calling generator.apply for test files, introduce logging statements upon encountering an IsADirectoryError, clearly indicating the erroneous directory path and intention to correct it.
    • Add a try-catch block to gracefully handle the IsADirectoryError and provide a retry mechanism with corrected file paths.
  3. Location: Workflow execution point

    • Review the function responsible for generating the test patch filename, ensuring it not only generates unique names but does so in a way that file paths do not overlap with existing directories.
    • Incorporate a configuration or mapping that differentiates directory paths from potential file paths during the patch application to prevent similar errors in future executions.

By implementing these changes, the system will be better equipped to handle unintended directory path issues during test generation and application, enhancing robustness and reliability.