Bug hunt

The Preview That Secretly Writes

The scariest bug a tool can have: a preview that isn't one. Pip ran tidy("inbox") in preview mode to check the plan first. The files moved anyway, and a new tidy folder appeared.

In a trustworthy preview, every change sits behind if apply:. Changes include rename(), mkdir(), write_text(), unlink() and open(..., "w"). Reading and printing are fine.

if apply:
    target.parent.mkdir(exist_ok=True)
    source.rename(target)
else:
    print(f"would move {source.name}")

The bug

tidy(folder, apply=False) should move every file into a tidy subfolder with a clean name, but only when apply is True. In preview mode it should only print would move OLD -> NEW lines. Right now the preview creates a folder and moves the files.

Assignment

Fix tidy so that:

  1. With apply=False, it prints one would move OLD -> NEW line per file and changes nothing on disk.
  2. With apply=True, it makes the tidy folder, moves each file, and prints moved OLD -> NEW.
  3. It still returns the plan.