mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix(debug): distinguish empty-log from missing-log in report placeholder
Copilot on #14138 flagged that the share report says '(file not found)' when the log exists but is empty (either because the primary is empty and no .1 rotation exists, or in the rare race where the file is truncated between _resolve_log_path() and stat()). - Split _primary_log_path() out of _resolve_log_path so both can share the LOG_FILES/home math without duplication. - _capture_log_snapshot now reports '(file empty)' when the primary path exists on disk with zero bytes, and keeps '(file not found)' for the truly-missing case. Tests: rename test_returns_none_for_empty → test_empty_primary_reports_file_empty with the new assertion, plus a race-path test that monkeypatches _resolve_log_path to exercise the size==0 branch directly.
This commit is contained in:
parent
3ef6992edf
commit
b641639e42
2 changed files with 36 additions and 15 deletions
|
|
@ -158,14 +158,27 @@ class TestCaptureLogSnapshot:
|
|||
assert snap.full_text is None
|
||||
assert snap.tail_text == "(file not found)"
|
||||
|
||||
def test_returns_none_for_empty(self, hermes_home):
|
||||
# Truncate agent.log to empty
|
||||
def test_empty_primary_reports_file_empty(self, hermes_home):
|
||||
"""Empty primary (no .1 fallback) surfaces as '(file empty)', not missing."""
|
||||
(hermes_home / "logs" / "agent.log").write_text("")
|
||||
|
||||
from hermes_cli.debug import _capture_log_snapshot
|
||||
snap = _capture_log_snapshot("agent", tail_lines=10)
|
||||
assert snap.full_text is None
|
||||
assert snap.tail_text == "(file not found)"
|
||||
assert snap.tail_text == "(file empty)"
|
||||
|
||||
def test_race_truncate_after_resolve_reports_empty(self, hermes_home, monkeypatch):
|
||||
"""If the log is truncated between resolve and stat, say 'empty', not 'missing'."""
|
||||
log_path = hermes_home / "logs" / "agent.log"
|
||||
from hermes_cli import debug
|
||||
|
||||
monkeypatch.setattr(debug, "_resolve_log_path", lambda _name: log_path)
|
||||
log_path.write_text("")
|
||||
|
||||
snap = debug._capture_log_snapshot("agent", tail_lines=10)
|
||||
assert snap.path == log_path
|
||||
assert snap.full_text is None
|
||||
assert snap.tail_text == "(file empty)"
|
||||
|
||||
def test_truncates_large_file(self, hermes_home):
|
||||
"""Files larger than max_bytes get tail-truncated."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue