diff --git a/M02_MasterTemplete/M02_MyMachine.py b/M02_MasterTemplete/M02_MyMachine.py index d09a85d72..d1b962409 100644 --- a/M02_MasterTemplete/M02_MyMachine.py +++ b/M02_MasterTemplete/M02_MyMachine.py @@ -92,8 +92,8 @@ def _move(folder: Path | None = None) -> None: for row in got.get("줄") or []: if isinstance(row, dict) and mine(row.get("키")): atomic_write_json(base / f"{row['키']}.json", row) - if not (base / NEXT).is_file(): - atomic_write_json(base / NEXT, {"다음": int(got.get("다음") or 1)}) + had = int(_load(base / NEXT).get("다음") or 1) # 옛 코드 창이 다시 쓴 옛 파일도 — 번호는 큰 쪽 + atomic_write_json(base / NEXT, {"다음": max(had, int(got.get("다음") or 1))}) old.unlink() diff --git a/resources/tester/test_826_2_machine_files.py b/resources/tester/test_826_2_machine_files.py index ae993cd8f..837b4083a 100644 --- a/resources/tester/test_826_2_machine_files.py +++ b/resources/tester/test_826_2_machine_files.py @@ -116,6 +116,8 @@ def test_my_machine_moves_once(tmp_path: Path) -> None: ] # fmt: skip assert mym._read(tmp_path) == old and mym.rows(tmp_path) == rows assert mym._read(tmp_path / "없음") == {"줄": [], "다음": 1} + (tmp_path / mym.FILE).write_text(json.dumps({"줄": [], "다음": 5}), encoding="utf-8") + assert mym._read(tmp_path)["다음"] == 11 # 옛 코드가 다시 쓴 옛 파일 — 번호 뒤로 안 감 # ④ 저장 검사 좁히기 = 옛 길과 같은 오류 ─────────────────────────────────