Skip to content

feat(tests): add scrubbers for dynamic snapshot values#273

Merged
j-d-ha merged 7 commits into
mainfrom
feature/#263-add-scrubbers-for-dynamic-snapshot-values
Dec 22, 2025
Merged

feat(tests): add scrubbers for dynamic snapshot values#273
j-d-ha merged 7 commits into
mainfrom
feature/#263-add-scrubbers-for-dynamic-snapshot-values

Conversation

@j-d-ha

@j-d-ha j-d-ha commented Dec 22, 2025

Copy link
Copy Markdown
Collaborator

🚀 Pull Request

📋 Summary

This PR implements standardized scrubbers in Verify tests to automatically normalize dynamic values that change between test runs, specifically GeneratedCodeAttribute version information and InterceptsLocation hash values.

Key Changes

  • Refactored LambdaHostOutputGenerator: Moved GeneratedCodeAttribute creation into a static property with backing field, eliminating the need to pass it through the entire generation pipeline
  • Simplified Generator Constructor: Removed version parameters from MapHandlerIncrementalGenerator constructor - version info is now handled internally via reflection
  • Added Regex-based Scrubbers: Implemented two regex scrubbers in test helpers:
    • GeneratedCodeAttributeRegex: Replaces version info in [GeneratedCode(...)] attributes
    • InterceptsLocationRegex: Replaces base64-encoded hash values in [InterceptsLocation(...)] attributes
  • Updated All Snapshots: Regenerated 94 snapshot files with scrubbed values (REPLACED for consistent verification)

Benefits

  • ✅ Reduces test fragility - snapshots no longer break when generator version changes
  • ✅ Improves snapshot stability across different build environments
  • ✅ Cleaner architecture - version handling centralized in one location
  • ✅ Less coupling - output generators no longer need version parameters

✅ Checklist

  • My changes build cleanly
  • I've added/updated relevant tests
  • I've added/updated documentation or README
  • I've followed the coding style for this project
  • I've tested the changes locally (if applicable)

🧪 Related Issues or PRs

Closes #263


💬 Notes for Reviewers

The bulk of the diff is regenerated snapshot files (94 files) with scrubbed attribute values. The core logic changes are:

  1. GeneratorTestHelpers.cs - Added scrubbing logic and regex helpers
  2. LambdaHostOutputGenerator.cs - Centralized GeneratedCodeAttribute creation
  3. MapHandlerIncrementalGenerator.cs - Removed constructor overload
  4. Various output generator files - Simplified to use centralized attribute

All tests pass with the new scrubbing approach, ensuring snapshots remain stable across builds.

…neratedCode attributes

- Introduced RegexHelper for replacing specific GeneratedCode attribute values in tests.
- Updated `GeneratorTestHelpers` to use scrubbing logic for verification snapshots.
- Adjusted existing test snapshots to align with the new scrubbing behavior.
- Introduced RegexHelper method to scrub [InterceptsLocation(...)] lines in test snapshots.
- Updated `GeneratorTestHelpers` with logic to replace InterceptsLocation attribute values.
- Enhanced snapshot verification to ensure consistency with new scrubbing behavior.
…elpers

- Updated `RegexHelper.GeneratedCodeAttributeRegex` to use a simplified pattern for GeneratedCode attributes.
- Refactored `GeneratorTestHelpers` to remove redundant generator arguments for clarity.
- Optimized test snapshot handling logic to reduce complexity.
- Adjusted `GeneratedCodeAttributeRegex` pattern to use an updated inline formatting approach.
- Changed `RegexHelper` class to be `static` for better utility alignment.
…plify usage

- Removed redundant fields and constructors for generator name and version in `MapHandlerIncrementalGenerator`.
- Moved `GeneratedCodeAttribute` logic to a single utility property in `LambdaHostOutputGenerator`.
- Updated generator outputs to reference `LambdaHostOutputGenerator.GeneratedCodeAttribute` directly.
- Simplified method signatures across output generator classes by removing unnecessary parameters.
- Added LH0005 and LH0006 to `AnalyzerReleases.Shipped.md` under version 2.1.1.
- Removed LH0001 from `AnalyzerReleases.Shipped.md` for version 2.0.0.
- Cleared `AnalyzerReleases.Unshipped.md` to reflect updates in shipped release notes.
@github-actions github-actions Bot added the type: feat New feature label Dec 22, 2025
- Updated `.claude/commands/pr.md` to include "tests" in the list of valid PR scopes.
- Modified `.github/workflows/validate-pr-title.yaml` to recognize "tests" as an allowed PR title scope.
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Dec 22, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #273      +/-   ##
==========================================
+ Coverage   88.89%   88.96%   +0.06%     
==========================================
  Files         132      132              
  Lines        3270     3252      -18     
  Branches      324      326       +2     
==========================================
- Hits         2907     2893      -14     
+ Misses        247      242       -5     
- Partials      116      117       +1     
Files with missing lines Coverage Δ
...SourceGenerators/MapHandlerIncrementalGenerator.cs 95.83% <100.00%> (+3.10%) ⬆️
...SourceGenerators/OutputGenerators/CommonSources.cs 100.00% <100.00%> (ø)
...nerators/OutputGenerators/GenericHandlerSources.cs 96.36% <100.00%> (ø)
...tors/OutputGenerators/LambdaHostOutputGenerator.cs 100.00% <100.00%> (ø)
...ceGenerators/OutputGenerators/MapHandlerSources.cs 97.95% <100.00%> (ø)
...enerators/OutputGenerators/UseMiddlewareTSource.cs 96.96% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d8b08f0...fbc8841. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@j-d-ha
j-d-ha merged commit 1b06279 into main Dec 22, 2025
8 checks passed
@j-d-ha
j-d-ha deleted the feature/#263-add-scrubbers-for-dynamic-snapshot-values branch December 22, 2025 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feat New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(verify): add scrubbers for dynamic snapshot values

1 participant