fix(sre): reconcile typed backup playbooks

This commit is contained in:
Your Name
2026-07-19 01:14:21 +08:00
parent 207f00522a
commit 4944d40b10
2 changed files with 96 additions and 1 deletions

View File

@@ -71,6 +71,47 @@ def test_backup_learning_profile_is_typed_and_no_write() -> None:
assert "verified recovery" not in profile["km_title"]
def test_existing_backup_playbook_profile_is_reconciled_idempotently() -> None:
identity = build_agent99_dispatch_identity(
project_id="awoooi",
incident_id="INC-20260719-BACKUP-PLAYBOOK",
source_fingerprint="backup-playbook-fingerprint",
route_id="agent99:backup_health:BackupCheck",
)
profile = job._learning_profile(identity, mode="BackupCheck")
playbook = SimpleNamespace(
description="legacy recovery",
symptom_pattern={"affected_services": ["cold-start-gate"]},
repair_steps=[{"action_type": "agent99_mode", "command": "Recover"}],
notes="legacy",
stateful_targets=["cold-start-gate"],
requires_pre_backup=True,
tags=["agent99", "controlled_dispatch"],
)
changed = job._reconcile_existing_playbook_profile(
playbook,
profile=profile,
mode="BackupCheck",
)
replay_changed = job._reconcile_existing_playbook_profile(
playbook,
profile=profile,
mode="BackupCheck",
)
assert changed is True
assert replay_changed is False
assert playbook.symptom_pattern["affected_services"] == ["backup_restore"]
assert playbook.repair_steps[0]["action_type"] == "agent99_readonly_check"
assert playbook.repair_steps[0]["command"] == "BackupCheck"
assert playbook.repair_steps[0]["rollback_command"] == (
"not_applicable_no_write"
)
assert "backup_restore" in playbook.tags
assert "cold-start" not in str(playbook.__dict__)
class _Context:
def __init__(self, db) -> None: # type: ignore[no-untyped-def]
self.db = db