Problem
IncrementalCacheTests only verifies "same compilation, second run → all stages Cached/Unchanged". This proves the value-equatable model refactoring works, but does not prove the core incremental value of source generators: when one file is edited, only the contracts in that file are regenerated; other contracts remain cached.
This is the primary performance benefit of IIncrementalGenerator in large projects. Without an edit-scenario test, there is no evidence that the incremental pipeline actually works for the real-world case it was designed for.
Current state
SourceGeneratorTestContext.AssertCacheHit runs the generator twice on the same compilation object (not Clone), then checks all tracked stages are Cached/Unchanged. This is a "no-op" cache test.
The Location reference equality limitation (P1-#5) means Clone would force re-execution, so the current test avoids it. But a proper incremental edit test needs to modify a syntax tree and re-run, which is the real scenario.
What's needed
A new test method (or test class) that:
- Creates a compilation with multiple contracts in separate files (e.g., two
[RegisterStrategy] contracts: IShippingStrategy in Shipping.cs and IPaymentStrategy in Payment.cs)
- Runs the generator once (populates cache)
- Modifies one file (e.g., adds a new strategy to
Shipping.cs, leaves Payment.cs unchanged)
- Re-runs the generator with the updated compilation
- Asserts that:
- The transform stage for the modified file's contract returns
Modified (re-executed)
- The transform stage for the unmodified file's contract returns
Cached or Unchanged
- The Collect stage returns
Modified (because one input changed)
- The Combine stage returns
Modified (because Collect changed)
This requires a new helper method in SourceGeneratorTestContext that:
- Accepts an initial set of sources and a modified set of sources
- Runs the generator on the first compilation, then on the second (with
Clone + tree replacement)
- Returns the
GeneratorDriverRunResult for the second run so the test can inspect tracked step reasons
Affected files
tests/DesignPatterns.SourceGenerators.Tests/SourceGeneratorTestContext.cs — add RunIncrementalEdit helper
tests/DesignPatterns.SourceGenerators.Tests/Generators/IncrementalCacheTests.cs — add edit-scenario tests
Test scope
Start with RegisterStrategyGenerator (most representative: dual-branch Collect + Combine). If the pattern works, extend to other generators.
Module
SourceGenerators (tests)
Problem
IncrementalCacheTestsonly verifies "same compilation, second run → all stages Cached/Unchanged". This proves the value-equatable model refactoring works, but does not prove the core incremental value of source generators: when one file is edited, only the contracts in that file are regenerated; other contracts remain cached.This is the primary performance benefit of
IIncrementalGeneratorin large projects. Without an edit-scenario test, there is no evidence that the incremental pipeline actually works for the real-world case it was designed for.Current state
SourceGeneratorTestContext.AssertCacheHitruns the generator twice on the same compilation object (notClone), then checks all tracked stages areCached/Unchanged. This is a "no-op" cache test.The
Locationreference equality limitation (P1-#5) meansClonewould force re-execution, so the current test avoids it. But a proper incremental edit test needs to modify a syntax tree and re-run, which is the real scenario.What's needed
A new test method (or test class) that:
[RegisterStrategy]contracts:IShippingStrategyinShipping.csandIPaymentStrategyinPayment.cs)Shipping.cs, leavesPayment.csunchanged)Modified(re-executed)CachedorUnchangedModified(because one input changed)Modified(because Collect changed)This requires a new helper method in
SourceGeneratorTestContextthat:Clone+ tree replacement)GeneratorDriverRunResultfor the second run so the test can inspect tracked step reasonsAffected files
tests/DesignPatterns.SourceGenerators.Tests/SourceGeneratorTestContext.cs— addRunIncrementalEdithelpertests/DesignPatterns.SourceGenerators.Tests/Generators/IncrementalCacheTests.cs— add edit-scenario testsTest scope
Start with
RegisterStrategyGenerator(most representative: dual-branch Collect + Combine). If the pattern works, extend to other generators.Module
SourceGenerators (tests)