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:
1 parent
27b3e81434
commit
23de1f1e34
7 files changed
+287
-89
No files matched your search
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user