mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 13:38:36 +00:00
first_light.py: refuse a linked first_light even when nothing stale lies behind it
Review of #3577: reset_run_folders() judged first_light only through the dxbc and spirv folders it found. When first_light is a symlink or a junction to a folder that has neither, there was nothing to judge, and the new dxbc was created in the folder the link points to, outside the work folder. first_light itself is now checked before its children. tests/test_first_light.py gains the case with neither folder behind the link (symlink and junction): it fails on the previous commit with "SystemExit not raised" and the far folder gets a dxbc; with the check the run is refused and the far folder stays empty. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@ -338,9 +338,26 @@ class RunFolderTests(unittest.TestCase):
|
||||
work, outside = self.linked(kind, "")
|
||||
with self.assertRaises(SystemExit) as refused:
|
||||
fl.reset_run_folders(str(work))
|
||||
self.assertIn(str(work / "first_light" / "dxbc"), str(refused.exception))
|
||||
self.assertIn(str(work / "first_light"), str(refused.exception))
|
||||
self.assertNotIn("\n", str(refused.exception))
|
||||
self.assertEqual(self.files(outside), ["dxbc/keep.dxbc", "keep.dxbc"])
|
||||
|
||||
def test_a_linked_first_light_with_no_run_folders_is_refused_too(self) -> None:
|
||||
# Nothing stale lies behind the link, so only the check of first_light itself can refuse it; without that
|
||||
# check the new dxbc was created in the folder the link points to, outside the work folder.
|
||||
for kind in LINK_KINDS:
|
||||
with self.subTest(kind=kind):
|
||||
work, outside = self.tmp / kind / "work", self.tmp / kind / "outside"
|
||||
outside.mkdir(parents=True)
|
||||
work.mkdir()
|
||||
if not link_folder(kind, work / "first_light", outside):
|
||||
self.skipTest(f"cannot create a {kind} here")
|
||||
with self.assertRaises(SystemExit) as refused:
|
||||
fl.reset_run_folders(str(work))
|
||||
self.assertIn(str(work / "first_light"), str(refused.exception))
|
||||
self.assertNotIn("\n", str(refused.exception))
|
||||
self.assertEqual(os.listdir(outside), [])
|
||||
|
||||
def test_a_file_that_cannot_be_removed_stops_the_run(self) -> None:
|
||||
self.prepare("first")
|
||||
held = self.staged / "first.dxbc"
|
||||
|
||||
@ -64,6 +64,15 @@ def reset_run_folders(work: str) -> str:
|
||||
"""
|
||||
base = os.path.join(work, "first_light")
|
||||
real_base = os.path.join(os.path.realpath(work), "first_light")
|
||||
# first_light itself is checked first: when it is a link to a folder with no dxbc or spirv in it, there is
|
||||
# nothing stale to judge below, and the new dxbc would be created on the far side of the link.
|
||||
if os.path.lexists(base) and (
|
||||
not os.path.isdir(base) or os.path.normcase(os.path.realpath(base)) != os.path.normcase(real_base)
|
||||
):
|
||||
raise SystemExit(
|
||||
f"{base} is a symlink, a junction or a file: each run removes and creates folders under it and does "
|
||||
"not follow a link to do it; remove it and run again"
|
||||
)
|
||||
stale = [os.path.join(base, name) for name in ("dxbc", "spirv") if os.path.lexists(os.path.join(base, name))]
|
||||
for folder in stale: # both are checked before either is removed
|
||||
real = os.path.join(real_base, os.path.basename(folder))
|
||||
|
||||
Reference in New Issue
Block a user