Repository navigation
Reporting: comparison reporters — Console, JSON, Markdown (#28) - #35
Merged
Merged
Conversation
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
3 tasks
AamiriYouness
force-pushed
the
feat/comparison-reporters
branch
from
August 5, 2026 10:12
0c90257 to
3382a68
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/Unstablevocabulary anywhere inany of the three, enforced by a dedicated test that greps real rendered
output, not just review.
Design notes
schemaVersion = 1, separate fromJsonDecisionReporter/JsonValidationReporter's counters. Full numericprecision preserved — nothing is rounded before serialization.
{ value, unit }objects, not flattened fields, forReference/Candidate. UnlikeJsonDecisionReporter's flatbaseline/current fields, a unit is meaningful metadata here — flattening
would mean dropping it or duplicating it into a parallel field.
UnreachableExceptionon an unmapped value) instead of raw
.ToString()forstatus/directionin JSON — a future enum rename fails the build instead of silently
changing the shipped contract. PascalCase, matching
JsonDecisionReporter'sexisting convention deliberately (casing is a project-wide JSON style
question, not something each schema should decide independently).
NumberHandling.AllowNamedFloatingPointLiteralsis required, notoptional.
ComparisonResultdeliberately preserves raw NaN/Infinity forInvalidReferenceValue/InvalidCandidateValuemetrics, andSystem.Text.Jsonthrows on those by default. Verified with exactstring-token assertions (
"NaN","Infinity"), not just "doesn't throw."ComparisonValueFormatterfor Console/Markdown, honoringMetricValue.Unitas the source of truth (rawG17fallback when unitis unknown) rather than reconstructing unit semantics from the metric
name alone — applies to both value formatting and absolute-delta
formatting.
zero-reference change (percent delta undefined,
"n/a") no longer hidesthe fact that something real still changed.
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.
MarkdownBuilder.CodeSpanhelper — CommonMark-correctbacktick-delimiter sizing. Needed because
MarkdownBuilder.Bulletdoesno escaping and .NET reflection names generic types with a literal
backtick (e.g.
List\1) — a real, reachable case forBenchmarkIdentity.TypeName, not a hypothetical one. Replaces an unsafe manual ``{identity}` `` wrap.from a real local run, line-endings normalized on both sides
(
ReplaceLineEndings("\n")) for CI portability, spacing left untouchedsince 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 — addedCodeSpan)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 testpassesPassed/Warning/Regressed/Unstablein real output)tokens, nested value+unit shape, omitted-vs-null field handling all
covered
CodeSpancovered directly (no backticks / one / a run / leading /trailing / empty) plus the identity-with-backtick integration case