Skip to content

Tool: benchmark-gate compare command (#29) - #37

Merged
AamiriYouness merged 1 commit into
mainfrom
feat/compare-command
Aug 6, 2026
Merged

AamiriYouness merged 1 commit into
mainfrom
feat/compare-command

Conversation

@AamiriYouness

@AamiriYouness AamiriYouness commented Aug 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Wires BenchmarkComparisonEngine (#26) and the comparison reporters (#28)
into a real benchmark-gate compare command:

benchmark-gate compare --results --baseline [--format console|json|markdown] [--output ] [--quiet]

No --policy, no --fail-on-warning, no JUnit output, no threshold
arguments -- compare is deliberately policy-free.

Also includes a doc-only update to CheckCommand (see Design notes) and
the README/ARCHITECTURE/EXIT-CODES updates this issue's scope requires.

Design notes

  • --output is required for --format json/markdown, optional for console
    (defaults to stdout). This is a conditional argument requirement
    System.CommandLine can't express declaratively, so it's validated
    explicitly as InvalidArguments (2) before any parsing/I/O is attempted.
  • --quiet suppresses terminal output only -- an explicitly requested
    --output file is always written regardless of --quiet.
  • Console-to-file output is atomic: rendered to a StringWriter, then
    written via AtomicFileWriter, matching every other text-report reporter
    in this codebase rather than a one-off raw StreamWriter.
  • compare always returns Passed (0) on successful completion -- it has no
    severity verdict. Reuses InvalidBaselineOrPolicy (3) for baseline
    failures even though compare has no policy, per the issue's exit-code
    table.
  • CheckCommand needed no functional refactor: its orchestration already
    matched this issue's required shape as of Core: Refactor RegressionEvaluator onto ComparisonResult #27's compile-fix. This PR
    only makes that explicit in its doc comments -- flagging so this isn't
    mistaken for an omitted refactor.
  • WriteReport is internal (not private) specifically so its
    format/output/quiet matrix is unit-testable directly, independent of
    Run()'s parsing/baseline steps.

Files

  • src/BenchmarkGate.Tool/Commands/CompareCommand.cs (new)
  • src/BenchmarkGate.Tool/Commands/CheckCommand.cs (doc-only change)
  • src/BenchmarkGate.Tool/Program.cs (compare command wiring)
  • tests/BenchmarkGate.Tool.Tests/Commands/CompareCommandTests.cs (new, 18 tests)
  • tests/BenchmarkGate.Tool.Tests/Fixtures/sample-results.json (new -- real,
    trimmed BenchmarkDotNet output)
  • tests/BenchmarkGate.Tool.Tests/BenchmarkGate.Tool.Tests.csproj (fixture
    copy-to-output)
  • README.md ("Comparing without a policy" section)
  • docs/ARCHITECTURE.md (branching pipeline diagram + Compare/Check split
    paragraph)
  • docs/EXIT-CODES.md (compare added to Returned-by column; new Notes bullet)

Testing checklist

  • dotnet build passes solution-wide
  • dotnet test passes
  • Argument validation covered (invalid format, missing --output for
    json/markdown, console-without-output passes validation)
  • Full format/output/quiet matrix covered via WriteReport directly
  • Valid comparison, each --format option, added/removed benchmarks,
    and nonexistent baseline/results paths all covered end-to-end
    through Run() against the real fixture
  • CheckCommand's existing behavior unchanged (doc-only diff)

Implements #29: wires BenchmarkComparisonEngine and the #28 comparison
reporters into a real `benchmark-gate compare` command, alongside a
doc-only update to CheckCommand.

CompareCommand supports --format console|json|markdown (default console)
and --output <path>. --output is required for json/markdown (those
reporters only know how to write to a path) but optional for console
(defaults to stdout) -- a conditional requirement System.CommandLine's
per-option Required flag can't express, so it's validated explicitly as
InvalidArguments before any I/O is attempted. --quiet controls terminal
output only; it never suppresses an explicitly requested --output file.

Console-to-file output renders to a StringWriter first, then writes via
AtomicFileWriter -- matching JsonComparisonReporter/MarkdownComparisonReporter's
atomicity guarantee (and MarkdownReporter/JunitReporter's established
pattern for a text-rendered report), not a one-off raw StreamWriter that
could leave a partially-written file on a mid-write failure.

compare always exits Passed (0) once it successfully produces a
comparison -- a regression, an added/removed benchmark, or a missing
metric are comparison results, not process failures. It reuses
InvalidBaselineOrPolicy (3) for a baseline load failure even though
compare has no policy, matching the issue's own exit-code table.

CheckCommand required no functional refactor for this issue -- its
orchestration (Parse -> load baseline -> load policy ->
BenchmarkComparisonEngine.Compare -> RegressionEvaluator.Evaluate ->
report -> exit code) was already the real, permanent shape as of #27's
compile-fix, not a stopgap. This commit only updates its doc comments to
state that explicitly and to mention CompareCommand shares the same
Compare step, so a reviewer doesn't assume the refactor was accidentally
omitted.

CompareCommandTests covers the full acceptance-criteria list: argument
validation (invalid format, --output required for json/markdown), the
format/output/quiet matrix (WriteReport made internal specifically for
this, tested directly against a hand-built ComparisonResult), and --
via a real trimmed BenchmarkDotNet full-report JSON fixture
(Fixtures/sample-results.json, 3 genuine benchmarks from an actual run,
not invented) parsed by the real BenchmarkDotNetResultParser -- valid
comparison, each --format option, added/removed benchmarks, and
nonexistent baseline/results paths, all through Run() end to end.
Baselines for these tests are built via the real BaselineFile.WriteCandidate
from real parsed observations, avoiding any guessing at the parser's
Identity.Job mapping or the baseline JSON schema.

README.md, docs/ARCHITECTURE.md (pipeline diagram now shows compare
branching directly off Compare, bypassing Check), and docs/EXIT-CODES.md
updated per the issue's docs scope.

Resolves #29
@AamiriYouness AamiriYouness linked an issue Aug 6, 2026 that may be closed by this pull request
4 tasks
@AamiriYouness
AamiriYouness merged commit 0f01ca9 into main Aug 6, 2026
1 check passed
@AamiriYouness
AamiriYouness deleted the feat/compare-command branch August 6, 2026 09:44
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.

Tool: benchmark-gate compare, check refactor, and docs

1 participant