Skip to content

Fix hint-name collisions in SourceGenerator when two .refitter files share a filename#1058

Closed
christianhelle with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-hint-name-collisions
Closed

Fix hint-name collisions in SourceGenerator when two .refitter files share a filename#1058
christianhelle with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-hint-name-collisions

Conversation

Copilot AI commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Description:

Two .refitter files with the same filename in different directories (e.g. src/ApiA/petstore.refitter and src/ApiB/petstore.refitter) both produced petstore.g.cs as the Roslyn hint name, causing the second context.AddSource() call to throw ArgumentException: hintName 'petstore.g.cs' was already added and crash the analyzer for the entire build/IDE session. The filename variable computed from settings.OutputFilename was also dead code — never used in the hint name.

src/Refitter.SourceGenerator/RefitterSourceGenerator.cs

  • When settings.OutputFilename is set, use it directly as the hint name (previously ignored)
  • Otherwise, disambiguate by prefixing the sanitized directory path: src_ApiA_petstore.g.cs vs src_ApiB_petstore.g.cs
  • Remove the dead filename variable

src/Refitter.Tests/SourceGeneratorFileIOTests.cs

  • Test_HintName_IsUnique_For_SameFilename_InDifferentDirectories — regression test for the collision scenario
  • Test_HintName_UsesOutputFilename_WhenSpecified — verifies OutputFilename is honored as the hint name

Example hint name disambiguation

src/ApiA/petstore.refitter  →  src_ApiA_petstore.g.cs
src/ApiB/petstore.refitter  →  src_ApiB_petstore.g.cs   ← no collision

With OutputFilename set in the .refitter file:

{
  "outputFilename": "PetstoreClient.g.cs"
}

→ hint name is PetstoreClient.g.cs (previously this value was computed but discarded)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • collector.exceptionless.io
    • Triggering command: /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/Refitter.Tests /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/Refitter.Tests (dns block)
  • config.exceptionless.io
    • Triggering command: /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/Refitter.Tests /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/Refitter.Tests (dns block)
  • developers.intellihr.io
    • Triggering command: /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/Refitter.Tests /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/Refitter.Tests (dns block)
  • heartbeat.exceptionless.io
    • Triggering command: /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/Refitter.Tests /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/Refitter.Tests (dns block)
  • http://dc.services.visualstudio.com:443/christianhelle/refitter/main/test/OpenAPI/v3.0/petstore.json
    • Triggering command: /usr/bin/dotnet dotnet build /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/f72145c88b6e4f4abfee9a141a882bf3/Project.csproj .Tests/bin/Releaowner (http block)
    • Triggering command: /usr/bin/dotnet dotnet build /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/c0d2055ae257419d9a85e36805452f8a/Project.csproj git conf�� 8e7e3244358bc65fd8b4a55fe27/Project.csproj committer.email /snap/bin/sh ect.csproj (http block)
  • http://dc.services.visualstudio.com:443/christianhelle/refitter/main/test/OpenAPI/v3.0/petstore.yaml
    • Triggering command: /usr/bin/dotnet dotnet build /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/f72145c88b6e4f4abfee9a141a882bf3/Project.csproj .Tests/bin/Releaowner (http block)
    • Triggering command: /usr/bin/dotnet dotnet build /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/c0d2055ae257419d9a85e36805452f8a/Project.csproj git conf�� 8e7e3244358bc65fd8b4a55fe27/Project.csproj committer.email /snap/bin/sh ect.csproj (http block)
  • petstore.swagger.io
    • Triggering command: /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/Refitter.Tests /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/Refitter.Tests (dns block)
  • petstore3.swagger.io
    • Triggering command: /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/Refitter.Tests /home/REDACTED/work/refitter/refitter/src/Refitter.Tests/bin/Release/net10.0/Refitter.Tests (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

…share a filename

- Replace filename-only hint name with full path-based disambiguation
- Honor settings.OutputFilename when present
- Remove dead `filename` variable
- Add regression tests for hint-name uniqueness

Agent-Logs-Url: https://github.com/christianhelle/refitter/sessions/cc94e817-e939-47bb-8be7-8bcc4353697f

Co-authored-by: christianhelle <710400+christianhelle@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI changed the title [WIP] Fix hint-name collisions for .refitter files with same filename Fix hint-name collisions in SourceGenerator when two .refitter files share a filename Apr 18, 2026
Copilot AI requested a review from christianhelle April 18, 2026 21:45
@codecov

codecov Bot commented Apr 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.18%. Comparing base (04787d9) to head (36e0a8a).
⚠️ Report is 27 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1058   +/-   ##
=======================================
  Coverage   93.18%   93.18%           
=======================================
  Files          27       27           
  Lines        1804     1804           
=======================================
  Hits         1681     1681           
  Misses         49       49           
  Partials       74       74           
Flag Coverage Δ
unittests 93.18% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

christianhelle added a commit that referenced this pull request Apr 20, 2026
Closes #1058

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

[v2.0 audit][C1] SourceGenerator: hint-name collisions when two .refitter files share a filename

2 participants