Skip to content

Fix PathTooLongException in analyzer tests Use Path.PathSeparator instead of hardcoded ';' to properly split TRUSTED_PLATFORM_ASSEMBLIES, and add validation to skip invalid paths. This prevents malformed or concatenated assembly paths from being processed, which was causing PathTooLongException during type initialization on the test runner. Fixes the failing analyzer tests: - EfQueryStandaloneMethodAnalyzerTests - EfQueryableModelTypeAnalyzerTests - #16

Merged
JayBazuzi merged 1 commit into
mainfrom
fix/path-too-long-exception-in-analyzer-tests
Aug 14, 2026

Conversation

@JayBazuzi

@JayBazuzi JayBazuzi commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Prevent analyzer tests from failing due to malformed TRUSTED_PLATFORM_ASSEMBLIES paths by making runtime reference discovery robust.

Bug Fixes:

  • Avoid PathTooLongException in analyzer test runners by ignoring invalid or non-existent assembly paths when building runtime metadata references.

Tests:

  • Harden EfQueryStandaloneMethodAnalyzerTests and EfQueryableModelTypeAnalyzerTests runtime reference setup to use platform path separator and validate assembly paths.

Use Path.PathSeparator instead of hardcoded ';' to properly split
TRUSTED_PLATFORM_ASSEMBLIES, and add validation to skip invalid paths.

This prevents malformed or concatenated assembly paths from being
processed, which was causing PathTooLongException during type
initialization on the test runner.

Fixes the failing analyzer tests:
- EfQueryStandaloneMethodAnalyzerTests
- EfQueryableModelTypeAnalyzerTests
@sourcery-ai

sourcery-ai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR hardens the analyzer test runtime reference discovery by using the platform-specific path separator for TRUSTED_PLATFORM_ASSEMBLIES and filtering out invalid or non-existent paths, preventing PathTooLongException during test initialization.

Flow diagram for updated runtime reference discovery in analyzer tests

flowchart TD
    A[AppContext.GetData TRUSTED_PLATFORM_ASSEMBLIES] --> B[Split Path.PathSeparator]
    B --> C{Filter paths}
    C -->|!string.IsNullOrWhiteSpace| D[Keep non-empty paths]
    D -->|EndsWith .dll| E[Keep .dll paths]
    E -->|File.Exists| F[Keep existing files]
    F --> G[MetadataReference.CreateFromFile]
    G --> H[Append DbContext assembly MetadataReference]
    H --> I[RuntimeReferences ImmutableArray]
Loading

File-Level Changes

Change Details Files
Make runtime metadata reference discovery robust by using platform-specific path separators and validating assembly paths before creating MetadataReference instances.
  • Replace hardcoded ';' split on TRUSTED_PLATFORM_ASSEMBLIES with Path.PathSeparator to respect OS-specific separators.
  • Add System.IO import to support path existence checks.
  • Filter out empty or whitespace entries from TRUSTED_PLATFORM_ASSEMBLIES before processing.
  • Restrict paths to those ending in .dll with case-insensitive comparison.
  • Skip any paths that do not exist on disk using File.Exists before creating metadata references.
src/ApprovalTests.EntityFramework.Analyzers.Tests/EfQueryStandaloneMethodAnalyzerTests.cs
src/ApprovalTests.EntityFramework.Analyzers.Tests/EfQueryableModelTypeAnalyzerTests.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Both test classes duplicate the same TRUSTED_PLATFORM_ASSEMBLIES parsing logic; consider extracting a shared helper to keep this logic in one place.
  • The use of the null-forgiving operator on AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES") assumes this value always exists; consider a safer fallback or assertion to handle cases where it may be null.
  • Calling File.Exists for every entry in TRUSTED_PLATFORM_ASSEMBLIES may have a performance impact; if this list is large, consider caching the filtered paths or short-circuiting earlier where possible.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Both test classes duplicate the same TRUSTED_PLATFORM_ASSEMBLIES parsing logic; consider extracting a shared helper to keep this logic in one place.
- The use of the null-forgiving operator on AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES") assumes this value always exists; consider a safer fallback or assertion to handle cases where it may be null.
- Calling File.Exists for every entry in TRUSTED_PLATFORM_ASSEMBLIES may have a performance impact; if this list is large, consider caching the filtered paths or short-circuiting earlier where possible.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@JayBazuzi
JayBazuzi merged commit 15dd57e into main Aug 14, 2026
7 checks passed
@JayBazuzi
JayBazuzi deleted the fix/path-too-long-exception-in-analyzer-tests branch August 14, 2026 10:28
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