ariadne/tests/test_hermes_issue_backfill.py
codex c9c205484e
All checks were successful
Tests / Declarative: Post Actions passed: 1196
feat(hermes): file the issue an escalated incident never received
An incident triaged before issue filing existed, or while its repository was
unmapped, is deduped on every later tick and so never reaches the service's
tracker even though the job is still red. soteria and metis sat in exactly
that state: broken, escalated, and permanently unable to file.

The backfill reuses the classification the original diagnosis recorded, so the
existing dedupe applies unchanged - one open issue per job and classification,
refiled only if it is closed while the job still fails. Filing under a guessed
label would miss the open issue and duplicate it, which is what the dedupe
exists to prevent, so an incident with no recorded classification is skipped
rather than guessed at.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 12:30:51 -03:00

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