Skip to content

Reporting: comparison reporters — Console, JSON, Markdown (#28) - #35

Merged
AamiriYouness merged 1 commit into
mainfrom
feat/comparison-reporters
Aug 5, 2026
Merged

AamiriYouness merged 1 commit into
mainfrom
feat/comparison-reporters

Conversation

@AamiriYouness

@AamiriYouness AamiriYouness commented Aug 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Implements the three comparison reporters for ComparisonResult: Console,
JSON, Markdown. No JUnit — a policy-free comparison has no test verdict to
encode. No Passed/Warning/Regressed/Unstable vocabulary anywhere in
any of the three, enforced by a dedicated test that greps real rendered
output, not just review.

Design notes

  • JSON schema is independent. schemaVersion = 1, separate from
    JsonDecisionReporter/JsonValidationReporter's counters. Full numeric
    precision preserved — nothing is rounded before serialization.
  • Nested { value, unit } objects, not flattened fields, for
    Reference/Candidate. Unlike JsonDecisionReporter's flat
    baseline/current fields, a unit is meaningful metadata here — flattening
    would mean dropping it or duplicating it into a parallel field.
  • Explicit enum→string mappers (switch expressions, UnreachableException
    on an unmapped value) instead of raw .ToString() for status/direction
    in JSON — a future enum rename fails the build instead of silently
    changing the shipped contract. PascalCase, matching JsonDecisionReporter's
    existing convention deliberately (casing is a project-wide JSON style
    question, not something each schema should decide independently).
  • NumberHandling.AllowNamedFloatingPointLiterals is required, not
    optional.
    ComparisonResult deliberately preserves raw NaN/Infinity for
    InvalidReferenceValue/InvalidCandidateValue metrics, and
    System.Text.Json throws on those by default. Verified with exact
    string-token assertions ("NaN", "Infinity"), not just "doesn't throw."
  • Shared ComparisonValueFormatter for Console/Markdown, honoring
    MetricValue.Unit as the source of truth (raw G17 fallback when unit
    is unknown) rather than reconstructing unit semantics from the metric
    name alone — applies to both value formatting and absolute-delta
    formatting.
  • Absolute delta is now always shown alongside percent delta. A
    zero-reference change (percent delta undefined, "n/a") no longer hides
    the fact that something real still changed.
  • No re-sorting. All three reporters preserve ComparisonResult.Benchmarks'
    given order rather than re-sorting by CanonicalString — per ADR-0004,
    canonical ordering is BenchmarkComparisonEngine's responsibility alone.
    Proven per-reporter by a dedicated order-preservation test using
    deliberately non-alphabetical input, independent of the engine's own
    ordering tests.
  • New MarkdownBuilder.CodeSpan helper — CommonMark-correct
    backtick-delimiter sizing. Needed because MarkdownBuilder.Bullet does
    no escaping and .NET reflection names generic types with a literal
    backtick (e.g. List\1) — a real, reachable case for BenchmarkIdentity.TypeName, not a hypothetical one. Replaces an unsafe manual `` {identity}` `` wrap.
  • Console and Markdown output verified against exact golden captures
    from a real local run, line-endings normalized on both sides
    (ReplaceLineEndings("\n")) for CI portability, spacing left untouched
    since alignment is the actual behavior under test. JSON intentionally
    uses structural + exact-contract assertions instead of a full-text
    golden match — serializer whitespace/property-ordering isn't itself part
    of the contract.

Files

Source (src/BenchmarkGate.Reporting/):
ComparisonValueFormatter.cs (new), ConsoleComparisonReporter.cs (new),
JsonComparisonReporter.cs (new), MarkdownComparisonReporter.cs (new),
MarkdownBuilder.cs (modified — added CodeSpan)

Tests (tests/BenchmarkGate.Reporting.Tests/):
ComparisonReportingFixtures.cs (new), ConsoleComparisonReporterTests.cs
(new), JsonComparisonReporterTests.cs (new),
MarkdownComparisonReporterTests.cs (new), MarkdownBuilderCodeSpanTests.cs
(new), ComparisonReportersVocabularyTests.cs (new)

Testing checklist

  • dotnet test passes
  • Vocabulary test passes for all three reporters (no
    Passed/Warning/Regressed/Unstable in real output)
  • Console and Markdown golden tests pass against the verified capture
  • JSON: schema version, full precision, exact NaN/Infinity string
    tokens, nested value+unit shape, omitted-vs-null field handling all
    covered
  • Order-preservation covered independently per reporter
  • CodeSpan covered directly (no backticks / one / a run / leading /
    trailing / empty) plus the identity-with-backtick integration case

Implements the three reporters for #28: ConsoleComparisonReporter,
JsonComparisonReporter, MarkdownComparisonReporter. No JUnit reporter --
a policy-free comparison has no test verdict to encode. No
Passed/Warning/Regressed/Unstable vocabulary in any of the three, enforced
by a dedicated test that greps real rendered output, not just review.

JsonComparisonReporter gets its own schemaVersion=1, independently versioned
from JsonDecisionReporter/JsonValidationReporter. Reference/Candidate are
nested {value, unit} objects rather than flattened fields, since unit is
meaningful metadata a flat schema would have to drop or duplicate. Status
and direction strings use explicit switch mappers (PascalCase, matching
JsonDecisionReporter's existing convention) rather than raw enum ToString(),
so a future enum rename fails the build instead of silently changing the
shipped contract. NumberHandling.AllowNamedFloatingPointLiterals is required,
not optional -- ComparisonResult deliberately preserves raw NaN/Infinity for
InvalidReferenceValue/InvalidCandidateValue metrics, and System.Text.Json
throws on those by default.

Console and Markdown share a new ComparisonValueFormatter, which honors
MetricValue.Unit as the source of truth (raw G17 fallback for unknown
metrics) rather than reconstructing unit semantics from the metric name
alone -- applies to both metric-value formatting and absolute-delta
formatting. Both show absolute delta alongside percent delta, so a
zero-reference change (percent delta undefined) doesn't silently disappear
from the report.

All three reporters preserve ComparisonResult.Benchmarks' given order
rather than re-sorting by CanonicalString -- per ADR-0004, canonical
ordering is BenchmarkComparisonEngine's responsibility alone. Proven by a
dedicated order-preservation test per reporter, independent of engine tests.

Adds MarkdownBuilder.CodeSpan: a CommonMark-safe backtick-delimited code
span, needed because MarkdownBuilder.Bullet does no escaping and .NET
reflection names generic types with a literal backtick (e.g. List`1) --
a real case for BenchmarkIdentity.TypeName, not hypothetical. The previous
manual `{identity}` wrap in MarkdownComparisonReporter was unsafe against
this.

Console and Markdown output verified against exact golden captures from a
real local run (ConsoleComparisonReporterTests/MarkdownComparisonReporterTests'
*_matches_the_verified_golden_capture tests), line-endings normalized on
both sides for CI portability, spacing left untouched since alignment is
the behavior under test. JSON uses structural + exact-contract assertions
instead of a full-text golden match, since serializer whitespace/ordering
is not itself the contract.

Resolves #28
@AamiriYouness AamiriYouness linked an issue Aug 5, 2026 that may be closed by this pull request
3 tasks
@AamiriYouness
AamiriYouness force-pushed the feat/comparison-reporters branch from 0c90257 to 3382a68 Compare August 5, 2026 10:12
@AamiriYouness
AamiriYouness merged commit 2da74bd into main Aug 5, 2026
1 check passed
@AamiriYouness
AamiriYouness deleted the feat/comparison-reporters branch August 5, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reporting: Comparison reporters

1 participant