Skip to content

Preserve and diagnose malformed BenchmarkDotNet parameter fragments (BGV306) - #58

Merged
AamiriYouness merged 2 commits into
mainfrom
feat/preserve-malformed-parameter-fragments
Aug 17, 2026
Merged

AamiriYouness merged 2 commits into
mainfrom
feat/preserve-malformed-parameter-fragments

Conversation

@AamiriYouness

Copy link
Copy Markdown
Collaborator

Summary

Closes #16. BdnParameterStringParser no longer silently drops parameter
fragments that don't contain = — it now preserves both successfully parsed
parameters and structured parse issues, and ObservationValidator reports
those issues as a new diagnostic, BGV306.

Design notes

  • ParameterParseIssueKind has two variants, not one: MissingSeparator
    (N1000000) and EmptyKey (=1000000). These are distinct malformed
    shapes and the diagnostic message differs for each. No broader taxonomy
    (e.g. EmptyValue) is introduced until a concrete BenchmarkDotNet output
    shape actually requires it.
  • IdentityFactory.TryCreate → Create, returning
    IdentityCreationResult(BenchmarkIdentity? Identity, IReadOnlyList<ParameterParseIssue> ParameterIssues)
    instead of a bare BenchmarkIdentity?. This is the single call site for
    BdnParameterStringParser.Parse, shared by ObservationValidator,
    ObservationSetValidator, and BenchmarkDotNetResultParser. Widening the
    return here — rather than having ObservationValidator call the parser a
    second time just to read issues — keeps parameter-string interpretation
    happening in exactly one place. Renamed from TryCreate since the method
    now always succeeds in producing a result object; only .Identity inside
    it can be absent, which isn't what TryXxx conventionally signals.
  • BGV306 is Error, not Warning. The issue's correctness
    investigation asked whether a malformed fragment could cause a false
    duplicate-identity diagnostic or bad baseline matching. Confirmed: a
    dropped MissingSeparator fragment can make a benchmark's parameter set
    collapse to {}, colliding with a genuinely parameterless benchmark of
    the same type/method/job (see parameter-collision.json fixture test).
    Since ValidationResult.IsValid only blocks on Error-severity
    diagnostics, BGV306 needed Error to actually prevent compilation of a
    potentially-corrupted identity — a Warning would let the collision
    through silently.
  • Parameters stays IReadOnlyDictionary<string,string> rather than the
    issue's suggested List<ParsedParameter>. Duplicate-parameter-name
    preservation is explicitly deferred to "future diagnostics" in the issue
    text, and BenchmarkIdentity's constructor already expects a dictionary
    — switching shapes here would be out of scope for Preserve and diagnose malformed BenchmarkDotNet parameter fragments #16.

Files

  • BdnParameterStringParser.cs — Parse returns ParameterParseResult;
    adds ParameterParseIssue, ParameterParseIssueKind
  • IdentityFactory.cs — TryCreate → Create, returns IdentityCreationResult
  • ObservationValidatorDiagnostics.cs — adds BGV306
  • ObservationValidator.cs — emits BGV306 per parse issue
  • ObservationSetValidator.cs — updated to IdentityFactory.Create(...).Identity
  • BenchmarkDotNetResultParser.cs — CompileObservation updated to .Create(...).Identity
  • BdnParameterStringParserTests.cs — new, full parser-level coverage
  • BenchmarkDotNetResultParserTests.cs — two new integration tests
  • Fixtures/malformed-parameter.json, Fixtures/parameter-collision.json — new

Testing

  • BdnParameterStringParser no longer silently loses malformed fragments
  • Parsing returns both successfully parsed parameters and structured parse issues
  • Existing valid parameter parsing behavior unchanged (regression-tested:
    trimming, duplicate keys, = inside values, empty/trailing-comma fragments)
  • Focused test covers a fragment without =
  • Focused test covers mixed valid and malformed fragments
  • BGV306 emitted with path /Benchmarks/{index}/Parameters
  • Tests confirm malformed fragments can collapse canonical benchmark identity
    (parameter-collision.json)
  • No duplicate parsing logic added to ObservationValidator — verified all
    three callers route through IdentityFactory.Create
  • Full suite green after clean rebuild

BdnParameterStringParser previously discarded any parameter fragment
without an '=' with a bare `continue`, so a malformed fragment was
indistinguishable from one that never existed by the time validation
ran.

Parse now returns a ParameterParseResult(Parameters, Issues) instead
of a bare dictionary, classifying each malformed fragment as either
MissingSeparator (no '=' at all) or EmptyKey ('=' present, key empty)
via the new ParameterParseIssueKind enum.

IdentityFactory.TryCreate is renamed to Create and widened to return
IdentityCreationResult(Identity, ParameterIssues), since it's the
single call site for parameter parsing shared by ObservationValidator,
ObservationSetValidator, and BenchmarkDotNetResultParser — this keeps
parsing happening exactly once rather than letting ObservationValidator
reparse independently just to read issues.

ObservationValidator now emits BGV306 (Error) per issue at
/Benchmarks/{index}/Parameters. Fixture testing confirmed a malformed
fragment can drop a parameter entirely and collapse two distinct
benchmarks onto the same canonical identity, so BGV306 blocks
compilation via the existing ValidationResult.IsValid path rather
than being a cosmetic warning.

Resolves #16.
@AamiriYouness AamiriYouness linked an issue Aug 17, 2026 that may be closed by this pull request
8 tasks
@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.38462% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...BenchmarkDotNet/Validation/ObservationValidator.cs 76.47% 3 Missing and 1 partial ⚠️
...hmarkDotNet/Parsing/BenchmarkDotNetResultParser.cs 0.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@AamiriYouness
AamiriYouness merged commit c112d85 into main Aug 17, 2026
3 checks passed
@AamiriYouness
AamiriYouness deleted the feat/preserve-malformed-parameter-fragments branch August 17, 2026 18:16
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.

Preserve and diagnose malformed BenchmarkDotNet parameter fragments

1 participant