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 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

This PR checks attribute metadata before constructing method data sources.

  • Reflection discovery checks typed-source metadata before building method data sources.

Reviews (2) · 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 Dec 1, 2026

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