refactor(utils): dedupe atomic JSONL write helper

Extract atomic_write_lines so history.jsonl, session JSONL saves, and
WebUI transcript rewrites share unique temp files, optional fsync, and
BaseException cleanup.

Closes #5290
This commit is contained in:
Frank_zhu authored and chengyongru committed 2026-09-23 14:48:29 +08:00
1 parent 27b3e81434
commit 23de1f1e34
7 files changed
+287 -89

No files matched your search

+6 -6
View File
@@ -66,12 +66,12 @@ class TestSaveFsync:
directory_fd = 987654
with (
manager.locked_session_files(),
patch("nanobot.session.manager.os.open", return_value=directory_fd) as open_dir,
patch("nanobot.utils.helpers.os.open", return_value=directory_fd) as open_dir,
patch(
"nanobot.session.manager.os.fsync",
"nanobot.utils.helpers.os.fsync",
side_effect=[None, OSError(errno.EINVAL, "Invalid argument")],
),
patch("nanobot.session.manager.os.close") as close_dir,
patch("nanobot.utils.helpers.os.close") as close_dir,
):
manager.save(session, fsync=True)
@@ -87,12 +87,12 @@ class TestSaveFsync:
directory_fd = 987654
with (
manager.locked_session_files(),
patch("nanobot.session.manager.os.open", return_value=directory_fd),
patch("nanobot.utils.helpers.os.open", return_value=directory_fd),
patch(
"nanobot.session.manager.os.fsync",
"nanobot.utils.helpers.os.fsync",
side_effect=[None, OSError(errno.EIO, "I/O error")],
),
patch("nanobot.session.manager.os.close") as close_dir,
patch("nanobot.utils.helpers.os.close") as close_dir,
pytest.raises(OSError, match="I/O error"),
):
manager.save(session, fsync=True)