The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(utils): trim atomic-write fsync coverage to the symlink case plus its control
teknium1f760dd234569
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..c58369ed31d--- /dev/null+++ b/contributors/emails/[email protected]@@ -0,0 +1 @@+xiaodu55diff --git a/tests/test_atomic_write_fsync_dir_target.py b/tests/test_atomic_write_fsync_dir_target.pyindex 8922c59978d..aeb8c87e1c4 100644--- a/tests/test_atomic_write_fsync_dir_target.py+++ b/tests/test_atomic_write_fsync_dir_target.py@@ -2,25 +2,20 @@replacement file.``atomic_replace`` resolves a symlinked destination so the write lands in the real file's-directory while the symlink survives — but the directory fsync still used the unresolved input-path's parent. A config stored as ``<state>/links/config.yaml`` → ``<state>/real/config.yaml``-then fsynced the wrong directory, leaving the rename that published the new file outside the-requested durability window (#115030).+directory while the symlink survives — but the directory fsync used the unresolved input path's+parent, so the rename that published the new file sat outside the requested durability window+(#115030). Both sides are compared through ``Path.resolve()``: on macOS the temp root is reached via+``/var`` -> ``/private/var`` and a raw comparison fails even on a correct fix."""from __future__ import annotations-import sysfrom pathlib import Pathfrom unittest.mock import patchimport pytest-# Ensure the repo root is importable when running via `pytest tests/...`.-_REPO_ROOT = Path(__file__).resolve().parent.parent-if str(_REPO_ROOT) not in sys.path:- sys.path.insert(0, str(_REPO_ROOT))--from utils import atomic_write_text, fsync_directory+import utils+from utils import atomic_write_text@pytest.mark.require_symlinks@@ -34,37 +29,21 @@ def test_fsync_dir_targets_resolved_parent_for_symlinked_destination(tmp_path: Plink = links / "value"link.symlink_to(target)- with patch.object(sys.modules["utils"], "fsync_directory") as sync:+ with patch.object(utils, "fsync_directory") as sync:atomic_write_text(link, "new", mode=0o600, fsync_dir=True)assert target.read_text(encoding="utf-8") == "new"assert link.is_symlink(), "symlink must survive the rewrite"- assert sync.call_args.args[0] == real+ assert Path(sync.call_args.args[0]).resolve() == real.resolve()def test_fsync_dir_uses_destination_parent_without_symlink(tmp_path: Path) -> None:+ """Control: a plain destination keeps today's behaviour (``atomic_replace`` returns it unchanged)."""target = tmp_path / "value"target.write_text("old", encoding="utf-8")- with patch.object(sys.modules["utils"], "fsync_directory") as sync:+ with patch.object(utils, "fsync_directory") as sync:atomic_write_text(target, "new", fsync_dir=True)assert target.read_text(encoding="utf-8") == "new"- assert sync.call_args.args[0] == tmp_path---def test_fsync_directory_is_skipped_without_the_flag(tmp_path: Path) -> None:- target = tmp_path / "value"- target.write_text("old", encoding="utf-8")-- with patch.object(sys.modules["utils"], "fsync_directory") as sync:- atomic_write_text(target, "new")-- sync.assert_not_called()---def test_real_fsync_directory_no_ops_on_windows(tmp_path: Path) -> None:- """Guards the mocked tests against drift: the real helper stays silent and safe off-POSIX."""- if sys.platform != "win32":- pytest.skip("Windows-only no-op check")- fsync_directory(tmp_path) # must not raise+ assert Path(sync.call_args.args[0]).resolve() == tmp_path.resolve()