mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 07:03:15 +08:00
- 在 oclaw/ 下重新初始化 Git 仓库 - 补齐子仓库 .gitignore,避免提交本地运行态数据(_local、node_modules、logs 等) - 提交当前工程代码与配置 Made-with: Cursor
38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import oclaw.platform.config.paths as paths_mod
|
|
|
|
|
|
def _mkdir(p: Path) -> None:
|
|
p.mkdir(parents=True, exist_ok=True)
|
|
(p / "marker.txt").write_text("x", encoding="utf-8")
|
|
|
|
|
|
def test_pre_merge_backup_retention_default_keep_3(tmp_path, monkeypatch) -> None:
|
|
data_dir = tmp_path / "oclaw" / "data"
|
|
for ts in ("20260101_000001", "20260101_000002", "20260101_000003", "20260101_000004", "20260101_000005"):
|
|
_mkdir(data_dir / f"_pre_merge_sqlite_{ts}")
|
|
monkeypatch.setenv("OPS_ASSISTANT_PREMERGE_BACKUP_KEEP", "")
|
|
monkeypatch.setattr(paths_mod, "PROJECT_ROOT", tmp_path)
|
|
paths_mod._cleanup_pre_merge_backups()
|
|
|
|
keep = sorted(p.name for p in data_dir.glob("_pre_merge_sqlite_*") if p.is_dir())
|
|
assert keep == [
|
|
"_pre_merge_sqlite_20260101_000003",
|
|
"_pre_merge_sqlite_20260101_000004",
|
|
"_pre_merge_sqlite_20260101_000005",
|
|
]
|
|
|
|
|
|
def test_pre_merge_backup_retention_respects_env_keep(tmp_path, monkeypatch) -> None:
|
|
data_dir = tmp_path / "oclaw" / "data"
|
|
for ts in ("20260101_000001", "20260101_000002", "20260101_000003"):
|
|
_mkdir(data_dir / f"_pre_merge_sqlite_{ts}")
|
|
monkeypatch.setenv("OPS_ASSISTANT_PREMERGE_BACKUP_KEEP", "1")
|
|
monkeypatch.setattr(paths_mod, "PROJECT_ROOT", tmp_path)
|
|
paths_mod._cleanup_pre_merge_backups()
|
|
|
|
keep = sorted(p.name for p in data_dir.glob("_pre_merge_sqlite_*") if p.is_dir())
|
|
assert keep == ["_pre_merge_sqlite_20260101_000003"]
|