Files
awoooi/scripts/backup/tests/test_backup_status_contract.py

36 lines
1.5 KiB
Python

from __future__ import annotations
from pathlib import Path
ROOT = Path(__file__).resolve().parents[3]
BACKUP_STATUS = ROOT / "scripts" / "backup" / "backup-status.sh"
def test_backup_status_keeps_aggregate_failure_out_of_core_blockers() -> None:
text = BACKUP_STATUS.read_text(encoding="utf-8")
assert "metric_sum_excluding_backup_all" in text
assert "component_failed_110" in text
assert "component_failed_188" in text
assert "aggregate_failed=${failed_total_110}" in text
core_line = next(line for line in text.splitlines() if line.startswith("core_blockers="))
assert "component_failed_110" in core_line
assert "component_failed_188" in core_line
assert "failed_total_110" not in core_line
assert "failed_total_188" not in core_line
def test_backup_status_uses_dynamic_healthy_over_monitored_ratio() -> None:
text = BACKUP_STATUS.read_text(encoding="utf-8")
core_line = next(line for line in text.splitlines() if line.startswith("core_blockers="))
assert 'fresh_ok_110="$(metric_count "${TEXTFILE_110}" "awoooi_backup_job_fresh" 1)"' in text
assert 'fresh_ok_188="$(metric_count "${TEXTFILE_188_TMP}" "awoooi_backup_job_fresh" 1)"' in text
assert "110備份=${fresh_ok_110}/${monitored_total_110}" in text
assert "188備份=${fresh_ok_188}/${monitored_total_188}" in text
assert "freshness_metrics_missing_110" in core_line
assert "freshness_metrics_missing_188" in core_line
assert "/13 fresh" not in text
assert "/2 fresh" not in text