from __future__ import annotations from pathlib import Path ROOT = Path(__file__).resolve().parents[3] SCRIPT = ROOT / "scripts" / "ops" / "deploy-alertmanager-runtime-scrape.sh" def test_controlled_scrape_apply_has_check_rollback_and_independent_verifier() -> None: text = SCRIPT.read_text(encoding="utf-8") assert 'TRACE_ID="${TRACE_ID:?TRACE_ID is required}"' in text assert 'RUN_ID="${RUN_ID:?RUN_ID is required}"' in text assert 'WORK_ITEM_ID="${WORK_ITEM_ID:?WORK_ITEM_ID is required}"' in text assert "promtool check config" in text assert "writes_performed=0" in text assert "rollback_receipt" in text assert "terminal=rollback_failed ready=false" in text assert "flock -n 9" in text assert '!= "${CANDIDATE_SHA}"' in text assert '!= "${SOURCE_SHA}"' in text assert "alertmanager_notification_requests_total" in text assert "alertmanager_notification_requests_failed_total" in text assert 'receiver="awoooi-webhook"' in text assert text.count('receiver="awoooi-webhook"') >= 4 assert "two_scrapes_up" in text assert "delivery_series_count" in text def test_controlled_scrape_apply_never_replaces_the_full_live_config() -> None: text = SCRIPT.read_text(encoding="utf-8") assert "BEGIN AWOOOI ALERTMANAGER RUNTIME DELIVERY TRUTH" in text assert "job_name: 'alertmanager-runtime'" in text assert "targets: ['alertmanager:9093']" in text assert "legacy_pattern" in text assert "k8s/monitoring/prometheus.yml" not in text