Skip to content

fix(reflection): don't construct data sources to detect typed class sources (#7671 regression) - #7911

Merged
thomhurst merged 1 commit into
mainfrom
fix/issue7671-reflection-regression
Nov 29, 2026
Merged

thomhurst merged 1 commit into
mainfrom
fix/issue7671-reflection-regression

Conversation

@thomhurst

@thomhurst thomhurst commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes the Engine tests failures on main (run 46319218712). All 5 cases of Issue7671Tests.Matching_Filter_Keeps_Constraint_Failure failed in reflection mode on Linux and Windows. Each found 0 tests where it expected 1 failed test.

Cause: #7904 changed BuildTestsFromMethodRows and the method-row inference beside class rows. Both now call ReflectionAttributeExtractor.ExtractDataSources(method) before they decide whether to skip a method, so they can check for a typed source that closes the class. That builds every data-source attribute on methods that were skipped before. In the #7671 fixture, [ThrowingSource] throws in its constructor. Its exception became a [DISCOVERY FAILED] test in place of the 'struct' constraint failure. Reading that test's attributes threw again, so it had no category or property, and the filter dropped it.

Fix: the typed-source check (DeclaresTypedClassSource) now reads attribute types from CustomAttributeData, with the same inherit: false used for methods. Data sources are built only for methods that take part in inference. InferClassTypesFromTypedMethodSource now calls a new overload that takes the attribute's type.

Validation

Summary by CodeRabbit

  • Bug Fixes
    • Improved test discovery for typed method sources, including cases where method parameters don’t include generic class parameters.

…methods don't construct data sources (#7671)

#7904 extracted a method's data sources before deciding whether the method
takes part in class type inference, so a throwing data-source constructor
replaced the generic constraint failure in reflection mode and the failed test
lost its filter attributes. Issue7671Tests.Matching_Filter_Keeps_Constraint_Failure
failed on main in reflection mode on every OS.

The typed-source check now reads attribute types from CustomAttributeData, and
data sources are constructed only for methods that are inferred from.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T23:19:54.323894Z 7d2518b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Method-row inference now checks attribute metadata for typed class sources before extracting data-source attributes. The typed-source detection helper accepts an attribute type, so these skip decisions do not require constructing data-source attributes.

Changes: Method-source inference

Layer / File(s) Summary
Typed source detection and inference
src/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs
The collector checks declared attribute types to detect typed class sources. Both method-row inference paths use this check before extracting data-source attributes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

  • thomhurst/TUnit#7671: The issue concerns throwing data-source attribute constructors during filter-attribute collection. This change avoids unnecessary construction during method-row inference.

Possibly related PRs

  • thomhurst/TUnit#7904: Both PRs change the reflection method-row inference path and its handling of data-source attributes.
Merge Risk: Minimal · up to 7d251

This change stops data-source attributes from being constructed for methods that don't take part in class type inference. That should fix the #7671 case where filtered tests were dropped in reflection mode. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the fix and its scope: reflection-mode data source handling, specifically avoiding construction of data sources when detecting typed class sources, and it references the #7671 regressi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix and its scope: reflection-mode data source handling, specifically avoiding construction of data sources when detecting typed class sources, and it references the #7671 regression. The raw summary confirms the change in ReflectionTestDataCollector.cs: typed-source declarations are now checked via attribute metadata before data-source attributes are extracted, and InferClassTypesFromTypedMethodSource gains an overload that accepts the attribute type. The objectives match this, describing the fix for the Issue7671Tests regression. The title is specific, single-sentence, and conventional. Its length (94 characters) is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each source by type,
Before its constructor enters the pipeline.
Method rows take the safer route,
Typed class sources still count.
No extra attributes spring to life,
Discovery follows metadata’s light.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1ac67e9e-bdc0-4156-abaa-93f42edd0b2b
Commits

Reviewing files that changed from the base of the PR and between 8ac3e32 and 7d2518b.

Files selected for processing: 1

  • src/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

Review

The fix looks correct and small. DeclaresTypedClassSource reads attribute types from GetCustomAttributesData(). That never constructs the attribute, so a throwing [ThrowingSource] ctor can no longer turn a skipped method into a [DISCOVERY FAILED] test. The check also uses the same inherit: false semantics as ExtractDataSources for methods. ExtractDataSources now runs only after the skip decision, in both call sites, which restores the pre-#7904 behaviour for skipped methods. InferClassTypesFromTypedMethodSource keeps its signature and delegates to the new type-based overload, so there is no duplicated base-type walk.

Non-blocking notes:

  • GetCustomAttributesData() allocates a CustomAttributeData per attribute. It runs once per candidate method during generic-class discovery, so that is acceptable. If it ever shows up in profiles, cache it per method.
  • Please add a regression test that doesn't depend on the Throwing data-source attribute constructors replace generic constraint discovery failures #7671 fixture, if that isn't already covered. It should have a generic class with a method whose data-source attribute throws in its constructor, and a skipped method with no generic parameters. It should assert that no [DISCOVERY FAILED] test appears. The current coverage depends on the Engine tests in CI, which this PR didn't run locally.
  • Attributes that implement IDataSourceAttribute through a custom subclass of a typed base are handled by the BaseType walk. A subclass that only implements the interface without deriving from the typed base still doesn't infer, but that matches the previous behaviour.

Validation in the description (both modes, 14 fixtures with identical counts) is thorough. Approving in spirit; CI on Engine tests is the remaining gate.

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · This PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

This PR checks method attribute types before constructing data sources during generic class inference.

  • Reflection checks typed source metadata before constructing method data sources.

Reviews (1) · Last reviewed commit: "fix(reflection): decide typed class sour..." · Reviewed by Greptile

@thomhurst
thomhurst enabled auto-merge (squash) November 29, 2026 23:20
@thomhurst
thomhurst merged commit b7aa601 into main Nov 29, 2026
28 checks passed
@thomhurst
thomhurst deleted the fix/issue7671-reflection-regression branch November 29, 2026 23:47
This was referenced Nov 30, 2026
github-actions Bot pushed a commit to BenjaminMichaelis/TrxLib that referenced this pull request Nov 30, 2026
Updated [TUnit](https://github.com/thomhurst/TUnit) from 1.87.12 to
1.90.0.

<details>
<summary>Release notes</summary>

_Sourced from [TUnit's
releases](https://github.com/thomhurst/TUnit/releases)._

## 1.90.0

<!-- Release notes generated using configuration in .github/release.yml
at b7aa60158f6f83fd74efb4974dfca3664dc5244c -->

## What's Changed
### Other Changes
* fix(generic): share generic inference and constructor-row binding
across source-gen, reflection and TUnit0001 by @​thomhurst in
thomhurst/TUnit#7883
* fix(engine): report missing required constructor and method arguments
consistently in both modes by @​thomhurst in
thomhurst/TUnit#7900
* feat(metadata): preserve generic array shape in TypeInfo and retire
constructor array recovery by @​thomhurst in
thomhurst/TUnit#7901
* fix(discovery): don't construct data sources when collecting generic
constraint failure filters by @​thomhurst in
thomhurst/TUnit#7902
* fix(reflection): discover internal and protected internal test methods
by @​thomhurst in thomhurst/TUnit#7898
* fix(generic): infer generic class types from member, typed and
type-free sources the same way in both modes by @​thomhurst in
thomhurst/TUnit#7904
* feat(engine): experimental adaptive [ParallelLimiter] limits, a shared
parallel budget across test processes, and child-process CPU in the
adaptive summary by @​thomhurst in
thomhurst/TUnit#7910
* fix(reflection): don't construct data sources to detect typed class
sources (#​7671 regression) by @​thomhurst in
thomhurst/TUnit#7911


**Full Changelog**:
thomhurst/TUnit@v1.88.3...v1.90.0

<!-- tunit-release-draft -->

## 1.88.3

<!-- Release notes generated using configuration in .github/release.yml
at 596354246a5059d42005f45787f2ebad4b4ad4cb -->

## What's Changed
### Other Changes
* fix(engine): hold the adaptive limit when other processes saturate the
CPUs by @​thomhurst in thomhurst/TUnit#7895
### Dependencies
* chore(deps): update all non-major dependencies to 1.88.2 by
@​thomhurst in thomhurst/TUnit#7897


**Full Changelog**:
thomhurst/TUnit@v1.88.2...v1.88.3

<!-- tunit-release-draft -->

## 1.88.2

<!-- Release notes generated using configuration in .github/release.yml
at 5eb1fcfb91bd5439d32c483eda3619ceffbb3dd7 -->

## What's Changed
### Other Changes
* test: stabilise CI tests that fail under load or on Windows checkouts
by @​thomhurst in thomhurst/TUnit#7882
* fix(engine): stop [ParallelLimiter] waits holding parallel slots, and
settle adaptive parallelism by @​thomhurst in
thomhurst/TUnit#7888


**Full Changelog**:
thomhurst/TUnit@v1.88.1...v1.88.2

<!-- tunit-release-draft -->

## 1.88.1

<!-- Release notes generated using configuration in .github/release.yml
at 01c0862e7bc168c559ed29b3239b620dfc789372 -->

## What's Changed
### Other Changes
* fix(engine): stop adaptive parallelism raising the limit while tests
wait on a fixture by @​thomhurst in
thomhurst/TUnit#7879
* feat(html-report): pin span attributes and add an AI tab for GenAI
spans by @​thomhurst in thomhurst/TUnit#7880
### Dependencies
* chore(deps): update all non-major dependencies to 1.88.0 by
@​thomhurst in thomhurst/TUnit#7875


**Full Changelog**:
thomhurst/TUnit@v1.88.0...v1.88.1

<!-- tunit-release-draft -->

## 1.88.0

<!-- Release notes generated using configuration in .github/release.yml
at f8e0aec133d6d30cb1a9a0bdf35e14c5d81f0354 -->

## What's Changed
### Adaptive Parallelism (Experimental Opt-in)
TUnit will attempt to dynamically control parallelism based on machine
contention. This is experimental. See the docs for how to opt-in:
https://tunit.dev/docs/execution/parallelism/#adaptive-parallelism
* feat(engine): opt-in adaptive parallelism driven by machine load and
throughput by @​thomhurst in
thomhurst/TUnit#7872

### Other Changes
* Reduce TUnit.Mocks setup and call history allocations by @​thomhurst
in thomhurst/TUnit#7840
* Speed up mock setup and invocation history by @​thomhurst in
thomhurst/TUnit#7841
* fix(assertions): suppress CS8619/CS8621 for a Task<T> delegate passed
to Assert.That by @​JohnVerheij in
thomhurst/TUnit#7805
* docs: explain the Rider discovery hang on .NET Framework with
non-ASCII test names by @​IG-ABHINAV in
thomhurst/TUnit#7815
* fix(assertions): CompletesWithin reports cancellation, stops its
timer, and returns a Task<T> result again by @​JohnVerheij in
thomhurst/TUnit#7853
### Dependencies
* chore(deps): update all non-major dependencies to 1.87.12 by
@​thomhurst in thomhurst/TUnit#7833
* chore(deps): update all non-major dependencies by @​thomhurst in
thomhurst/TUnit#7835
* chore(deps): update dependency gitversion.tool to v7 by @​thomhurst in
thomhurst/TUnit#7808
* chore(deps): update all non-major dependencies to 10.0.4 by
@​thomhurst in thomhurst/TUnit#7836
* chore(deps): update dependency azure.storage.blobs to 12.30.2 by
@​thomhurst in thomhurst/TUnit#7839
* chore(deps): update all non-major dependencies to 33.7.2 by
@​thomhurst in thomhurst/TUnit#7842
* chore(deps): update dependency polyfill to v12 by @​thomhurst in
thomhurst/TUnit#7845
* chore(deps): update dependency dompurify to v3.5.0 by @​thomhurst in
thomhurst/TUnit#7846
* chore(deps): update dependency node-forge to v1.4.4 by @​thomhurst in
thomhurst/TUnit#7848
* chore(deps): update all non-major dependencies by @​thomhurst in
thomhurst/TUnit#7850
* chore(deps): update all non-major dependencies to 33.7.3 by
@​thomhurst in thomhurst/TUnit#7854
* chore(deps): update dependency serilog.sinks.seq to 9.2.0 by
@​thomhurst in thomhurst/TUnit#7855

## New Contributors
* @​IG-ABHINAV made their first contribution in
thomhurst/TUnit#7815

**Full Changelog**:
thomhurst/TUnit@v1.87.12...v1.88.0

<!-- tunit-release-draft -->

Commits viewable in [compare
view](thomhurst/TUnit@v1.87.12...v1.90.0).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=TUnit&package-manager=nuget&previous-version=1.87.12&new-version=1.90.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
Pull Requests — 7d2518b7 Deployed Nov 29, 2026 by thomhurst via modularpipeline (ubuntu-latest) #21925
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.

1 participant