mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
test: cover atomic temp cleanup on interrupts
- add regression coverage for BaseException cleanup in atomic_json_write - add dedicated atomic_yaml_write tests, including interrupt cleanup - document why BaseException is intentional in both helpers
This commit is contained in:
parent
15bf0b4af2
commit
b117bbc125
3 changed files with 64 additions and 0 deletions
4
utils.py
4
utils.py
|
|
@ -50,6 +50,8 @@ def atomic_json_write(
|
|||
os.fsync(f.fileno())
|
||||
os.replace(tmp_path, path)
|
||||
except BaseException:
|
||||
# Intentionally catch BaseException so temp-file cleanup still runs for
|
||||
# KeyboardInterrupt/SystemExit before re-raising the original signal.
|
||||
try:
|
||||
os.unlink(tmp_path)
|
||||
except OSError:
|
||||
|
|
@ -96,6 +98,8 @@ def atomic_yaml_write(
|
|||
os.fsync(f.fileno())
|
||||
os.replace(tmp_path, path)
|
||||
except BaseException:
|
||||
# Match atomic_json_write: cleanup must also happen for process-level
|
||||
# interruptions before we re-raise them.
|
||||
try:
|
||||
os.unlink(tmp_path)
|
||||
except OSError:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue