Skip to content

Isolate nested SourceGenerator build/pack outputs in package reference tests#1096

Closed
christianhelle with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-ci-job-failure-1095
Closed

Isolate nested SourceGenerator build/pack outputs in package reference tests#1096
christianhelle with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-ci-job-failure-1095

Conversation

Copilot AI commented May 29, 2026

Copy link
Copy Markdown
Contributor

Description:

CI was intermittently failing in SourceGeneratorPackageReferenceTests when nested dotnet build/dotnet pack touched shared src/Refitter.SourceGenerator/bin and obj paths, causing GenerateDepsFile file-lock contention on Refitter.SourceGenerator.deps.json.

  • What changed

    • Updated SourceGeneratorPackageReferenceTests to create per-test workspace artifact paths:
      • build for OutputPath
      • obj for IntermediateOutputPath
      • existing packages for PackageOutputPath
    • Passed the same isolated output/intermediate paths to both nested dotnet build and dotnet pack --no-build, so pack consumes the same build artifacts without writing to shared repo outputs.
  • Scope

    • Test-only change in src/Refitter.SourceGenerator.Tests/SourceGeneratorPackageReferenceTests.cs
    • Test intent remains unchanged: verify the nupkg does not expose generator implementation dependencies and only contains intended analyzer assets.

Example OpenAPI Specifications:

Not applicable for this test infrastructure/packaging isolation change.

Example generated Refit interface

var buildOutputPath = Path.Combine(workspace, "build");
var intermediateOutputPath = Path.Combine(workspace, "obj");

BuildSourceGeneratorProject(repoRoot, projectFile, version, buildOutputPath, intermediateOutputPath);

// dotnet pack ... --no-build
$"-p:OutputPath={buildOutputPath}{Path.DirectorySeparatorChar}",
$"-p:IntermediateOutputPath={intermediateOutputPath}{Path.DirectorySeparatorChar}"
Original prompt

Apply the fix for the failing CI job on pull request #1095 in repository christianhelle/refitter.

Context:

  • The failing job shows GenerateDepsFile throwing System.IO.IOException while building src/Refitter.SourceGenerator/Refitter.SourceGenerator.csproj during test execution.
  • The failure occurs in src/Refitter.SourceGenerator.Tests/SourceGeneratorPackageReferenceTests.cs when the test launches nested dotnet build/dotnet pack commands against Refitter.SourceGenerator.csproj.
  • The likely root cause is that the test builds/packs into the shared project bin/Release and obj directories, causing file locking/contention on Refitter.SourceGenerator.deps.json in CI.

Requested change:

  • Update src/Refitter.SourceGenerator.Tests/SourceGeneratorPackageReferenceTests.cs so the nested build and pack operations use per-test isolated output/intermediate directories under the test workspace.
  • Ensure both dotnet build and dotnet pack use the same isolated OutputPath / BaseIntermediateOutputPath (or equivalent isolated artifact paths) so --no-build pack can consume the build output without touching the shared repo output directories.
  • Keep the test intent the same: validate the produced nupkg does not expose generator implementation dependencies and only ships the intended analyzer assets.
  • Make the smallest clean change needed.

Files likely involved:

  • src/Refitter.SourceGenerator.Tests/SourceGeneratorPackageReferenceTests.cs
  • Possibly inspect src/Refitter.SourceGenerator/Refitter.SourceGenerator.csproj only if needed for compatibility.

Deliverable:

  • Commit the code change on the PR branch and open/update the pull request with the fix.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: The failure is caused by a file-locking race during a nested dotnet build of Refitter.SourceGenerator inside the test run.

Root cause

The failing test launches a separate dotnet build process for the same project while the overall test/build job is already operating in the same repo output directories:

The error in the logs is:

  • GenerateDepsFile failed
  • System.IO.IOException: The process cannot access the file .../src/Refitter.SourceGenerator/bin/Release/netstandard2.0/Refitter.SourceGenerator.deps.json

That strongly indicates concurrent access to the same bin/Release/netstandard2.0 output.

Why this happens

In the workflow, tests are run after a solution build:

  • Build step: .github/workflows/build.yml:45
  • Test step: .github/workflows/build.yml:47

During the test run, SourceGeneratorPackageReferenceTests.BuildSourceGeneratorProject(...) executes:

  • dotnet build src/Refitter.SourceGenerator/Refitter.SourceGenerator.csproj -c Release ...

from SourceGeneratorPackageReferenceTests.cs:102-125.

That nested build writes to the normal project output path, which can conflict with other test host activity or multi-targeted test execution. The logs show only net10.0 fails while net8.0 passes, which is consistent with timing-sensitive file contention rather than a package-content problem.

Solution

Isolate the build and pack outputs used by the test into the test workspace instead of writing into the shared project bin/obj folders.

Recommended code change

Update BuildSourceGeneratorProject and PackSourceGeneratorPackage to set unique BaseIntermediateOutputPath, OutputPath, and PackageOutputPath under the per-test workspace.

Example patch:

private static string PackSourceGeneratorPackage(string workspace, string version)
{
    var repoRoot = GetRepositoryRoot();
    var projectFile = Path.Combine(repoRoot, "src", "Refitter.SourceGenerator", "Refitter.SourceGenerator.csproj");
    var artifactsPath = Path.Combine(workspace, "artifacts");
    var packageOutputPath = Path.Combine(workspace, "packages");
    var objPath = Path.Combine(workspace, "obj");

    Directory.CreateDirectory(artifactsPath);
    Directory.CreateDirectory(packageOutputPath);
    Directory.CreateDirectory(objPath);

    BuildSourceGeneratorProject(repoRoot, projectFile, version, artifactsPath, objPath);

    var startInfo = CreateDotNetStartInfo(
        repoRoot,
        "pack",
        ...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

Copilot AI changed the title [WIP] Fix CI job failure in SourceGenerator tests Isolate nested SourceGenerator build/pack outputs in package reference tests May 29, 2026
Copilot AI requested a review from christianhelle May 29, 2026 23:31
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.29%. Comparing base (761d93d) to head (7c364e7).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1096      +/-   ##
==========================================
- Coverage   95.90%   95.29%   -0.62%     
==========================================
  Files          27       27              
  Lines        2590     2997     +407     
==========================================
+ Hits         2484     2856     +372     
- Misses         36       45       +9     
- Partials       70       96      +26     
Flag Coverage Δ
unittests 95.29% <ø> (-0.62%) ⬇️

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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@christianhelle
christianhelle marked this pull request as ready for review May 30, 2026 06:47
Copilot AI review requested due to automatic review settings May 30, 2026 06:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the source-generator package reference tests to avoid nested build/pack operations writing to shared project output paths, reducing CI file-lock contention around package generation.

Changes:

  • Creates per-test build, intermediate, and package output directories under the test workspace.
  • Passes isolated output/intermediate paths to nested dotnet build and dotnet pack --no-build.

$"-p:PackageOutputPath={packageOutputPath}");
$"-p:PackageOutputPath={packageOutputPath}",
$"-p:OutputPath={buildOutputPath}{Path.DirectorySeparatorChar}",
$"-p:IntermediateOutputPath={intermediateOutputPath}{Path.DirectorySeparatorChar}");
$"-p:PackageVersion={version}");
$"-p:PackageVersion={version}",
$"-p:OutputPath={buildOutputPath}{Path.DirectorySeparatorChar}",
$"-p:IntermediateOutputPath={intermediateOutputPath}{Path.DirectorySeparatorChar}");
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.

3 participants