69 lines
2.4 KiB
Python
69 lines
2.4 KiB
Python
|
|
"""Tests for filing the issue an escalated incident never received."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from ariadne.services import hermes_autotriage as module
|
||
|
|
from tests.hermes_autotriage_harness import (
|
||
|
|
INCIDENT_ID,
|
||
|
|
JOB,
|
||
|
|
_build,
|
||
|
|
_prepare_code,
|
||
|
|
_seed_incident,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def _diagnosis_event(storage, incident_id: str, classification: str) -> None:
|
||
|
|
storage.record_event(
|
||
|
|
module.DIAGNOSIS_EVENT_TYPE,
|
||
|
|
{"incident_id": incident_id, "job": JOB, "outcome": {"classification": classification}},
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def test_a_deduped_escalation_files_the_issue_it_never_got(monkeypatch) -> None:
|
||
|
|
"""The job is still red; the tracker should not stay empty forever."""
|
||
|
|
|
||
|
|
env = _prepare_code(monkeypatch, last_build=_build(12, "FAILURE"))
|
||
|
|
_seed_incident(env.storage, "human_required")
|
||
|
|
_diagnosis_event(env.storage, INCIDENT_ID, "coverage_quality_gate_failure")
|
||
|
|
|
||
|
|
summary = module.run_hermes_autotriage(env.storage)["jobs"][JOB]
|
||
|
|
|
||
|
|
assert summary == {"status": "deduped", "incident_id": INCIDENT_ID}
|
||
|
|
filed = env.calls["issues"]
|
||
|
|
assert len(filed) == 1
|
||
|
|
assert filed[0]["classification"] == "coverage_quality_gate_failure"
|
||
|
|
|
||
|
|
|
||
|
|
def test_backfill_reuses_the_recorded_classification(monkeypatch) -> None:
|
||
|
|
"""A different label would miss the open issue and duplicate it."""
|
||
|
|
|
||
|
|
env = _prepare_code(monkeypatch, last_build=_build(12, "FAILURE"))
|
||
|
|
_seed_incident(env.storage, "human_required")
|
||
|
|
_diagnosis_event(env.storage, INCIDENT_ID, "pytest_test_failure")
|
||
|
|
|
||
|
|
module.run_hermes_autotriage(env.storage)
|
||
|
|
|
||
|
|
assert env.calls["issues"][0]["classification"] == "pytest_test_failure"
|
||
|
|
|
||
|
|
|
||
|
|
def test_no_recorded_classification_means_no_backfill(monkeypatch) -> None:
|
||
|
|
"""Guessing a label would duplicate rather than dedupe."""
|
||
|
|
|
||
|
|
env = _prepare_code(monkeypatch, last_build=_build(12, "FAILURE"))
|
||
|
|
_seed_incident(env.storage, "human_required")
|
||
|
|
|
||
|
|
module.run_hermes_autotriage(env.storage)
|
||
|
|
|
||
|
|
assert env.calls["issues"] == []
|
||
|
|
|
||
|
|
|
||
|
|
def test_only_human_required_incidents_are_backfilled(monkeypatch) -> None:
|
||
|
|
"""A resolved or in-flight incident needs no issue."""
|
||
|
|
|
||
|
|
for status in ("resolved", "awaiting_rebuild", "repairing"):
|
||
|
|
env = _prepare_code(monkeypatch, last_build=_build(12, "FAILURE"))
|
||
|
|
_seed_incident(env.storage, status)
|
||
|
|
_diagnosis_event(env.storage, INCIDENT_ID, "pytest_test_failure")
|
||
|
|
module.run_hermes_autotriage(env.storage)
|
||
|
|
assert env.calls["issues"] == [], status
|