Skip to content

symfonic.diagnostics.result

result

Result and report dataclasses for symfonic doctor (v7.16, item 5).

Pure data with zero runtime dependencies. Used by every check function to communicate its findings to the runner, and by the runner to render human-readable + --json output.

AuditReport dataclass

AuditReport(results: list[CheckResult] = list())

Aggregate of every :class:CheckResult produced by one run.

The runner builds this object after invoking every check function; the CLI consumes it to render either human-readable text or --json output.

counts

counts() -> dict[str, int]

Return per-severity counts plus ok (= no findings).

Source code in src/symfonic/diagnostics/result.py
def counts(self) -> dict[str, int]:
    """Return per-severity counts plus ``ok`` (= no findings)."""
    info = sum(1 for r in self.results if r.severity is Severity.INFO)
    warn = sum(1 for r in self.results if r.severity is Severity.WARN)
    error = sum(1 for r in self.results if r.severity is Severity.ERROR)
    return {
        "ok": 1 if not self.results else 0,
        "info": info,
        "warn": warn,
        "error": error,
    }

exit_code

exit_code(*, strict: bool = False) -> int

Compute the CLI exit code.

Semantics (mypy-style):

  • No findings, or only INFO -> 0.
  • WARN present, ERROR absent -> 0 (or 2 if strict=True).
  • ERROR present -> 1.
Source code in src/symfonic/diagnostics/result.py
def exit_code(self, *, strict: bool = False) -> int:
    """Compute the CLI exit code.

    Semantics (mypy-style):

    * No findings, or only ``INFO`` -> ``0``.
    * ``WARN`` present, ``ERROR`` absent -> ``0`` (or ``2`` if
      ``strict=True``).
    * ``ERROR`` present -> ``1``.
    """
    worst = self.worst_severity()
    if worst is None or worst is Severity.INFO:
        return 0
    if worst is Severity.WARN:
        return 2 if strict else 0
    # Severity.ERROR
    return 1

to_json_dict

to_json_dict(*, strict: bool = False) -> dict[str, Any]

Serialise to the documented --json shape.

Source code in src/symfonic/diagnostics/result.py
def to_json_dict(self, *, strict: bool = False) -> dict[str, Any]:
    """Serialise to the documented ``--json`` shape."""
    return {
        "checks": [
            {
                "name": r.name,
                "severity": r.severity.value,
                "message": r.message,
                "fix_hint": r.fix_hint,
            }
            for r in self.results
        ],
        "summary": self.counts(),
        "exit_code": self.exit_code(strict=strict),
    }

worst_severity

worst_severity() -> Severity | None

Return the highest severity present, or None if clean.

Source code in src/symfonic/diagnostics/result.py
def worst_severity(self) -> Severity | None:
    """Return the highest severity present, or ``None`` if clean."""
    if not self.results:
        return None
    return max(
        (r.severity for r in self.results), key=lambda s: s.rank,
    )

CheckResult dataclass

CheckResult(
    name: str,
    severity: Severity,
    message: str,
    fix_hint: str | None = None,
)

Single audit finding emitted by a check function.

Attributes

name: Stable short identifier (e.g. "embedding_provider.stub"). Used in the JSON output and in human-readable headers. severity: :class:Severity of the finding. message: One-line human-readable summary. Rendered as the headline of the human output line. fix_hint: Optional remediation hint. Rendered on the line after the message, and surfaced in the JSON payload.