ariadne/tests/test_hermes_incident_attribution.py
codex dca283a17b fix(hermes): stop crediting a diagnosis that never happened
The hung-build path escalates without calling a model, but the issue footer
said unconditionally that the finding came "from a Hermes Agent diagnosis
(run `unknown`)". Live example: lesavka issue #3, filed for a build that
overran, attributed a direct observation to a model conclusion that was never
requested. That misrepresents where the finding came from, which matters most
in exactly the artifact a human reads first.

Attribute to Ariadne when there was no run, and carry the recorded console
text into the body so the issue says what was actually observed instead of
leaving "Why a human is needed: hung_build" as the whole explanation.

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

55 lines
2.0 KiB
Python

"""Tests that an issue attributes its finding to whoever actually made it."""
from __future__ import annotations
from ariadne.services import hermes_incident_body as body
from ariadne.services import hermes_incident_issue as module
def test_body_does_not_claim_a_diagnosis_that_never_happened() -> None:
"""A hung build is escalated without any model call.
Saying it came "from a Hermes Agent diagnosis" would misattribute a direct
observation to a model conclusion.
"""
context = module.issue_context(
{"incident_id": "metis/272", "job": "metis", "build_number": 272},
{
"bundle": {
"jenkins": {
"url": "https://ci.example/job/metis/272/",
"console_failures": [],
"console_tail": "Build metis #272 has been running for 75.0 minutes.",
}
},
"outcome": None,
"authorize_reason": "hung_build",
"run_id": None,
},
)
rendered = body.issue_body(context)
assert "No Hermes diagnosis was requested" in rendered
assert "from a Hermes Agent diagnosis" not in rendered
assert "has been running for 75.0 minutes" in rendered
def test_body_keeps_the_hermes_attribution_when_a_run_happened() -> None:
context = module.issue_context(
{"incident_id": "metis/272", "job": "metis", "build_number": 272},
{"bundle": {}, "outcome": None, "authorize_reason": "x", "run_id": "run_abc"},
)
rendered = body.issue_body(context)
assert "run `run_abc`" in rendered
assert "No Hermes diagnosis was requested" not in rendered
def test_observation_is_omitted_when_a_diagnosis_cited_facts() -> None:
"""Console text is a fallback, not a duplicate of a real diagnosis."""
jenkins = {"console_failures": [{"text": "boom"}], "console_tail": "tail text"}
assert module._observation(jenkins) == ""
assert module._observation(None) == ""
assert module._observation({"console_tail": " only tail "}) == "only tail"