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
7 changes: 5 additions & 2 deletions lode/dotnet/analyzers.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# .NET 10 Roslyn Analyzers
*Updated: 2026-11-13T13:54:59Z*
*Updated: 2026-11-16T16:20:12Z*

## Strategy: Deny by Default

Expand Down Expand Up @@ -33,13 +33,16 @@ In `Directory.Build.props`:
```xml
<AnalysisLevel>latest-all</AnalysisLevel>
<AnalysisMode>All</AnalysisMode>
<AnalysisModeSecurity>All</AnalysisModeSecurity>
<AnalysisModeReliability>All</AnalysisModeReliability>
<AnalysisModePerformance>All</AnalysisModePerformance>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
```

Key interactions:
- `AnalysisLevel=latest-all` and `AnalysisMode=All` both select mode `All` in every category. A compound `AnalysisLevel` wins over `AnalysisMode<Category>`, so the repo sets no category line. Do not set `AnalysisMode` below `All`, because the CA rules that are off in `Recommended` would stop running.
- `AnalysisLevel=latest-all` and `AnalysisMode=All` both select mode `All` in every category. The security, reliability, and performance category lines repeat that mode. They state the AI SDLC Readier policy explicitly. Do not set `AnalysisMode` below `All`, because the CA rules that are off in `Recommended` would stop running.
- `EnforceCodeStyleInBuild` makes IDE rules (IDE*) fire during `dotnet build`
- `TreatWarningsAsErrors` promotes all enabled warnings to errors

Expand Down
26 changes: 23 additions & 3 deletions lode/dotnet/architecture-testing.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Architecture Testing
*Updated: 2026-11-08T17:33:22Z*
*Updated: 2026-11-16T16:20:12Z*

## Overview

Expand All @@ -9,7 +9,12 @@

- `TngTech.ArchUnitNET.xUnitV3`: xUnit v3 integration (includes core and assertions). Version pinned in `Directory.Packages.props`.

The test project references only `E128.Reference.Core`. The architecture model loads the Core assembly (`typeof(Greeter).Assembly`). To analyze additional layers (Web, Cli), add both a `ProjectReference` to those projects and their assemblies to `ArchitectureBaseline`. A project carrying a `ProjectReference` without a loaded assembly is dead weight (`/prune-deps` flags it).
The test project references every production project under `src/`. Two models exist:

- `ArchitectureBaseline` loads only the Core assembly (`typeof(Greeter).Assembly`). The layer, naming, sealed, and service rules use it.
- `ProjectReferenceBaseline` loads every production assembly by name. `ProjectBoundaryTests` uses it.

A `ProjectReference` without a loaded assembly is dead weight (`/prune-deps` flags it).

## How It Works

Expand Down Expand Up @@ -66,10 +71,25 @@ Enforces dependency direction: Models depend on nothing, Services depend on Mode
- Service classes must have "Service" suffix
- Repository classes (in `Repositories` namespace) must implement `IGreetingRepository`

### Project Boundaries (`ProjectBoundaryTests`)

Each production assembly has one rule. The rule forbids a dependency on a production assembly outside the transitive `ProjectReference` closure of the project. An analyzer reference with `ReferenceOutputAssembly="false"` is not a compile reference, so it is not in the closure.

```mermaid
graph LR
CodeFixers[E128.Analyzers.CodeFixers] --> Analyzers[E128.Analyzers]
Cli[E128.Reference.Cli] --> Core[E128.Reference.Core]
Web[E128.Reference.Web] --> Core
```

The allowed graph is a literal baseline. The tests never compute it from the current graph. A new `ProjectReference` therefore fails a rule until a reviewer updates the baseline.

Coverage instrumentation injects a tracker type with one full name into each instrumented assembly. ArchUnitNET merges that type across assemblies, so the rules exclude the `Microsoft.CodeCoverage.Instrumentation.Static.Tracker` namespace. Without the exclusion, `scripts/coverage.sh` fails the boundary rules.

## Adding New Rules

1. Create a new test class in `tests/Architecture.Tests/`
2. Reference `ArchitectureBaseline.Instance`
2. Reference `ArchitectureBaseline.Instance`, or `ProjectReferenceBaseline.Instance` for a rule across assemblies
3. Define rules using `ArchRuleDefinition` fluent API
4. Tag with `[Trait("Category", "CI")]`
5. If analyzing additional assemblies, add a `ProjectReference` to the target project **and** load its assembly in `ArchitectureBaseline`
Expand Down
4 changes: 2 additions & 2 deletions lode/terminology.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Terminology
*Updated: 2026-11-12T00:54:46Z*
*Updated: 2026-11-16T16:20:12Z*

- **CPM**: Central Package Management. NuGet feature where all package versions are declared in `Directory.Packages.props` rather than per-project.
- **MTP**: Microsoft Testing Platform. The modern test execution platform used by xUnit v3, replacing the legacy vstest runner.
Expand All @@ -12,7 +12,7 @@
- **Roslyn Analyzer**: A .NET compiler extension that provides real-time code analysis and diagnostics. This project ships `E128.Analyzers`, a custom analyzer package with design, style, and file-system rules.
- **MCP**: Model Context Protocol. An open protocol that exposes tools, prompts, and resources to an AI client. This repository connects the Roslyn Navigator server over stdio. See `lode/infrastructure/roslyn-navigator-mcp.md`.
- **Roslyn Navigator**: The `cwm-roslyn-navigator` .NET tool. It loads the solution with Roslyn and answers structural code questions over MCP. See `lode/infrastructure/roslyn-navigator-mcp.md`.
- **ArchUnitNET**: Architecture testing library for .NET. Used in `tests/Architecture.Tests/` to enforce layer dependencies, naming conventions, and sealed-class policies.
- **ArchUnitNET**: Architecture testing library for .NET. Used in `tests/Architecture.Tests/` to enforce project boundaries, layer dependencies, naming conventions, and sealed-class policies.
- **Trusted Publishing**: OIDC-based NuGet publishing. The `publish.yml` workflow authenticates to NuGet via OIDC rather than long-lived API keys.
- **OIDC**: OpenID Connect. The token protocol behind Trusted Publishing. It exchanges a short-lived token for a publish credential instead of a stored API key.
- **Renovate**: Dependency management bot. Configured in `renovate.json` to group updates, auto-merge patch/minor, and flag majors for review.
Expand Down
4 changes: 4 additions & 0 deletions tests/Architecture.Tests/Architecture.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\E128.Analyzers\E128.Analyzers.csproj" />
<ProjectReference Include="..\..\src\E128.Analyzers.CodeFixers\E128.Analyzers.CodeFixers.csproj" />
<ProjectReference Include="..\..\src\E128.Reference.Cli\E128.Reference.Cli.csproj" />
<ProjectReference Include="..\..\src\E128.Reference.Core\E128.Reference.Core.csproj" />
<ProjectReference Include="..\..\src\E128.Reference.Web\E128.Reference.Web.csproj" />
</ItemGroup>

</Project>
101 changes: 101 additions & 0 deletions tests/Architecture.Tests/ProjectBoundaryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using ArchUnitNET.Fluent;
using ArchUnitNET.xUnitV3;
using Xunit;
using static ArchUnitNET.Fluent.ArchRuleDefinition;

namespace Architecture.Tests;

/// <summary>
/// Generated from the project references. A production project must not use a first-party
/// production project outside its transitive references.
/// </summary>
public sealed class ProjectBoundaryTests
{
// Coverage instrumentation injects a tracker type with one full name into every instrumented
// assembly. ArchUnitNET merges it across assemblies, so it is excluded from both sides.
private const string CoverageTrackerNamespace = "Microsoft.CodeCoverage.Instrumentation.Static.Tracker";

private static readonly ArchUnitNET.Domain.Architecture Architecture = ProjectReferenceBaseline.Instance;

[Fact]
[Trait("Category", "CI")]
public void E128_Analyzers_ShouldNotDependOn_UnreferencedProjects()
{
IArchRule rule = Types()
.That().ResideInAssembly(ProjectReferenceBaseline.Load("E128.Analyzers"))
.Should().NotDependOnAny(
Types().That().ResideInAssembly(
ProjectReferenceBaseline.Load("E128.Analyzers.CodeFixers"),
ProjectReferenceBaseline.Load("E128.Reference.Cli"),
ProjectReferenceBaseline.Load("E128.Reference.Core"),
ProjectReferenceBaseline.Load("E128.Reference.Web"))
.And().DoNotResideInNamespace(CoverageTrackerNamespace));

rule.Check(Architecture);
}

[Fact]
[Trait("Category", "CI")]
public void E128_Analyzers_CodeFixers_ShouldNotDependOn_UnreferencedProjects()
{
IArchRule rule = Types()
.That().ResideInAssembly(ProjectReferenceBaseline.Load("E128.Analyzers.CodeFixers"))
.Should().NotDependOnAny(
Types().That().ResideInAssembly(
ProjectReferenceBaseline.Load("E128.Reference.Cli"),
ProjectReferenceBaseline.Load("E128.Reference.Core"),
ProjectReferenceBaseline.Load("E128.Reference.Web"))
.And().DoNotResideInNamespace(CoverageTrackerNamespace));

rule.Check(Architecture);
}

[Fact]
[Trait("Category", "CI")]
public void E128_Reference_Cli_ShouldNotDependOn_UnreferencedProjects()
{
IArchRule rule = Types()
.That().ResideInAssembly(ProjectReferenceBaseline.Load("E128.Reference.Cli"))
.Should().NotDependOnAny(
Types().That().ResideInAssembly(
ProjectReferenceBaseline.Load("E128.Analyzers"),
ProjectReferenceBaseline.Load("E128.Analyzers.CodeFixers"),
ProjectReferenceBaseline.Load("E128.Reference.Web"))
.And().DoNotResideInNamespace(CoverageTrackerNamespace));

rule.Check(Architecture);
}

[Fact]
[Trait("Category", "CI")]
public void E128_Reference_Core_ShouldNotDependOn_UnreferencedProjects()
{
IArchRule rule = Types()
.That().ResideInAssembly(ProjectReferenceBaseline.Load("E128.Reference.Core"))
.Should().NotDependOnAny(
Types().That().ResideInAssembly(
ProjectReferenceBaseline.Load("E128.Analyzers"),
ProjectReferenceBaseline.Load("E128.Analyzers.CodeFixers"),
ProjectReferenceBaseline.Load("E128.Reference.Cli"),
ProjectReferenceBaseline.Load("E128.Reference.Web"))
.And().DoNotResideInNamespace(CoverageTrackerNamespace));

rule.Check(Architecture);
}

[Fact]
[Trait("Category", "CI")]
public void E128_Reference_Web_ShouldNotDependOn_UnreferencedProjects()
{
IArchRule rule = Types()
.That().ResideInAssembly(ProjectReferenceBaseline.Load("E128.Reference.Web"))
.Should().NotDependOnAny(
Types().That().ResideInAssembly(
ProjectReferenceBaseline.Load("E128.Analyzers"),
ProjectReferenceBaseline.Load("E128.Analyzers.CodeFixers"),
ProjectReferenceBaseline.Load("E128.Reference.Cli"))
.And().DoNotResideInNamespace(CoverageTrackerNamespace));

rule.Check(Architecture);
}
}
29 changes: 29 additions & 0 deletions tests/Architecture.Tests/ProjectReferenceBaseline.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using ArchUnitNET.Loader;

namespace Architecture.Tests;

/// <summary>
/// Loads the first-party production assemblies once per test run.
/// </summary>
internal static class ProjectReferenceBaseline
{
private static readonly ImmutableArray<string> AssemblyNames =
[
"E128.Analyzers",
"E128.Analyzers.CodeFixers",
"E128.Reference.Cli",
"E128.Reference.Core",
"E128.Reference.Web"
];

public static readonly ArchUnitNET.Domain.Architecture Instance =
new ArchLoader().LoadAssemblies([.. AssemblyNames.Select(Load)]).Build();

public static Assembly Load(string name)
{
return Assembly.Load(new AssemblyName(name));
}
}