Skip to content

fix: Bind catalog execution deterministically and keep builder state - #2199

Merged
DaveSkender merged 1 commit into
catalog-executable-listingsfrom
catalog-executor-binding
Aug 21, 2026
Merged

DaveSkender merged 1 commit into
catalog-executable-listingsfrom
catalog-executor-binding

Conversation

@DaveSkender

Copy link
Copy Markdown
Member

Fixes #2191
Fixes #2192

Stacked on #2198. Base is catalog-executable-listings so this PR's diff shows only its own changes — both PRs touch the same overload-selection code. Retarget to main once #2198 merges.

#2191 — the builder dropped the source

ListingExecutionBuilder is copy-on-write, but WithParamValue and WithParams rebuilt it without carrying _bars:

return new ListingExecutionBuilder(BaseListing, newOverrides);   // _bars lost

Only one call order worked — parameters before source. The natural reading of a fluent API, pick the source then configure it, silently discarded the bars and threw at Execute:

System.InvalidOperationException: Bars must be set using From() before calling Execute()

docs/utilities/catalog.md presents these methods as freely chainable and says nothing about ordering. Now the source is carried through every copy, so order stops mattering.

#2192 — overload chosen by unspecified order

ListingExecutor picked by argument count alone. ToGator has two arity-one overloads — IReadOnlyList<IReusable> and IReadOnlyList<AlligatorResult> — so Type.GetMethods order decided which ran, and that order is documented as unspecified.

Worth being precise about the failure shape, because it is not the silent-wrong-value class of #2187. The AlligatorResult overload rejects bars, so an unfavourable ordering throws rather than miscomputing:

System.ArgumentException: Object of type 'List<Bar>' cannot be converted to
type 'IReadOnlyList<AlligatorResult>'

It happens to bind favourably today. Nothing guarantees it keeps doing so across runtimes, target frameworks, or builds.

The fix prefers the candidate whose parameter types actually accept the assembled arguments. Generic method definitions are exempt from the check — their parameter types are still open until the type argument is substituted further down. When a genuine tie remains, candidates are ordered by declaring type and parameter types so the outcome is at least reproducible instead of incidental.

Verification

Both tests compare catalog execution against the direct call, so they assert the right overload ran rather than merely that something ran.

Mutation-tested in both directions:

  • reverting the builder change → Bars must be set using From() before calling Execute()
  • simulating unfavourable reflection order (LastOrDefault) → the AlligatorResult conversion failure above

Quality gates:

Build:       0 Warning(s), 0 Error(s)   (--no-incremental, net10.0/net9.0/net8.0)
Unit:        Failed: 0, Passed: 2523, Skipped: 12
PublicApi:   Failed: 0, Passed: 76
Integration: Failed: 0, Passed: 4, Skipped: 1
markdownlint-cli2: 0 issues in 183 files
dotnet format --severity info: clean

Notes for review

  • No public API is added, renamed, or removed. WithParamValue/WithParams change only in what they carry forward; the ordering that already worked still works.
  • SelectByArity short-circuits when there is one candidate, which is every listing except GATOR today — so the common path is unchanged.

Two defects in the catalog execution path, both reachable from the
documented public API.

ListingExecutionBuilder is a copy-on-write fluent builder, but
WithParamValue and WithParams rebuilt it without carrying the source bars.
Only one call order worked: setting parameters before the source. The
natural reading of the API — pick the source, then configure it — dropped
the bars and threw at Execute. Carry the source through every copy so
order stops mattering.

ListingExecutor selected an overload by argument count alone. ToGator has
two arity-one overloads, one taking IReadOnlyList<IReusable> and one
taking IReadOnlyList<AlligatorResult>, so which one ran was decided by
Type.GetMethods order — documented as unspecified. The same call could
bind differently across runtimes or builds, and the AlligatorResult
overload rejects bars, so an unfavourable ordering throws. It happens to
work today; nothing guarantees it keeps working.

Prefer the candidate whose parameter types actually accept the assembled
arguments. Generic definitions are left alone, since their parameter types
are still open until the type argument is substituted. When a genuine tie
remains, order candidates by declaring type and parameter types so the
choice is reproducible rather than incidental.

Both are covered by tests that compare catalog execution against the
direct call, and both were mutation-tested: reverting the builder change
reproduces "Bars must be set using From()", and simulating an unfavourable
reflection order reproduces the AlligatorResult conversion failure.

Fixes #2191
Fixes #2192
@facioquoqa

facioquoqa Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

:neckbeard: FaciōQuōqa Mage Reviewer is standing by.

  • Trigger review

@codacy-production

codacy-production Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 13 complexity · 0 duplication

Metric Results
Complexity 13
Duplication 0

View in Codacy

🟢 Coverage 78.13% diff coverage · -0.03% coverage variation

Metric Results
Coverage variation ✅ -0.03% coverage variation (-1.00%)
Diff coverage ✅ 78.13% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (af18994) 19550 18868 96.51%
Head commit (5c2543e) 19579 (+29) 18891 (+23) 96.49% (-0.03%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#2199) 32 25 78.13%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@DaveSkender
DaveSkender merged commit c366527 into main Aug 21, 2026
7 checks passed
@DaveSkender
DaveSkender deleted the catalog-executor-binding branch August 21, 2026 18:40
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Catalog execution picks overloads by unspecified reflection order ListingExecutionBuilder discards bars when parameters are set after FromSource

1 participant