Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ dotnet test TUnit.Core.SourceGenerator.Tests

**Rule**: Only run TUnit.TestProject with explicit `--treenode-filter` to target specific tests or classes.

**IMPORTANT: Run filters ONE AT A TIME!** Using OR patterns (`Pattern1|Pattern2`) can match thousands of unintended tests. Always run one specific filter per command:

```bash
# ❌ WRONG - OR patterns can match too broadly
--treenode-filter "/*/*/ClassA/*|/*/*/ClassB/*"

# ✅ CORRECT - Run separate commands for each class
dotnet run -- --treenode-filter "/*/*/ClassA/*"
dotnet run -- --treenode-filter "/*/*/ClassB/*"
```

---

### Most Common Commands
Expand Down
26 changes: 24 additions & 2 deletions TUnit.Core/Discovery/ObjectGraphDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ private static void TraverseInitializerProperties(
/// Collects root-level objects (class args, method args, properties) from test details.
/// Eliminates duplicate loops in DiscoverObjectGraph and DiscoverAndTrackObjects.
/// </summary>
/// <remarks>
/// For injected properties, only DIRECT test class properties are added at depth 0.
/// Nested properties (properties of injected objects) are discovered through normal
/// graph traversal at appropriate depths (1+), ensuring correct initialization order
/// for nested IAsyncInitializer dependencies. See GitHub issue #4032.
/// </remarks>
private static void CollectRootObjects(
TestDetails testDetails,
TryAddObjectFunc tryAdd,
Expand All @@ -488,8 +494,24 @@ private static void CollectRootObjects(
// Process method arguments
ProcessRootCollection(testDetails.TestMethodArguments, tryAdd, onRootObjectAdded, cancellationToken);

// Process injected property values
ProcessRootCollection(testDetails.TestClassInjectedPropertyArguments.Values, tryAdd, onRootObjectAdded, cancellationToken);
// Process ONLY direct test class injected properties at depth 0.
// Nested properties will be discovered through normal graph traversal at depth 1+.
// This ensures proper initialization order for nested IAsyncInitializer dependencies.
// Cache keys are formatted as "{ContainingType.FullName}.{PropertyName}" (see PropertyCacheKeyGenerator).
var testClassPrefix = testDetails.ClassType.FullName + ".";
foreach (var kvp in testDetails.TestClassInjectedPropertyArguments)
{
cancellationToken.ThrowIfCancellationRequested();

// Only add properties that belong directly to the test class (not nested properties)
if (kvp.Key.StartsWith(testClassPrefix, StringComparison.Ordinal) && kvp.Value != null)
{
if (tryAdd(kvp.Value, 0))
{
onRootObjectAdded(kvp.Value);
}
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 'if' statements can be combined.

Suggested change
if (kvp.Key.StartsWith(testClassPrefix, StringComparison.Ordinal) && kvp.Value != null)
{
if (tryAdd(kvp.Value, 0))
{
onRootObjectAdded(kvp.Value);
}
if (kvp.Key.StartsWith(testClassPrefix, StringComparison.Ordinal) && kvp.Value != null && tryAdd(kvp.Value, 0))
{
onRootObjectAdded(kvp.Value);

Copilot uses AI. Check for mistakes.
}
}
}

/// <summary>
Expand Down
Loading
Loading