Skip to content

test(generators): lock all three tracked pipeline steps in the caching regression test#183

Merged
ANcpLua merged 1 commit into
mainfrom
test/lock-tracked-step-caching
Jun 30, 2026
Merged

test(generators): lock all three tracked pipeline steps in the caching regression test#183
ANcpLua merged 1 commit into
mainfrom
test/lock-tracked-step-caching

Conversation

@ANcpLua

@ANcpLua ANcpLua commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Why

Generator_Caches_Output_When_Source_Unchanged asserted IsCached on only one of the generator's three registered tracked steps:

Tracked step (WithTrackingName) Asserted cached before After
ErrorOrContext
ResultsUnionMaxArity
EndpointBindingFlow.<attr>

ErrorOrContext is exactly the step the original incremental-caching bug regressed — it captured Compilation and compared by reference, so every compilation mutation invalidated the cache. That was fixed on 2026-04-21 (aa6cbc8, value-equatable ErrorOrContext; 9dbd497, migrate off AwaitableContext). The production fix is complete and correct — this PR just closes the test-coverage gap so a future regression of that exact step is caught directly, not only transitively through the downstream EndpointBindingFlow assertion.

Change

Three lines added to the existing test (same source, same single pipeline run — the testing framework accumulates the assertions and verifies them on result disposal):

result.IsCached("ErrorOrContext");
result.IsCached("ResultsUnionMaxArity");
result.IsCached("EndpointBindingFlow");

Running the new assertions also confirms both previously-unguarded steps are in fact cached today (no latent caching defect was hiding behind the missing coverage).

Verification — complete & verified

  • dotnet build tests/ErrorOrX.Generators.Tests -c Release0 / 0
  • Generator_Caches_Output_When_Source_Unchanged (all 3 assertions) → pass
  • Full generator suite → 156 passed, 0 failed, 0 skipped

🤖 Generated with Claude Code

…g test

Generator_Caches_Output_When_Source_Unchanged asserted caching only on the
EndpointBindingFlow step, leaving the other two registered tracked steps —
ErrorOrContext and ResultsUnionMaxArity — unguarded by name. ErrorOrContext
is precisely the step the original incremental-caching bug regressed (it
captured Compilation and compared by reference; fixed 2026-04-21 in aa6cbc8
by making it value-equatable).

Assert IsCached on all three so a future re-introduction of a
non-value-equatable cached model is caught directly at its source step, not
only transitively via the downstream EndpointBindingFlow assertion.

Verified: all three assertions pass; full generator suite 156/156 green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2b60ba50-bc49-461b-9432-c50304f53076

📥 Commits

Reviewing files that changed from the base of the PR and between a9537b4 and 593fd2f.

📒 Files selected for processing (1)
  • tests/ErrorOrX.Generators.Tests/GeneratorCachingTests.cs
📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: aot-publish
🧰 Additional context used
📓 Path-based instructions (4)
tests/ErrorOrX.Generators.Tests/**/*.cs

📄 CodeRabbit inference engine (CLAUDE.md)

Generator snapshot tests should verify the emitted code paths and diagnostics for the source generator.

tests/ErrorOrX.Generators.Tests/**/*.cs: Write snapshot tests for the ErrorOrX source generator so generated code matches the expected output.
Cover generator output scenarios for basic endpoints, parameter binding, Results<Ok<T>, NotFound<PD>, ...> generation, middleware emission, and ErrorOrJsonContext generation.
Cover analyzer diagnostics for EOE001, EOE002, EOE003-005, EOE021, and EOE034-036.
Use GeneratorTestHelper.RunGenerator(source) and await Verify(result) for generator snapshot verification.
Use GeneratorTestHelper.cs, TestCompilationHelper.cs, and SnapshotSettings.cs as the test infrastructure for generator snapshot tests.

Files:

  • tests/ErrorOrX.Generators.Tests/GeneratorCachingTests.cs
**

⚙️ CodeRabbit configuration file

**: # ErrorOrX

Source generator converting ErrorOr<T> handlers into ASP.NET Core Minimal API endpoints with full Native AOT support.

Automatic Routing (for Claude)

Always invoke /working-in-erroror skill when starting work in this repo.

Task Use
Implementation Task tool → erroror-generator-specialist
Debugging Task tool → deep-debugger
Before completion Run dotnet build + dotnet test, show output
Cross-repo work Invoke /ancplua-ecosystem first

Quick Reference

dotnet build ErrorOrX.slnx
dotnet test --solution ErrorOrX.slnx # VERIFY
dotnet pack src/ErrorOrX/ErrorOrX.csproj -c Release
dotnet pack src/ErrorOrX.Generators/ErrorOrX.Generators.csproj -c Release

Note: The # VERIFY comment bypasses the MTP smart-test-filtering hook that blocks full suite runs. Always
include it for verification runs.

What the Generator Does

Convert ErrorOr<T> handlers into fully-wired ASP.NET endpoints:

User writes:                         Generator produces:
[Get("/todos/{id:guid}")]             app.MapGet("/todos/{id:guid}", (Delegate)Invoke_Ep1)
ErrorOr<Todo> GetById(Guid id)  ->       .WithName("TodoApi_GetById")
                                         .WithMetadata(new ProducesResponseTypeMetadata(...))
                                         .RequireAuthorization("Admin")
                                         ;

                                     static async Task<Results<Ok<Todo>, ...>> Invoke_Ep1(HttpContext ctx)
                                     {
                                         return await Invoke_Ep1_Core(ctx);
                                     }

                                     static Task<Results<Ok<Todo>, ...>> Invoke_Ep1_Core(...)
                                     {
        ...

Files:

  • tests/ErrorOrX.Generators.Tests/GeneratorCachingTests.cs
tests/ErrorOrX.Generators.Tests/**

⚙️ CodeRabbit configuration file

tests/ErrorOrX.Generators.Tests/**: # ErrorOrX.Generators.Tests

Snapshot tests for the ErrorOrX source generator. Target: net10.0.

Running Tests

dotnet test --project tests/ErrorOrX.Generators.Tests
dotnet test --project tests/ErrorOrX.Generators.Tests --filter-class "*ResultsUnionTypeBuilder*"
dotnet test --project tests/ErrorOrX.Generators.Tests --filter-method "*Payload_Returns_Ok200*"

Test Categories

Generator Output Tests

Snapshot tests verify generated code matches expected output:

Test Area What It Tests
Basic endpoints Simple GET/POST/PUT/DELETE handlers
Parameter binding Route, query, body, service inference
Results union Results<Ok<T>, NotFound<PD>, ...> generation
Middleware Authorization, rate limiting, caching emission
JSON context ErrorOrJsonContext generation

Analyzer Tests

Verify diagnostics are emitted correctly:

Diagnostic Test Coverage
EOE001 Invalid return type
EOE002 Handler must be static
EOE003-005 Route validation
EOE021 Ambiguous parameter binding
EOE034-036 Validation reflection, JSON context warnings

Snapshot Testing

Uses ANcpLua.Roslyn.Utilities.Testing for generator snapshot verification:

[Fact]
public async Task Endpoint_With_Body_Generates_AcceptsMetadata()
{
    var source = """
        [Post("/todos")]
        public static ErrorOr<Todo> Create(CreateTodoRequest req) => ...
        """;

    var result = await GeneratorTestHelper.RunGenerator(source);

    await Verify(result);
}

Snapshots stored in Snapshots/ directory.

Test Infrastruc...

Files:

  • tests/ErrorOrX.Generators.Tests/GeneratorCachingTests.cs
tests/**/*.cs

⚙️ CodeRabbit configuration file

xUnit.v3 test projects using xunit.v3.mtp-v2 with AwesomeAssertions and NSubstitute. Follow Arrange-Act-Assert pattern. Use descriptive test names: MethodName_Scenario_ExpectedResult. Test async methods with async Task, not async void. Flag hardcoded test data that should come from the seeded DuckDB file (the single source of truth for demo/test data). Prefer [Theory] with [InlineData] or [MemberData] over duplicated [Fact] methods testing variations of the same behavior. Flag tests that depend on test execution order.

Files:

  • tests/ErrorOrX.Generators.Tests/GeneratorCachingTests.cs
🔇 Additional comments (1)
tests/ErrorOrX.Generators.Tests/GeneratorCachingTests.cs (1)

89-95: LGTM!


Summary by CodeRabbit

  • Tests
    • Expanded caching test coverage to verify additional steps remain cached when the source is unchanged.
    • Improved confidence that repeated runs reuse more of the generated output as expected.

Walkthrough

A single test method in GeneratorCachingTests.cs is extended with two additional cache-step assertions—ErrorOrContext and ResultsUnionMaxArity—along with explanatory comments, to verify these pipeline steps remain cached when the source is unchanged.

Changes

Generator Caching Test Coverage

Layer / File(s) Summary
Add cache assertions for unchanged source
tests/ErrorOrX.Generators.Tests/GeneratorCachingTests.cs
Adds IsCached("ErrorOrContext") and IsCached("ResultsUnionMaxArity") assertions with comments, extending the existing cached-step coverage beyond EndpointBindingFlow.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Title check ❌ Error The title matches the change, but it violates the required format: scope 'generators' is not allowed and it exceeds 72 characters. Use an allowed prefix and scope, and shorten the title to under 72 characters.
✅ Passed checks (7 passed)
Check name Status Explanation
Description check ✅ Passed The description directly explains the caching coverage gap, the added assertions, and verification, so it is clearly related.
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.
Otel Instrumentation Required ✅ Passed Only change is a test update in GeneratorCachingTests; no new DI-registered service class was added, so OTel instrumentation is not applicable.
No Unbounded Mcp Responses ✅ Passed No files under src/qyl.mcp exist or changed in this PR, so the bounded-response MCP check is not applicable.
Duckdb Backpressure On Write Paths ✅ Passed PR only adds test assertions in GeneratorCachingTests; no production DuckDB write path was introduced.
Cancellationtoken Threading ✅ Passed PR only changes tests/ErrorOrX.Generators.Tests/GeneratorCachingTests.cs; no new public async methods were added under src/.

Comment @coderabbitai help to get the list of available commands.

@ANcpLua ANcpLua merged commit 3bf88e2 into main Jun 30, 2026
5 checks passed
@ANcpLua ANcpLua deleted the test/lock-tracked-step-caching branch June 30, 2026 22:45
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.

2 participants