Repository navigation
Preserve and diagnose malformed BenchmarkDotNet parameter fragments (BGV306) - #58
Merged
Merged
Conversation
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.
8 tasks
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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
Closes #16.
BdnParameterStringParserno longer silently drops parameterfragments that don't contain
=— it now preserves both successfully parsedparameters and structured parse issues, and
ObservationValidatorreportsthose issues as a new diagnostic,
BGV306.Design notes
ParameterParseIssueKindhas two variants, not one:MissingSeparator(
N1000000) andEmptyKey(=1000000). These are distinct malformedshapes and the diagnostic message differs for each. No broader taxonomy
(e.g.
EmptyValue) is introduced until a concrete BenchmarkDotNet outputshape actually requires it.
IdentityFactory.TryCreate→Create, returningIdentityCreationResult(BenchmarkIdentity? Identity, IReadOnlyList<ParameterParseIssue> ParameterIssues)instead of a bare
BenchmarkIdentity?. This is the single call site forBdnParameterStringParser.Parse, shared byObservationValidator,ObservationSetValidator, andBenchmarkDotNetResultParser. Widening thereturn here — rather than having
ObservationValidatorcall the parser asecond time just to read issues — keeps parameter-string interpretation
happening in exactly one place. Renamed from
TryCreatesince the methodnow always succeeds in producing a result object; only
.Identityinsideit can be absent, which isn't what
TryXxxconventionally signals.BGV306isError, notWarning. The issue's correctnessinvestigation asked whether a malformed fragment could cause a false
duplicate-identity diagnostic or bad baseline matching. Confirmed: a
dropped
MissingSeparatorfragment can make a benchmark's parameter setcollapse to
{}, colliding with a genuinely parameterless benchmark ofthe same type/method/job (see
parameter-collision.jsonfixture test).Since
ValidationResult.IsValidonly blocks onError-severitydiagnostics,
BGV306neededErrorto actually prevent compilation of apotentially-corrupted identity — a
Warningwould let the collisionthrough silently.
ParametersstaysIReadOnlyDictionary<string,string>rather than theissue's suggested
List<ParsedParameter>. Duplicate-parameter-namepreservation 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—ParsereturnsParameterParseResult;adds
ParameterParseIssue,ParameterParseIssueKindIdentityFactory.cs—TryCreate→Create, returnsIdentityCreationResultObservationValidatorDiagnostics.cs— addsBGV306ObservationValidator.cs— emitsBGV306per parse issueObservationSetValidator.cs— updated toIdentityFactory.Create(...).IdentityBenchmarkDotNetResultParser.cs—CompileObservationupdated to.Create(...).IdentityBdnParameterStringParserTests.cs— new, full parser-level coverageBenchmarkDotNetResultParserTests.cs— two new integration testsFixtures/malformed-parameter.json,Fixtures/parameter-collision.json— newTesting
BdnParameterStringParserno longer silently loses malformed fragmentstrimming, duplicate keys,
=inside values, empty/trailing-comma fragments)=BGV306emitted with path/Benchmarks/{index}/Parameters(
parameter-collision.json)ObservationValidator— verified allthree callers route through
IdentityFactory.Create