Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion plugins/disk-cleanup/disk_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,12 @@ def guess_category(path: Path) -> Optional[str]:
}:
return None
if top == "cron" or top == "cronjobs":
return "cron-output"
# Only the per-run artefact subtree is disposable. Top-level
# files like jobs.json (the durable scheduler registry) and
# .tick.lock must never be auto-tracked for cleanup.
if len(rel.parts) >= 2 and rel.parts[1] == "output":
return "cron-output"
return None
if top == "cache":
return "temp"
except ValueError:
Expand Down
32 changes: 30 additions & 2 deletions tests/plugins/test_disk_cleanup_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,41 @@ def test_skips_protected_top_level(self, _isolate_env):
# Even though it matches test_* pattern, logs/ is excluded.
assert dg.guess_category(p) is None

def test_cron_subtree_categorised(self, _isolate_env):
def test_cron_output_subtree_categorised(self, _isolate_env):
dg = _load_lib()
run_dir = _isolate_env / "cron" / "output" / "job-123"
run_dir.mkdir(parents=True)
p = run_dir / "run.md"
p.write_text("x")
assert dg.guess_category(p) == "cron-output"

def test_cron_jobs_registry_not_categorised(self, _isolate_env):
"""Regression: ~/.hermes/cron/jobs.json is the durable scheduler
registry and must never be auto-tracked as cleanup candidate."""
dg = _load_lib()
cron_dir = _isolate_env / "cron"
cron_dir.mkdir()
p = cron_dir / "jobs.json"
p.write_text("[]")
assert dg.guess_category(p) is None

def test_cron_tick_lock_not_categorised(self, _isolate_env):
"""Regression: the scheduler's tick lock is control-plane state."""
dg = _load_lib()
cron_dir = _isolate_env / "cron"
cron_dir.mkdir()
p = cron_dir / ".tick.lock"
p.write_text("")
assert dg.guess_category(p) is None

def test_cron_top_level_file_not_categorised(self, _isolate_env):
"""Any other top-level cron/ file should also be left alone."""
dg = _load_lib()
cron_dir = _isolate_env / "cron"
cron_dir.mkdir()
p = cron_dir / "job_output.md"
p.write_text("x")
assert dg.guess_category(p) == "cron-output"
assert dg.guess_category(p) is None

def test_ordinary_file_returns_none(self, _isolate_env):
dg = _load_lib()
Expand Down
Loading