Skip to content

Commit c9409fa

Browse files
Mokuroh54claude
andcommitted
test(auto-calibrate): stray files are written during the run, not planted before it
Ported from the parked fix/stray-cleanup-tests-real-calibration branch (b95680ae): the three stray-cleanup tests now have the fake subprocess write the calibration file DURING the run (new _follower_file_path helper) instead of planting it before start(). A file that exists before start() is, by construction, indistinguishable from the user's previous calibration under the same name, which the cleanup's design deliberately preserves (P0-1 / C1) — planting made the tests assert removal of something the design says to keep. b95680ae's conftest hardening is already on this branch in evolved form; this test-fidelity piece was the one part left behind. Verified: tests/test_auto_calibrate.py 56 passed; pre-commit --all-files clean; real calibration tree untouched (session canary passed). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 135ec23 commit c9409fa

1 file changed

Lines changed: 39 additions & 6 deletions

File tree

tests/test_auto_calibrate.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,17 +330,36 @@ def _plant_follower_file(base: str, stem: str) -> str:
330330
return path
331331

332332

333+
def _follower_file_path(base: str, stem: str) -> str:
334+
"""Where the subprocess WOULD write, without creating it.
335+
336+
Stray-file tests must let the run itself create the file (see
337+
`_write_during_run`): a file planted before `start()` is, by construction,
338+
indistinguishable from the user's previous calibration under the same name,
339+
and the cleanup deliberately keeps those (P0-1 / C1)."""
340+
path = os.path.join(base, "so_follower", f"{stem}.json")
341+
os.makedirs(os.path.dirname(path), exist_ok=True)
342+
return path
343+
344+
333345
def test_stray_file_removed_when_run_fails_nonzero(monkeypatch: pytest.MonkeyPatch, tmp_path) -> None:
334346
"""A run that exits non-zero after the subprocess already wrote its file
335-
must not leave a phantom library entry behind."""
347+
must not leave a phantom library entry behind.
348+
349+
The file is written by the fake subprocess DURING the run (not planted
350+
before `start`), so it is genuinely this run's output — which is what makes
351+
it a stray rather than the user's previous calibration (P0-1 / C1).
352+
"""
336353
_point_robots_base_at(monkeypatch, str(tmp_path))
337-
stray = _plant_follower_file(str(tmp_path), "my_arm")
354+
stray = _follower_file_path(str(tmp_path), "my_arm")
338355

339356
class FailProc:
340357
def __init__(self) -> None:
341358
self.stdout = iter(["Stage 0: init\n"])
342359

343360
def wait(self) -> int:
361+
with open(stray, "w") as f: # the subprocess wrote it, then failed
362+
f.write("{}")
344363
return 1
345364

346365
def terminate(self) -> None:
@@ -360,15 +379,21 @@ def terminate(self) -> None:
360379
def test_stray_file_removed_when_post_processing_fails(monkeypatch: pytest.MonkeyPatch, tmp_path) -> None:
361380
"""A successful subprocess whose post-processing (_finalize_success) raises
362381
must clean up the file the subprocess wrote — the run is 'failed', so its
363-
name must not persist as a phantom entry."""
382+
name must not persist as a phantom entry.
383+
384+
As above, the fake subprocess writes the file during the run so it is this
385+
run's output rather than a pre-existing calibration.
386+
"""
364387
_point_robots_base_at(monkeypatch, str(tmp_path))
365-
stray = _plant_follower_file(str(tmp_path), "my_arm")
388+
stray = _follower_file_path(str(tmp_path), "my_arm")
366389

367390
class OkProc:
368391
def __init__(self) -> None:
369392
self.stdout = iter(["calibration done\n"])
370393

371394
def wait(self) -> int:
395+
with open(stray, "w") as f: # the subprocess succeeded and wrote it
396+
f.write("{}")
372397
return 0
373398

374399
def terminate(self) -> None:
@@ -392,14 +417,22 @@ def _boom() -> None:
392417

393418
def test_stray_file_removed_on_stop(monkeypatch: pytest.MonkeyPatch, tmp_path) -> None:
394419
"""A stopped run must leave no phantom file even if a stop landed just after
395-
the subprocess wrote it."""
420+
the subprocess wrote it.
421+
422+
The file appears AFTER `start()` — i.e. the running subprocess wrote it —
423+
which is what distinguishes it from the user's previous calibration under the
424+
same name (P0-1 / C1).
425+
"""
396426
_point_robots_base_at(monkeypatch, str(tmp_path))
397-
stray = _plant_follower_file(str(tmp_path), "my_arm")
427+
stray = _follower_file_path(str(tmp_path), "my_arm")
398428

399429
proc = StoppableFakeProc()
400430
released: list[str] = []
401431
mgr, _ = _start_with_fake_proc(monkeypatch, proc, released)
402432

433+
with open(stray, "w") as f: # written mid-run, just before the stop lands
434+
f.write("{}")
435+
403436
assert mgr.stop()["success"] is True
404437
_join_stop(mgr)
405438

0 commit comments

Comments
 (0)