Coverage for src/governed_harness/reporting/fingerprint.py: 100%
12 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-12 16:06 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-12 16:06 +0000
1"""Stable identity of a finding across attempts and runs.
3The fingerprint ignores the finding id, the run, the line number and the time: it is the rule,
4the validator, the path and the message with whitespace collapsed and digits that look like
5line or column numbers removed. The same problem reported again in a later attempt or run gets
6the same fingerprint; a different message or file gets another one. It identifies findings in
7the review delta, in exception scopes and as SARIF ``partialFingerprints``."""
9from __future__ import annotations
11import hashlib
12import re
14from governed_harness.domain.models import Finding
16FINGERPRINT_VERSION = "harnessFinding/v1"
18_POSITIONS = re.compile(r"(?<=[:(,])\d+|\bline \d+|\bcolumn \d+", re.IGNORECASE)
21def normalized_message(message: str) -> str:
22 return " ".join(_POSITIONS.sub("#", message).split())
25def finding_fingerprint(finding: Finding) -> str:
26 path = finding.location.path if finding.location and finding.location.path else ""
27 material = "\x1f".join(
28 (finding.rule_id, finding.validator_id, path, normalized_message(finding.message))
29 )
30 return "sha256:" + hashlib.sha256(material.encode("utf-8")).hexdigest()