Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lode/dotnet/analyzers/testing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Analyzer Testing

*Updated: 2026-11-12T13:55:10Z*
*Updated: 2026-11-16T20:16:49Z*

How a test drives an analyzer and a code fix. The harness types live in
`Microsoft.CodeAnalysis.CSharp.Testing`. The repo wrapper lives in
Expand Down Expand Up @@ -144,6 +144,22 @@ confirm the test count in the run output.
- xUnit v3 runs on the Microsoft Testing Platform. Only `scripts/test.sh`
works.

## Branch Coverage Tests

A file named `<Subject>BranchCoverageTests.cs` closes the branches that the rule
tests leave open. One file targets one analyzer, code fix provider, or helper
class. Each test asserts a reported diagnostic or a fix result.

A branch that no valid input reaches gets no test. Two examples are the
`context is null` guard in `Initialize` and a null syntax root in a fix
provider. Do not pin a production defect as expected behavior. Report it
instead.

The NuGet package `E128.Analyzers` carries two assemblies: `E128.Analyzers` and
`E128.Analyzers.CodeFixers`. Add their branch totals to get the package surface.
As of 2026-11-16, that surface covers about 87 percent of its branches. See
[Code Coverage](../code-coverage.md) for collection and the CI floors.

## Related

- [New Analyzer Checklist](new-analyzer-checklist.md): pitfalls and gates
Expand Down
40 changes: 26 additions & 14 deletions lode/infrastructure/agent-worktree-builds.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
# Agent Worktree Builds
*Updated: 2026-11-05T04:06:10Z*
*Updated: 2026-11-16T20:16:49Z*

A subagent spawned with worktree isolation lands under
`.claude/worktrees/agent-<id>/`. That worktree holds a full copy of the
repository and a branch of its own.

## Verified Behavior

These runs build clean at the same commit:

- `scripts/build.sh --project E128.Analyzers` in a nested worktree.
- `scripts/build.sh --project E128.Analyzers.Tests` in a nested worktree.
- The same two builds, run side by side in two worktrees at once.

`ArtifactsPath` resolves through `$(MSBuildThisFileDirectory)`, so each worktree
writes its own `artifacts/` directory. Concurrent builds do not share output.

## The Unreproduced Failure
A build that finds current output in `artifacts/` skips compilation and
reports success. That result does not show that the worktree compiles.

## The Nested Globalconfig Collision

One batch of five delegated agents each reported about 500 errors in files they
did not touch: CS1591, S3267, and S3358. A direct probe did not reproduce it, so
the cause stays unknown. Do not record a cause for it without a reproduction.
A forced rebuild in a nested worktree fails with phantom errors in files nobody
touched. A rebuild of `E128.Analyzers` with `-t:Rebuild` reports RS0016, CS1591,
RS0017, S3267, IDE0046, and S3358.

The SDK targets (`Microsoft.Managed.Core.targets`) add the `.globalconfig` of
every ancestor directory to `GlobalAnalyzerConfigFiles`. A nested worktree
therefore loads two files: its own and the primary checkout root file. Both set
`global_level = 100`. Roslyn drops the keys that two global configs set at the
same level. The rules that the file sets to `none` then fall back to the
blanket error severity.

Check the evaluation with
`dotnet msbuild <project> -getItem:EditorConfigFiles` and look for both root
`.globalconfig` paths.

## Dispatch Rule

Treat a phantom error report from a delegated agent as suspect. Discard its
build log and build in the primary checkout instead. The parent holds the
merged tree, and one build there costs less than five worktree builds.
Do not build or test inside a nested worktree. Treat an error report from a
worktree agent as this collision until the evaluation shows one root file.

Run delegated test writers in the primary checkout, one agent at a time,
because builds share `artifacts/`. A worktree outside the repository tree has
no ancestor root `.globalconfig`, so the collision cannot occur there. Do not
edit `global_level` or add a targets file to bypass the collision.

Give each agent write access to its own new files only. The parent edits the
shared surfaces: `src/E128.Analyzers/README.md`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using System.Threading.Tasks;
using E128.Analyzers.Performance;
using Microsoft.CodeAnalysis.Testing;
using Xunit;

namespace E128.Analyzers.Tests;

public sealed class AggressiveOptimizationBranchCoverageTests
{
private static Task VerifyFixAsync(string source, string fixedCode)
{
return CodeFixTestRunner.RunAsync<AggressiveOptimizationAnalyzer, AggressiveOptimizationCodeFixProvider>(source, fixedCode);
}

[Fact]
[Trait("Category", "CI")]
public Task Analyzer_Silent_ForOtherAttributesAndAnAttributeWithoutArguments()
{
return AnalyzerTestRunner.VerifyAsync<AggressiveOptimizationAnalyzer>(
"""
using System;
using System.Runtime.CompilerServices;
class C
{
[Obsolete("old")]
void First()
{
}

[MethodImpl]
void Second()
{
}
}
""",
options: new AnalyzerTestOptions { CompilerDiagnostics = CompilerDiagnostics.None });
}

[Fact]
[Trait("Category", "CI")]
public Task Fix_KeepsTheRightOptionWhenTheLeftOneIsRemoved()
{
return VerifyFixAsync(
"""
using System.Runtime.CompilerServices;
class C
{
[{|E128116:MethodImpl(MethodImplOptions.AggressiveOptimization | MethodImplOptions.AggressiveInlining)|}]
void M()
{
}
}
""",
"""
using System.Runtime.CompilerServices;
class C
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void M()
{
}
}
""");
}

[Fact]
[Trait("Category", "CI")]
public Task Fix_RemovesOnlyTheAttributeWhenTheListHoldsSeveral()
{
return VerifyFixAsync(
"""
using System;
using System.Runtime.CompilerServices;
class C
{
[Obsolete, {|E128116:MethodImpl(MethodImplOptions.AggressiveOptimization)|}]
void M()
{
}
}
""",
"""
using System;
using System.Runtime.CompilerServices;
class C
{
[Obsolete]
void M()
{
}
}
""");
}

[Fact]
[Trait("Category", "CI")]
public Task Fix_RemovesALaterAttributeList()
{
return VerifyFixAsync(
"""
using System;
using System.Runtime.CompilerServices;
class C
{
[Obsolete]
[{|E128116:MethodImpl(MethodImplOptions.AggressiveOptimization)|}]
void M()
{
}
}
""",
"""
using System;
using System.Runtime.CompilerServices;
class C
{
[Obsolete]
void M()
{
}
}
""");
}
}
Loading