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
10 changes: 9 additions & 1 deletion plugins/disk-cleanup/disk_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,15 @@ def guess_category(path: Path) -> Optional[str]:
}:
return None
if top == "cron" or top == "cronjobs":
return "cron-output"
# Only ``cron/output/**`` holds disposable run artifacts. The
# top level of ``cron/`` holds durable scheduler state
# (``jobs.json``, ``.tick.lock``) β€” auto-tracking those as
# ``cron-output`` makes the registry eligible for deletion
# during the next quick cleanup, which silently wipes all
# scheduled jobs (#32164).
if len(rel.parts) >= 2 and rel.parts[1] == "output":
return "cron-output"
return None
if top == "cache":
return "temp"
except ValueError:
Expand Down
41 changes: 37 additions & 4 deletions tests/plugins/test_disk_cleanup_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,47 @@ 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):
# Only ``cron/output/**`` artifacts are disposable cron-output;
# tested via a typical per-job run artifact.
dg = _load_lib()
cron_dir = _isolate_env / "cron"
cron_dir.mkdir()
p = cron_dir / "job_output.md"
output_dir = _isolate_env / "cron" / "output" / "myjob"
output_dir.mkdir(parents=True)
p = output_dir / "run.md"
p.write_text("x")
assert dg.guess_category(p) == "cron-output"

def test_cron_registry_not_classified(self, _isolate_env):
# Regression for #32164: the live scheduler registry must never
# be auto-tracked as ``cron-output`` or quick cleanup will delete
# it and Hermes will then read missing-registry as zero jobs.
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_classified(self, _isolate_env):
# ``cron/.tick.lock`` is also durable control-plane state; same
# invariant as ``jobs.json``.
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_cronjobs_registry_not_classified(self, _isolate_env):
# ``cronjobs`` is the legacy alias for the same top-level dir;
# the same registry-preservation invariant must hold.
dg = _load_lib()
cron_dir = _isolate_env / "cronjobs"
cron_dir.mkdir()
p = cron_dir / "jobs.json"
p.write_text("[]")
assert dg.guess_category(p) is None
Comment on lines +161 to +169

Comment on lines +140 to +170
def test_ordinary_file_returns_none(self, _isolate_env):
dg = _load_lib()
p = _isolate_env / "notes.md"
Expand Down
Loading