fix(awooop): make learning receipt backfill idempotent
All checks were successful
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 19s
CD Pipeline / build-and-deploy (push) Successful in 5m13s
CD Pipeline / post-deploy-checks (push) Successful in 59s
All checks were successful
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 19s
CD Pipeline / build-and-deploy (push) Successful in 5m13s
CD Pipeline / post-deploy-checks (push) Successful in 59s
This commit is contained in:
@@ -1590,12 +1590,42 @@ def test_ansible_apply_operation_row_can_backfill_auto_repair_receipt() -> None:
|
||||
assert result.duration_ms == 456
|
||||
|
||||
|
||||
def test_ansible_apply_operation_row_reconstructs_from_columns_when_input_is_sparse() -> None:
|
||||
reconstructed = _claim_from_apply_operation_row({
|
||||
"op_id": "apply-op-2",
|
||||
"parent_op_id": "check-op-2",
|
||||
"incident_id": "INC-20260629-231F8E",
|
||||
"status": "success",
|
||||
"catalog_id": "ansible:188-momo-backup-user",
|
||||
"playbook_path": "infra/ansible/playbooks/188-momo-backup-user.yml",
|
||||
"risk_level": "low",
|
||||
"input": {
|
||||
"incident_id": "INC-20260629-231F8E",
|
||||
"source_candidate_op_id": "candidate-op-2",
|
||||
"check_mode_op_id": "check-op-2",
|
||||
},
|
||||
"output": {"returncode": 0, "stdout_tail": "ok"},
|
||||
"dry_run_result": {"apply_executed": True},
|
||||
"duration_ms": 7727,
|
||||
})
|
||||
|
||||
assert reconstructed is not None
|
||||
claim, result = reconstructed
|
||||
assert claim.catalog_id == "ansible:188-momo-backup-user"
|
||||
assert claim.inventory_hosts == ("host_188",)
|
||||
assert claim.apply_playbook_path == "infra/ansible/playbooks/188-momo-backup-user.yml"
|
||||
assert claim.risk_level == "low"
|
||||
assert result.returncode == 0
|
||||
|
||||
|
||||
def test_ansible_apply_receipt_backfill_queries_existing_apply_rows() -> None:
|
||||
source = inspect.getsource(backfill_missing_auto_repair_execution_receipts_once)
|
||||
|
||||
assert "operation_type = 'ansible_apply_executed'" in source
|
||||
assert "auto_repair_executions existing" in source
|
||||
assert "executed_steps::text LIKE" in source
|
||||
assert "apply.catalog_id" in source
|
||||
assert "apply.playbook_path" in source
|
||||
|
||||
|
||||
def test_ansible_auto_repair_receipt_insert_casts_asyncpg_parameters() -> None:
|
||||
@@ -1628,6 +1658,19 @@ def test_ansible_learning_writeback_receipt_records_learning_service_call() -> N
|
||||
assert "stores_secret_values" in source
|
||||
|
||||
|
||||
def test_ansible_post_apply_km_writeback_is_idempotent_for_learning_backfill() -> None:
|
||||
from src.services.awooop_ansible_check_mode_service import (
|
||||
_record_post_apply_verifier_and_learning,
|
||||
)
|
||||
|
||||
source = inspect.getsource(_record_post_apply_verifier_and_learning)
|
||||
|
||||
assert "SELECT id" in source
|
||||
assert "FROM knowledge_entries" in source
|
||||
assert "path_type = :path_type" in source
|
||||
assert "KnowledgeDBRepository" in source
|
||||
|
||||
|
||||
def test_ansible_live_controlled_apply_sends_telegram_receipt_but_backfill_does_not() -> None:
|
||||
live_source = inspect.getsource(run_controlled_apply_for_claim)
|
||||
backfill_source = inspect.getsource(backfill_missing_auto_repair_execution_receipts_once)
|
||||
|
||||
Reference in New Issue
Block a user